Changeset 1750 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-07-08T21:50:32+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 added
- 48 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r1722 r1750 150 150 panel.setVisible(false); 151 151 panel.removeAll(); 152 if (map != null) 152 if (map != null) { 153 153 map.fillPanel(panel); 154 else {154 } else { 155 155 old.destroy(); 156 156 panel.add(gettingStarted, BorderLayout.CENTER); … … 169 169 if (map != null) { 170 170 map.mapView.removeLayer(layer); 171 if (layer instanceof OsmDataLayer) 171 if (layer instanceof OsmDataLayer) { 172 172 ds = new DataSet(); 173 if (map.mapView.getAllLayers().isEmpty()) 173 } 174 if (map.mapView.getAllLayers().isEmpty()) { 174 175 setMapFrame(null); 176 } 175 177 } 176 178 } … … 182 184 public Main(SplashScreen splash) { 183 185 main = this; 184 // platform = determinePlatformHook();186 // platform = determinePlatformHook(); 185 187 platform.startupHook(); 186 188 contentPane.add(panel, BorderLayout.CENTER); 187 189 panel.add(gettingStarted, BorderLayout.CENTER); 188 190 189 if(splash != null) splash.setStatus(tr("Creating main GUI")); 191 if(splash != null) { 192 splash.setStatus(tr("Creating main GUI")); 193 } 190 194 menu = new MainMenu(); 191 195 … … 197 201 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) 198 202 .put(Shortcut.registerShortcut("system:help", tr("Help"), 199 KeyEvent.VK_F1, Shortcut.GROUP_DIRECT).getKeyStroke(), "Help");203 KeyEvent.VK_F1, Shortcut.GROUP_DIRECT).getKeyStroke(), "Help"); 200 204 contentPane.getActionMap().put("Help", menu.help); 201 205 … … 223 227 } 224 228 /** 225 * @return The edit osm layer. If none exists, it will be created. 226 */ 227 public final OsmDataLayer editLayer() { 228 if (map == null || map.mapView.editLayer == null) 229 * Replies the current edit layer. Creates one if no {@see OsmDataLayer} 230 * exists. Replies null, if the currently active layer isn't an instance 231 * of {@see OsmDataLayer}. 232 * 233 * @return the current edit layer 234 */ 235 public final OsmDataLayer createOrGetEditLayer() { 236 if (map == null || map.mapView.getEditLayer() == null) { 229 237 menu.newAction.actionPerformed(null); 230 return map.mapView.editLayer; 238 } 239 return map.mapView.getEditLayer(); 240 } 241 242 /** 243 * Replies true if this map view has an edit layer 244 * 245 * @return true if this map view has an edit layer 246 */ 247 public boolean hasEditLayer() { 248 if (map == null) return false; 249 if (map.mapView == null) return false; 250 if (map.mapView.getEditLayer() == null) return false; 251 return true; 231 252 } 232 253 … … 263 284 if(!Main.proj.equals(oldProj)) 264 285 { 265 if(b != null) 286 if(b != null) { 266 287 map.mapView.zoomTo(b); 267 /* TODO - remove layers with fixed projection */ 288 /* TODO - remove layers with fixed projection */ 289 } 268 290 } 269 291 } … … 279 301 try { 280 302 String laf = Main.pref.get("laf"); 281 if(laf != null && laf.length() > 0) 303 if(laf != null && laf.length() > 0) { 282 304 UIManager.setLookAndFeel(laf); 305 } 283 306 } 284 307 catch (final javax.swing.UnsupportedLookAndFeelException e) { … … 310 333 x = Integer.valueOf(m.group(5)); 311 334 y = Integer.valueOf(m.group(7)); 312 if (m.group(4).equals("-")) 335 if (m.group(4).equals("-")) { 313 336 x = screenDimension.width - x - w; 314 if (m.group(6).equals("-")) 337 } 338 if (m.group(6).equals("-")) { 315 339 y = screenDimension.height - y - h; 340 } 316 341 } 317 342 bounds = new Rectangle(x,y,w,h); … … 324 349 } 325 350 } 326 if (bounds == null) 351 if (bounds == null) { 327 352 bounds = !args.containsKey("no-maximize") ? new Rectangle(0,0,screenDimension.width,screenDimension.height) : new Rectangle(1000,740); 328 329 // preinitialize a wait dialog for all early downloads (e.g. via command line) 330 pleaseWaitDlg = new PleaseWaitDialog(null); 353 } 354 355 // preinitialize a wait dialog for all early downloads (e.g. via command line) 356 pleaseWaitDlg = new PleaseWaitDialog(null); 331 357 } 332 358 … … 335 361 pleaseWaitDlg = new PleaseWaitDialog(parent); 336 362 337 if (args.containsKey("download")) 338 for (String s : args.get("download")) 363 if (args.containsKey("download")) { 364 for (String s : args.get("download")) { 339 365 downloadFromParamString(false, s); 340 if (args.containsKey("downloadgps")) 341 for (String s : args.get("downloadgps")) 366 } 367 } 368 if (args.containsKey("downloadgps")) { 369 for (String s : args.get("downloadgps")) { 342 370 downloadFromParamString(true, s); 343 if (args.containsKey("selection")) 344 for (String s : args.get("selection")) 371 } 372 } 373 if (args.containsKey("selection")) { 374 for (String s : args.get("selection")) { 345 375 SearchAction.search(s, SearchAction.SearchMode.add, false, false); 376 } 377 } 346 378 } 347 379 … … 360 392 if (modified) { 361 393 final String msg = uploadedModified ? "\n" 362 +tr("Hint: Some changes came from uploading new data to the server.") : ""; 363 int result = new ExtendedDialog(parent, tr("Unsaved Changes"), 364 new javax.swing.JLabel(tr("There are unsaved changes. Discard the changes and continue?")+msg), 365 new String[] {tr("Save and Exit"), tr("Discard and Exit"), tr("Cancel")}, 366 new String[] {"save.png", "exit.png", "cancel.png"}).getValue(); 367 368 // Save before exiting 369 if(result == 1) { 370 Boolean savefailed = false; 371 for (final Layer l : map.mapView.getAllLayers()) { 372 if (l instanceof OsmDataLayer && ((OsmDataLayer)l).isModified()) { 373 SaveAction save = new SaveAction(l); 374 if(!save.doSave()) 375 savefailed = true; 394 +tr("Hint: Some changes came from uploading new data to the server.") : ""; 395 int result = new ExtendedDialog(parent, tr("Unsaved Changes"), 396 new javax.swing.JLabel(tr("There are unsaved changes. Discard the changes and continue?")+msg), 397 new String[] {tr("Save and Exit"), tr("Discard and Exit"), tr("Cancel")}, 398 new String[] {"save.png", "exit.png", "cancel.png"}).getValue(); 399 400 // Save before exiting 401 if(result == 1) { 402 Boolean savefailed = false; 403 for (final Layer l : map.mapView.getAllLayers()) { 404 if (l instanceof OsmDataLayer && ((OsmDataLayer)l).isModified()) { 405 SaveAction save = new SaveAction(l); 406 if(!save.doSave()) { 407 savefailed = true; 408 } 409 } 410 } 411 return savefailed; 376 412 } 377 } 378 return savefailed; 379 } 380 else if(result != 2) // Cancel exiting unless the 2nd button was clicked 381 return true; 413 else if(result != 2) // Cancel exiting unless the 2nd button was clicked 414 return true; 382 415 } 383 416 } … … 388 421 if (s.startsWith("http:")) { 389 422 final Bounds b = OsmUrlToBounds.parse(s); 390 if (b == null) 423 if (b == null) { 391 424 JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed URL: \"{0}\"", s)); 392 else {425 } else { 393 426 //DownloadTask osmTask = main.menu.download.downloadTasks.get(0); 394 427 DownloadTask osmTask = new DownloadOsmTask(); … … 428 461 platform = new PlatformHookWindows(); 429 462 } else if (os.equals("Linux") || os.equals("Solaris") || 430 os.equals("SunOS") || os.equals("AIX") ||431 os.equals("FreeBSD") || os.equals("NetBSD") || os.equals("OpenBSD")) {463 os.equals("SunOS") || os.equals("AIX") || 464 os.equals("FreeBSD") || os.equals("NetBSD") || os.equals("OpenBSD")) { 432 465 platform = new PlatformHookUnixoid(); 433 466 } else if (os.toLowerCase().startsWith("mac os x")) { … … 468 501 int x = (int)bounds.getX(); 469 502 int y = (int)bounds.getY(); 470 if (width > screenDimension.width) 503 if (width > screenDimension.width) { 471 504 width = screenDimension.width; 472 if (height > screenDimension.height) 505 } 506 if (height > screenDimension.height) { 473 507 width = screenDimension.height; 474 if (x < 0) 508 } 509 if (x < 0) { 475 510 x = 0; 476 if (y < 0) 511 } 512 if (y < 0) { 477 513 y = 0; 514 } 478 515 newGeometry = width + "x" + height + "+" + x + "+" + y; 479 516 } -
trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
r1662 r1750 8 8 import java.awt.event.KeyEvent; 9 9 import java.util.Collection; 10 import java.util.HashSet; 10 11 11 12 import javax.swing.JOptionPane; … … 70 71 BoundingXYVisitor v = new BoundingXYVisitor(); 71 72 if (mode.equals("data")) { 72 for (Layer l : Main.map.mapView.getAllLayers()) 73 for (Layer l : Main.map.mapView.getAllLayers()) { 73 74 l.visitBoundingBox(v); 74 } else if (mode.equals("layer")) 75 } 76 } else if (mode.equals("layer")) { 75 77 Main.map.mapView.getActiveLayer().visitBoundingBox(v); 76 else if (mode.equals("selection") || mode.equals("conflict")) { 77 Collection<OsmPrimitive> sel = mode.equals("selection") ? Main.ds.getSelected() 78 : Main.map.conflictDialog.conflicts.keySet(); 78 } else if (mode.equals("selection") || mode.equals("conflict")) { 79 Collection<OsmPrimitive> sel = new HashSet<OsmPrimitive>(); 80 if (mode.equals("selection")) { 81 sel = Main.ds.getSelected(); 82 } else if (mode.equals("conflict")) { 83 if (Main.map.conflictDialog.getConflicts() != null) { 84 sel = Main.map.conflictDialog.getConflicts().getMyConflictParties(); 85 } 86 } 79 87 if (sel.isEmpty()) { 80 88 JOptionPane.showMessageDialog(Main.parent, … … 82 90 return null; 83 91 } 84 for (OsmPrimitive osm : sel) 92 for (OsmPrimitive osm : sel) { 85 93 osm.visit(v); 94 } 86 95 // increase bbox by 0.001 degrees on each side. this is required 87 96 // especially if the bbox contains one single node, but helpful -
trunk/src/org/openstreetmap/josm/actions/CopyAction.java
r1592 r1750 48 48 49 49 Main.pasteBuffer = copyData(); 50 Main.pasteSource = Main.main. editLayer();50 Main.pasteSource = Main.main.createOrGetEditLayer(); 51 51 Main.main.menu.paste.setEnabled(true); /* now we have a paste buffer we can make paste available */ 52 52 -
trunk/src/org/openstreetmap/josm/actions/DeleteAction.java
r1418 r1750 25 25 26 26 public void actionPerformed(ActionEvent e) { 27 if(!Main.map.mapView.is VisibleDrawableLayer())27 if(!Main.map.mapView.isActiveLayerVisible()) 28 28 return; 29 29 new org.openstreetmap.josm.actions.mapmode.DeleteAction(Main.map) -
trunk/src/org/openstreetmap/josm/actions/DuplicateAction.java
r1594 r1750 28 28 29 29 public void actionPerformed(ActionEvent e) { 30 PasteAction.pasteData(CopyAction.copyData(), Main.main. editLayer(), e);30 PasteAction.pasteData(CopyAction.copyData(), Main.main.createOrGetEditLayer(), e); 31 31 } 32 32 -
trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java
r1677 r1750 64 64 return; 65 65 66 exportGpx(file, this.layer == null ? Main.main. editLayer() : this.layer);66 exportGpx(file, this.layer == null ? Main.main.createOrGetEditLayer() : this.layer); 67 67 } 68 68 -
trunk/src/org/openstreetmap/josm/actions/MoveAction.java
r1640 r1750 46 46 sc = Shortcut.registerShortcut("core:moveright", tr("Move objects {0}", directiontext), KeyEvent.VK_RIGHT, Shortcut.GROUPS_ALT1+Shortcut.GROUP_DIRECT); 47 47 } 48 if (text) {48 if (text) 49 49 return directiontext; 50 } else {50 else 51 51 return sc; 52 }53 52 } 54 53 55 54 public MoveAction(Direction dir) { 56 55 super(tr("Move {0}", calltosupermustbefirststatementinconstructor(dir, true)), null, 57 tr("Moves Objects {0}", calltosupermustbefirststatementinconstructor(dir, true)),58 (Shortcut)calltosupermustbefirststatementinconstructor(dir, false), true);56 tr("Moves Objects {0}", calltosupermustbefirststatementinconstructor(dir, true)), 57 (Shortcut)calltosupermustbefirststatementinconstructor(dir, false), true); 59 58 myDirection = dir; 60 59 } … … 92 91 ? Main.main.undoRedo.commands.getLast() : null; 93 92 94 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand)c). objects))93 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand)c).getMovedNodes())) { 95 94 ((MoveCommand)c).moveAgain(distx, disty); 96 else95 } else { 97 96 Main.main.undoRedo.add( 98 97 c = new MoveCommand(selection, distx, disty)); 98 } 99 99 100 100 for (Node n : affectedNodes) { -
trunk/src/org/openstreetmap/josm/actions/PasteAction.java
r1640 r1750 69 69 Node nnew = new Node(n); 70 70 nnew.id = 0; 71 if (Main.main. editLayer() == source) {71 if (Main.main.createOrGetEditLayer() == source) { 72 72 nnew.setEastNorth(nnew.getEastNorth().add(offsetEast, offsetNorth)); 73 73 } -
trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
r1677 r1750 20 20 import org.apache.tools.bzip2.CBZip2OutputStream; 21 21 import org.openstreetmap.josm.Main; 22 import org.openstreetmap.josm.data.conflict.ConflictCollection; 22 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 24 import org.openstreetmap.josm.gui.ExtendedDialog; … … 49 50 Layer layer = this.layer; 50 51 if (layer == null && Main.map != null && (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer 51 || Main.map.mapView.getActiveLayer() instanceof GpxLayer)) 52 || Main.map.mapView.getActiveLayer() instanceof GpxLayer)) { 52 53 layer = Main.map.mapView.getActiveLayer(); 53 if (layer == null) 54 layer = Main.main.editLayer(); 54 } 55 if (layer == null) { 56 layer = Main.main.createOrGetEditLayer(); 57 } 55 58 56 59 if (!checkSaveConditions(layer)) … … 87 90 } 88 91 89 if (layer instanceof OsmDataLayer && isDataSetEmpty((OsmDataLayer)layer) && 1 != new ExtendedDialog(Main.parent, tr("Empty document"), tr("The document contains no data."), new String[] {tr("Save anyway"), tr("Cancel")}, new String[] {"save.png", "cancel.png"}).getValue()) { 90 return false; 91 } 92 if (layer instanceof GpxLayer && ((GpxLayer)layer).data == null) { 93 return false; 94 } 95 if (!Main.map.conflictDialog.conflicts.isEmpty()) { 96 int answer = new ExtendedDialog(Main.parent, 97 tr("Conflicts"), 98 tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?"), 99 new String[] {tr("Reject Conflicts and Save"), tr("Cancel")}, 100 new String[] {"save.png", "cancel.png"}).getValue(); 101 102 if (answer != 1) return false; 92 if (layer instanceof OsmDataLayer && isDataSetEmpty((OsmDataLayer)layer) && 1 != new ExtendedDialog(Main.parent, tr("Empty document"), tr("The document contains no data."), new String[] {tr("Save anyway"), tr("Cancel")}, new String[] {"save.png", "cancel.png"}).getValue()) 93 return false; 94 if (layer instanceof GpxLayer && ((GpxLayer)layer).data == null) 95 return false; 96 if (layer instanceof OsmDataLayer) { 97 ConflictCollection conflicts = ((OsmDataLayer)layer).getConflicts(); 98 if (conflicts != null && !conflicts.isEmpty()) { 99 int answer = new ExtendedDialog(Main.parent, 100 tr("Conflicts"), 101 tr("There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?"), 102 new String[] {tr("Reject Conflicts and Save"), tr("Cancel")}, 103 new String[] {"save.png", "cancel.png"}).getValue(); 104 105 if (answer != 1) return false; 106 } 103 107 } 104 108 return true; … … 148 152 OsmGzipImporter osmGzipImporter = new OsmGzipImporter(); 149 153 OsmBzip2Importer osmBzip2Importer = new OsmBzip2Importer(); 150 if (gpxImExporter.acceptFile(file)) 154 if (gpxImExporter.acceptFile(file)) { 151 155 GpxExportAction.exportGpx(file, layer); 152 else if (osmImExporter.acceptFile(file)156 } else if (osmImExporter.acceptFile(file) 153 157 || osmGzipImporter.acceptFile(file) 154 158 || osmBzip2Importer.acceptFile(file)) … … 180 184 w.close(); 181 185 // FIXME - how to close? 182 if (!Main.pref.getBoolean("save.keepbackup") && (tmpFile != null)) 186 if (!Main.pref.getBoolean("save.keepbackup") && (tmpFile != null)) { 183 187 tmpFile.delete(); 188 } 184 189 } else { 185 190 JOptionPane.showMessageDialog(Main.parent, tr("Unknown file extension.")); -
trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java
r1670 r1750 32 32 int bboxCount = 0; 33 33 List<Area> areas = new ArrayList<Area>(); 34 for(DataSource ds : Main.main. editLayer().data.dataSources) {34 for(DataSource ds : Main.main.createOrGetEditLayer().data.dataSources) { 35 35 areas.add(new Area(ds.bounds.asRect())); 36 36 } -
trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java
r1690 r1750 35 35 protected void handlePrimitiveGoneException(long id) { 36 36 MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader(); 37 reader.append(Main.main. editLayer().data,id);37 reader.append(Main.main.createOrGetEditLayer().data,id); 38 38 DataSet ds = null; 39 39 try { … … 43 43 return; 44 44 } 45 Main.main. editLayer().mergeFrom(ds);45 Main.main.createOrGetEditLayer().mergeFrom(ds); 46 46 } 47 47 … … 90 90 return; 91 91 } 92 Main.main. editLayer().mergeFrom(ds);92 Main.main.createOrGetEditLayer().mergeFrom(ds); 93 93 } 94 94 95 95 public void updatePrimitive(long id) { 96 OsmPrimitive primitive = Main.main. editLayer().data.getPrimitiveById(id);96 OsmPrimitive primitive = Main.main.createOrGetEditLayer().data.getPrimitiveById(id); 97 97 Set<OsmPrimitive> s = new HashSet<OsmPrimitive>(); 98 98 s.add(primitive); -
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r1698 r1750 23 23 24 24 import org.openstreetmap.josm.Main; 25 import org.openstreetmap.josm.data.conflict.ConflictCollection; 25 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; 26 27 import org.openstreetmap.josm.gui.ExtendedDialog; … … 159 160 } 160 161 161 if (!Main.map.conflictDialog.conflicts.isEmpty()) { 162 ConflictCollection conflicts = Main.main.createOrGetEditLayer().getConflicts(); 163 if (conflicts !=null && !conflicts.isEmpty()) { 162 164 JOptionPane.showMessageDialog(Main.parent,tr("There are unresolved conflicts. You have to resolve these first.")); 163 165 Main.map.conflictDialog.action.button.setSelected(true); … … 212 214 try { 213 215 server.uploadOsm(Main.ds.version, all); 214 Main.main. editLayer().cleanData(server.processed, !add.isEmpty());216 Main.main.createOrGetEditLayer().cleanData(server.processed, !add.isEmpty()); 215 217 } catch (Exception sxe) { 216 218 if (uploadCancelled) { -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r1670 r1750 39 39 private DataSet dataSet; 40 40 private boolean newLayer; 41 private int num = 1;42 41 private String msg = ""; 43 42 … … 69 68 } 70 69 rememberDownloadedData(dataSet); 71 OsmDataLayer layer = new OsmDataLayer(dataSet, tr("Data Layer {0}", num), null);70 OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null); 72 71 if (newLayer) { 73 72 Main.main.addLayer(layer); 74 73 } else { 75 Main.main. editLayer().mergeFrom(layer);74 Main.main.createOrGetEditLayer().mergeFrom(layer); 76 75 } 77 76 -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskList.java
r1690 r1750 42 42 public void download(boolean newLayer, List<Rectangle2D> rects) { 43 43 if(newLayer) { 44 Layer l = new OsmDataLayer(new DataSet(), tr("Data Layer"), null);44 Layer l = new OsmDataLayer(new DataSet(), OsmDataLayer.createNewName(), null); 45 45 Main.main.addLayer(l); 46 46 Main.map.mapView.setActiveLayer(l); … … 98 98 } 99 99 100 Set<Long> myPrimitiveIds = Main.main. editLayer().data.getPrimitiveIds();100 Set<Long> myPrimitiveIds = Main.main.createOrGetEditLayer().data.getPrimitiveIds(); 101 101 Set<Long> downloadedIds = getDownloadedIds(); 102 102 myPrimitiveIds.removeAll(downloadedIds); … … 108 108 109 109 protected void checkPotentiallyDeletedPrimitives(Set<Long> potentiallyDeleted) { 110 DataSet ds = Main.main. editLayer().data;110 DataSet ds = Main.main.createOrGetEditLayer().data; 111 111 ArrayList<OsmPrimitive> toSelect = new ArrayList<OsmPrimitive>(); 112 112 for (Long id : potentiallyDeleted) { -
trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r1677 r1750 64 64 @Override public void actionPerformed(ActionEvent e) { 65 65 super.actionPerformed(e); 66 if(!Main.map.mapView.is DrawableLayer())66 if(!Main.map.mapView.isActiveLayerDrawable()) 67 67 return; 68 68 doActionPerformed(e); … … 70 70 71 71 public void doActionPerformed(ActionEvent e) { 72 if(!Main.map.mapView.is DrawableLayer())72 if(!Main.map.mapView.isActiveLayerDrawable()) 73 73 return; 74 74 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; … … 96 96 if (e.getButton() != MouseEvent.BUTTON1) 97 97 return; 98 if(!Main.map.mapView.is VisibleDrawableLayer())98 if(!Main.map.mapView.isActiveLayerVisible()) 99 99 return; 100 100 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r1725 r1750 240 240 */ 241 241 public void eventDispatched(AWTEvent event) { 242 if(Main.map == null || Main.map.mapView == null || !Main.map.mapView.is DrawableLayer())242 if(Main.map == null || Main.map.mapView == null || !Main.map.mapView.isActiveLayerDrawable()) 243 243 return; 244 244 updateKeyModifiers((InputEvent) event); … … 251 251 */ 252 252 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 253 if(!Main.map.mapView.is DrawableLayer())253 if(!Main.map.mapView.isActiveLayerDrawable()) 254 254 return; 255 255 computeHelperLine(); … … 288 288 if (e.getButton() != MouseEvent.BUTTON1) 289 289 return; 290 if(!Main.map.mapView.is DrawableLayer())290 if(!Main.map.mapView.isActiveLayerDrawable()) 291 291 return; 292 292 … … 576 576 577 577 @Override public void mouseMoved(MouseEvent e) { 578 if(!Main.map.mapView.is DrawableLayer())578 if(!Main.map.mapView.isActiveLayerDrawable()) 579 579 return; 580 580 … … 705 705 */ 706 706 @Override public void mouseExited(MouseEvent e) { 707 if(!Main.map.mapView.is DrawableLayer())707 if(!Main.map.mapView.isActiveLayerDrawable()) 708 708 return; 709 709 mousePos = e.getPoint(); -
trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
r1677 r1750 126 126 */ 127 127 @Override public void mouseDragged(MouseEvent e) { 128 if(!Main.map.mapView.is VisibleDrawableLayer())128 if(!Main.map.mapView.isActiveLayerVisible()) 129 129 return; 130 130 if (mode == Mode.select) return; … … 195 195 */ 196 196 @Override public void mousePressed(MouseEvent e) { 197 if(!Main.map.mapView.is VisibleDrawableLayer())197 if(!Main.map.mapView.isActiveLayerVisible()) 198 198 return; 199 199 if (!(Boolean)this.getValue("active")) return; … … 227 227 */ 228 228 @Override public void mouseReleased(MouseEvent e) { 229 if(!Main.map.mapView.is VisibleDrawableLayer())229 if(!Main.map.mapView.isActiveLayerVisible()) 230 230 return; 231 231 restoreCursor(); -
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r1725 r1750 96 96 public SelectAction(MapFrame mapFrame) { 97 97 super(tr("Select"), "move/move", tr("Select, move and rotate objects"), 98 Shortcut.registerShortcut("mapmode:select", tr("Mode: {0}", tr("Select")), KeyEvent.VK_S, Shortcut.GROUP_EDIT),99 mapFrame,100 getCursor("normal", "selection", Cursor.DEFAULT_CURSOR));98 Shortcut.registerShortcut("mapmode:select", tr("Mode: {0}", tr("Select")), KeyEvent.VK_S, Shortcut.GROUP_EDIT), 99 mapFrame, 100 getCursor("normal", "selection", Cursor.DEFAULT_CURSOR)); 101 101 putValue("help", "Action/Move/Move"); 102 102 selectionManager = new SelectionManager(this, false, mapFrame.mapView); … … 131 131 Main.map.mapView.addMouseListener(this); 132 132 Main.map.mapView.addMouseMotionListener(this); 133 Main.map.mapView. enableVirtualNodes(134 Main.pref.getInteger("mappaint.node.virtual-size", 8) != 0);133 Main.map.mapView.setVirtualNodesEnabled( 134 Main.pref.getInteger("mappaint.node.virtual-size", 8) != 0); 135 135 } 136 136 … … 140 140 Main.map.mapView.removeMouseListener(this); 141 141 Main.map.mapView.removeMouseMotionListener(this); 142 Main.map.mapView. enableVirtualNodes(false);142 Main.map.mapView.setVirtualNodesEnabled(false); 143 143 } 144 144 … … 149 149 */ 150 150 @Override public void mouseDragged(MouseEvent e) { 151 if(!Main.map.mapView.is VisibleDrawableLayer())151 if(!Main.map.mapView.isActiveLayerVisible()) 152 152 return; 153 153 … … 162 162 return; 163 163 164 if (mode == Mode.move) 164 if (mode == Mode.move) { 165 165 setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 166 } 166 167 167 168 if (mousePos == null) { … … 196 197 virtualCmds.add(new MoveCommand(virtualNode, dx, dy)); 197 198 String text = trn("Add and move a virtual new node to way", 198 "Add and move a virtual new node to {0} ways", virtualWays.size(),199 virtualWays.size());199 "Add and move a virtual new node to {0} ways", virtualWays.size(), 200 virtualWays.size()); 200 201 201 202 Main.main.undoRedo.add(new SequenceCommand(text, virtualCmds)); … … 214 215 215 216 Command c = !Main.main.undoRedo.commands.isEmpty() 216 217 if (c instanceof SequenceCommand) 217 ? Main.main.undoRedo.commands.getLast() : null; 218 if (c instanceof SequenceCommand) { 218 219 c = ((SequenceCommand)c).getLastCommand(); 220 } 219 221 220 222 if (mode == Mode.move) { 221 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand)c). objects))223 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand)c).getMovedNodes())) { 222 224 ((MoveCommand)c).moveAgain(dx,dy); 223 else225 } else { 224 226 Main.main.undoRedo.add( 225 c = new MoveCommand(selection, dx, dy)); 227 c = new MoveCommand(selection, dx, dy)); 228 } 226 229 227 230 for (Node n : affectedNodes) { … … 231 234 232 235 JOptionPane.showMessageDialog(Main.parent, 233 tr("Cannot move objects outside of the world."));236 tr("Cannot move objects outside of the world.")); 234 237 restoreCursor(); 235 238 return; … … 237 240 } 238 241 } else if (mode == Mode.rotate) { 239 if (c instanceof RotateCommand && affectedNodes.equals(((RotateCommand)c). objects))242 if (c instanceof RotateCommand && affectedNodes.equals(((RotateCommand)c).getRotatedNodes())) { 240 243 ((RotateCommand)c).rotateAgain(mouseStartEN, mouseEN); 241 else244 } else { 242 245 Main.main.undoRedo.add(new RotateCommand(selection, mouseStartEN, mouseEN)); 246 } 243 247 } 244 248 } … … 255 259 */ 256 260 @Override public void mouseMoved(MouseEvent e) { 257 if (needMouseMove && mode == Mode.rotate) 261 if (needMouseMove && mode == Mode.rotate) { 258 262 mouseDragged(e); 263 } 259 264 } 260 265 … … 271 276 { 272 277 Collection<WaySegment> nearestWaySegs = allSegements 273 274 : Collections.singleton(c.getNearestWaySegment(p));278 ? c.getNearestWaySegments(p) 279 : Collections.singleton(c.getNearestWaySegment(p)); 275 280 276 281 for(WaySegment nearestWS : nearestWaySegs) { 277 if (nearestWS == null) 282 if (nearestWS == null) { 278 283 continue; 284 } 279 285 280 286 osm = nearestWS.way; … … 294 300 if(virtualWayNode != null) { 295 301 if( !w.nodes.get(nearestWS.lowerIndex+1).equals(virtualWayNode) 296 && !w.nodes.get(nearestWS.lowerIndex ).equals(virtualWayNode))302 && !w.nodes.get(nearestWS.lowerIndex ).equals(virtualWayNode)) { 297 303 continue; 298 } else 304 } 305 } else { 299 306 virtualWayNode = w.nodes.get(nearestWS.lowerIndex+1); 307 } 300 308 301 309 virtualWays.add(nearestWS); 302 if(virtualNode == null) 310 if(virtualNode == null) { 303 311 virtualNode = new Node(Main.map.mapView.getLatLon(pc.x, pc.y)); 312 } 304 313 } 305 314 } … … 322 331 */ 323 332 @Override public void mousePressed(MouseEvent e) { 324 if(!Main.map.mapView.is VisibleDrawableLayer())333 if(!Main.map.mapView.isActiveLayerVisible()) 325 334 return; 326 335 … … 335 344 // We don't want to change to draw tool if the user tries to (de)select 336 345 // stuff but accidentally clicks in an empty area when selection is empty 337 if(shift || ctrl) 346 if(shift || ctrl) { 338 347 cancelDrawMode = true; 348 } 339 349 340 350 mouseDownTime = System.currentTimeMillis(); … … 345 355 346 356 if (ctrl && shift) { 347 if (Main.ds.getSelected().isEmpty()) selectPrims(osmColl, true, false, false, false); 357 if (Main.ds.getSelected().isEmpty()) { 358 selectPrims(osmColl, true, false, false, false); 359 } 348 360 mode = Mode.rotate; 349 361 setCursor(ImageProvider.getCursor("rotate", null)); … … 354 366 // move. 355 367 selectPrims(osmColl, 356 shift || Main.ds.getSelected().containsAll(osmColl),357 ctrl, false, false);368 shift || Main.ds.getSelected().containsAll(osmColl), 369 ctrl, false, false); 358 370 mode = Mode.move; 359 371 } else { … … 373 385 // Mode.move redraws when mouseDragged is called 374 386 // Mode.rotate redraws here 375 if(mode == Mode.rotate) 387 if(mode == Mode.rotate) { 376 388 Main.map.mapView.repaint(); 389 } 377 390 378 391 mousePos = e.getPoint(); … … 383 396 */ 384 397 @Override public void mouseReleased(MouseEvent e) { 385 if(!Main.map.mapView.is VisibleDrawableLayer())398 if(!Main.map.mapView.isActiveLayerVisible()) 386 399 return; 387 400 … … 402 415 if (!didMove) { 403 416 selectPrims( 404 Main.map.mapView.getNearestCollection(e.getPoint()),405 shift, ctrl, true, false);417 Main.map.mapView.getNearestCollection(e.getPoint()), 418 shift, ctrl, true, false); 406 419 407 420 // If the user double-clicked a node, change to draw mode … … 423 436 for (OsmPrimitive osm : selection) 424 437 { 425 if(osm instanceof Node) 438 if(osm instanceof Node) { 426 439 s.add(osm); 427 else if(osm instanceof Way)440 } else if(osm instanceof Way) 428 441 { 429 442 s.add(osm); … … 433 446 { 434 447 if(1 != new ExtendedDialog(Main.parent, tr("Move elements"), 435 tr("You did move more than {0} elements. "436 + "Moving a large number of elements is often an error.\n"437 + "Really move them?", max),438 new String[] {tr("Move them"), tr("Undo move")},439 new String[] {"reorder.png", "cancel.png"}).getValue())448 tr("You did move more than {0} elements. " 449 + "Moving a large number of elements is often an error.\n" 450 + "Really move them?", max), 451 new String[] {tr("Move them"), tr("Undo move")}, 452 new String[] {"reorder.png", "cancel.png"}).getValue()) 440 453 { 441 454 Main.main.undoRedo.undo(); … … 451 464 LinkedList<Node> selNodes = new LinkedList<Node>(); 452 465 for (OsmPrimitive osm : selection) 453 if (osm instanceof Node) 466 if (osm instanceof Node) { 454 467 selNodes.add((Node)osm); 468 } 455 469 if (selNodes.size() > 0) { 456 470 selNodes.add(n); … … 474 488 475 489 public void selectPrims(Collection<OsmPrimitive> selectionList, boolean shift, 476 boolean ctrl, boolean released, boolean area) {490 boolean ctrl, boolean released, boolean area) { 477 491 if ((shift && ctrl) || (ctrl && !released)) 478 492 return; // not allowed together 479 493 480 494 Collection<OsmPrimitive> curSel; 481 if (!ctrl && !shift) 495 if (!ctrl && !shift) { 482 496 curSel = new LinkedList<OsmPrimitive>(); // new selection will replace the old. 483 else497 } else { 484 498 curSel = Main.ds.getSelected(); 499 } 485 500 486 501 for (OsmPrimitive osm : selectionList) … … 488 503 if (ctrl) 489 504 { 490 if(curSel.contains(osm)) 505 if(curSel.contains(osm)) { 491 506 curSel.remove(osm); 492 else if(!area)507 } else if(!area) { 493 508 curSel.add(osm); 494 }495 else509 } 510 } else { 496 511 curSel.add(osm); 512 } 497 513 } 498 514 Main.ds.setSelected(curSel); … … 501 517 502 518 @Override public String getModeHelpText() { 503 if (mode == Mode.select) {519 if (mode == Mode.select) 504 520 return tr("Release the mouse button to select the objects in the rectangle."); 505 } else if (mode == Mode.move) {521 else if (mode == Mode.move) 506 522 return tr("Release the mouse button to stop moving. Ctrl to merge with nearest node."); 507 } else if (mode == Mode.rotate) {523 else if (mode == Mode.rotate) 508 524 return tr("Release the mouse button to stop rotating."); 509 } else {525 else 510 526 return tr("Move objects by dragging; Shift to add to selection (Ctrl to toggle); Shift-Ctrl to rotate selected; or change selection"); 511 }512 527 } 513 528 -
trunk/src/org/openstreetmap/josm/command/AddCommand.java
r1169 r1750 10 10 import javax.swing.tree.MutableTreeNode; 11 11 12 import org.openstreetmap.josm.Main;13 import org.openstreetmap.josm.data.osm.DataSet;14 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 13 import org.openstreetmap.josm.data.osm.visitor.AddVisitor; 16 14 import org.openstreetmap.josm.data.osm.visitor.DeleteVisitor; 17 15 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 18 import org.openstreetmap.josm.gui.layer.Layer;19 import org.openstreetmap.josm.gui.layer.OsmDataLayer;20 16 21 17 /** … … 23 19 * way. 24 20 * 25 * See {@ link ChangeCommandChangeCommand} for comments on relation back references.21 * See {@see ChangeCommand} for comments on relation back references. 26 22 * 27 23 * @author imi … … 34 30 private final OsmPrimitive osm; 35 31 36 private DataSet ds;37 38 32 /** 39 33 * Create the command and specify the element to add. 40 34 */ 41 35 public AddCommand(OsmPrimitive osm) { 36 super(); 42 37 this.osm = osm; 43 this.ds = Main.main.editLayer().data;44 38 } 45 39 46 40 @Override public boolean executeCommand() { 47 osm.visit(new AddVisitor( ds));41 osm.visit(new AddVisitor(getLayer().data)); 48 42 return true; 49 43 } 50 44 51 45 @Override public void undoCommand() { 52 osm.visit(new DeleteVisitor( ds));46 osm.visit(new DeleteVisitor(getLayer().data)); 53 47 } 54 48 … … 57 51 } 58 52 59 // faster implementation60 @Override public boolean invalidBecauselayerRemoved(Layer oldLayer) {61 return oldLayer instanceof OsmDataLayer && ((OsmDataLayer)oldLayer).data == ds;62 }63 64 53 @Override public MutableTreeNode description() { 65 54 NameVisitor v = new NameVisitor(); 66 55 osm.visit(v); 67 return new DefaultMutableTreeNode(new JLabel(tr("Add")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL)); 56 return new DefaultMutableTreeNode( 57 new JLabel(tr("Add {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL)); 68 58 } 69 59 } -
trunk/src/org/openstreetmap/josm/command/ChangeCommand.java
r1169 r1750 25 25 26 26 public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) { 27 super(); 27 28 this.osm = osm; 28 29 this.newOsm = newOsm; … … 43 44 NameVisitor v = new NameVisitor(); 44 45 osm.visit(v); 45 return new DefaultMutableTreeNode(new JLabel(tr("Change ")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL));46 return new DefaultMutableTreeNode(new JLabel(tr("Change {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL)); 46 47 } 47 48 } -
trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java
r1347 r1750 40 40 41 41 public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, String key, String value) { 42 super(); 42 43 this.objects = new LinkedList<OsmPrimitive>(); 43 44 this.key = key; … … 45 46 if (value == null) { 46 47 for (OsmPrimitive osm : objects) { 47 if(osm.get(key) != null) 48 if(osm.get(key) != null) { 48 49 this.objects.add(osm); 50 } 49 51 } 50 52 } else { … … 64 66 String val = object.get(key); 65 67 if ((value == null && val != null) 66 || (value != null && (val == null || !value.equals(val))))68 || (value != null && (val == null || !value.equals(val)))) { 67 69 this.objects.add(object); 70 } 68 71 } 69 72 … … 95 98 text = value == null 96 99 ? tr("Remove \"{0}\" for {1} ''{2}''", key, tr(v.className), v.name) 97 : tr("Set {0}={1} for {2} ''{3}''",key,value, tr(v.className), v.name);100 : tr("Set {0}={1} for {2} ''{3}''",key,value, tr(v.className), v.name); 98 101 } 99 102 else … … 101 104 text = value == null 102 105 ? tr("Remove \"{0}\" for {1} {2}", key, objects.size(), trn("object","objects",objects.size())) 103 : tr("Set {0}={1} for {2} {3}",key,value, objects.size(), trn("object","objects",objects.size()));106 : tr("Set {0}={1} for {2} {3}",key,value, objects.size(), trn("object","objects",objects.size())); 104 107 } 105 108 DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JLabel(text, ImageProvider.get("data", "key"), JLabel.HORIZONTAL)); -
trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java
r1617 r1750 13 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 14 import org.openstreetmap.josm.data.osm.Relation; 15 import org.openstreetmap.josm.data.osm.RelationMember;16 17 15 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 18 16 … … 36 34 37 35 public ChangeRelationMemberRoleCommand(Relation relation, int position, String newRole) { 36 super(); 38 37 this.relation = relation; 39 38 this.position = position; … … 67 66 NameVisitor v = new NameVisitor(); 68 67 relation.visit(v); 69 return new DefaultMutableTreeNode(new JLabel(tr("ChangeRelationMemberRole ")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL));68 return new DefaultMutableTreeNode(new JLabel(tr("ChangeRelationMemberRole {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL)); 70 69 } 71 70 } -
trunk/src/org/openstreetmap/josm/command/Command.java
r1523 r1750 11 11 12 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.data.osm.DataSet;14 13 import org.openstreetmap.josm.data.osm.Node; 15 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 25 24 * one atomic action on a specific dataset, such as move or delete. 26 25 * 27 * Remember that the command must be executable and undoable, even if the 28 * Main.ds has changed, so the command must save the dataset it operates on 29 * if necessary. 30 * 26 * The command remembers the {@see OsmDataLayer} it is operating on. 27 * 31 28 * @author imi 32 29 */ 33 30 abstract public class Command { 34 31 35 private static final class CloneVisitor extends AbstractVisitor {36 public Map<OsmPrimitive, OsmPrimitive> orig = new HashMap<OsmPrimitive, OsmPrimitive>();32 private static final class CloneVisitor extends AbstractVisitor { 33 public Map<OsmPrimitive, OsmPrimitive> orig = new HashMap<OsmPrimitive, OsmPrimitive>(); 37 34 38 public void visit(Node n) {39 orig.put(n, new Node(n));40 }41 public void visit(Way w) {42 orig.put(w, new Way(w));43 }44 public void visit(Relation e) {45 orig.put(e, new Relation(e));46 }47 }35 public void visit(Node n) { 36 orig.put(n, new Node(n)); 37 } 38 public void visit(Way w) { 39 orig.put(w, new Way(w)); 40 } 41 public void visit(Relation e) { 42 orig.put(e, new Relation(e)); 43 } 44 } 48 45 49 private CloneVisitor orig; 46 /** the map of OsmPrimitives in the original state to OsmPrimitives in cloned state */ 47 private Map<OsmPrimitive, OsmPrimitive> cloneMap = new HashMap<OsmPrimitive, OsmPrimitive>(); 50 48 51 protected DataSet ds; 49 /** the layer which this command is applied to */ 50 private OsmDataLayer layer; 52 51 53 public Command() {54 this.ds = Main.main.editLayer().data;55 }56 /**57 * Executes the command on the dataset. This implementation will remember all58 * primitives returned by fillModifiedData for restoring them on undo.59 */60 public boolean did_execute = false;61 public boolean executeCommand() {62 did_execute = true;63 orig = new CloneVisitor();64 Collection<OsmPrimitive> all = new HashSet<OsmPrimitive>();65 fillModifiedData(all, all, all);66 for (OsmPrimitive osm : all)67 osm.visit(orig);68 return true;69 }52 public Command() { 53 this.layer = Main.main.map.mapView.getEditLayer(); 54 } 55 /** 56 * Executes the command on the dataset. This implementation will remember all 57 * primitives returned by fillModifiedData for restoring them on undo. 58 */ 59 public boolean executeCommand() { 60 CloneVisitor visitor = new CloneVisitor(); 61 Collection<OsmPrimitive> all = new HashSet<OsmPrimitive>(); 62 fillModifiedData(all, all, all); 63 for (OsmPrimitive osm : all) { 64 osm.visit(visitor); 65 } 66 cloneMap = visitor.orig; 67 return true; 68 } 70 69 71 /** 72 * Undoes the command. 73 * It can be assumed that all objects are in the same state they were before. 74 * It can also be assumed that executeCommand was called exactly once before. 75 * 76 * This implementation undoes all objects stored by a former call to executeCommand. 77 */ 78 public void undoCommand() { 79 for (Entry<OsmPrimitive, OsmPrimitive> e : orig.orig.entrySet()) 80 e.getKey().cloneFrom(e.getValue()); 81 } 70 /** 71 * Undoes the command. 72 * It can be assumed that all objects are in the same state they were before. 73 * It can also be assumed that executeCommand was called exactly once before. 74 * 75 * This implementation undoes all objects stored by a former call to executeCommand. 76 */ 77 public void undoCommand() { 78 for (Entry<OsmPrimitive, OsmPrimitive> e : cloneMap.entrySet()) { 79 e.getKey().cloneFrom(e.getValue()); 80 } 81 } 82 82 83 /** 84 * Called when a layer has been removed to have the command remove itself from 85 * any buffer if it is not longer applicable to the dataset (e.g. it was part of 86 * the removed layer) 87 */ 88 public boolean invalidBecauselayerRemoved(Layer oldLayer) { 89 if (!(oldLayer instanceof OsmDataLayer)) 90 return false; 91 HashSet<OsmPrimitive> modified = new HashSet<OsmPrimitive>(); 92 fillModifiedData(modified, modified, modified); 93 if (modified.isEmpty()) 94 return false; 95 96 HashSet<OsmPrimitive> all = new HashSet<OsmPrimitive>(((OsmDataLayer)oldLayer).data.allPrimitives()); 97 for (OsmPrimitive osm : all) 98 if (all.contains(osm)) 99 return true; 100 101 return false; 102 } 83 /** 84 * Called when a layer has been removed to have the command remove itself from 85 * any buffer if it is not longer applicable to the dataset (e.g. it was part of 86 * the removed layer) 87 * 88 * @param oldLayer the old layer 89 * @return true if this command 90 */ 91 public boolean invalidBecauselayerRemoved(Layer oldLayer) { 92 if (!(oldLayer instanceof OsmDataLayer)) 93 return false; 94 return layer == oldLayer; 95 } 103 96 104 97 /** … … 107 100 */ 108 101 public OsmPrimitive getOrig(OsmPrimitive osm) { 109 OsmPrimitive o = orig.orig.get(osm);102 OsmPrimitive o = cloneMap.get(osm); 110 103 if (o != null) 111 104 return o; 112 105 Main.debug("unable to find osm with id: " + osm.id + " hashCode: " + osm.hashCode()); 113 for (OsmPrimitive t : orig.orig.keySet()) {114 OsmPrimitive to = orig.orig.get(t);115 116 106 for (OsmPrimitive t : cloneMap.keySet()) { 107 OsmPrimitive to = cloneMap.get(t); 108 Main.debug("now: " + t.id + " hashCode: " + t.hashCode()); 109 Main.debug("orig: " + to.id + " hashCode: " + to.hashCode()); 117 110 } 118 111 return o; 119 112 } 120 113 121 /** 122 * Fill in the changed data this command operates on. 123 * Add to the lists, don't clear them. 124 * 125 * @param modified The modified primitives 126 * @param deleted The deleted primitives 127 * @param added The added primitives 128 */ 129 abstract public void fillModifiedData(Collection<OsmPrimitive> modified, 130 Collection<OsmPrimitive> deleted, 131 Collection<OsmPrimitive> added); 114 /** 115 * Replies the layer this command is (or was) applied to. 116 * 117 * @return 118 */ 119 protected OsmDataLayer getLayer() { 120 return layer; 121 } 132 122 133 abstract public MutableTreeNode description(); 123 /** 124 * Fill in the changed data this command operates on. 125 * Add to the lists, don't clear them. 126 * 127 * @param modified The modified primitives 128 * @param deleted The deleted primitives 129 * @param added The added primitives 130 */ 131 abstract public void fillModifiedData(Collection<OsmPrimitive> modified, 132 Collection<OsmPrimitive> deleted, 133 Collection<OsmPrimitive> added); 134 135 abstract public MutableTreeNode description(); 136 137 138 134 139 } -
trunk/src/org/openstreetmap/josm/command/CoordinateConflictResolveCommand.java
r1670 r1750 10 10 import javax.swing.tree.MutableTreeNode; 11 11 12 import org.openstreetmap.josm. Main;12 import org.openstreetmap.josm.data.conflict.Conflict; 13 13 import org.openstreetmap.josm.data.osm.Node; 14 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 import org.openstreetmap.josm.data.osm.Relation;16 import org.openstreetmap.josm.data.osm.Way;17 15 import org.openstreetmap.josm.gui.conflict.MergeDecisionType; 18 16 import org.openstreetmap.josm.tools.ImageProvider; … … 22 20 * 23 21 */ 24 public class CoordinateConflictResolveCommand extends Co mmand {22 public class CoordinateConflictResolveCommand extends ConflictResolveCommand { 25 23 26 /** my node (in the local dataset). merge decisions are applied to this 27 * node 28 */ 29 private final Node my; 30 /** their node (in the server dataset) */ 31 private final Node their; 24 /** the conflict to resolve */ 25 private Conflict<Node> conflict; 32 26 33 27 /** the merge decision */ … … 42 36 */ 43 37 public CoordinateConflictResolveCommand(Node my, Node their, MergeDecisionType decision) { 44 this.my = my; 45 this.their = their; 38 this.conflict = new Conflict<Node>(my,their); 46 39 this.decision = decision; 47 40 } … … 52 45 return new DefaultMutableTreeNode( 53 46 new JLabel( 54 tr("Resolve conflicts in coordinates in {0}", my.id),47 tr("Resolve conflicts in coordinates in {0}",conflict.getMy().id), 55 48 ImageProvider.get("data", "object"), 56 49 JLabel.HORIZONTAL … … 69 62 // do nothing 70 63 } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) { 64 Node my = conflict.getMy(); 65 Node their = conflict.getTheir(); 71 66 my.setCoor(their.getCoor()); 72 67 } else 73 68 // should not happen 74 69 throw new IllegalStateException(tr("cannot resolve undecided conflict")); 70 71 // remember the layer this command was applied to 72 // 73 rememberConflict(conflict); 75 74 76 75 return true; … … 80 79 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 81 80 Collection<OsmPrimitive> added) { 82 modified.add(my); 83 } 84 85 @Override 86 public void undoCommand() { 87 // restore former state of modified primitives 88 // 89 super.undoCommand(); 90 91 // restore a conflict if necessary 92 // 93 if (!Main.map.conflictDialog.conflicts.containsKey(my)) { 94 Main.map.conflictDialog.addConflict(my, their); 95 } 81 modified.add(conflict.getMy()); 96 82 } 97 83 } -
trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
r1656 r1750 42 42 43 43 /** 44 * The primitive that get deleted.45 */ 46 private final Collection<? extends OsmPrimitive> data;44 * The primitives that get deleted. 45 */ 46 private final Collection<? extends OsmPrimitive> toDelete; 47 47 48 48 /** … … 50 50 */ 51 51 public DeleteCommand(Collection<? extends OsmPrimitive> data) { 52 this.data = data; 52 super(); 53 this.toDelete = data; 53 54 } 54 55 … … 58 59 */ 59 60 public DeleteCommand(OsmPrimitive data) { 60 this. data= Collections.singleton(data);61 this.toDelete = Collections.singleton(data); 61 62 } 62 63 63 64 @Override public boolean executeCommand() { 64 65 super.executeCommand(); 65 for (OsmPrimitive osm : data) {66 for (OsmPrimitive osm : toDelete) { 66 67 osm.delete(true); 67 68 } … … 71 72 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 72 73 Collection<OsmPrimitive> added) { 73 deleted.addAll( data);74 deleted.addAll(toDelete); 74 75 } 75 76 … … 77 78 NameVisitor v = new NameVisitor(); 78 79 79 if ( data.size() == 1) {80 data.iterator().next().visit(v);80 if (toDelete.size() == 1) { 81 toDelete.iterator().next().visit(v); 81 82 return new DefaultMutableTreeNode(new JLabel(tr("Delete {1} {0}", v.name, tr(v.className)), v.icon, 82 83 JLabel.HORIZONTAL)); … … 85 86 String cname = null; 86 87 String cnamem = null; 87 for (OsmPrimitive osm : data) {88 for (OsmPrimitive osm : toDelete) { 88 89 osm.visit(v); 89 90 if (cname == null) { … … 95 96 } 96 97 } 97 DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JLabel(tr("Delete {0} {1}", data.size(), trn(98 cname, cnamem, data.size())), ImageProvider.get("data", cname), JLabel.HORIZONTAL));99 for (OsmPrimitive osm : data) {98 DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JLabel(tr("Delete {0} {1}", toDelete.size(), trn( 99 cname, cnamem, toDelete.size())), ImageProvider.get("data", cname), JLabel.HORIZONTAL)); 100 for (OsmPrimitive osm : toDelete) { 100 101 osm.visit(v); 101 102 root.add(new DefaultMutableTreeNode(v.toLabel())); … … 276 277 Relation rel = new Relation(cur); 277 278 for (OsmPrimitive osm : relationsToBeChanged.get(cur)) { 278 for (RelationMember rm : rel.members) { 279 if (rm.member == osm) { 280 RelationMember mem = new RelationMember(); 281 mem.role = rm.role; 282 mem.member = rm.member; 283 rel.members.remove(mem); 284 break; 285 } 286 } 279 rel.removeMembersFor(osm); 287 280 } 288 281 cmds.add(new ChangeCommand(cur, rel)); -
trunk/src/org/openstreetmap/josm/command/DeletedStateConflictResolveCommand.java
r1690 r1750 10 10 import javax.swing.tree.MutableTreeNode; 11 11 12 import org.openstreetmap.josm. Main;12 import org.openstreetmap.josm.data.conflict.Conflict; 13 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 14 import org.openstreetmap.josm.gui.conflict.MergeDecisionType; 15 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 15 16 import org.openstreetmap.josm.tools.ImageProvider; 16 17 … … 19 20 * 20 21 */ 21 public class DeletedStateConflictResolveCommand extends Co mmand {22 public class DeletedStateConflictResolveCommand extends ConflictResolveCommand { 22 23 23 /** my primitive (in the local dataset). merge decisions are applied to this 24 * node 25 */ 26 private final OsmPrimitive my; 27 /** their primitive (in the server dataset) */ 28 private final OsmPrimitive their; 24 /** the conflict to resolve */ 25 private Conflict<OsmPrimitive> conflict; 29 26 30 27 /** the merge decision */ 31 28 private final MergeDecisionType decision; 32 33 34 29 35 30 /** … … 41 36 */ 42 37 public DeletedStateConflictResolveCommand(OsmPrimitive my, OsmPrimitive their, MergeDecisionType decision) { 43 this.my = my; 44 this.their = their; 38 this.conflict = new Conflict<OsmPrimitive>(my, their); 45 39 this.decision = decision; 46 40 } … … 51 45 return new DefaultMutableTreeNode( 52 46 new JLabel( 53 tr("Resolve conflicts in deleted state in {0}", my.id),47 tr("Resolve conflicts in deleted state in {0}",conflict.getMy().id), 54 48 ImageProvider.get("data", "object"), 55 49 JLabel.HORIZONTAL … … 65 59 super.executeCommand(); 66 60 61 OsmDataLayer layer = getLayer(); 62 67 63 if (decision.equals(MergeDecisionType.KEEP_MINE)) { 68 if ( my.deleted) {64 if (conflict.getMy().deleted) { 69 65 // because my was involved in a conflict it my still be referred 70 66 // to from a way or a relation. Fix this now. 71 67 // 72 Main.main.editLayer().data.unlinkReferencesToPrimitive(my);68 layer.data.unlinkReferencesToPrimitive(conflict.getMy()); 73 69 } 74 70 } else if (decision.equals(MergeDecisionType.KEEP_THEIR)) { 75 if ( their.deleted) {76 Main.main.editLayer().data.unlinkReferencesToPrimitive(my);77 my.delete(true);71 if (conflict.getTheir().deleted) { 72 layer.data.unlinkReferencesToPrimitive(conflict.getMy()); 73 conflict.getMy().delete(true); 78 74 } else { 79 my.deleted = their.deleted;75 conflict.getMy().deleted = conflict.getTheir().deleted; 80 76 } 81 77 } else … … 83 79 throw new IllegalStateException(tr("cannot resolve undecided conflict")); 84 80 81 rememberConflict(conflict); 85 82 return true; 86 83 } … … 89 86 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 90 87 Collection<OsmPrimitive> added) { 91 modified.add(my); 92 } 93 94 @Override 95 public void undoCommand() { 96 // restore former state of modified primitives 97 // 98 super.undoCommand(); 99 100 // restore a conflict if necessary 101 // 102 if (!Main.map.conflictDialog.conflicts.containsKey(my)) { 103 Main.map.conflictDialog.addConflict(my, their); 104 } 88 modified.add(conflict.getMy()); 105 89 } 106 90 } -
trunk/src/org/openstreetmap/josm/command/MoveCommand.java
r1728 r1750 15 15 import javax.swing.tree.MutableTreeNode; 16 16 17 import org.openstreetmap.josm.data.coor.EastNorth;18 17 import org.openstreetmap.josm.data.coor.LatLon; 19 18 import org.openstreetmap.josm.data.osm.Node; … … 32 31 * The objects that should be moved. 33 32 */ 34 p ublic Collection<Node> objects = new LinkedList<Node>();33 private Collection<Node> nodes = new LinkedList<Node>(); 35 34 /** 36 35 * x difference movement. Coordinates are in northern/eastern … … 64 63 */ 65 64 public MoveCommand(Collection<OsmPrimitive> objects, double x, double y) { 65 super(); 66 66 this.x = x; 67 67 this.y = y; 68 this. objects = AllNodesVisitor.getAllNodes(objects);69 for (Node n : this. objects) {68 this.nodes = AllNodesVisitor.getAllNodes(objects); 69 for (Node n : this.nodes) { 70 70 OldState os = new OldState(); 71 71 os.latlon = new LatLon(n.getCoor()); … … 84 84 */ 85 85 public void moveAgain(double x, double y) { 86 for (Node n : objects) {86 for (Node n : nodes) { 87 87 n.setEastNorth(n.getEastNorth().add(x, y)); 88 88 } … … 92 92 93 93 @Override public boolean executeCommand() { 94 for (Node n : objects) {94 for (Node n : nodes) { 95 95 n.setEastNorth(n.getEastNorth().add(x, y)); 96 96 n.modified = true; … … 101 101 @Override public void undoCommand() { 102 102 Iterator<OldState> it = oldState.iterator(); 103 for (Node n : objects) {103 for (Node n : nodes) { 104 104 OldState os = it.next(); 105 105 n.setCoor(os.latlon); … … 109 109 110 110 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 111 for (OsmPrimitive osm : objects)111 for (OsmPrimitive osm : nodes) { 112 112 modified.add(osm); 113 } 113 114 } 114 115 115 116 @Override public MutableTreeNode description() { 116 return new DefaultMutableTreeNode(new JLabel(tr("Move")+" "+objects.size()+" "+trn("node","nodes",objects.size()), ImageProvider.get("data", "node"), JLabel.HORIZONTAL)); 117 return new DefaultMutableTreeNode(new JLabel(tr("Move")+" "+nodes.size()+" "+trn("node","nodes",nodes.size()), ImageProvider.get("data", "node"), JLabel.HORIZONTAL)); 118 } 119 120 public Collection<Node> getMovedNodes() { 121 return nodes; 117 122 } 118 123 } -
trunk/src/org/openstreetmap/josm/command/PurgePrimitivesCommand.java
r1690 r1750 6 6 import java.util.ArrayList; 7 7 import java.util.Collection; 8 import java.util.HashMap;9 8 import java.util.List; 10 import java.util. Map;9 import java.util.logging.Logger; 11 10 12 11 import javax.swing.JLabel; … … 15 14 16 15 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm.data.conflict.ConflictCollection; 17 17 import org.openstreetmap.josm.data.osm.DataSet; 18 18 import org.openstreetmap.josm.data.osm.Node; … … 21 21 import org.openstreetmap.josm.data.osm.RelationMember; 22 22 import org.openstreetmap.josm.data.osm.Way; 23 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 23 24 import org.openstreetmap.josm.tools.ImageProvider; 24 25 … … 34 35 * 35 36 */ 36 public class PurgePrimitivesCommand extends Command{ 37 37 public class PurgePrimitivesCommand extends ConflictResolveCommand{ 38 39 static private final Logger logger = Logger.getLogger(PurgePrimitivesCommand.class.getName()); 38 40 39 41 /** … … 144 146 private ArrayList<OsmParentChildPair> pairs; 145 147 146 private Map<OsmPrimitive, OsmPrimitive> resolvedConflicts;147 148 148 149 /** … … 154 155 purgedPrimitives = new ArrayList<OsmPrimitive>(); 155 156 pairs = new ArrayList<OsmParentChildPair>(); 156 resolvedConflicts = new HashMap<OsmPrimitive, OsmPrimitive>();157 157 } 158 158 … … 219 219 purge(toPurge, Main.ds, hive); 220 220 if (toPurge instanceof Node) { 221 Main.ds.nodes.remove(toPurge);221 getLayer().data.nodes.remove(toPurge); 222 222 } else if (primitive instanceof Way) { 223 Main.ds.ways.remove(toPurge);223 getLayer().data.ways.remove(toPurge); 224 224 } else if (primitive instanceof Relation) { 225 Main.ds.relations.remove(toPurge);225 getLayer().data.relations.remove(toPurge); 226 226 } 227 227 purgedPrimitives.add(toPurge); 228 if (Main.map.conflictDialog.conflicts.containsKey(toPurge)) { 229 resolvedConflicts.put(toPurge, Main.map.conflictDialog.conflicts.get(toPurge)); 230 Main.map.conflictDialog.removeConflictForPrimitive(toPurge); 228 ConflictCollection conflicts = getLayer().getConflicts(); 229 if (conflicts.hasConflictForMy(toPurge)) { 230 rememberConflict(conflicts.getConflictForMy(toPurge)); 231 conflicts.remove(toPurge); 231 232 } 232 233 } … … 246 247 @Override 247 248 public void undoCommand() { 249 if (! Main.map.mapView.hasLayer(getLayer())) { 250 logger.warning(tr("Can't undo command ''{0}'' because layer ''{1}'' is not present anymore", 251 this.toString(), 252 getLayer().toString() 253 )); 254 return; 255 } 256 Main.map.mapView.setActiveLayer(getLayer()); 248 257 249 258 // restore purged primitives 250 259 // 251 260 for (OsmPrimitive purged : purgedPrimitives) { 252 Main.ds.addPrimitive(purged); 253 } 254 255 // restore conflicts 256 // 257 for (OsmPrimitive primitive : resolvedConflicts.keySet()) { 258 Main.map.conflictDialog.addConflict(primitive, resolvedConflicts.get(primitive)); 259 } 260 261 getLayer().data.addPrimitive(purged); 262 } 263 reconstituteConflicts(); 261 264 // will restore the former references to the purged nodes 262 265 // -
trunk/src/org/openstreetmap/josm/command/RelationMemberConflictResolverCommand.java
r1676 r1750 6 6 import java.util.Collection; 7 7 import java.util.List; 8 import java.util.logging.Logger; 8 9 9 10 import javax.swing.JLabel; … … 15 16 import org.openstreetmap.josm.data.osm.Relation; 16 17 import org.openstreetmap.josm.data.osm.RelationMember; 18 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 17 19 import org.openstreetmap.josm.tools.ImageProvider; 18 20 … … 23 25 */ 24 26 public class RelationMemberConflictResolverCommand extends Command { 27 private static final Logger logger = Logger.getLogger(RelationMemberConflictResolverCommand.class.getName()); 25 28 26 29 /** my relation */ … … 32 35 */ 33 36 private final List<RelationMember> mergedMembers; 37 38 /** the layer this conflict is resolved in */ 39 private OsmDataLayer layer; 34 40 35 41 /** … … 71 77 my.members.add(n); 72 78 } 79 80 // remember the layer 81 layer = Main.main.map.mapView.getEditLayer(); 73 82 return true; 74 83 } … … 82 91 @Override 83 92 public void undoCommand() { 93 if (! Main.map.mapView.hasLayer(layer)) { 94 logger.warning(tr("Can't undo command ''{0}'' because layer ''{1}'' is not present anymore", 95 this.toString(), 96 layer.toString() 97 )); 98 return; 99 } 100 101 Main.map.mapView.setActiveLayer(layer); 102 OsmDataLayer editLayer = Main.map.mapView.getEditLayer(); 103 84 104 // restore the former state 85 105 // … … 88 108 // restore a conflict if necessary 89 109 // 90 if (! Main.map.conflictDialog.conflicts.containsKey(my)) {91 Main.map.conflictDialog.conflicts.put(my,their);110 if (!editLayer.getConflicts().hasConflictForMy(my)) { 111 editLayer.getConflicts().add(my,their); 92 112 } 93 113 } -
trunk/src/org/openstreetmap/josm/command/RemoveRelationMemberCommand.java
r630 r1750 64 64 NameVisitor v = new NameVisitor(); 65 65 relation.visit(v); 66 return new DefaultMutableTreeNode(new JLabel(tr("RemoveRelationMember ")+" "+tr(v.className)+" "+v.name, v.icon, JLabel.HORIZONTAL));66 return new DefaultMutableTreeNode(new JLabel(tr("RemoveRelationMember {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL)); 67 67 } 68 68 } -
trunk/src/org/openstreetmap/josm/command/RotateCommand.java
r1728 r1750 30 30 * The objects to rotate. 31 31 */ 32 p ublic Collection<Node> objects = new LinkedList<Node>();32 private Collection<Node> nodes = new LinkedList<Node>(); 33 33 34 34 /** … … 70 70 public RotateCommand(Collection<OsmPrimitive> objects, EastNorth start, EastNorth end) { 71 71 72 this. objects = AllNodesVisitor.getAllNodes(objects);72 this.nodes = AllNodesVisitor.getAllNodes(objects); 73 73 pivot = new EastNorth(0,0); 74 74 75 for (Node n : this. objects) {75 for (Node n : this.nodes) { 76 76 OldState os = new OldState(); 77 77 os.latlon = new LatLon(n.getCoor()); … … 81 81 pivot = pivot.add(os.eastNorth.east(), os.eastNorth.north()); 82 82 } 83 pivot = new EastNorth(pivot.east()/this. objects.size(), pivot.north()/this.objects.size());83 pivot = new EastNorth(pivot.east()/this.nodes.size(), pivot.north()/this.nodes.size()); 84 84 85 85 rotationAngle = Math.PI/2; … … 105 105 */ 106 106 private void rotateNodes(boolean setModified) { 107 for (Node n : objects) {107 for (Node n : nodes) { 108 108 double cosPhi = Math.cos(rotationAngle); 109 109 double sinPhi = Math.sin(rotationAngle); … … 114 114 double ny = -cosPhi * x + sinPhi * y + pivot.north(); 115 115 n.setEastNorth(new EastNorth(nx, ny)); 116 if (setModified) 116 if (setModified) { 117 117 n.modified = true; 118 } 118 119 } 119 120 } … … 125 126 126 127 @Override public void undoCommand() { 127 for (Node n : objects) {128 for (Node n : nodes) { 128 129 OldState os = oldState.get(n); 129 130 n.setCoor(os.latlon); … … 133 134 134 135 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 135 for (OsmPrimitive osm : objects)136 for (OsmPrimitive osm : nodes) { 136 137 modified.add(osm); 138 } 137 139 } 138 140 139 141 @Override public MutableTreeNode description() { 140 return new DefaultMutableTreeNode(new JLabel(tr("Rotate")+" "+objects.size()+" "+trn("node","nodes",objects.size()), ImageProvider.get("data", "node"), JLabel.HORIZONTAL)); 142 return new DefaultMutableTreeNode(new JLabel(tr("Rotate {0} {1}",nodes.size(),trn("node","nodes",nodes.size())), ImageProvider.get("data", "node"), JLabel.HORIZONTAL)); 143 } 144 145 public Collection<Node> getRotatedNodes() { 146 return nodes; 141 147 } 142 148 } -
trunk/src/org/openstreetmap/josm/command/SequenceCommand.java
r1169 r1750 33 33 */ 34 34 public SequenceCommand(String name, Collection<Command> sequenz) { 35 super(); 35 36 this.name = name; 36 37 this.sequence = new Command[sequenz.size()]; … … 45 46 } 46 47 47 public int executed_commands = 0;48 48 @Override public boolean executeCommand() { 49 49 for (int i=0; i < sequence.length; i++) { 50 50 Command c = sequence[i]; 51 51 boolean result = c.executeCommand(); 52 if (!result) 52 if (!result) { 53 53 Main.debug("SequenceCommand, executing command[" + i + "] " + c + " result: " + result); 54 } 54 55 if (!result && !continueOnError) { 55 56 this.undoCommands(i-1); … … 72 73 if (!sequence_complete) 73 74 return; 74 for (int i = start; i >= 0; --i) 75 for (int i = start; i >= 0; --i) { 75 76 sequence[i].undoCommand(); 77 } 76 78 } 77 79 … … 81 83 82 84 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 83 for (Command c : sequence) 85 for (Command c : sequence) { 84 86 c.fillModifiedData(modified, deleted, added); 87 } 85 88 } 86 89 87 90 @Override public MutableTreeNode description() { 88 91 DefaultMutableTreeNode root = new DefaultMutableTreeNode(tr("Sequence")+": "+name); 89 for (Command c : sequence) 92 for (Command c : sequence) { 90 93 root.add(c.description()); 94 } 91 95 return root; 92 96 } -
trunk/src/org/openstreetmap/josm/command/TagConflictResolveCommand.java
r1670 r1750 6 6 import java.util.Collection; 7 7 import java.util.List; 8 import java.util.logging.Logger; 8 9 9 10 import javax.swing.JLabel; … … 11 12 import javax.swing.tree.MutableTreeNode; 12 13 13 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.data.osm.Node; 14 import org.openstreetmap.josm.data.conflict.Conflict; 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 17 import org.openstreetmap.josm.data.osm.Relation;18 import org.openstreetmap.josm.data.osm.Way;19 17 import org.openstreetmap.josm.gui.conflict.MergeDecisionType; 20 18 import org.openstreetmap.josm.gui.conflict.tags.TagMergeItem; … … 25 23 * 26 24 */ 27 public class TagConflictResolveCommand extends Command { 25 public class TagConflictResolveCommand extends ConflictResolveCommand { 26 private static final Logger logger = Logger.getLogger(TagConflictResolveCommand.class.getName()); 28 27 29 /** my primitive (in the local dataset). merge decisions are applied to this 30 * primitive 31 */ 32 private final OsmPrimitive my; 33 /** their primitive (in the server dataset) */ 34 private final OsmPrimitive their; 28 29 /** the conflict to resolve */ 30 private Conflict<OsmPrimitive> conflict; 35 31 36 32 /** the list of merge decisions, represented as {@see TagMergeItem}s */ 37 33 private final List<TagMergeItem> mergeItems; 34 38 35 39 36 /** … … 60 57 */ 61 58 public TagConflictResolveCommand(OsmPrimitive my, OsmPrimitive their, List<TagMergeItem> mergeItems) { 62 this.my = my; 63 this.their = their; 59 this.conflict = new Conflict<OsmPrimitive>(my,their); 64 60 this.mergeItems = mergeItems; 65 61 } … … 70 66 return new DefaultMutableTreeNode( 71 67 new JLabel( 72 tr("Resolve {0} tag conflicts in {1} {2}",getNumDecidedConflicts(), OsmPrimitiveType.from( my).getLocalizedDisplayNameSingular(), my.id),68 tr("Resolve {0} tag conflicts in {1} {2}",getNumDecidedConflicts(), OsmPrimitiveType.from(conflict.getMy()).getLocalizedDisplayNameSingular(), conflict.getMy().id), 73 69 ImageProvider.get("data", "object"), 74 70 JLabel.HORIZONTAL … … 88 84 for (TagMergeItem item: mergeItems) { 89 85 if (! item.getMergeDecision().equals(MergeDecisionType.UNDECIDED)) { 90 item.applyToMyPrimitive( my);86 item.applyToMyPrimitive(conflict.getMy()); 91 87 } 92 88 } 89 rememberConflict(conflict); 93 90 return true; 94 91 } … … 97 94 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 98 95 Collection<OsmPrimitive> added) { 99 modified.add(my); 100 } 101 102 @Override 103 public void undoCommand() { 104 // restore former state of modified primitives 105 // 106 super.undoCommand(); 107 108 // restore a conflict if necessary 109 // 110 if (!Main.map.conflictDialog.conflicts.containsKey(my)) { 111 Main.map.conflictDialog.addConflict(my, their); 112 } 96 modified.add(conflict.getMy()); 113 97 } 114 98 } -
trunk/src/org/openstreetmap/josm/command/UndeletePrimitivesCommand.java
r1690 r1750 6 6 import java.util.ArrayList; 7 7 import java.util.Collection; 8 import java.util.HashMap; 9 import java.util.Map; 8 import java.util.logging.Logger; 10 9 11 10 import javax.swing.JLabel; … … 15 14 import org.openstreetmap.josm.Main; 16 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 17 17 import org.openstreetmap.josm.tools.ImageProvider; 18 18 19 19 /** 20 * Represents a command for undeleting a nodewhich was deleted on the server.20 * Represents a command for undeleting an {@see OsmPrimitive} which was deleted on the server. 21 21 * The command remembers the former node id and sets the node id to 0. This turns 22 22 * the node into a new node which can be uploaded to the server. 23 23 * 24 24 */ 25 public class UndeletePrimitivesCommand extends Command { 25 public class UndeletePrimitivesCommand extends ConflictResolveCommand { 26 static private final Logger logger = Logger.getLogger(UndeletePrimitivesCommand.class.getName()); 26 27 27 28 /** the node to undelete */ 28 29 private ArrayList<OsmPrimitive> toUndelete; 29 private Map<OsmPrimitive,OsmPrimitive> resolvedConflicts;30 30 31 31 protected UndeletePrimitivesCommand() { 32 32 toUndelete = new ArrayList<OsmPrimitive>(); 33 resolvedConflicts = new HashMap<OsmPrimitive, OsmPrimitive>();34 33 } 35 34 /** … … 77 76 public boolean executeCommand() { 78 77 super.executeCommand(); 78 79 79 for(OsmPrimitive primitive: toUndelete) { 80 if (Main.map.conflictDialog.conflicts.containsKey(primitive)) {81 re solvedConflicts.put(primitive, Main.map.conflictDialog.conflicts.get(primitive));82 Main.map.conflictDialog.removeConflictForPrimitive(primitive);80 if(getLayer().getConflicts().hasConflictForMy(primitive)) { 81 rememberConflict(getLayer().getConflicts().getConflictForMy(primitive)); 82 getLayer().getConflicts().remove(primitive); 83 83 } 84 84 primitive.id = 0; … … 92 92 modified.addAll(toUndelete); 93 93 } 94 @Override95 public void undoCommand() {96 super.undoCommand();97 98 for (OsmPrimitive my: resolvedConflicts.keySet()) {99 if (!Main.map.conflictDialog.conflicts.containsKey(my)) {100 Main.map.conflictDialog.addConflict(my, resolvedConflicts.get(my));101 }102 }103 }104 94 } -
trunk/src/org/openstreetmap/josm/command/VersionConflictResolveCommand.java
r1690 r1750 10 10 import javax.swing.tree.MutableTreeNode; 11 11 12 import org.openstreetmap.josm. Main;12 import org.openstreetmap.josm.data.conflict.Conflict; 13 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 14 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; … … 20 20 * 21 21 */ 22 public class VersionConflictResolveCommand extends Co mmand {22 public class VersionConflictResolveCommand extends ConflictResolveCommand { 23 23 24 private final OsmPrimitive my;25 private final OsmPrimitive their;24 /** the conflict to resolve */ 25 private Conflict<OsmPrimitive> conflict; 26 26 27 27 /** … … 31 31 */ 32 32 public VersionConflictResolveCommand(OsmPrimitive my, OsmPrimitive their) { 33 this.my = my; 34 this.their = their; 33 conflict = new Conflict<OsmPrimitive>(my, their); 35 34 } 36 35 … … 39 38 return new DefaultMutableTreeNode( 40 39 new JLabel( 41 tr("Resolve version conflicts for {0} {1}",OsmPrimitiveType.from( my).getLocalizedDisplayNameSingular(), my.id),40 tr("Resolve version conflicts for {0} {1}",OsmPrimitiveType.from(conflict.getMy()).getLocalizedDisplayNameSingular(),conflict.getMy().id), 42 41 ImageProvider.get("data", "object"), 43 42 JLabel.HORIZONTAL … … 49 48 public boolean executeCommand() { 50 49 super.executeCommand(); 51 my.version = Math.max(my.version, their.version); 52 Main.map.conflictDialog.removeConflictForPrimitive(my); 50 conflict.getMy().version = Math.max(conflict.getMy().version, conflict.getTheir().version); 51 getLayer().getConflicts().remove(conflict); 52 rememberConflict(conflict); 53 53 return true; 54 54 } … … 57 57 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 58 58 Collection<OsmPrimitive> added) { 59 modified.add(my); 60 } 61 62 @Override 63 public void undoCommand() { 64 super.undoCommand(); 65 66 // restore a conflict if necessary 67 // 68 if (!Main.map.conflictDialog.conflicts.containsKey(my)) { 69 Main.map.conflictDialog.addConflict(my, their); 70 } 59 modified.add(conflict.getMy()); 71 60 } 72 61 } -
trunk/src/org/openstreetmap/josm/command/WayNodesConflictResolverCommand.java
r1654 r1750 6 6 import java.util.Collection; 7 7 import java.util.List; 8 import java.util.logging.Logger; 8 9 9 10 import javax.swing.JLabel; … … 11 12 import javax.swing.tree.MutableTreeNode; 12 13 13 import org.openstreetmap.josm. Main;14 import org.openstreetmap.josm.data.conflict.Conflict; 14 15 import org.openstreetmap.josm.data.osm.Node; 15 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 22 23 * 23 24 */ 24 public class WayNodesConflictResolverCommand extends Co mmand {25 public class WayNodesConflictResolverCommand extends ConflictResolveCommand { 25 26 26 /** my way */ 27 private final Way my; 28 /** their way */ 29 private final Way their; 27 static private final Logger logger = Logger.getLogger(WayNodesConflictResolverCommand.class.getName()); 28 29 /** the conflict to resolve */ 30 private Conflict<Way> conflict; 31 30 32 /** the list of merged nodes. This becomes the list of news of my way after the 31 33 * command is executed 32 34 */ 33 35 private final List<Node> mergedNodeList; 36 34 37 35 38 /** … … 40 43 */ 41 44 public WayNodesConflictResolverCommand(Way my, Way their, List<Node> mergedNodeList) { 42 this.my = my; 43 this.their = their; 45 conflict = new Conflict<Way>(my,their); 44 46 this.mergedNodeList = mergedNodeList; 45 47 } … … 50 52 return new DefaultMutableTreeNode( 51 53 new JLabel( 52 tr("Resolve conflicts in node list of of way {0}", my.id),54 tr("Resolve conflicts in node list of of way {0}", conflict.getMy().id), 53 55 ImageProvider.get("data", "object"), 54 56 JLabel.HORIZONTAL … … 66 68 // nodes 67 69 // 68 my.nodes.clear();70 conflict.getMy().nodes.clear(); 69 71 for (int i=0; i<mergedNodeList.size();i++) { 70 72 Node n = mergedNodeList.get(i); 71 my.nodes.add(n);72 if (! Main.ds.nodes.contains(n)) {73 System.out.println("Main.ds doesn't include node " + n.toString());73 conflict.getMy().nodes.add(n); 74 if (! getLayer().data.nodes.contains(n)) { 75 logger.warning(tr("Main.ds doesn't include node {0}", n.toString())); 74 76 } 75 77 } 78 rememberConflict(conflict); 76 79 return true; 77 80 } … … 80 83 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 81 84 Collection<OsmPrimitive> added) { 82 modified.add(my); 83 } 84 85 @Override 86 public void undoCommand() { 87 // restore the former state 88 // 89 super.undoCommand(); 90 91 // restore a conflict if necessary 92 // 93 if (!Main.map.conflictDialog.conflicts.containsKey(my)) { 94 Main.map.conflictDialog.addConflict(my, their); 95 } 85 modified.add(conflict.getMy()); 96 86 } 97 87 } -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r1747 r1750 5 5 6 6 import org.openstreetmap.josm.Main; 7 import org.openstreetmap.josm.data.coor.CachedLatLon; 7 8 import org.openstreetmap.josm.data.coor.EastNorth; 8 import org.openstreetmap.josm.data.coor.CachedLatLon;9 9 import org.openstreetmap.josm.data.coor.LatLon; 10 10 import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat; 11 import org.openstreetmap.josm.data.projection.Projection;12 11 import org.openstreetmap.josm.data.osm.visitor.Visitor; 13 import org.openstreetmap.josm.data.osm.Node;14 12 15 13 /** … … 25 23 if(coor != null) 26 24 { 27 if(this.coor == null) 25 if(this.coor == null) { 28 26 this.coor = new CachedLatLon(coor); 29 else27 } else { 30 28 this.coor.setCoor(coor); 29 } 31 30 } 32 31 } … … 39 38 if(eastNorth != null) 40 39 { 41 if(coor != null) 40 if(coor != null) { 42 41 coor.setEastNorth(eastNorth); 43 else42 } else { 44 43 coor = new CachedLatLon(eastNorth); 44 } 45 45 } 46 46 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java
r1701 r1750 10 10 import java.util.logging.Logger; 11 11 12 import org.openstreetmap.josm.data.conflict.ConflictCollection; 12 13 import org.openstreetmap.josm.data.osm.DataSet; 13 14 import org.openstreetmap.josm.data.osm.Node; … … 31 32 * round than merged) 32 33 */ 33 private Map<OsmPrimitive, OsmPrimitive> conflicts; 34 private ConflictCollection conflicts; 35 34 36 35 37 private final DataSet myDataSet; … … 68 70 relshash.put(r.id, r); 69 71 } 70 conflicts = new HashMap<OsmPrimitive, OsmPrimitive>();72 conflicts = new ConflictCollection(); 71 73 merged = new HashMap<OsmPrimitive, OsmPrimitive>(); 72 74 } … … 113 115 // differences in deleted state have to be merged manually 114 116 // 115 conflicts. put(my, other);117 conflicts.add(my, other); 116 118 } else { 117 119 // copy the technical attributes from other … … 158 160 fixRelation(r); 159 161 } 160 for (OsmPrimitive osm : conflicts. values())162 for (OsmPrimitive osm : conflicts.getMyConflictParties()) 161 163 if (osm instanceof Way) { 162 164 fixWay((Way)osm); … … 235 237 // because it was deleted on the server. 236 238 // 237 conflicts. put(my,other);239 conflicts.add(my,other); 238 240 } else if (my.incomplete) { 239 241 // my is incomplete, other completes it … … 250 252 // differences in deleted state have to be resolved manually 251 253 // 252 conflicts. put(my,other);254 conflicts.add(my,other); 253 255 } else if (! my.modified && other.modified) { 254 256 // my not modified. We can assume that other is the most recent version. … … 278 280 // resolve the differences 279 281 // => create a conflict 280 conflicts. put(my,other);282 conflicts.add(my,other); 281 283 } else { 282 284 // clone from other, but keep the modified flag. Clone will mainly copy … … 326 328 * @return the map of conflicts 327 329 */ 328 public Map<OsmPrimitive, OsmPrimitive>getConflicts() {330 public ConflictCollection getConflicts() { 329 331 return conflicts; 330 332 } -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r1722 r1750 9 9 import java.awt.Graphics2D; 10 10 import java.awt.Point; 11 import java.awt.event.ComponentAdapter; 12 import java.awt.event.ComponentEvent; 11 13 import java.awt.event.MouseEvent; 12 14 import java.awt.event.MouseMotionListener; 13 import java.awt.event.ComponentAdapter;14 import java.awt.event.ComponentEvent;15 15 import java.awt.image.BufferedImage; 16 16 import java.util.ArrayList; 17 import java.util.Enumeration;18 17 import java.util.Collection; 19 18 import java.util.Collections; 19 import java.util.Enumeration; 20 20 import java.util.LinkedList; 21 21 … … 27 27 import org.openstreetmap.josm.actions.AutoScaleAction; 28 28 import org.openstreetmap.josm.actions.JosmAction; 29 import org.openstreetmap.josm.actions.MoveAction; 29 30 import org.openstreetmap.josm.actions.mapmode.MapMode; 30 import org.openstreetmap.josm.actions.MoveAction;31 import org.openstreetmap.josm.data.Bounds;32 31 import org.openstreetmap.josm.data.ProjectionBounds; 33 32 import org.openstreetmap.josm.data.SelectionChangedListener; 34 import org.openstreetmap.josm.data.coor.EastNorth;35 import org.openstreetmap.josm.data.coor.LatLon;36 33 import org.openstreetmap.josm.data.osm.DataSet; 37 34 import org.openstreetmap.josm.data.osm.DataSource; 38 35 import org.openstreetmap.josm.data.osm.OsmPrimitive; 39 36 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 40 import org.openstreetmap.josm.data.projection.Projection;41 37 import org.openstreetmap.josm.gui.layer.Layer; 42 38 import org.openstreetmap.josm.gui.layer.MapViewPaintable; … … 61 57 public class MapView extends NavigatableComponent { 62 58 59 63 60 /** 64 61 * A list of all layers currently loaded. … … 69 66 */ 70 67 public PlayHeadMarker playHeadMarker = null; 71 /** 72 * Direct link to the edit layer (if any) in the layers list. 73 */ 74 public OsmDataLayer editLayer; 68 75 69 /** 76 70 * The layer from the layers list that is currently active. … … 100 94 scaler.setLocation(10,30); 101 95 102 if (!zoomToEditLayerBoundingBox()) 96 if (!zoomToEditLayerBoundingBox()) { 103 97 new AutoScaleAction("data").actionPerformed(null); 98 } 104 99 105 100 new MapMover(MapView.this, Main.contentPane); … … 152 147 public void addLayer(Layer layer) { 153 148 if (layer instanceof OsmDataLayer) { 154 editLayer = (OsmDataLayer)layer;149 OsmDataLayer editLayer = (OsmDataLayer)layer; 155 150 Main.ds = editLayer.data; 156 151 editLayer.listenerModified.add(new ModifiedChangedListener(){ 157 152 public void modifiedChanged(boolean value, OsmDataLayer source) { 158 153 JOptionPane.getFrameForComponent(Main.parent).setTitle((value?"*":"") 159 +tr("Java OpenStreetMap Editor"));154 +tr("Java OpenStreetMap Editor")); 160 155 } 161 156 }); 162 157 } 163 if (layer instanceof MarkerLayer && playHeadMarker == null) 158 if (layer instanceof MarkerLayer && playHeadMarker == null) { 164 159 playHeadMarker = PlayHeadMarker.create(); 160 } 165 161 int pos = layers.size(); 166 while(pos > 0 && layers.get(pos-1).background) 162 while(pos > 0 && layers.get(pos-1).background) { 167 163 --pos; 164 } 168 165 layers.add(pos, layer); 169 166 170 for (Layer.LayerChangeListener l : Layer.listeners) 167 for (Layer.LayerChangeListener l : Layer.listeners) { 171 168 l.layerAdded(layer); 169 } 172 170 if (layer instanceof OsmDataLayer || activeLayer == null) { 173 171 // autoselect the new layer 174 172 Layer old = activeLayer; 175 173 setActiveLayer(layer); 176 for (Layer.LayerChangeListener l : Layer.listeners) 174 for (Layer.LayerChangeListener l : Layer.listeners) { 177 175 l.activeLayerChange(old, layer); 176 } 178 177 } 179 178 AudioPlayer.reset(); … … 182 181 183 182 @Override 184 protected DataSet getData() 185 { 183 protected DataSet getData() { 186 184 if(activeLayer != null && activeLayer instanceof OsmDataLayer) 187 185 return ((OsmDataLayer)activeLayer).data; … … 189 187 } 190 188 191 public Boolean isDrawableLayer() 192 { 189 /** 190 * Replies true if the active layer is drawable. 191 * 192 * @return true if the active layer is drawable, false otherwise 193 */ 194 public boolean isActiveLayerDrawable() { 193 195 return activeLayer != null && activeLayer instanceof OsmDataLayer; 194 196 } 195 197 196 public Boolean isVisibleDrawableLayer() { 197 return isDrawableLayer() && activeLayer.visible; 198 /** 199 * Replies true if the active layer is visible. 200 * 201 * @return true if the active layer is visible, false otherwise 202 */ 203 public boolean isActiveLayerVisible() { 204 return isActiveLayerDrawable() && activeLayer.visible; 198 205 } 199 206 … … 204 211 public void removeLayer(Layer layer) { 205 212 if (layers.remove(layer)) { 206 for (Layer.LayerChangeListener l : Layer.listeners) 213 for (Layer.LayerChangeListener l : Layer.listeners) { 207 214 l.layerRemoved(layer); 208 } 209 if (layer == editLayer) { 210 editLayer = null; 211 Main.ds.setSelected(); 215 } 216 } 217 if (layer == activeLayer) { 218 if (layer instanceof OsmDataLayer) { 219 Main.ds.setSelected(); 220 } 212 221 } 213 222 layer.destroy(); … … 215 224 } 216 225 217 private Boolean virtualnodes = false; 218 public void enableVirtualNodes(Boolean state) 219 { 220 if(virtualnodes != state) 221 { 222 virtualnodes = state; 226 private boolean virtualNodesEnabled = false; 227 public void setVirtualNodesEnabled(boolean enabled) { 228 if(virtualNodesEnabled != enabled) { 229 virtualNodesEnabled = enabled; 223 230 repaint(); 224 231 } 225 232 } 226 public Boolean useVirtualNodes() 227 { 228 return virtualnodes; 233 public boolean isVirtualNodesEnabled() { 234 return virtualNodesEnabled; 229 235 } 230 236 … … 241 247 return; // already in place. 242 248 layers.remove(curLayerPos); 243 if (pos >= layers.size()) 249 if (pos >= layers.size()) { 244 250 layers.add(layer); 245 else251 } else { 246 252 layers.add(pos, layer); 253 } 247 254 AudioPlayer.reset(); 248 255 } … … 266 273 // just re-use it. 267 274 if (null == offscreenBuffer || offscreenBuffer.getWidth() != getWidth() 268 || offscreenBuffer.getHeight() != getHeight()) 275 || offscreenBuffer.getHeight() != getHeight()) { 269 276 offscreenBuffer = new BufferedImage(getWidth(), getHeight(), 270 277 BufferedImage.TYPE_INT_ARGB); 278 } 271 279 272 280 Graphics2D tempG = offscreenBuffer.createGraphics(); … … 276 284 for (int i = layers.size()-1; i >= 0; --i) { 277 285 Layer l = layers.get(i); 278 if (l.visible/* && l != getActiveLayer()*/) 286 if (l.visible/* && l != getActiveLayer()*/) { 279 287 l.paint(tempG, this); 288 } 280 289 } 281 290 … … 296 305 int x2 = Math.max(min.x, max.x); 297 306 int y2 = Math.max(min.y, max.y); 298 if (x1 > 0 || y1 > 0 || x2 < getWidth() || y2 < getHeight()) 307 if (x1 > 0 || y1 > 0 || x2 < getWidth() || y2 < getHeight()) { 299 308 tempG.drawRect(x1, y1, x2-x1+1, y2-y1+1); 300 301 if (playHeadMarker != null) 309 } 310 311 if (playHeadMarker != null) { 302 312 playHeadMarker.paint(tempG, this); 313 } 303 314 304 315 g.drawImage(offscreenBuffer, 0, 0, null); … … 310 321 */ 311 322 public void recalculateCenterScale(BoundingXYVisitor box) { 312 if(box == null) 323 if(box == null) { 313 324 box = new BoundingXYVisitor(); 314 if(box.getBounds() == null) 325 } 326 if(box.getBounds() == null) { 315 327 box.visit(getProjection().getWorldBounds()); 316 if(!box.hasExtend()) 317 box.enlargeBoundingBox(); 328 } 329 if(!box.hasExtend()) { 330 box.enlargeBoundingBox(); 331 } 318 332 319 333 zoomTo(box.getBounds()); … … 321 335 322 336 /** 323 * @return An unmodifi cable listof all layers337 * @return An unmodifiable collection of all layers 324 338 */ 325 339 public Collection<Layer> getAllLayers() { … … 328 342 329 343 /** 330 * Set the active selection to the given value and raise an layerchange event. 344 * Sets the active layer to <code>layer</code>. If <code>layer</code> is an instance 345 * of {@see OsmDataLayer} also sets {@see #editLayer} to <code>layer</code>. 346 * 347 * @param layer the layer to be activate; must be one of the layers in the list of layers 348 * @exception IllegalArgumentException thrown if layer is not in the lis of layers 331 349 */ 332 350 public void setActiveLayer(Layer layer) { 333 351 if (!layers.contains(layer)) 334 throw new IllegalArgumentException( "Layer must be in layerlist");352 throw new IllegalArgumentException(tr("Layer {0} must be in list of layers", layer.toString())); 335 353 if (layer instanceof OsmDataLayer) { 336 editLayer = (OsmDataLayer)layer;354 OsmDataLayer editLayer = (OsmDataLayer)layer; 337 355 Main.ds = editLayer.data; 338 } 339 else 356 } else { 340 357 Main.ds.setSelected(); 358 } 341 359 DataSet.fireSelectionChanged(Main.ds.getSelected()); 342 360 Layer old = activeLayer; 343 361 activeLayer = layer; 344 362 if (old != layer) { 345 for (Layer.LayerChangeListener l : Layer.listeners) 363 for (Layer.LayerChangeListener l : Layer.listeners) { 346 364 l.activeLayerChange(old, layer); 365 } 347 366 } 348 367 … … 360 379 361 380 /** 362 * @return The current active layer 381 * Replies the currently active layer 382 * 383 * @return the currently active layer (may be null) 363 384 */ 364 385 public Layer getActiveLayer() { 365 386 return activeLayer; 387 } 388 389 /** 390 * Replies the current edit layer, if any 391 * 392 * @return the current edit layer. May be null. 393 */ 394 public OsmDataLayer getEditLayer() { 395 if (activeLayer instanceof OsmDataLayer) 396 return (OsmDataLayer)activeLayer; 397 return null; 398 } 399 400 /** 401 * replies true if the list of layers managed by this map view contain layer 402 * 403 * @param layer the layer 404 * @return true if the list of layers managed by this map view contain layer 405 */ 406 public boolean hasLayer(Layer layer) { 407 return layers.contains(layer); 366 408 } 367 409 … … 377 419 // workaround for #1461 (zoom to download bounding box instead of all data) 378 420 // In case we already have an existing data layer ... 379 Collection<DataSource> dataSources = Main.main. editLayer().data.dataSources;421 Collection<DataSource> dataSources = Main.main.createOrGetEditLayer().data.dataSources; 380 422 // ... with bounding box[es] of data loaded from OSM or a file... 381 423 BoundingXYVisitor bbox = new BoundingXYVisitor(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
r1706 r1750 29 29 public CommandStackDialog(final MapFrame mapFrame) { 30 30 super(tr("Command Stack"), "commandstack", tr("Open a list of all commands (undo buffer)."), 31 Shortcut.registerShortcut("subwindow:commandstack", tr("Toggle: {0}", tr("Command Stack")), KeyEvent.VK_O, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 100);31 Shortcut.registerShortcut("subwindow:commandstack", tr("Toggle: {0}", tr("Command Stack")), KeyEvent.VK_O, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 100); 32 32 Main.main.undoRedo.listenerCommands.add(this); 33 33 … … 52 52 53 53 @Override public void setVisible(boolean v) { 54 if (v) 54 if (v) { 55 55 buildList(); 56 else if (tree != null)56 } else if (tree != null) { 57 57 treeModel.setRoot(new DefaultMutableTreeNode()); 58 } 58 59 super.setVisible(v); 59 60 } … … 65 66 setTitle(tr("Command Stack"), false); 66 67 } 67 if (Main.map == null || Main.map.mapView == null || Main.map.mapView. editLayer== null)68 if (Main.map == null || Main.map.mapView == null || Main.map.mapView.getEditLayer() == null) 68 69 return; 69 70 Collection<Command> commands = Main.main.undoRedo.commands; 70 71 DefaultMutableTreeNode root = new DefaultMutableTreeNode(); 71 for (Command c : commands) 72 for (Command c : commands) { 72 73 root.add(c.description()); 74 } 73 75 treeModel.setRoot(root); 74 76 tree.scrollRowToVisible(treeModel.getChildCount(root)-1); -
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r1725 r1750 11 11 import java.awt.Point; 12 12 import java.awt.event.ActionEvent; 13 import java.awt.event.ActionListener;14 13 import java.awt.event.KeyEvent; 15 14 import java.awt.event.MouseAdapter; 16 15 import java.awt.event.MouseEvent; 17 16 import java.util.Collection; 18 import java.util. HashMap;17 import java.util.Iterator; 19 18 import java.util.LinkedList; 20 import java.util.Map; 21 22 import javax.swing.DefaultListModel; 19 import java.util.concurrent.CopyOnWriteArrayList; 20 21 import javax.swing.AbstractAction; 22 import javax.swing.JButton; 23 23 import javax.swing.JList; 24 24 import javax.swing.JPanel; 25 25 import javax.swing.JScrollPane; 26 import javax.swing.ListModel; 26 27 import javax.swing.ListSelectionModel; 28 import javax.swing.event.ListDataEvent; 29 import javax.swing.event.ListDataListener; 27 30 import javax.swing.event.ListSelectionEvent; 28 31 import javax.swing.event.ListSelectionListener; … … 30 33 import org.openstreetmap.josm.Main; 31 34 import org.openstreetmap.josm.data.SelectionChangedListener; 35 import org.openstreetmap.josm.data.conflict.Conflict; 36 import org.openstreetmap.josm.data.conflict.ConflictCollection; 37 import org.openstreetmap.josm.data.conflict.IConflictListener; 32 38 import org.openstreetmap.josm.data.osm.DataSet; 33 39 import org.openstreetmap.josm.data.osm.Node; … … 40 46 import org.openstreetmap.josm.gui.NavigatableComponent; 41 47 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 42 import org.openstreetmap.josm.gui.SideButton; 48 import org.openstreetmap.josm.gui.layer.Layer; 49 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 50 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 51 import org.openstreetmap.josm.tools.ImageProvider; 43 52 import org.openstreetmap.josm.tools.Shortcut; 44 53 45 public final class ConflictDialog extends ToggleDialog { 46 47 public final Map<OsmPrimitive, OsmPrimitive> conflicts = new HashMap<OsmPrimitive, OsmPrimitive>(); 48 private final DefaultListModel model = new DefaultListModel(); 49 private final JList displaylist = new JList(model); 50 51 private final SideButton sbSelect = new SideButton(marktr("Select"), "select", "Conflict", 52 tr("Set the selected elements on the map to the selected items in the list above."), new ActionListener(){ 53 public void actionPerformed(ActionEvent e) { 54 Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>(); 55 for (Object o : displaylist.getSelectedValues()) { 56 sel.add((OsmPrimitive)o); 57 } 58 Main.ds.setSelected(sel); 59 } 60 }); 61 private final SideButton sbResolve = new SideButton(marktr("Resolve"), "conflict", "Conflict", 62 tr("Open a merge dialog of all selected items in the list above."), new ActionListener(){ 63 public void actionPerformed(ActionEvent e) { 64 resolve(); 65 } 66 }); 67 68 public ConflictDialog() { 69 super(tr("Conflict"), "conflict", tr("Merging conflicts."), 70 Shortcut.registerShortcut("subwindow:conflict", tr("Toggle: {0}", tr("Conflict")), KeyEvent.VK_C, Shortcut.GROUP_LAYER), 100); 71 displaylist.setCellRenderer(new OsmPrimitivRenderer()); 72 displaylist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 73 displaylist.addMouseListener(new MouseAdapter(){ 54 /** 55 * This dialog displays the {@see ConflictCollection} of the active {@see OsmDataLayer} in a toggle 56 * dialog on the right of the main frame. 57 * 58 */ 59 public final class ConflictDialog extends ToggleDialog implements LayerChangeListener, IConflictListener, SelectionChangedListener{ 60 61 static public Color getColor() { 62 return Main.pref.getColor(marktr("conflict"), Color.gray); 63 } 64 65 /** the collection of conflicts displayed by this conflict dialog*/ 66 private ConflictCollection conflicts; 67 68 /** the model for the list of conflicts */ 69 private ConflictListModel model; 70 /** the list widget for the list of conflicts */ 71 private JList lstConflicts; 72 73 private ResolveAction actResolve; 74 private SelectAction actSelect; 75 76 private OsmDataLayer layer = null; 77 78 79 /** 80 * builds the GUI 81 */ 82 protected void build() { 83 model = new ConflictListModel(); 84 85 lstConflicts = new JList(model); 86 lstConflicts.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 87 lstConflicts.setCellRenderer(new OsmPrimitivRenderer()); 88 lstConflicts.addMouseListener(new MouseAdapter(){ 74 89 @Override public void mouseClicked(MouseEvent e) { 75 90 if (e.getClickCount() >= 2) { … … 78 93 } 79 94 }); 80 add(new JScrollPane(displaylist), BorderLayout.CENTER); 81 82 JPanel buttonPanel = new JPanel(new GridLayout(1,2)); 83 buttonPanel.add(sbResolve); 84 buttonPanel.add(sbSelect); 85 add(buttonPanel, BorderLayout.SOUTH); 86 87 DataSet.selListeners.add(new SelectionChangedListener(){ 88 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 89 displaylist.clearSelection(); 90 for (OsmPrimitive osm : newSelection) { 91 if (conflicts.containsKey(osm)) { 92 int pos = model.indexOf(osm); 93 displaylist.addSelectionInterval(pos, pos); 94 } 95 } 96 } 97 }); 98 displaylist.getSelectionModel().addListSelectionListener(new ListSelectionListener(){ 95 lstConflicts.getSelectionModel().addListSelectionListener(new ListSelectionListener(){ 99 96 public void valueChanged(ListSelectionEvent e) { 100 97 Main.map.mapView.repaint(); … … 102 99 }); 103 100 104 rebuildList(); 105 } 106 101 add(new JScrollPane(lstConflicts), BorderLayout.CENTER); 102 103 JButton btnResolve = new JButton(actResolve = new ResolveAction()); 104 lstConflicts.getSelectionModel().addListSelectionListener(actResolve); 105 106 JButton btnSelect = new JButton(actSelect = new SelectAction()); 107 lstConflicts.getSelectionModel().addListSelectionListener(actSelect); 108 109 JPanel buttonPanel = new JPanel(new GridLayout(1,2)); 110 buttonPanel.add(btnResolve); 111 buttonPanel.add(btnSelect); 112 add(buttonPanel, BorderLayout.SOUTH); 113 } 114 115 /** 116 * constructor 117 */ 118 public ConflictDialog() { 119 super(tr("Conflict"), "conflict", tr("Merging conflicts."), 120 Shortcut.registerShortcut("subwindow:conflict", tr("Toggle: {0}", tr("Conflict")), KeyEvent.VK_C, Shortcut.GROUP_LAYER), 100); 121 122 build(); 123 DataSet.selListeners.add(this); 124 Layer.listeners.add(this); 125 refreshView(); 126 } 127 128 /** 129 * Launches a conflict resolution dialog for the first selected conflict 130 * 131 */ 107 132 private final void resolve() { 108 if(model.size() == 1) { 109 displaylist.setSelectedIndex(0); 110 } 111 112 if (displaylist.getSelectedIndex() == -1) 133 if (conflicts == null) return; 134 if (conflicts.size() == 1) { 135 lstConflicts.setSelectedIndex(0); 136 } 137 138 if (lstConflicts.getSelectedIndex() == -1) 113 139 return; 114 140 115 int [] selectedRows = displaylist.getSelectedIndices();141 int [] selectedRows = lstConflicts.getSelectedIndices(); 116 142 if (selectedRows == null || selectedRows.length == 0) 117 143 return; 118 144 int row = selectedRows[0]; 119 OsmPrimitive my = (OsmPrimitive)model.get(row); 120 OsmPrimitive their = conflicts.get(my); 145 Conflict c = conflicts.get(row); 146 OsmPrimitive my = c.getMy(); 147 OsmPrimitive their = c.getTheir(); 121 148 ConflictResolutionDialog dialog = new ConflictResolutionDialog(Main.parent); 122 149 dialog.getConflictResolver().populate(my, their); … … 125 152 } 126 153 127 public final void rebuildList() { 128 model.removeAllElements(); 129 for (OsmPrimitive osm : this.conflicts.keySet()) { 130 model.addElement(osm); 131 } 132 133 if(model.size() != 0) { 134 setTitle(tr("Conflicts: {0}", model.size()), true); 135 } else { 136 setTitle(tr("Conflicts"), false); 137 } 138 139 sbSelect.setEnabled(model.size() > 0); 140 sbResolve.setEnabled(model.size() > 0); 141 } 142 143 public final void add(Map<OsmPrimitive, OsmPrimitive> conflicts) { 144 this.conflicts.putAll(conflicts); 145 rebuildList(); 146 } 147 148 149 /** 150 * removes a conflict registered for {@see OsmPrimitive} <code>my</code> 151 * 152 * @param my the {@see OsmPrimitive} for which a conflict is registered 153 * with this dialog 154 */ 155 public void removeConflictForPrimitive(OsmPrimitive my) { 156 if (! conflicts.keySet().contains(my)) 157 return; 158 conflicts.remove(my); 159 rebuildList(); 160 repaint(); 161 } 162 163 /** 164 * registers a conflict with this dialog. The conflict is represented 165 * by a pair of {@see OsmPrimitive} with differences in their tag sets, 166 * their node lists (for {@see Way}s) or their member lists (for {@see Relation}s) 167 * 168 * @param my my version of the {@see OsmPrimitive} 169 * @param their their version of the {@see OsmPrimitive} 170 */ 171 public void addConflict(OsmPrimitive my, OsmPrimitive their) { 172 conflicts.put(my, their); 173 rebuildList(); 174 repaint(); 175 } 176 177 static public Color getColor() 178 { 179 return Main.pref.getColor(marktr("conflict"), Color.gray); 154 155 /** 156 * refreshes the view of this dialog 157 */ 158 public final void refreshView() { 159 model.fireContentChanged(); 180 160 } 181 161 … … 215 195 } 216 196 }; 217 for (Object o : displaylist.getSelectedValues()) {218 if ( conflicts.get(o) == null) {197 for (Object o : lstConflicts.getSelectedValues()) { 198 if (!conflicts.hasConflictForMy((OsmPrimitive)o)) { 219 199 continue; 220 200 } 221 conflicts.get(o).visit(conflictPainter); 201 conflicts.getConflictForMy((OsmPrimitive)o).getTheir().visit(conflictPainter); 202 } 203 } 204 205 206 /** 207 * replies the conflict collection currently held by this dialog; may be null 208 * 209 * @return the conflict collection currently held by this dialog; may be null 210 */ 211 public ConflictCollection getConflicts() { 212 return conflicts; 213 } 214 215 /** 216 * invoked if the active {@see Layer} changes 217 */ 218 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 219 if (oldLayer instanceof OsmDataLayer) { 220 this.layer = (OsmDataLayer)oldLayer; 221 this.layer.getConflicts().removeConflictListener(this); 222 } 223 this.layer = null; 224 if (newLayer instanceof OsmDataLayer) { 225 this.layer = (OsmDataLayer)newLayer; 226 layer.getConflicts().addConflictListener(this); 227 this.conflicts = layer.getConflicts(); 228 } 229 refreshView(); 230 } 231 232 public void layerAdded(Layer newLayer) { 233 // ignore 234 } 235 236 public void layerRemoved(Layer oldLayer) { 237 if (this.layer == oldLayer) { 238 this.layer = null; 239 refreshView(); 240 } 241 } 242 243 public void onConflictsAdded(ConflictCollection conflicts) { 244 refreshView(); 245 } 246 247 public void onConflictsRemoved(ConflictCollection conflicts) { 248 refreshView(); 249 } 250 251 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 252 lstConflicts.clearSelection(); 253 for (OsmPrimitive osm : newSelection) { 254 if (conflicts.hasConflictForMy(osm)) { 255 int pos = model.indexOf(osm); 256 if (pos >= 0) { 257 lstConflicts.addSelectionInterval(pos, pos); 258 } 259 } 260 } 261 } 262 263 /** 264 * The {@see ListModel} for conflicts 265 * 266 */ 267 class ConflictListModel implements ListModel { 268 269 private CopyOnWriteArrayList<ListDataListener> listeners; 270 271 public ConflictListModel() { 272 listeners = new CopyOnWriteArrayList<ListDataListener>(); 273 } 274 275 public void addListDataListener(ListDataListener l) { 276 if (l != null && ! listeners.contains(l)) { 277 listeners.add(l); 278 } 279 } 280 281 public void removeListDataListener(ListDataListener l) { 282 listeners.remove(l); 283 } 284 285 protected void fireContentChanged() { 286 ListDataEvent evt = new ListDataEvent( 287 this, 288 ListDataEvent.CONTENTS_CHANGED, 289 0, 290 getSize() 291 ); 292 Iterator<ListDataListener> it = listeners.iterator(); 293 while(it.hasNext()) { 294 it.next().contentsChanged(evt); 295 } 296 } 297 298 public Object getElementAt(int index) { 299 if (index < 0) return null; 300 if (index >= getSize()) return null; 301 return conflicts.get(index).getMy(); 302 } 303 304 public int getSize() { 305 if (conflicts == null) return 0; 306 return conflicts.size(); 307 } 308 309 public int indexOf(OsmPrimitive my) { 310 if (conflicts == null) return -1; 311 for (int i=0; i < conflicts.size();i++) { 312 if (conflicts.get(i).isMatchingMy(my)) 313 return i; 314 } 315 return -1; 316 } 317 318 public OsmPrimitive get(int idx) { 319 if (conflicts == null) return null; 320 return conflicts.get(idx).getMy(); 321 } 322 } 323 324 class ResolveAction extends AbstractAction implements ListSelectionListener { 325 public ResolveAction() { 326 putValue(NAME, tr("Resolve")); 327 putValue(SHORT_DESCRIPTION, tr("Open a merge dialog of all selected items in the list above.")); 328 putValue(SMALL_ICON, ImageProvider.get("dialogs", "conflict")); 329 } 330 331 public void actionPerformed(ActionEvent e) { 332 resolve(); 333 } 334 335 public void valueChanged(ListSelectionEvent e) { 336 ListSelectionModel model = (ListSelectionModel)e.getSource(); 337 boolean enabled = model.getMinSelectionIndex() >= 0 338 && model.getMaxSelectionIndex() >= model.getMinSelectionIndex(); 339 setEnabled(enabled); 340 } 341 } 342 343 class SelectAction extends AbstractAction implements ListSelectionListener { 344 public SelectAction() { 345 putValue(NAME, tr("Select")); 346 putValue(SHORT_DESCRIPTION, tr("Set the selected elements on the map to the selected items in the list above.")); 347 putValue(SMALL_ICON, ImageProvider.get("dialogs", "select")); 348 } 349 350 public void actionPerformed(ActionEvent e) { 351 Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>(); 352 for (Object o : lstConflicts.getSelectedValues()) { 353 sel.add((OsmPrimitive)o); 354 } 355 Main.ds.setSelected(sel); 356 } 357 358 public void valueChanged(ListSelectionEvent e) { 359 ListSelectionModel model = (ListSelectionModel)e.getSource(); 360 boolean enabled = model.getMinSelectionIndex() >= 0 361 && model.getMaxSelectionIndex() >= model.getMinSelectionIndex(); 362 setEnabled(enabled); 222 363 } 223 364 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java
r1709 r1750 48 48 import org.openstreetmap.josm.gui.history.HistoryBrowserDialog; 49 49 import org.openstreetmap.josm.io.OsmApi; 50 import org.openstreetmap.josm.io.OsmApiException; 50 51 import org.openstreetmap.josm.io.OsmServerHistoryReader; 51 52 import org.openstreetmap.josm.io.OsmTransferException; … … 233 234 if (task.getLastException() != null) { 234 235 task.getLastException().printStackTrace(); 235 String msg = task.getLastException().getMessage(); 236 String msg = null; 237 if (task.getLastException() instanceof OsmApiException) { 238 msg = ((OsmApiException)task.getLastException()).getErrorBody(); 239 if (msg == null) { 240 msg = ((OsmApiException)task.getLastException()).getErrorHeader(); 241 } 242 } 243 if (msg == null) { 244 msg = task.getLastException().getMessage(); 245 } 236 246 if (msg == null) { 237 247 msg = task.getLastException().toString(); … … 452 462 } catch(OsmTransferException e) { 453 463 lastException = e; 454 throw e;464 return; 455 465 } finally { 456 466 setInterminateEnabled(false); -
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r1332 r1750 53 53 54 54 public void actionPerformed(ActionEvent e) { 55 if (e != null && !(e.getSource() instanceof AbstractButton)) 55 if (e != null && !(e.getSource() instanceof AbstractButton)) { 56 56 button.setSelected(!button.isSelected()); 57 } 57 58 Boolean selected = button.isSelected(); 58 59 setVisible(selected); 59 60 Main.pref.put(prefname+".visible", selected); 60 if(!selected && winadapter != null) 61 if(!selected && winadapter != null) { 61 62 winadapter.windowClosing(null); 62 else if (!Main.pref.getBoolean(action.prefname+".docked", true)) {63 } else if (!Main.pref.getBoolean(action.prefname+".docked", true)) { 63 64 EventQueue.invokeLater(new Runnable(){ 64 65 public void run() { … … 174 175 setVisible(false); 175 176 parent.add(ToggleDialog.this); 176 if(Main.pref.getBoolean(action.prefname+".visible")) 177 if(Main.pref.getBoolean(action.prefname+".visible")) { 177 178 setVisible(true); 179 } 178 180 titleBar.setVisible(true); 179 if(e != null) 181 if(e != null) { 180 182 Main.pref.put(action.prefname+".docked", true); 183 } 181 184 } 182 185 })); … … 190 193 String[] b = bounds.split(","); 191 194 f.setBounds(Integer.parseInt(b[0]),Integer.parseInt(b[1]),Integer.parseInt(b[2]),Integer.parseInt(b[3])); 192 } else 195 } else { 193 196 f.pack(); 197 } 194 198 Main.pref.put(action.prefname+".docked", false); 195 199 f.setVisible(true); … … 241 245 public void close() 242 246 { 243 if(winadapter != null) 247 if(winadapter != null) { 244 248 winadapter.windowClosing(null); 249 } 245 250 } 246 251 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r1748 r1750 367 367 RelationMember m = clone.members.get(i); 368 368 if (m.member.incomplete) 369 {370 369 // TODO: emit some message that sorting failed 371 370 return; 372 }373 371 try 374 372 { … … 765 763 DataSet dataSet = reader.parseOsm(); 766 764 if (dataSet != null) { 767 final MergeVisitor visitor = new MergeVisitor(Main.main 768 . editLayer().data, dataSet);765 final MergeVisitor visitor = new MergeVisitor(Main.main.map.mapView.getEditLayer() 766 .data, dataSet); 769 767 visitor.merge(); 770 768 771 769 // copy the merged layer's data source info 772 770 for (DataSource src : dataSet.dataSources) { 773 Main.main. editLayer().data.dataSources.add(src);774 } 775 Main.main. editLayer().fireDataChange();771 Main.main.map.mapView.getEditLayer().data.dataSources.add(src); 772 } 773 Main.main.map.mapView.getEditLayer().fireDataChange(); 776 774 777 775 if (visitor.getConflicts().isEmpty()) 778 776 return; 779 777 final ConflictDialog dlg = Main.map.conflictDialog; 780 dlg. add(visitor.getConflicts());778 dlg.getConflicts().add(visitor.getConflicts()); 781 779 JOptionPane.showMessageDialog(Main.parent, 782 780 tr("There were conflicts during import.")); -
trunk/src/org/openstreetmap/josm/gui/history/PointInTimeType.java
r1709 r1750 2 2 package org.openstreetmap.josm.gui.history; 3 3 4 import org.openstreetmap.josm.data.osm.OsmPrimitive;5 4 6 5 /** -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r1690 r1750 19 19 import java.awt.event.ActionEvent; 20 20 import java.awt.geom.Area; 21 import java.awt.geom.Rectangle2D;22 21 import java.awt.image.BufferedImage; 23 22 import java.io.File; … … 42 41 import org.openstreetmap.josm.actions.SaveAction; 43 42 import org.openstreetmap.josm.actions.SaveAsAction; 43 import org.openstreetmap.josm.data.conflict.Conflict; 44 import org.openstreetmap.josm.data.conflict.ConflictCollection; 44 45 import org.openstreetmap.josm.data.coor.EastNorth; 45 46 import org.openstreetmap.josm.data.coor.LatLon; … … 60 61 import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor; 61 62 import org.openstreetmap.josm.gui.MapView; 62 import org.openstreetmap.josm.gui.dialogs.ConflictDialog;63 63 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 64 64 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; … … 74 74 */ 75 75 public class OsmDataLayer extends Layer { 76 77 /** the global counter for created data layers */ 78 static private int dataLayerCounter = 0; 79 80 /** 81 * Replies a new unique name for a data layer 82 * 83 * @return a new unique name for a data layer 84 */ 85 static public String createNewName() { 86 dataLayerCounter++; 87 return tr("Data Layer {0}", dataLayerCounter); 88 } 76 89 77 90 public final static class DataCountVisitor extends AbstractVisitor { … … 114 127 */ 115 128 public final DataSet data; 129 130 /** 131 * the collection of conflicts detected in this layer 132 */ 133 private ConflictCollection conflicts; 116 134 117 135 /** … … 159 177 this.data = data; 160 178 this.setAssociatedFile(associatedFile); 179 conflicts = new ConflictCollection(); 161 180 } 162 181 … … 177 196 boolean active = Main.map.mapView.getActiveLayer() == this; 178 197 boolean inactive = !active && Main.pref.getBoolean("draw.data.inactive_color", true); 179 boolean virtual = !inactive && Main.map.mapView. useVirtualNodes();198 boolean virtual = !inactive && Main.map.mapView.isVirtualNodesEnabled(); 180 199 181 200 // draw the hatched area for non-downloaded region. only draw if we're the active … … 271 290 Main.map.mapView.repaint(); 272 291 273 if (visitor.getConflicts().isEmpty()) 274 return; 275 final ConflictDialog dlg = Main.map.conflictDialog; 276 dlg.add(visitor.getConflicts()); 277 JOptionPane.showMessageDialog(Main.parent,tr("There were {0} conflicts during import.", visitor.getConflicts().size())); 278 if (!dlg.isVisible()) { 279 dlg.action.actionPerformed(new ActionEvent(this, 0, "")); 292 int numNewConflicts = 0; 293 for (Conflict c : visitor.getConflicts()) { 294 if (!conflicts.hasConflict(c)) { 295 numNewConflicts++; 296 conflicts.add(c); 297 } 298 } 299 if (numNewConflicts > 0) { 300 JOptionPane.showMessageDialog(Main.parent,tr("There were {0} conflicts during import.", numNewConflicts)); 280 301 } 281 302 } … … 510 531 return layer_bounds_point; 511 532 } 533 534 /** 535 * replies the set of conflicts currently managed in this layer 536 * 537 * @return the set of conflicts currently managed in this layer 538 */ 539 public ConflictCollection getConflicts() { 540 return conflicts; 541 } 512 542 } -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r1691 r1750 330 330 String diffresult = sendRequest("POST", "changeset/" + changeset.id + "/upload", diff); 331 331 DiffResultReader.parseDiffResult(diffresult, list, processed, duv.getNewIdMap(), Main.pleaseWaitDlg); 332 } catch(OsmTransferException e) { 333 throw e; 332 334 } catch(Exception e) { 333 335 throw new OsmTransferException(e); … … 443 445 444 446 if (retCode != 200) 445 throw new OsmApiException(retCode,errorHeader ,responseBody.toString());447 throw new OsmApiException(retCode,errorHeader.trim(),responseBody.toString().trim()); 446 448 447 449 return responseBody.toString(); -
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r1691 r1750 94 94 boolean useChangeset = Main.pref.getBoolean("osm-server.atomic-upload", apiVersion.compareTo("0.6")>=0); 95 95 if (useChangeset && ! canUseChangeset) { 96 System.out.println(tr("WARNING: preference ''{0}'' or api version ''{1}'' of dataset requires to use changesets, but API is not handle them. Ignoring changesets.", "osm-server.atomic-upload", apiVersion));96 System.out.println(tr("WARNING: preference ''{0}'' or api version ''{1}'' of dataset requires to use changesets, but API is not able to handle them. Ignoring changesets.", "osm-server.atomic-upload", apiVersion)); 97 97 useChangeset = false; 98 98 }
Note:
See TracChangeset
for help on using the changeset viewer.