Changeset 19282 in osm for applications/editors/josm/plugins/openstreetbugs/src
- Timestamp:
- 2010-01-05T15:01:09+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb
- Files:
-
- 4 added
- 10 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/ConfigKeys.java
r14816 r19282 40 40 public static final String OSB_NEW_HISTORY = "osb.new.history"; 41 41 public static final String OSB_NICKNAME = "osb.nickname"; 42 public static final String OSB_API_OFFLINE = "osb.api.offline"; 42 43 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbDownloadLoop.java
r18147 r19282 78 78 79 79 // auto download if configured 80 if( Main.pref.getBoolean(ConfigKeys.OSB_AUTO_DOWNLOAD) && 80 if( Main.pref.getBoolean(ConfigKeys.OSB_AUTO_DOWNLOAD) && !Main.pref.getBoolean(ConfigKeys.OSB_API_OFFLINE) && 81 81 plugin != null && plugin.getDialog() != null && plugin.getDialog().isDialogShowing() ) { 82 82 if(countdown < 0) { -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbLayer.java
r18595 r19282 58 58 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 59 59 import org.openstreetmap.josm.gui.layer.Layer; 60 import org.openstreetmap.josm.plugins.osb.gui. action.OsbAction;60 import org.openstreetmap.josm.plugins.osb.gui.OsbDialog; 61 61 import org.openstreetmap.josm.plugins.osb.gui.action.PopupFactory; 62 62 import org.openstreetmap.josm.tools.ColorHelper; … … 72 72 private static ImageIcon iconError = OsbPlugin.loadIcon("icon_error16.png"); 73 73 private static ImageIcon iconValid = OsbPlugin.loadIcon("icon_valid16.png"); 74 75 public OsbLayer(DataSet dataSet, String name) { 74 75 private OsbDialog dialog; 76 77 public OsbLayer(DataSet dataSet, String name, OsbDialog dialog) { 76 78 super(name); 77 79 this.data = dataSet; 80 this.dialog = dialog; 78 81 DataSet.selListeners.add(new SelectionChangedListener() { 79 82 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { … … 234 237 Node n = getNearestNode(e.getPoint()); 235 238 if(data.getNodes().contains(n)) { 236 d ata.setSelected(n);239 dialog.setSelectedNode(n); 237 240 } 238 241 } … … 252 255 if(Main.map.mapView.getActiveLayer() == this) { 253 256 Node n = getNearestNode(e.getPoint()); 254 OsbAction.setSelectedNode(n);255 257 if(data.getNodes().contains(n)) { 256 PopupFactory.createPopup(n).show(e.getComponent(), e.getX(), e.getY()); 258 PopupFactory.createPopup(n, dialog).show(e.getComponent(), e.getX(), e.getY()); 257 259 } 258 260 } … … 263 265 264 266 public void mouseExited(MouseEvent e) {} 267 268 public DataSet getDataSet() { 269 return data; 270 } 265 271 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/OsbPlugin.java
r19060 r19282 156 156 } 157 157 158 try { 159 // download the data 160 download.execute(dataSet, bounds); 161 162 // display the parsed data 163 if(!dataSet.getNodes().isEmpty() && dialog.isDialogShowing()) { 164 // if the map layer has been closed, while we are requesting the osb db, 165 // we don't have to update the gui, because the user is not interested 166 // in this area anymore 167 if(Main.map != null && Main.map.mapView != null) { 168 updateGui(); 158 // download data for the new bounds, if the plugin is not in offline mode 159 if(!Main.pref.getBoolean(ConfigKeys.OSB_API_OFFLINE)) { 160 try { 161 // download the data 162 download.execute(dataSet, bounds); 163 164 // display the parsed data 165 if(!dataSet.getNodes().isEmpty() && dialog.isDialogShowing()) { 166 // if the map layer has been closed, while we are requesting the osb db, 167 // we don't have to update the gui, because the user is not interested 168 // in this area anymore 169 if(Main.map != null && Main.map.mapView != null) { 170 updateGui(); 171 } 169 172 } 173 } catch (Exception e) { 174 JOptionPane.showMessageDialog(Main.parent, e.getMessage()); 175 e.printStackTrace(); 170 176 } 171 } catch (Exception e) {172 JOptionPane.showMessageDialog(Main.parent, e.getMessage());173 e.printStackTrace();174 177 } 175 178 } … … 188 191 private void updateLayer(DataSet osbData) { 189 192 if(layer == null) { 190 layer = new OsbLayer(osbData, "OpenStreetBugs"); 193 layer = new OsbLayer(osbData, "OpenStreetBugs", dialog); 191 194 Main.main.addLayer(layer); 192 195 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/OsbBugListCellRenderer.java
r19256 r19282 41 41 import org.openstreetmap.josm.plugins.osb.OsbPlugin; 42 42 43 public class OsbListCellRenderer implements ListCellRenderer { 43 public class OsbBugListCellRenderer implements ListCellRenderer { 44 44 45 45 private Color background = Color.WHITE; -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/OsbDialog.java
r19060 r19282 38 38 import java.awt.event.MouseListener; 39 39 import java.util.ArrayList; 40 import java.util.Collection;41 40 import java.util.Collections; 42 41 import java.util.Comparator; … … 50 49 import javax.swing.JPanel; 51 50 import javax.swing.JScrollPane; 51 import javax.swing.JTabbedPane; 52 52 import javax.swing.JToggleButton; 53 53 import javax.swing.ListSelectionModel; … … 57 57 58 58 import org.openstreetmap.josm.Main; 59 import org.openstreetmap.josm.data.SelectionChangedListener;60 59 import org.openstreetmap.josm.data.osm.DataSet; 61 60 import org.openstreetmap.josm.data.osm.Node; … … 69 68 import org.openstreetmap.josm.plugins.osb.OsbObserver; 70 69 import org.openstreetmap.josm.plugins.osb.OsbPlugin; 70 import org.openstreetmap.josm.plugins.osb.gui.action.ActionQueue; 71 71 import org.openstreetmap.josm.plugins.osb.gui.action.AddCommentAction; 72 72 import org.openstreetmap.josm.plugins.osb.gui.action.CloseIssueAction; 73 import org.openstreetmap.josm.plugins.osb.gui.action.NewIssueAction;74 73 import org.openstreetmap.josm.plugins.osb.gui.action.OsbAction; 75 74 import org.openstreetmap.josm.plugins.osb.gui.action.OsbActionObserver; 75 import org.openstreetmap.josm.plugins.osb.gui.action.PointToNewIssueAction; 76 76 import org.openstreetmap.josm.plugins.osb.gui.action.PopupFactory; 77 import org.openstreetmap.josm.plugins.osb.gui.action.ToggleConnectionModeAction; 77 78 import org.openstreetmap.josm.tools.OsmUrlToBounds; 78 79 import org.openstreetmap.josm.tools.Shortcut; … … 82 83 83 84 private static final long serialVersionUID = 1L; 84 private DefaultListModel model; 85 private JList list; 85 private JPanel bugListPanel, queuePanel; 86 private DefaultListModel bugListModel; 87 private JList bugList; 88 private JList queueList; 86 89 private OsbPlugin osbPlugin; 87 90 private boolean fireSelectionChanged = true; 88 91 private JButton refresh; 89 private JButton addComment = new JButton(new AddCommentAction()); 90 private JButton closeIssue = new JButton(new CloseIssueAction()); 92 private JButton addComment; 93 private JButton closeIssue; 94 private JButton processQueue = new JButton(tr("Process queue")); 91 95 private JToggleButton newIssue = new JToggleButton(); 92 96 private JToggleButton toggleConnectionMode; 97 private JTabbedPane tabbedPane = new JTabbedPane(); 98 private boolean queuePanelVisible = false; 99 93 100 private boolean buttonLabels = Main.pref.getBoolean(ConfigKeys.OSB_BUTTON_LABELS); 94 101 … … 100 107 101 108 osbPlugin = plugin; 102 103 model = new DefaultListModel(); 104 list = new JList(model); 105 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 106 list.addListSelectionListener(this); 107 list.addMouseListener(this); 108 list.setCellRenderer(new OsbListCellRenderer()); 109 add(new JScrollPane(list), BorderLayout.CENTER); 110 109 bugListPanel = new JPanel(new BorderLayout()); 110 bugListPanel.setName(tr("Bug list")); 111 add(bugListPanel, BorderLayout.CENTER); 112 113 bugListModel = new DefaultListModel(); 114 bugList = new JList(bugListModel); 115 bugList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 116 bugList.addListSelectionListener(this); 117 bugList.addMouseListener(this); 118 bugList.setCellRenderer(new OsbBugListCellRenderer()); 119 bugListPanel.add(new JScrollPane(bugList), BorderLayout.CENTER); 120 111 121 // create dialog buttons 112 GridLayout layout = buttonLabels ? new GridLayout( 2, 2) : new GridLayout(1,4);122 GridLayout layout = buttonLabels ? new GridLayout(3, 2) : new GridLayout(1, 5); 113 123 JPanel buttonPanel = new JPanel(layout); 114 add(buttonPanel, BorderLayout.SOUTH);115 124 refresh = new JButton(tr("Refresh")); 116 125 refresh.setToolTipText(tr("Refresh")); 117 126 refresh.setIcon(OsbPlugin.loadIcon("view-refresh22.png")); 118 127 refresh.addActionListener(new ActionListener() { 119 120 128 public void actionPerformed(ActionEvent e) { 121 129 int zoom = OsmUrlToBounds.getZoom(Main.map.mapView.getRealBounds()); … … 131 139 } 132 140 }); 133 141 bugListPanel.add(buttonPanel, BorderLayout.SOUTH); 142 Action toggleConnectionModeAction = new ToggleConnectionModeAction(this, osbPlugin); 143 toggleConnectionMode = new JToggleButton(toggleConnectionModeAction); 144 toggleConnectionMode.setToolTipText(ToggleConnectionModeAction.MSG_OFFLINE); 145 boolean offline = Main.pref.getBoolean(ConfigKeys.OSB_API_OFFLINE); 146 toggleConnectionMode.setIcon(OsbPlugin.loadIcon("online22.png")); 147 toggleConnectionMode.setSelectedIcon(OsbPlugin.loadIcon("offline22.png")); 148 if(offline) { 149 // inverse the current value and then do a click, so that 150 // we are offline and the gui represents the offline state, too 151 Main.pref.put(ConfigKeys.OSB_API_OFFLINE, false); 152 toggleConnectionMode.doClick(); 153 } 154 155 156 AddCommentAction addCommentAction = new AddCommentAction(this); 157 addComment = new JButton(addCommentAction); 134 158 addComment.setEnabled(false); 135 159 addComment.setToolTipText((String) addComment.getAction().getValue(Action.NAME)); 136 160 addComment.setIcon(OsbPlugin.loadIcon("add_comment22.png")); 161 CloseIssueAction closeIssueAction = new CloseIssueAction(this); 162 closeIssue = new JButton(closeIssueAction); 137 163 closeIssue.setEnabled(false); 138 164 closeIssue.setToolTipText((String) closeIssue.getAction().getValue(Action.NAME)); 139 165 closeIssue.setIcon(OsbPlugin.loadIcon("icon_valid22.png")); 140 NewIssueAction nia = new NewIssueAction(newIssue, osbPlugin); 166 PointToNewIssueAction nia = new PointToNewIssueAction(newIssue, osbPlugin); 141 167 newIssue.setAction(nia); 142 168 newIssue.setToolTipText((String) newIssue.getAction().getValue(Action.NAME)); 143 169 newIssue.setIcon(OsbPlugin.loadIcon("icon_error_add22.png")); 144 170 171 buttonPanel.add(toggleConnectionMode); 145 172 buttonPanel.add(refresh); 146 173 buttonPanel.add(newIssue); 147 174 buttonPanel.add(addComment); 148 175 buttonPanel.add(closeIssue); 176 177 queuePanel = new JPanel(new BorderLayout()); 178 queuePanel.setName(tr("Queue")); 179 queueList = new JList(ActionQueue.getInstance()); 180 queueList.setCellRenderer(new OsbQueueListCellRenderer()); 181 queuePanel.add(new JScrollPane(queueList), BorderLayout.CENTER); 182 queuePanel.add(processQueue, BorderLayout.SOUTH); 183 processQueue.addActionListener(new ActionListener() { 184 public void actionPerformed(ActionEvent e) { 185 Main.pref.put(ConfigKeys.OSB_API_OFFLINE, "false"); 186 setConnectionMode(false); 187 try { 188 ActionQueue.getInstance().processQueue(); 189 190 // refresh, if the api is enabled 191 if(!Main.pref.getBoolean(ConfigKeys.OSB_API_DISABLED)) { 192 plugin.updateData(); 193 } 194 } catch (Exception e1) { 195 System.err.println("Couldn't process action queue"); 196 e1.printStackTrace(); 197 } 198 } 199 }); 200 tabbedPane.add(queuePanel); 149 201 150 202 if (buttonLabels) { 203 toggleConnectionMode.setHorizontalAlignment(SwingConstants.LEFT); 151 204 refresh.setHorizontalAlignment(SwingConstants.LEFT); 152 205 addComment.setHorizontalAlignment(SwingConstants.LEFT); … … 154 207 newIssue.setHorizontalAlignment(SwingConstants.LEFT); 155 208 } else { 209 toggleConnectionMode.setText(null); 156 210 refresh.setText(null); 157 211 addComment.setText(null); … … 160 214 } 161 215 162 // add a selection listener to the data 163 DataSet.selListeners.add(new SelectionChangedListener() { 164 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 165 fireSelectionChanged = false; 166 list.clearSelection(); 167 for (OsmPrimitive osmPrimitive : newSelection) { 168 for (int i = 0; i < model.getSize(); i++) { 169 OsbListItem item = (OsbListItem) model.get(i); 170 if (item.getNode() == osmPrimitive) { 171 list.addSelectionInterval(i, i); 172 } 173 } 174 } 175 fireSelectionChanged = true; 176 } 177 }); 178 179 AddCommentAction.addActionObserver(this); 180 CloseIssueAction.addActionObserver(this); 216 addCommentAction.addActionObserver(this); 217 closeIssueAction.addActionObserver(this); 218 setConnectionMode(offline); 181 219 } 182 220 183 221 public synchronized void update(final DataSet dataset) { 184 Node lastNode = OsbAction.getSelectedNode(); 185 model = new DefaultListModel(); 222 // store the last selection 223 OsbListItem listItem = (OsbListItem) bugList.getSelectedValue(); 224 Node lastNode = null; 225 if(listItem != null) { 226 lastNode = listItem.getNode(); 227 } 228 229 // create a new list model 230 bugListModel = new DefaultListModel(); 186 231 List<Node> sortedList = new ArrayList<Node>(dataset.getNodes()); 187 232 Collections.sort(sortedList, new BugComparator()); 188 189 233 for (Node node : sortedList) { 190 234 if (node.isUsable()) { 191 model.addElement(new OsbListItem(node)); 192 } 193 } 194 list.setModel(model); 195 list.setSelectedValue(new OsbListItem(lastNode), true); 235 bugListModel.addElement(new OsbListItem(node)); 236 } 237 } 238 bugList.setModel(bugListModel); 239 240 // restore the last selection 241 if(lastNode != null) { 242 bugList.setSelectedValue(new OsbListItem(lastNode), true); 243 } 196 244 } 197 245 198 246 public void valueChanged(ListSelectionEvent e) { 199 if ( list.getSelectedValues().length == 0) {247 if (bugList.getSelectedValues().length == 0) { 200 248 addComment.setEnabled(false); 201 249 closeIssue.setEnabled(false); 202 OsbAction.setSelectedNode(null);203 250 return; 204 251 } 205 252 206 253 List<OsmPrimitive> selected = new ArrayList<OsmPrimitive>(); 207 for (Object listItem : list.getSelectedValues()) {254 for (Object listItem : bugList.getSelectedValues()) { 208 255 Node node = ((OsbListItem) listItem).getNode(); 209 256 selected.add(node); … … 217 264 } 218 265 219 OsbAction.setSelectedNode(node);220 266 scrollToSelected(node); 221 267 } … … 224 270 // If so, a temporary DataSet is created because it's the simplest way 225 271 // to fire all necessary events so OSB updates its popups. 226 DataSet ds = Main.main.getCurrentDataSet();272 DataSet ds = osbPlugin.getLayer().getDataSet(); 227 273 if (fireSelectionChanged) { 228 274 if(ds == null) … … 233 279 234 280 private void scrollToSelected(Node node) { 235 for (int i = 0; i < model.getSize(); i++) {236 Node current = ((OsbListItem) model.get(i)).getNode();281 for (int i = 0; i < bugListModel.getSize(); i++) { 282 Node current = ((OsbListItem) bugListModel.get(i)).getNode(); 237 283 if (current.getId()== node.getId()) { 238 list.scrollRectToVisible(list.getCellBounds(i, i));239 list.setSelectedIndex(i);284 bugList.scrollRectToVisible(bugList.getCellBounds(i, i)); 285 bugList.setSelectedIndex(i); 240 286 return; 241 287 } … … 255 301 public void layerRemoved(Layer oldLayer) { 256 302 if (oldLayer == osbPlugin.getLayer()) { 257 model.removeAllElements();303 bugListModel.removeAllElements(); 258 304 } 259 305 } … … 269 315 public void mouseClicked(MouseEvent e) { 270 316 if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { 271 OsbListItem item = (OsbListItem) list.getSelectedValue(); 272 zoomToNode(item.getNode()); 317 zoomToNode(getSelectedNode()); 273 318 } 274 319 } … … 284 329 private void mayTriggerPopup(MouseEvent e) { 285 330 if (e.isPopupTrigger()) { 286 int selectedRow = list.locationToIndex(e.getPoint()); 287 list.setSelectedIndex(selectedRow); 288 Node n = ((OsbListItem) list.getSelectedValue()).getNode(); 289 OsbAction.setSelectedNode(n); 290 PopupFactory.createPopup(n).show(e.getComponent(), e.getX(), e.getY()); 331 int selectedRow = bugList.locationToIndex(e.getPoint()); 332 bugList.setSelectedIndex(selectedRow); 333 PopupFactory.createPopup(getSelectedNode(), this).show(e.getComponent(), e.getX(), e.getY()); 291 334 } 292 335 } … … 334 377 super.showDialog(); 335 378 } 379 380 public void showQueuePanel() { 381 if(!queuePanelVisible) { 382 remove(bugListPanel); 383 tabbedPane.add(bugListPanel, 0); 384 add(tabbedPane, BorderLayout.CENTER); 385 tabbedPane.setSelectedIndex(0); 386 queuePanelVisible = true; 387 invalidate(); 388 repaint(); 389 } 390 } 391 392 public void hideQueuePanel() { 393 if(queuePanelVisible) { 394 tabbedPane.remove(bugListPanel); 395 remove(tabbedPane); 396 add(bugListPanel, BorderLayout.CENTER); 397 queuePanelVisible = false; 398 invalidate(); 399 repaint(); 400 } 401 } 402 403 public Node getSelectedNode() { 404 return ((OsbListItem)bugList.getSelectedValue()).getNode(); 405 } 406 407 public void setSelectedNode(Node node) { 408 bugList.setSelectedValue(new OsbListItem(node), true); 409 } 410 411 public void setConnectionMode(boolean offline) { 412 refresh.setEnabled(!offline); 413 setTitle("OpenStreetBugs (" + (offline ? "offline" : "online") + ")"); 414 toggleConnectionMode.setSelected(offline); 415 } 336 416 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/AddCommentAction.java
r17872 r19282 31 31 32 32 import java.awt.event.ActionEvent; 33 import java.io.IOException; 33 34 import java.util.LinkedList; 34 35 import java.util.List; 35 36 36 37 import org.openstreetmap.josm.Main; 38 import org.openstreetmap.josm.data.osm.Node; 37 39 import org.openstreetmap.josm.gui.widgets.HistoryChangedListener; 38 40 import org.openstreetmap.josm.plugins.osb.ConfigKeys; 39 41 import org.openstreetmap.josm.plugins.osb.OsbPlugin; 40 42 import org.openstreetmap.josm.plugins.osb.api.EditAction; 43 import org.openstreetmap.josm.plugins.osb.gui.OsbDialog; 41 44 import org.openstreetmap.josm.plugins.osb.gui.dialogs.TextInputDialog; 42 45 … … 46 49 47 50 private EditAction editAction = new EditAction(); 51 52 private String comment; 53 54 private Node node; 48 55 49 public AddCommentAction() { 50 super(tr("Add a comment")); 56 public AddCommentAction(OsbDialog dialog) { 57 super(tr("Add a comment"), dialog); 51 58 } 52 59 … … 59 66 } 60 67 }; 61 String comment = TextInputDialog.showDialog( 68 node = dialog.getSelectedNode(); 69 comment = TextInputDialog.showDialog( 62 70 Main.map, 63 71 tr("Add a comment"), … … 65 73 OsbPlugin.loadIcon("add_comment22.png"), 66 74 history, l); 67 68 if(comment != null) { 69 comment = addMesgInfo(comment); 70 editAction.execute(getSelectedNode(), comment); 75 76 if(comment == null) { 77 cancelled = true; 71 78 } 72 79 } 80 81 @Override 82 public void execute() throws IOException { 83 comment = addMesgInfo(comment); 84 editAction.execute(node, comment); 85 } 86 87 @Override 88 public String toString() { 89 return tr("Comment: " + node.get("note") + " - " + comment); 90 } 91 92 @Override 93 public AddCommentAction clone() { 94 AddCommentAction action = new AddCommentAction(dialog); 95 action.comment = comment; 96 action.cancelled = cancelled; 97 action.node = node; 98 return action; 99 } 73 100 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/CloseIssueAction.java
r17872 r19282 31 31 32 32 import java.awt.event.ActionEvent; 33 import java.io.IOException; 33 34 import java.util.LinkedList; 34 35 import java.util.List; 35 36 36 37 import org.openstreetmap.josm.Main; 38 import org.openstreetmap.josm.data.osm.Node; 37 39 import org.openstreetmap.josm.gui.widgets.HistoryChangedListener; 38 40 import org.openstreetmap.josm.plugins.osb.ConfigKeys; … … 40 42 import org.openstreetmap.josm.plugins.osb.api.CloseAction; 41 43 import org.openstreetmap.josm.plugins.osb.api.EditAction; 44 import org.openstreetmap.josm.plugins.osb.gui.OsbDialog; 42 45 import org.openstreetmap.josm.plugins.osb.gui.dialogs.TextInputDialog; 43 46 … … 48 51 private CloseAction closeAction = new CloseAction(); 49 52 private EditAction commentAction = new EditAction(); 53 54 private String comment; 55 56 private Node node; 50 57 51 public CloseIssueAction() { 52 super(tr("Mark as done")); 58 public CloseIssueAction(OsbDialog dialog) { 59 super(tr("Mark as done"), dialog); 53 60 } 54 61 … … 61 68 } 62 69 }; 63 String comment = TextInputDialog.showDialog(Main.map, 70 node = dialog.getSelectedNode(); 71 comment = TextInputDialog.showDialog(Main.map, 64 72 tr("Really close?"), 65 73 tr("<html>Really mark this issue as ''done''?<br><br>You may add an optional comment:</html>"), 66 74 OsbPlugin.loadIcon("icon_valid22.png"), 67 75 history, l); 76 77 if(comment == null) { 78 cancelled = true; 79 } 68 80 69 if(comment != null) { 70 if(comment.length() > 0) { 71 comment = addMesgInfo(comment); 72 commentAction.execute(getSelectedNode(), comment); 73 } 74 closeAction.execute(getSelectedNode()); 81 } 82 83 @Override 84 public void execute() throws IOException { 85 if (comment.length() > 0) { 86 comment = addMesgInfo(comment); 87 commentAction.execute(node, comment); 75 88 } 89 closeAction.execute(node); 90 } 91 92 @Override 93 public String toString() { 94 return tr("Close: " + node.get("note") + " - Comment: " + comment); 95 } 96 97 @Override 98 public CloseIssueAction clone() { 99 CloseIssueAction action = new CloseIssueAction(dialog); 100 action.cancelled = cancelled; 101 action.comment = comment; 102 action.node = node; 103 return action; 76 104 } 77 105 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/NewIssueAction.java
r17872 r19282 30 30 import static org.openstreetmap.josm.tools.I18n.tr; 31 31 32 import java.awt. Cursor;32 import java.awt.Point; 33 33 import java.awt.event.ActionEvent; 34 import java.awt.event.MouseEvent;35 import java.awt.event.MouseListener;36 34 import java.io.IOException; 37 35 import java.util.LinkedList; 38 36 import java.util.List; 39 40 import javax.swing.JOptionPane;41 import javax.swing.JToggleButton;42 37 43 38 import org.openstreetmap.josm.Main; … … 49 44 import org.openstreetmap.josm.plugins.osb.gui.dialogs.TextInputDialog; 50 45 51 public class NewIssueAction extends OsbAction implements MouseListener{46 public class NewIssueAction extends OsbAction { 52 47 53 48 private static final long serialVersionUID = 1L; 54 49 55 private NewAction newAction = new NewAction();56 57 private JToggleButton button;58 59 50 private OsbPlugin plugin; 60 51 61 private Cursor previousCursor; 62 63 public NewIssueAction(JToggleButton button, OsbPlugin plugin) { 64 super(tr("New issue")); 65 this.button = button; 52 private String result; 53 54 private Point p; 55 56 private NewAction newAction = new NewAction(); 57 58 public NewIssueAction(OsbPlugin plugin, Point p) { 59 super(tr("New issue"), plugin.getDialog()); 66 60 this.plugin = plugin; 61 this.p = p; 67 62 } 68 63 69 64 @Override 70 protected void doActionPerformed(ActionEvent e) throws IOException { 71 if(button.isSelected()) { 72 previousCursor = Main.map.mapView.getCursor(); 73 Main.map.mapView.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); 74 Main.map.mapView.addMouseListener(this); 75 } else { 76 reset(); 77 } 78 } 79 80 private void reset() { 81 Main.map.mapView.setCursor(previousCursor); 82 Main.map.mapView.removeMouseListener(this); 83 button.setSelected(false); 84 } 85 86 public void mouseClicked(MouseEvent e) { 87 addNewIssue(e); 88 } 89 90 public void mouseEntered(MouseEvent e) {} 91 92 public void mouseExited(MouseEvent e) {} 93 94 public void mousePressed(MouseEvent e) { 95 addNewIssue(e); 96 } 97 98 private void addNewIssue(MouseEvent e) { 65 protected void doActionPerformed(ActionEvent e) throws IOException, InterruptedException { 99 66 List<String> history = new LinkedList<String>(Main.pref.getCollection(ConfigKeys.OSB_NEW_HISTORY, new LinkedList<String>())); 100 67 HistoryChangedListener l = new HistoryChangedListener() { … … 103 70 } 104 71 }; 105 String result = TextInputDialog.showDialog( 72 73 result = TextInputDialog.showDialog( 106 74 Main.map, 107 75 tr("Create issue"), … … 109 77 OsbPlugin.loadIcon("icon_error_add22.png"), 110 78 history, l); 79 80 if(result == null) { 81 cancelled = true; 82 } 83 } 111 84 112 if(result != null && result.length() > 0) { 113 try { 114 result = addMesgInfo(result); 115 Node n = newAction.execute(e.getPoint(), result); 116 plugin.getDataSet().addPrimitive(n); 117 if(Main.pref.getBoolean(ConfigKeys.OSB_API_DISABLED)) { 118 plugin.updateGui(); 119 } else { 120 plugin.updateData(); 121 } 122 } catch (Exception e1) { 123 e1.printStackTrace(); 124 JOptionPane.showMessageDialog(Main.parent, 125 tr("An error occurred: {0}", new Object[] {result}), 126 tr("Error"), 127 JOptionPane.ERROR_MESSAGE); 85 @Override 86 public void execute() throws IOException { 87 if (result.length() > 0) { 88 result = addMesgInfo(result); 89 Node n = newAction.execute(p, result); 90 plugin.getDataSet().addPrimitive(n); 91 if (Main.pref.getBoolean(ConfigKeys.OSB_API_DISABLED)) { 92 plugin.updateGui(); 93 } else { 94 plugin.updateData(); 128 95 } 129 96 } 130 131 reset();132 97 } 133 134 public void mouseReleased(MouseEvent e) {} 98 99 @Override 100 public String toString() { 101 return tr("Create: " + result); 102 } 103 104 @Override 105 public OsbAction clone() { 106 NewIssueAction action = new NewIssueAction(plugin, p); 107 action.cancelled = cancelled; 108 action.p = p; 109 action.result = result; 110 return action; 111 } 135 112 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/OsbAction.java
r13497 r19282 41 41 42 42 import org.openstreetmap.josm.Main; 43 import org.openstreetmap.josm.data.osm.Node;44 43 import org.openstreetmap.josm.plugins.osb.ConfigKeys; 44 import org.openstreetmap.josm.plugins.osb.gui.OsbDialog; 45 45 46 46 public abstract class OsbAction extends AbstractAction { … … 48 48 private static final long serialVersionUID = 1L; 49 49 50 private static List<OsbActionObserver> observers = new ArrayList<OsbActionObserver>(); 50 private List<OsbActionObserver> observers = new ArrayList<OsbActionObserver>(); 51 52 protected OsbDialog dialog; 53 54 protected boolean cancelled = false; 51 55 52 private static Node selectedNode; 53 54 public OsbAction(String name) { 56 public OsbAction(String name, OsbDialog osbDialog) { 55 57 super(name); 56 } 57 58 public static Node getSelectedNode() { 59 return selectedNode; 60 } 61 62 public static void setSelectedNode(Node selectedNode) { 63 OsbAction.selectedNode = selectedNode; 58 this.dialog = osbDialog; 64 59 } 65 60 66 61 public void actionPerformed(ActionEvent e) { 62 cancelled = false; 67 63 try { 68 64 doActionPerformed(e); 69 for (OsbActionObserver obs : observers) { 70 obs.actionPerformed(this); 65 if(!cancelled) { 66 if (!Main.pref.getBoolean(ConfigKeys.OSB_API_OFFLINE)) { 67 execute(); 68 for (OsbActionObserver obs : observers) { 69 obs.actionPerformed(this); 70 } 71 } else { 72 OsbAction action = clone(); 73 ActionQueue.getInstance().offer(action); 74 } 71 75 } 72 76 } catch (Exception e1) { … … 78 82 protected abstract void doActionPerformed(ActionEvent e) throws Exception; 79 83 80 public staticvoid addActionObserver(OsbActionObserver obs) {84 public void addActionObserver(OsbActionObserver obs) { 81 85 observers.add(obs); 82 86 } 83 87 84 public staticvoid removeActionObserver(OsbActionObserver obs) {88 public void removeActionObserver(OsbActionObserver obs) { 85 89 observers.remove(obs); 86 90 } … … 114 118 return msg; 115 119 } 120 121 public List<OsbActionObserver> getActionObservers() { 122 return observers; 123 } 124 125 public abstract void execute() throws Exception; 126 127 public abstract OsbAction clone(); 116 128 } -
applications/editors/josm/plugins/openstreetbugs/src/org/openstreetmap/josm/plugins/osb/gui/action/PopupFactory.java
r13497 r19282 35 35 import org.openstreetmap.josm.data.osm.Node; 36 36 import org.openstreetmap.josm.plugins.osb.OsbPlugin; 37 import org.openstreetmap.josm.plugins.osb.gui.OsbDialog; 37 38 38 39 public class PopupFactory { … … 41 42 private static JPopupMenu fixedPopup; 42 43 43 public static synchronized JPopupMenu createPopup(Node node) { 44 public static synchronized JPopupMenu createPopup(Node node, OsbDialog dialog) { 44 45 if("0".equals(node.get("state"))) { 45 return getIssuePopup(); 46 return getIssuePopup(dialog); 46 47 } else if("1".equals(node.get("state"))) { 47 return getFixedPopup(); 48 return getFixedPopup(dialog); 48 49 } else { 49 50 throw new RuntimeException(tr("Unknown issue state")); … … 51 52 } 52 53 53 private static JPopupMenu getIssuePopup() { 54 private static JPopupMenu getIssuePopup(OsbDialog dialog) { 54 55 if(issuePopup == null) { 55 56 issuePopup = new JPopupMenu(); 56 57 JMenuItem add = new JMenuItem(); 57 add.setAction(new AddCommentAction()); 58 add.setAction(new AddCommentAction(dialog)); 58 59 add.setIcon(OsbPlugin.loadIcon("add_comment16.png")); 59 60 issuePopup.add(add); 60 61 JMenuItem close = new JMenuItem(); 61 close.setAction(new CloseIssueAction()); 62 close.setAction(new CloseIssueAction(dialog)); 62 63 close.setIcon(OsbPlugin.loadIcon("icon_valid16.png")); 63 64 issuePopup.add(close); … … 66 67 } 67 68 68 private static JPopupMenu getFixedPopup() { 69 private static JPopupMenu getFixedPopup(OsbDialog dialog) { 69 70 if(fixedPopup == null) { 70 71 fixedPopup = new JPopupMenu(); 71 72 JMenuItem add = new JMenuItem(); 72 AddCommentAction aca = new AddCommentAction(); 73 AddCommentAction aca = new AddCommentAction(dialog); 73 74 aca.setEnabled(false); 74 75 add.setAction(aca); 75 76 add.setIcon(OsbPlugin.loadIcon("add_comment16.png")); 76 77 JMenuItem close = new JMenuItem(); 77 CloseIssueAction cia = new CloseIssueAction(); 78 CloseIssueAction cia = new CloseIssueAction(dialog); 78 79 cia.setEnabled(false); 79 80 close.setAction(cia);
Note:
See TracChangeset
for help on using the changeset viewer.