Changeset 18617 in osm for applications/editors/josm/plugins/waydownloader/src
- Timestamp:
- 2009-11-15T12:40:58+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/waydownloader/src/org/openstreetmap/josm/plugins/waydownloader/WayDownloaderPlugin.java
r18613 r18617 56 56 "way-download", 57 57 tr("Download map data on the end of selected way"), 58 Shortcut.registerShortcut("waydownloader:waydownload", "Way Download", KeyEvent.VK_W, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), 58 Shortcut.registerShortcut("waydownloader:waydownload", tr("Way Download"), KeyEvent.VK_W, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), 59 59 true); 60 60 } 61 61 62 62 protected void showWarningMessage(String msg) { 63 if(msg == null) return;63 if(msg == null) return; 64 64 JOptionPane.showMessageDialog( 65 Main.parent,66 msg,67 tr("Warning"),68 JOptionPane.WARNING_MESSAGE65 Main.parent, 66 msg, 67 tr("Warning"), 68 JOptionPane.WARNING_MESSAGE 69 69 ); 70 70 } 71 71 72 72 protected void showErrorMessage(String msg) { 73 if(msg == null) return;74 JOptionPane.showMessageDialog(75 Main.parent,76 msg,77 tr("Error"),78 JOptionPane.ERROR_MESSAGE79 );73 if(msg == null) return; 74 JOptionPane.showMessageDialog( 75 Main.parent, 76 msg, 77 tr("Error"), 78 JOptionPane.ERROR_MESSAGE 79 ); 80 80 } 81 81 82 82 protected void showInfoMessage(String msg) { 83 if(msg == null) return;83 if(msg == null) return; 84 84 JOptionPane.showMessageDialog( 85 Main.parent,86 msg,87 tr("Information"),88 JOptionPane.INFORMATION_MESSAGE85 Main.parent, 86 msg, 87 tr("Information"), 88 JOptionPane.INFORMATION_MESSAGE 89 89 ); 90 90 } 91 91 92 92 /** Called when the WayDownloadAction action is triggered (e.g. user clicked the menu option) */ 93 93 public void actionPerformed(ActionEvent e) { … … 97 97 selection = Main.main.getCurrentDataSet().getSelectedWays(); 98 98 if (!workFromWaySelection(selection)) { 99 showWarningMessage(tr("<html>Neither a node nor a way with an endpoint outside of the<br>current download areas is selected.<br>Select a node on the start or end of a way or an entire way first.</html>"));100 return;99 showWarningMessage(tr("<html>Neither a node nor a way with an endpoint outside of the<br>current download areas is selected.<br>Select a node on the start or end of a way or an entire way first.</html>")); 100 return; 101 101 } 102 102 selection = Main.main.getCurrentDataSet().getSelectedNodes(); … … 104 104 105 105 if ( selection.size()==0 || selection.size()>1 || ! (selection.iterator().next() instanceof Node)) { 106 showWarningMessage(tr("<html>Could not find a unique node to start downloading from.</html>"));107 return; 108 } 109 106 showWarningMessage(tr("<html>Could not find a unique node to start downloading from.</html>")); 107 return; 108 } 109 110 110 selectedNode = (Node) selection.iterator().next(); 111 111 Main.map.mapView.zoomTo(selectedNode.getEastNorth()); … … 115 115 List<Way> connectedWays = findConnectedWays(selectedNode); 116 116 if (connectedWays.size()==0) { 117 showWarningMessage(118 tr("<html>There are no ways connected to node ''{0}''. Aborting.</html>",119 selectedNode.getDisplayName(DefaultNameFormatter.getInstance()))120 );121 return;122 } 117 showWarningMessage( 118 tr("<html>There are no ways connected to node ''{0}''. Aborting.</html>", 119 selectedNode.getDisplayName(DefaultNameFormatter.getInstance())) 120 ); 121 return; 122 } 123 123 priorConnectedWay =connectedWays.get(0); 124 124 … … 129 129 final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(); 130 130 final Future<?> future = downloadTask.download( 131 false /* no new layer */,132 new Bounds(133 selectedNode.getCoor().lat()- latbuffer,134 selectedNode.getCoor().lon()- lonbuffer,135 selectedNode.getCoor().lat()+ latbuffer,136 selectedNode.getCoor().lon()+ lonbuffer137 ),138 monitor131 false /* no new layer */, 132 new Bounds( 133 selectedNode.getCoor().lat()- latbuffer, 134 selectedNode.getCoor().lon()- lonbuffer, 135 selectedNode.getCoor().lat()+ latbuffer, 136 selectedNode.getCoor().lon()+ lonbuffer 137 ), 138 monitor 139 139 ); 140 140 // schedule closing of the progress monitor after the download … … 166 166 167 167 if (connectedWays.size()==0) { 168 String msg = tr("Way downloader data inconsistency. Prior connected way ''{0}'' wasn''t discovered after download",169 priorConnectedWay.getDisplayName(DefaultNameFormatter.getInstance())170 );171 System.err.println(msg);172 showErrorMessage(msg);173 return;174 } 175 168 String msg = tr("Way downloader data inconsistency. Prior connected way ''{0}'' wasn''t discovered after download", 169 priorConnectedWay.getDisplayName(DefaultNameFormatter.getInstance()) 170 ); 171 System.err.println(msg); 172 showErrorMessage(msg); 173 return; 174 } 175 176 176 if (connectedWays.size()==1) { 177 177 //Just one way connecting still to the node . Presumably the one which was there before 178 178 //Check if it's just a duplicate node 179 179 180 180 Node dupeNode = findDuplicateNode(selectedNode); 181 181 if (dupeNode!=null) { 182 String msg = tr("<html>There aren''t further connected ways to download.<br>"183 + "A potential duplicate node of the currently selected node was found, though.<br><br>"184 + "The currently selected node is ''{0}''<br>"185 + "The potential duplicate node is ''{1}''<br>"186 + "Merge the duplicate node onto the currently selected node and continue way downloading?"187 + "</html>",188 selectedNode.getDisplayName(DefaultNameFormatter.getInstance()),189 dupeNode.getDisplayName(DefaultNameFormatter.getInstance())190 );191 192 int ret = JOptionPane.showConfirmDialog(193 Main.parent,194 msg,195 tr("Merge duplicate node?"),196 JOptionPane.YES_NO_OPTION,197 JOptionPane.QUESTION_MESSAGE198 );199 if (ret != JOptionPane.YES_OPTION)200 return;182 String msg = tr("<html>There aren''t further connected ways to download.<br>" 183 + "A potential duplicate node of the currently selected node was found, though.<br><br>" 184 + "The currently selected node is ''{0}''<br>" 185 + "The potential duplicate node is ''{1}''<br>" 186 + "Merge the duplicate node onto the currently selected node and continue way downloading?" 187 + "</html>", 188 selectedNode.getDisplayName(DefaultNameFormatter.getInstance()), 189 dupeNode.getDisplayName(DefaultNameFormatter.getInstance()) 190 ); 191 192 int ret = JOptionPane.showConfirmDialog( 193 Main.parent, 194 msg, 195 tr("Merge duplicate node?"), 196 JOptionPane.YES_NO_OPTION, 197 JOptionPane.QUESTION_MESSAGE 198 ); 199 if (ret != JOptionPane.YES_OPTION) 200 return; 201 201 Command cmd = MergeNodesAction.mergeNodes( 202 Main.main.getEditLayer(),203 Collections.singletonList(dupeNode),204 selectedNode202 Main.main.getEditLayer(), 203 Collections.singletonList(dupeNode), 204 selectedNode 205 205 ); 206 206 if (cmd != null) { … … 210 210 connectedWays = findConnectedWays(selectedNode); 211 211 } else { 212 showInfoMessage(tr("<html>No more connected ways to download.</html>"));213 return;214 } 215 return; 216 } 217 212 showInfoMessage(tr("<html>No more connected ways to download.</html>")); 213 return; 214 } 215 return; 216 } 217 218 218 if (connectedWays.size()>2) { 219 219 //Three or more ways meeting at this node. Means we have a junction. 220 String msg = tr(221 "Node ''{0}'' is a junction with more than 2 connected ways.",222 selectedNode.getDisplayName(DefaultNameFormatter.getInstance())223 );224 showWarningMessage(msg);225 return;226 } 227 220 String msg = tr( 221 "Node ''{0}'' is a junction with more than 2 connected ways.", 222 selectedNode.getDisplayName(DefaultNameFormatter.getInstance()) 223 ); 224 showWarningMessage(msg); 225 return; 226 } 227 228 228 if (connectedWays.size()==2) { 229 229 //Two connected ways (The "normal" way downloading case) … … 242 242 } 243 243 244 @Override245 protected void updateEnabledState() {246 setEnabled(getEditLayer() != null);247 }248 249 @Override250 protected void updateEnabledState(251 Collection<? extends OsmPrimitive> selection) {252 // do nothing253 }254 } 255 256 /** 244 @Override 245 protected void updateEnabledState() { 246 setEnabled(getEditLayer() != null); 247 } 248 249 @Override 250 protected void updateEnabledState( 251 Collection<? extends OsmPrimitive> selection) { 252 // do nothing 253 } 254 } 255 256 /** 257 257 * Check whether there is a potentially duplicate node for <code>referenceNode</code>. 258 * 259 * @param referenceNode the reference node 258 * 259 * @param referenceNode the reference node 260 260 * @return the potential duplicate node. null, if no duplicate found. 261 261 */ 262 262 private Node findDuplicateNode(Node referenceNode) { 263 DataSet ds = Main.main.getCurrentDataSet();264 List<Node> candidates = ds.searchNodes(new BBox(new Bounds(referenceNode.getCoor(), 0.0003, 0.0005)));263 DataSet ds = Main.main.getCurrentDataSet(); 264 List<Node> candidates = ds.searchNodes(new BBox(new Bounds(referenceNode.getCoor(), 0.0003, 0.0005))); 265 265 for (Node candidate: candidates) { 266 266 if (!candidate.equals(referenceNode) 267 267 && !candidate.incomplete 268 268 && candidate.getCoor().equals(referenceNode.getCoor())) 269 return candidate; 269 return candidate; 270 270 } 271 271 return null; … … 279 279 } 280 280 281 /** 282 * Replies the list of ways <code>referenceNode</code> is either the first or the 281 /** 282 * Replies the list of ways <code>referenceNode</code> is either the first or the 283 283 * last node in. 284 * 285 * @param referenceNode the reference node 284 * 285 * @param referenceNode the reference node 286 286 * @return the list of ways. May be empty, but null. 287 287 */ 288 288 private List<Way> findConnectedWays(Node referenceNode) { 289 List<Way> referers = OsmPrimitive.getFilteredList(referenceNode.getReferrers(), Way.class);289 List<Way> referers = OsmPrimitive.getFilteredList(referenceNode.getReferrers(), Way.class); 290 290 ArrayList<Way> connectedWays = new ArrayList<Way>(referers.size()); 291 291
Note:
See TracChangeset
for help on using the changeset viewer.
