Changeset 12718 in josm
- Timestamp:
- 2017-09-04T00:50:22+02:00 (7 years ago)
- Location:
- trunk
- Files:
-
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r12696 r12718 137 137 * The commands undo/redo handler. 138 138 */ 139 public final UndoRedoHandler undoRedo = MainApplication.undoRedo;139 public final UndoRedoHandler undoRedo = new UndoRedoHandler(); 140 140 141 141 /** … … 630 630 631 631 /** 632 * Gets the data set of the active edit layer.633 * @return That data set, <code>null</code> if there is no edit layer.632 * Gets the active edit data set. 633 * @return That data set, <code>null</code>. 634 634 * @since 12691 635 635 */ 636 public DataSet getEditDataSet() { 637 return null; 638 } 636 public abstract DataSet getEditDataSet(); 637 638 /** 639 * Sets the active data set. 640 * @param ds New edit data set, or <code>null</code> 641 * @since 12718 642 */ 643 public abstract void setEditDataSet(DataSet ds); 644 645 /** 646 * Determines if the list of data sets managed by JOSM contains {@code ds}. 647 * @param ds the data set to look for 648 * @return {@code true} if the list of data sets managed by JOSM contains {@code ds} 649 * @since 12718 650 */ 651 public abstract boolean containsDataSet(DataSet ds); 639 652 640 653 /** -
trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
r12641 r12718 693 693 // Delete the discarded inner ways 694 694 if (!discardedWays.isEmpty()) { 695 Command deleteCmd = DeleteCommand.delete( getLayerManager().getEditLayer(),discardedWays, true);695 Command deleteCmd = DeleteCommand.delete(discardedWays, true); 696 696 if (deleteCmd != null) { 697 697 cmds.add(deleteCmd); … … 1018 1018 1019 1019 if (chunks.size() > 1) { 1020 SplitWayResult split = SplitWayAction.splitWay( getLayerManager().getEditLayer(),way, chunks,1020 SplitWayResult split = SplitWayAction.splitWay(way, chunks, 1021 1021 Collections.<OsmPrimitive>emptyList(), SplitWayAction.Strategy.keepFirstChunk()); 1022 1022 … … 1467 1467 newRel.addMember(new RelationMember("inner", w)); 1468 1468 } 1469 cmds.add(layer != null ? new AddCommand(layer , newRel) :1469 cmds.add(layer != null ? new AddCommand(layer.data, newRel) : 1470 1470 new AddCommand(inner.iterator().next().getDataSet(), newRel)); 1471 1471 addedRelations.add(newRel); … … 1538 1538 } 1539 1539 1540 OsmDataLayer layer = getLayerManager().getEditLayer();1541 1540 Relation newRel; 1542 1541 switch (multiouters.size()) { … … 1567 1566 } 1568 1567 newRel.addMember(new RelationMember("outer", outer)); 1569 cmds.add( layer != null ? new AddCommand(layer, newRel) :new AddCommand(outer.getDataSet(), newRel));1568 cmds.add(new AddCommand(outer.getDataSet(), newRel)); 1570 1569 } 1571 1570 } -
trunk/src/org/openstreetmap/josm/actions/PurgeAction.java
r12688 r12718 118 118 layer = getLayerManager().getEditLayer(); 119 119 toPurgeAdditionally = new ArrayList<>(); 120 PurgeCommand cmd = PurgeCommand.build( layer,sel, toPurgeAdditionally);120 PurgeCommand cmd = PurgeCommand.build(sel, toPurgeAdditionally); 121 121 modified = cmd.getParticipatingPrimitives().stream().anyMatch(OsmPrimitive::isModified); 122 122 return cmd; -
trunk/src/org/openstreetmap/josm/actions/RedoAction.java
r12641 r12718 9 9 10 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener; 11 12 import org.openstreetmap.josm.gui.MainApplication; 12 13 import org.openstreetmap.josm.gui.MapFrame; 13 import org.openstreetmap.josm.gui.layer.OsmDataLayer;14 14 import org.openstreetmap.josm.tools.Shortcut; 15 15 … … 19 19 * @author imi 20 20 */ 21 public class RedoAction extends JosmAction implements OsmDataLayer.CommandQueueListener {21 public class RedoAction extends JosmAction implements CommandQueueListener { 22 22 23 23 /** -
trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
r12663 r12718 214 214 } 215 215 if (wayToKeep != null) { 216 final SplitWayResult result = doSplitWay( getLayerManager().getEditLayer(),selectedWay, wayToKeep, newWays, sel);216 final SplitWayResult result = doSplitWay(selectedWay, wayToKeep, newWays, sel); 217 217 MainApplication.undoRedo.add(result.getCommand()); 218 218 if (!result.getNewSelection().isEmpty()) { … … 294 294 toggleSaveState(); // necessary since #showDialog() does not handle it due to the non-modal dialog 295 295 if (getValue() == 1) { 296 SplitWayResult result = doSplitWay(MainApplication.getLayerManager().getEditLayer(), 297 selectedWay, list.getSelectedValue(), newWays, selection); 296 SplitWayResult result = doSplitWay(selectedWay, list.getSelectedValue(), newWays, selection); 298 297 MainApplication.undoRedo.add(result.getCommand()); 299 298 if (!result.getNewSelection().isEmpty()) { … … 498 497 * @param selection The list of currently selected primitives 499 498 * @return the result from the split operation 500 */ 499 * @deprecated to be removed end of 2017. Use {@link #splitWay(Way, List, Collection)} instead 500 */ 501 @Deprecated 501 502 public static SplitWayResult splitWay(OsmDataLayer layer, Way way, List<List<Node>> wayChunks, 502 503 Collection<? extends OsmPrimitive> selection) { 503 return splitWay(layer, way, wayChunks, selection, Strategy.keepLongestChunk()); 504 return splitWay(way, wayChunks, selection); 505 } 506 507 /** 508 * Splits the way {@code way} into chunks of {@code wayChunks} and replies 509 * the result of this process in an instance of {@link SplitWayResult}. 510 * 511 * Note that changes are not applied to the data yet. You have to 512 * submit the command in {@link SplitWayResult#getCommand()} first, 513 * i.e. {@code Main.main.undoredo.add(result.getCommand())}. 514 * 515 * @param way the way to split. Must not be null. 516 * @param wayChunks the list of way chunks into the way is split. Must not be null. 517 * @param selection The list of currently selected primitives 518 * @return the result from the split operation 519 * @since 12718 520 */ 521 public static SplitWayResult splitWay(Way way, List<List<Node>> wayChunks, 522 Collection<? extends OsmPrimitive> selection) { 523 return splitWay(way, wayChunks, selection, Strategy.keepLongestChunk()); 504 524 } 505 525 … … 521 541 * @return the result from the split operation 522 542 * @since 8954 523 */ 543 * @deprecated to be removed end of 2017. Use {@link #splitWay(Way, List, Collection, Strategy)} instead 544 */ 545 @Deprecated 524 546 public static SplitWayResult splitWay(OsmDataLayer layer, Way way, List<List<Node>> wayChunks, 547 Collection<? extends OsmPrimitive> selection, Strategy splitStrategy) { 548 return splitWay(way, wayChunks, selection, splitStrategy); 549 } 550 551 /** 552 * Splits the way {@code way} into chunks of {@code wayChunks} and replies 553 * the result of this process in an instance of {@link SplitWayResult}. 554 * The {@link org.openstreetmap.josm.actions.SplitWayAction.Strategy} is used to determine which 555 * way chunk should reuse the old id and its history. 556 * 557 * Note that changes are not applied to the data yet. You have to 558 * submit the command in {@link SplitWayResult#getCommand()} first, 559 * i.e. {@code Main.main.undoredo.add(result.getCommand())}. 560 * 561 * @param way the way to split. Must not be null. 562 * @param wayChunks the list of way chunks into the way is split. Must not be null. 563 * @param selection The list of currently selected primitives 564 * @param splitStrategy The strategy used to determine which way chunk should reuse the old id and its history 565 * @return the result from the split operation 566 * @since 12718 567 */ 568 public static SplitWayResult splitWay(Way way, List<List<Node>> wayChunks, 525 569 Collection<? extends OsmPrimitive> selection, Strategy splitStrategy) { 526 570 // build a list of commands, and also a new selection list … … 534 578 final Way wayToKeep = splitStrategy.determineWayToKeep(newWays); 535 579 536 return wayToKeep != null ? doSplitWay(layer, way, wayToKeep, newWays, newSelection) : null; 537 } 538 539 static SplitWayResult doSplitWay(OsmDataLayer layer, Way way, Way wayToKeep, List<Way> newWays, 540 List<OsmPrimitive> newSelection) { 580 return wayToKeep != null ? doSplitWay(way, wayToKeep, newWays, newSelection) : null; 581 } 582 583 static SplitWayResult doSplitWay(Way way, Way wayToKeep, List<Way> newWays, List<OsmPrimitive> newSelection) { 541 584 542 585 Collection<Command> commandList = new ArrayList<>(newWays.size()); … … 550 593 final Way changedWay = new Way(way); 551 594 changedWay.setNodes(wayToKeep.getNodes()); 552 commandList.add( layer != null ? new ChangeCommand(layer, way, changedWay) :new ChangeCommand(way.getDataSet(), way, changedWay));595 commandList.add(new ChangeCommand(way.getDataSet(), way, changedWay)); 553 596 if (!isMapModeDraw && !newSelection.contains(way)) { 554 597 newSelection.add(way); … … 561 604 } 562 605 for (Way wayToAdd : newWays) { 563 commandList.add( layer != null ? new AddCommand(layer, wayToAdd) :new AddCommand(way.getDataSet(), wayToAdd));606 commandList.add(new AddCommand(way.getDataSet(), wayToAdd)); 564 607 } 565 608 … … 688 731 689 732 if (c != null) { 690 commandList.add( layer != null ? new ChangeCommand(layer, r, c) :new ChangeCommand(r.getDataSet(), r, c));733 commandList.add(new ChangeCommand(r.getDataSet(), r, c)); 691 734 } 692 735 } … … 741 784 * @param selection The list of currently selected primitives 742 785 * @return the result from the split operation 743 */ 786 * @deprecated to be removed end of 2017. Use {@link #split(Way, List, Collection) instead} 787 */ 788 @Deprecated 744 789 public static SplitWayResult split(OsmDataLayer layer, Way way, List<Node> atNodes, Collection<? extends OsmPrimitive> selection) { 790 return split(way, atNodes, selection); 791 } 792 793 /** 794 * Splits the way {@code way} at the nodes in {@code atNodes} and replies 795 * the result of this process in an instance of {@link SplitWayResult}. 796 * 797 * Note that changes are not applied to the data yet. You have to 798 * submit the command in {@link SplitWayResult#getCommand()} first, 799 * i.e. {@code Main.main.undoredo.add(result.getCommand())}. 800 * 801 * Replies null if the way couldn't be split at the given nodes. 802 * 803 * @param way the way to split. Must not be null. 804 * @param atNodes the list of nodes where the way is split. Must not be null. 805 * @param selection The list of currently selected primitives 806 * @return the result from the split operation 807 * @since 12718 808 */ 809 public static SplitWayResult split(Way way, List<Node> atNodes, Collection<? extends OsmPrimitive> selection) { 745 810 List<List<Node>> chunks = buildSplitChunks(way, atNodes); 746 return chunks != null ? splitWay( layer,way, chunks, selection) : null;811 return chunks != null ? splitWay(way, chunks, selection) : null; 747 812 } 748 813 -
trunk/src/org/openstreetmap/josm/actions/UndoAction.java
r12641 r12718 9 9 10 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener; 11 12 import org.openstreetmap.josm.gui.MainApplication; 12 13 import org.openstreetmap.josm.gui.MapFrame; 13 import org.openstreetmap.josm.gui.layer.OsmDataLayer;14 14 import org.openstreetmap.josm.tools.Shortcut; 15 15 … … 19 19 * @author imi 20 20 */ 21 public class UndoAction extends JosmAction implements OsmDataLayer.CommandQueueListener {21 public class UndoAction extends JosmAction implements CommandQueueListener { 22 22 23 23 /** -
trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r12641 r12718 151 151 Command c; 152 152 if (ctrl) { 153 c = DeleteCommand.deleteWithReferences( editLayer,lm.getEditDataSet().getSelected());153 c = DeleteCommand.deleteWithReferences(lm.getEditDataSet().getSelected()); 154 154 } else { 155 c = DeleteCommand.delete( editLayer,lm.getEditDataSet().getSelected(), !alt /* also delete nodes in way */);155 c = DeleteCommand.delete(lm.getEditDataSet().getSelected(), !alt /* also delete nodes in way */); 156 156 } 157 157 // if c is null, an error occurred or the user aborted. Don't do anything in that case. … … 352 352 CheckParameterUtil.ensureParameterNotNull(toDelete, "toDelete"); 353 353 354 final Command cmd = DeleteCommand.delete( layer,toDelete);354 final Command cmd = DeleteCommand.delete(toDelete); 355 355 if (cmd != null) { 356 356 // cmd can be null if the user cancels dialogs DialogCommand displays … … 404 404 private Command buildDeleteCommands(MouseEvent e, int modifiers, boolean silent) { 405 405 DeleteParameters parameters = getDeleteParameters(e, modifiers); 406 OsmDataLayer editLayer = getLayerManager().getEditLayer();407 406 switch (parameters.mode) { 408 407 case node: 409 return DeleteCommand.delete( editLayer,Collections.singleton(parameters.nearestNode), false, silent);408 return DeleteCommand.delete(Collections.singleton(parameters.nearestNode), false, silent); 410 409 case node_with_references: 411 return DeleteCommand.deleteWithReferences( editLayer,Collections.singleton(parameters.nearestNode), silent);410 return DeleteCommand.deleteWithReferences(Collections.singleton(parameters.nearestNode), silent); 412 411 case segment: 413 return DeleteCommand.deleteWaySegment( editLayer,parameters.nearestSegment);412 return DeleteCommand.deleteWaySegment(parameters.nearestSegment); 414 413 case way: 415 return DeleteCommand.delete( editLayer,Collections.singleton(parameters.nearestSegment.way), false, silent);414 return DeleteCommand.delete(Collections.singleton(parameters.nearestSegment.way), false, silent); 416 415 case way_with_nodes: 417 return DeleteCommand.delete( editLayer,Collections.singleton(parameters.nearestSegment.way), true, silent);416 return DeleteCommand.delete(Collections.singleton(parameters.nearestSegment.way), true, silent); 418 417 case way_with_references: 419 return DeleteCommand.deleteWithReferences( editLayer,Collections.singleton(parameters.nearestSegment.way), true);418 return DeleteCommand.deleteWithReferences(Collections.singleton(parameters.nearestSegment.way), true); 420 419 default: 421 420 return null; -
trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java
r12641 r12718 488 488 newWay.setNodes(nodes); 489 489 if (nodes.size() < 2) { 490 final Command deleteCmd = DeleteCommand.delete( getLayerManager().getEditLayer(),Collections.singleton(targetWay), true);490 final Command deleteCmd = DeleteCommand.delete(Collections.singleton(targetWay), true); 491 491 if (deleteCmd != null) { 492 492 MainApplication.undoRedo.add(deleteCmd); … … 500 500 tr("Error"), JOptionPane.ERROR_MESSAGE); 501 501 } else { 502 final Command deleteCmd = DeleteCommand.delete( getLayerManager().getEditLayer(),Collections.singleton(candidateNode), true);502 final Command deleteCmd = DeleteCommand.delete(Collections.singleton(candidateNode), true); 503 503 if (deleteCmd != null) { 504 504 MainApplication.undoRedo.add(deleteCmd); -
trunk/src/org/openstreetmap/josm/actions/relation/RecentRelationsAction.java
r12663 r12718 19 19 20 20 import org.openstreetmap.josm.actions.JosmAction; 21 import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener; 21 22 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; 22 23 import org.openstreetmap.josm.data.osm.Relation; … … 25 26 import org.openstreetmap.josm.gui.layer.Layer; 26 27 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 27 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;28 28 import org.openstreetmap.josm.tools.ImageProvider; 29 29 import org.openstreetmap.josm.tools.Shortcut; -
trunk/src/org/openstreetmap/josm/command/AddCommand.java
r12663 r12718 45 45 * @param layer The data layer. Must not be {@code null} 46 46 * @param osm The primitive to add 47 * @deprecated to be removed end of 2017. Use {@link #AddCommand(DataSet, OsmPrimitive)} instead 47 48 */ 49 @Deprecated 48 50 public AddCommand(OsmDataLayer layer, OsmPrimitive osm) { 49 51 super(layer); -
trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java
r11609 r12718 59 59 * @param toSelect The OSM primitives to select at the end. Can be {@code null} 60 60 * @param layer The target data layer. Must not be {@code null} 61 */ 61 * @deprecated to be removed end of 2017. Use {@link #AddPrimitivesCommand(List, List, DataSet)} instead 62 */ 63 @Deprecated 62 64 public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect, OsmDataLayer layer) { 63 65 super(layer); 66 init(data, toSelect); 67 } 68 69 /** 70 * Constructs a new {@code AddPrimitivesCommand} to add data to the given data set. 71 * @param data The OSM primitives data to add. Must not be {@code null} 72 * @param toSelect The OSM primitives to select at the end. Can be {@code null} 73 * @param ds The target data set. Must not be {@code null} 74 * @since 12718 75 */ 76 public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect, DataSet ds) { 77 super(ds); 64 78 init(data, toSelect); 65 79 } -
trunk/src/org/openstreetmap/josm/command/ChangeCommand.java
r12663 r12718 45 45 * @param osm The existing primitive to modify 46 46 * @param newOsm The new primitive 47 * @deprecated to be removed end of 2017. Use {@link #ChangeCommand(DataSet, OsmPrimitive, OsmPrimitive)} instead 47 48 */ 49 @Deprecated 48 50 public ChangeCommand(OsmDataLayer layer, OsmPrimitive osm, OsmPrimitive newOsm) { 49 51 super(layer); -
trunk/src/org/openstreetmap/josm/command/Command.java
r12636 r12718 35 35 * one atomic action on a specific dataset, such as move or delete. 36 36 * 37 * The command remembers the {@link OsmDataLayer} it is operating on.37 * The command remembers the {@link DataSet} it is operating on. 38 38 * 39 39 * @author imi … … 135 135 private Map<OsmPrimitive, PrimitiveData> cloneMap = new HashMap<>(); 136 136 137 /** the layer which this command is applied to */ 137 /** 138 * the layer which this command is applied to 139 * @deprecated to be removed end of 2017. Use {@link #data} instead 140 */ 141 @Deprecated 138 142 private final OsmDataLayer layer; 139 143 … … 146 150 public Command() { 147 151 this.layer = MainApplication.getLayerManager().getEditLayer(); 148 this.data = layer != null ? layer.data : null;152 this.data = layer != null ? layer.data : Main.main.getEditDataSet(); 149 153 } 150 154 … … 154 158 * @param layer the data layer. Must not be null. 155 159 * @throws IllegalArgumentException if layer is null 156 */ 160 * @deprecated to be removed end of 2017. Use {@link #Command(DataSet)} instead 161 */ 162 @Deprecated 157 163 public Command(OsmDataLayer layer) { 158 164 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); … … 216 222 * @param oldLayer the old layer that was removed 217 223 * @return true if this command is invalid after that layer is removed. 218 */ 224 * @deprecated to be removed end of 2017. 225 */ 226 @Deprecated 219 227 public boolean invalidBecauselayerRemoved(Layer oldLayer) { 220 228 return layer == oldLayer; … … 234 242 * Replies the layer this command is (or was) applied to. 235 243 * @return the layer this command is (or was) applied to 236 */ 244 * @deprecated to be removed end of 2017. Use {@link #getAffectedDataSet} instead 245 */ 246 @Deprecated 237 247 protected OsmDataLayer getLayer() { 238 248 return layer; … … 371 381 * Invalidate all layers that were affected by this command. 372 382 * @see Layer#invalidate() 373 */ 383 * @deprecated to be removed end of 2017. 384 */ 385 @Deprecated 374 386 public void invalidateAffectedLayers() { 375 387 OsmDataLayer layer = getLayer(); -
trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
r12663 r12718 108 108 109 109 /** 110 * Constructor for a single data item. Use the collection constructor to delete multiple 111 * objects. 110 * Constructor for a single data item. Use the collection constructor to delete multiple objects. 112 111 * 113 112 * @param layer the layer context for deleting this primitive. Must not be null. … … 115 114 * @throws IllegalArgumentException if data is null 116 115 * @throws IllegalArgumentException if layer is null 117 */ 116 * @deprecated to be removed end of 2017. Use {@link #DeleteCommand(DataSet, OsmPrimitive)} instead 117 */ 118 @Deprecated 118 119 public DeleteCommand(OsmDataLayer layer, OsmPrimitive data) { 119 120 this(layer, Collections.singleton(data)); … … 121 122 122 123 /** 123 * Constructor for a collection of data to be deleted in the context of 124 * a specific layer 124 * Constructor for a single data item. Use the collection constructor to delete multiple objects. 125 * 126 * @param dataset the data set context for deleting this primitive. Must not be null. 127 * @param data the primitive to delete. Must not be null. 128 * @throws IllegalArgumentException if data is null 129 * @throws IllegalArgumentException if layer is null 130 * @since 12718 131 */ 132 public DeleteCommand(DataSet dataset, OsmPrimitive data) { 133 this(dataset, Collections.singleton(data)); 134 } 135 136 /** 137 * Constructor for a collection of data to be deleted in the context of a specific layer 125 138 * 126 139 * @param layer the layer context for deleting these primitives. Must not be null. … … 128 141 * @throws IllegalArgumentException if layer is null 129 142 * @throws IllegalArgumentException if data is null or empty 130 */ 143 * @deprecated to be removed end of 2017. Use {@link #DeleteCommand(DataSet, Collection)} instead 144 */ 145 @Deprecated 131 146 public DeleteCommand(OsmDataLayer layer, Collection<? extends OsmPrimitive> data) { 132 147 super(layer); … … 137 152 138 153 /** 139 * Constructor for a collection of data to be deleted in the context of 140 * a specific data set 154 * Constructor for a collection of data to be deleted in the context of a specific data set 141 155 * 142 156 * @param dataset the dataset context for deleting these primitives. Must not be null. … … 286 300 * @return command A command to perform the deletions, or null of there is nothing to delete. 287 301 * @throws IllegalArgumentException if layer is null 288 */ 302 * @deprecated to be removed end of 2017. Use {@link #deleteWithReferences(Collection, boolean)} instead 303 */ 304 @Deprecated 289 305 public static Command deleteWithReferences(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection, boolean silent) { 290 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 306 return deleteWithReferences(selection, silent); 307 } 308 309 /** 310 * Delete the primitives and everything they reference. 311 * 312 * If a node is deleted, the node and all ways and relations the node is part of are deleted as well. 313 * If a way is deleted, all relations the way is member of are also deleted. 314 * If a way is deleted, only the way and no nodes are deleted. 315 * 316 * @param selection The list of all object to be deleted. 317 * @param silent Set to true if the user should not be bugged with additional dialogs 318 * @return command A command to perform the deletions, or null of there is nothing to delete. 319 * @throws IllegalArgumentException if layer is null 320 * @since 12718 321 */ 322 public static Command deleteWithReferences(Collection<? extends OsmPrimitive> selection, boolean silent) { 291 323 if (selection == null || selection.isEmpty()) return null; 292 324 Set<OsmPrimitive> parents = OsmPrimitive.getReferrer(selection); … … 297 329 if (!silent && !checkAndConfirmOutlyingDelete(parents, null)) 298 330 return null; 299 return new DeleteCommand( layer, parents);331 return new DeleteCommand(parents.iterator().next().getDataSet(), parents); 300 332 } 301 333 … … 307 339 * If a way is deleted, only the way and no nodes are deleted. 308 340 * 309 * @param layer the {@link OsmDataLayer} in whose context primitives are deleted. Must not be null.341 * @param layer unused 310 342 * @param selection The list of all object to be deleted. 311 343 * @return command A command to perform the deletions, or null of there is nothing to delete. 312 344 * @throws IllegalArgumentException if layer is null 313 */ 345 * @deprecated to be removed end of 2017. Use {@link #deleteWithReferences(Collection)} instead 346 */ 347 @Deprecated 314 348 public static Command deleteWithReferences(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection) { 315 return deleteWithReferences(layer, selection, false); 349 return deleteWithReferences(selection); 350 } 351 352 /** 353 * Delete the primitives and everything they reference. 354 * 355 * If a node is deleted, the node and all ways and relations the node is part of are deleted as well. 356 * If a way is deleted, all relations the way is member of are also deleted. 357 * If a way is deleted, only the way and no nodes are deleted. 358 * 359 * @param selection The list of all object to be deleted. 360 * @return command A command to perform the deletions, or null of there is nothing to delete. 361 * @throws IllegalArgumentException if layer is null 362 * @since 12718 363 */ 364 public static Command deleteWithReferences(Collection<? extends OsmPrimitive> selection) { 365 return deleteWithReferences(selection, false); 316 366 } 317 367 … … 325 375 * they are part of a relation, inform the user and do not delete. 326 376 * 327 * @param layer the {@link OsmDataLayer} in whose context the primitives are deleted377 * @param layer unused 328 378 * @param selection the objects to delete. 329 379 * @return command a command to perform the deletions, or null if there is nothing to delete. 330 */ 380 * @deprecated to be removed end of 2017. Use {@link #delete(Collection)} instead 381 */ 382 @Deprecated 331 383 public static Command delete(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection) { 332 return delete(layer, selection, true, false); 384 return delete(selection); 385 } 386 387 /** 388 * Try to delete all given primitives. 389 * 390 * If a node is used by a way, it's removed from that way. If a node or a way is used by a 391 * relation, inform the user and do not delete. 392 * 393 * If this would cause ways with less than 2 nodes to be created, delete these ways instead. If 394 * they are part of a relation, inform the user and do not delete. 395 * 396 * @param selection the objects to delete. 397 * @return command a command to perform the deletions, or null if there is nothing to delete. 398 * @since 12718 399 */ 400 public static Command delete(Collection<? extends OsmPrimitive> selection) { 401 return delete(selection, true, false); 333 402 } 334 403 … … 376 445 * they are part of a relation, inform the user and do not delete. 377 446 * 378 * @param layer the {@link OsmDataLayer} in whose context the primitives are deleted447 * @param layer unused 379 448 * @param selection the objects to delete. 380 449 * @param alsoDeleteNodesInWay <code>true</code> if nodes should be deleted as well 381 450 * @return command a command to perform the deletions, or null if there is nothing to delete. 382 */ 451 * @deprecated to be removed end of 2017. Use {@link #delete(Collection, boolean)} instead 452 */ 453 @Deprecated 383 454 public static Command delete(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection, 384 455 boolean alsoDeleteNodesInWay) { 385 return delete( layer, selection, alsoDeleteNodesInWay, false /* not silent */);456 return delete(selection, alsoDeleteNodesInWay); 386 457 } 387 458 … … 395 466 * they are part of a relation, inform the user and do not delete. 396 467 * 397 * @param layer the {@link OsmDataLayer} in whose context the primitives are deleted 468 * @param selection the objects to delete. 469 * @param alsoDeleteNodesInWay <code>true</code> if nodes should be deleted as well 470 * @return command a command to perform the deletions, or null if there is nothing to delete. 471 * @since 12718 472 */ 473 public static Command delete(Collection<? extends OsmPrimitive> selection, boolean alsoDeleteNodesInWay) { 474 return delete(selection, alsoDeleteNodesInWay, false /* not silent */); 475 } 476 477 /** 478 * Try to delete all given primitives. 479 * 480 * If a node is used by a way, it's removed from that way. If a node or a way is used by a 481 * relation, inform the user and do not delete. 482 * 483 * If this would cause ways with less than 2 nodes to be created, delete these ways instead. If 484 * they are part of a relation, inform the user and do not delete. 485 * 486 * @param layer unused 398 487 * @param selection the objects to delete. 399 488 * @param alsoDeleteNodesInWay <code>true</code> if nodes should be deleted as well 400 489 * @param silent set to true if the user should not be bugged with additional questions 401 490 * @return command a command to perform the deletions, or null if there is nothing to delete. 402 */ 491 * @deprecated to be removed end of 2017. Use {@link #delete(Collection, boolean, boolean)} instead 492 */ 493 @Deprecated 403 494 public static Command delete(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection, 404 495 boolean alsoDeleteNodesInWay, boolean silent) { 496 return delete(selection, alsoDeleteNodesInWay, silent); 497 } 498 499 /** 500 * Try to delete all given primitives. 501 * 502 * If a node is used by a way, it's removed from that way. If a node or a way is used by a 503 * relation, inform the user and do not delete. 504 * 505 * If this would cause ways with less than 2 nodes to be created, delete these ways instead. If 506 * they are part of a relation, inform the user and do not delete. 507 * 508 * @param selection the objects to delete. 509 * @param alsoDeleteNodesInWay <code>true</code> if nodes should be deleted as well 510 * @param silent set to true if the user should not be bugged with additional questions 511 * @return command a command to perform the deletions, or null if there is nothing to delete. 512 * @since 12718 513 */ 514 public static Command delete(Collection<? extends OsmPrimitive> selection, boolean alsoDeleteNodesInWay, boolean silent) { 405 515 if (selection == null || selection.isEmpty()) 406 516 return null; … … 460 570 // 461 571 if (!primitivesToDelete.isEmpty()) { 462 cmds.add(layer != null ? new DeleteCommand(layer, primitivesToDelete) : 463 new DeleteCommand(primitivesToDelete.iterator().next().getDataSet(), primitivesToDelete)); 572 cmds.add(new DeleteCommand(primitivesToDelete.iterator().next().getDataSet(), primitivesToDelete)); 464 573 } 465 574 … … 469 578 /** 470 579 * Create a command that deletes a single way segment. The way may be split by this. 471 * @param layer The layer the segment is in.580 * @param layer unused 472 581 * @param ws The way segment that should be deleted 473 582 * @return A matching command to safely delete that segment. 474 */ 583 * @deprecated to be removed end of 2017. Use {@link #deleteWaySegment(WaySegment)} instead 584 */ 585 @Deprecated 475 586 public static Command deleteWaySegment(OsmDataLayer layer, WaySegment ws) { 587 return deleteWaySegment(ws); 588 } 589 590 /** 591 * Create a command that deletes a single way segment. The way may be split by this. 592 * @param ws The way segment that should be deleted 593 * @return A matching command to safely delete that segment. 594 * @since 12718 595 */ 596 public static Command deleteWaySegment(WaySegment ws) { 476 597 if (ws.way.getNodesCount() < 3) 477 return delete( layer,Collections.singleton(ws.way), false);598 return delete(Collections.singleton(ws.way), false); 478 599 479 600 if (ws.way.isClosed()) { … … 506 627 return new ChangeCommand(ws.way, wnew); 507 628 } else { 508 SplitWayResult split = SplitWayAction.splitWay( layer,ws.way, Arrays.asList(n1, n2), Collections.<OsmPrimitive>emptyList());629 SplitWayResult split = SplitWayAction.splitWay(ws.way, Arrays.asList(n1, n2), Collections.<OsmPrimitive>emptyList()); 509 630 return split != null ? split.getCommand() : null; 510 631 } -
trunk/src/org/openstreetmap/josm/command/PurgeCommand.java
r12688 r12718 54 54 * @param toPurge primitives to purge 55 55 * @param makeIncomplete primitives to make incomplete 56 * @deprecated to be removed end of 2017. Use {@link #PurgeCommand(DataSet, Collection, Collection)} instead 56 57 */ 58 @Deprecated 57 59 public PurgeCommand(OsmDataLayer layer, Collection<OsmPrimitive> toPurge, Collection<OsmPrimitive> makeIncomplete) { 58 60 super(layer); … … 319 321 * @return command to purge selected OSM primitives 320 322 * @since 12688 323 * @deprecated to be removed end of 2017. Use {@link #build(Collection, List)} instead 321 324 */ 325 @Deprecated 322 326 public static PurgeCommand build(OsmDataLayer layer, Collection<OsmPrimitive> sel, List<OsmPrimitive> toPurgeAdditionally) { 327 return build(sel, toPurgeAdditionally); 328 } 329 330 /** 331 * Creates a new {@code PurgeCommand} to purge selected OSM primitives. 332 * @param sel selected OSM primitives 333 * @param toPurgeAdditionally optional list that will be filled with primitives to be purged that have not been in the selection 334 * @return command to purge selected OSM primitives 335 * @since 12718 336 */ 337 public static PurgeCommand build(Collection<OsmPrimitive> sel, List<OsmPrimitive> toPurgeAdditionally) { 323 338 Set<OsmPrimitive> toPurge = new HashSet<>(sel); 324 339 // finally, contains all objects that are purged … … 423 438 } 424 439 425 return layer != null ? new PurgeCommand(layer, toPurgeChecked, makeIncomplete) 426 : new PurgeCommand(toPurgeChecked.iterator().next().getDataSet(), toPurgeChecked, makeIncomplete); 440 return new PurgeCommand(toPurgeChecked.iterator().next().getDataSet(), toPurgeChecked, makeIncomplete); 427 441 } 428 442 -
trunk/src/org/openstreetmap/josm/command/SequenceCommand.java
r11874 r12718 12 12 13 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 import org.openstreetmap.josm.gui.layer.Layer; 14 15 import org.openstreetmap.josm.tools.ImageProvider; 15 16 import org.openstreetmap.josm.tools.Utils; … … 136 137 } 137 138 139 /** 140 * Invalidate all layers that were affected by this command. 141 * @see Layer#invalidate() 142 * @deprecated to be removed end of 2017. 143 */ 138 144 @Override 145 @Deprecated 139 146 public void invalidateAffectedLayers() { 140 147 super.invalidateAffectedLayers(); -
trunk/src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java
r12672 r12718 16 16 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; 17 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 import org.openstreetmap.josm.gui.MainApplication;19 18 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 20 19 import org.openstreetmap.josm.tools.ImageProvider; … … 33 32 * @param layer the data layer. Must not be null. 34 33 * @param conflict the conflict to add 34 * @deprecated to be removed end of 2017. Use {@link #ConflictAddCommand(DataSet, Conflict)} instead 35 35 */ 36 @Deprecated 36 37 public ConflictAddCommand(OsmDataLayer layer, Conflict<? extends OsmPrimitive> conflict) { 37 38 super(layer); … … 56 57 + "''{1}''.<br>" 57 58 + "This conflict cannot be added.</html>", 58 Utils.escapeReservedCharactersHTML(get Layer().getName()),59 Utils.escapeReservedCharactersHTML(getAffectedDataSet().getName()), 59 60 Utils.escapeReservedCharactersHTML(conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance())) 60 61 ), … … 77 78 @Override 78 79 public void undoCommand() { 79 if (MainApplication.isDisplayingMapView() && !MainApplication.getLayerManager().containsLayer(getLayer())) { 80 DataSet ds = getAffectedDataSet(); 81 if (!Main.main.containsDataSet(ds)) { 80 82 Logging.warn(tr("Layer ''{0}'' does not exist any more. Cannot remove conflict for object ''{1}''.", 81 getLayer().getName(),83 ds.getName(), 82 84 conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance()) 83 85 )); 84 86 return; 85 87 } 86 getAffectedDataSet().getConflicts().remove(conflict);88 ds.getConflicts().remove(conflict); 87 89 } 88 90 -
trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java
r12672 r12718 6 6 import java.util.Objects; 7 7 8 import org.openstreetmap.josm.Main; 8 9 import org.openstreetmap.josm.command.Command; 9 10 import org.openstreetmap.josm.data.conflict.Conflict; 10 11 import org.openstreetmap.josm.data.conflict.ConflictCollection; 11 12 import org.openstreetmap.josm.data.osm.DataSet; 12 import org.openstreetmap.josm.gui.MainApplication;13 13 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 14 14 import org.openstreetmap.josm.tools.Logging; … … 24 24 public abstract class ConflictResolveCommand extends Command { 25 25 /** the list of resolved conflicts */ 26 private final ConflictCollection resolvedConflicts ;26 private final ConflictCollection resolvedConflicts = new ConflictCollection(); 27 27 28 28 /** … … 30 30 */ 31 31 public ConflictResolveCommand() { 32 super(); 33 resolvedConflicts = new ConflictCollection(); 32 // Do nothing 34 33 } 35 34 … … 37 36 * Constructs a new {@code ConflictResolveCommand} in the context of a given data layer. 38 37 * @param layer the data layer. Must not be null. 38 * @deprecated to be removed end of 2017. Use {@link #ConflictResolveCommand(DataSet)} instead 39 39 */ 40 @Deprecated 40 41 public ConflictResolveCommand(OsmDataLayer layer) { 41 42 super(layer); 42 resolvedConflicts = new ConflictCollection(); 43 } 44 45 /** 46 * Constructs a new {@code ConflictResolveCommand} in the context of a given data set. 47 * @param ds the data set. Must not be null. 48 */ 49 public ConflictResolveCommand(DataSet ds) { 50 super(ds); 43 51 } 44 52 … … 56 64 /** 57 65 * reconstitutes all remembered conflicts. Add the remembered conflicts to the 58 * set of conflicts of the {@link OsmDataLayer} this command was applied to.66 * set of conflicts of the {@link DataSet} this command was applied to. 59 67 * 60 68 */ … … 72 80 super.undoCommand(); 73 81 74 if (MainApplication.isDisplayingMapView()) {75 if (!MainApplication.getLayerManager().containsLayer(getLayer())) {76 77 78 getLayer().toString()79 80 81 82 DataSet ds = getAffectedDataSet(); 83 if (!Main.main.containsDataSet(ds)) { 84 Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more", 85 this.toString(), 86 ds.getName() 87 )); 88 return; 89 } 82 90 83 MainApplication.getLayerManager().setActiveLayer(getLayer()); 84 } 91 Main.main.setEditDataSet(ds); 85 92 reconstituteConflicts(); 86 93 } -
trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java
r12672 r12718 10 10 import javax.swing.Icon; 11 11 12 import org.openstreetmap.josm.Main; 12 13 import org.openstreetmap.josm.data.conflict.Conflict; 13 14 import org.openstreetmap.josm.data.osm.DataSet; … … 15 16 import org.openstreetmap.josm.data.osm.Relation; 16 17 import org.openstreetmap.josm.data.osm.RelationMember; 17 import org.openstreetmap.josm.gui.MainApplication;18 import org.openstreetmap.josm.gui.layer.OsmDataLayer;19 18 import org.openstreetmap.josm.tools.ImageProvider; 20 19 import org.openstreetmap.josm.tools.Logging; … … 72 71 @Override 73 72 public void undoCommand() { 74 OsmDataLayer layer = getLayer();75 if (!Main Application.getLayerManager().containsLayer(layer)) {73 DataSet editDs = getAffectedDataSet(); 74 if (!Main.main.containsDataSet(editDs)) { 76 75 Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more", 77 76 this.toString(), 78 layer.toString()77 editDs.getName() 79 78 )); 80 79 return; 81 80 } 82 81 83 MainApplication.getLayerManager().setActiveLayer(layer); 84 DataSet editDs = MainApplication.getLayerManager().getEditDataSet(); 82 Main.main.setEditDataSet(editDs); 85 83 86 84 // restore the former state -
trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java
r12691 r12718 11 11 import org.openstreetmap.josm.data.osm.DataSet; 12 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 import org.openstreetmap.josm.gui.MainApplication;14 import org.openstreetmap.josm.gui.layer.Layer;15 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;16 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;17 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;18 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;19 import org.openstreetmap.josm.gui.layer.OsmDataLayer;20 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;21 13 import org.openstreetmap.josm.tools.CheckParameterUtil; 22 14 23 15 /** 24 * This is the global undo/redo handler for all {@link OsmDataLayer}s.16 * This is the global undo/redo handler for all {@link DataSet}s. 25 17 * <p> 26 * If you want to change a data layer, you can use {@link #add(Command)} to execute a command on it and make that command undoable.18 * If you want to change a data set, you can use {@link #add(Command)} to execute a command on it and make that command undoable. 27 19 */ 28 public class UndoRedoHandler implements LayerChangeListener{20 public class UndoRedoHandler { 29 21 30 22 /** … … 45 37 */ 46 38 public UndoRedoHandler() { 47 MainApplication.getLayerManager().addLayerChangeListener(this); 39 // Do nothing 40 } 41 42 /** 43 * A listener that gets notified of command queue (undo/redo) size changes. 44 * @since 12718 (moved from {@code OsmDataLayer} 45 */ 46 @FunctionalInterface 47 public interface CommandQueueListener { 48 /** 49 * Notifies the listener about the new queue size 50 * @param queueSize Undo stack size 51 * @param redoSize Redo stack size 52 */ 53 void commandChanged(int queueSize, int redoSize); 48 54 } 49 55 … … 92 98 } 93 99 addNoRedraw(c); 94 c.invalidateAffectedLayers();95 100 afterAdd(); 96 101 … … 125 130 final Command c = commands.removeLast(); 126 131 c.undoCommand(); 127 c.invalidateAffectedLayers();128 132 redoCommands.addFirst(c); 129 133 if (commands.isEmpty()) { … … 161 165 final Command c = redoCommands.removeFirst(); 162 166 c.executeCommand(); 163 c.invalidateAffectedLayers();164 167 commands.add(c); 165 168 if (redoCommands.isEmpty()) { … … 197 200 198 201 /** 199 * Resets all commands that affect the given layer. 200 * @param layer The layer that was affected. 201 */ 202 public void clean(Layer layer) { 203 if (layer == null) 202 * Resets all commands that affect the given dataset. 203 * @param dataSet The data set that was affected. 204 * @since 12718 205 */ 206 public void clean(DataSet dataSet) { 207 if (dataSet == null) 204 208 return; 205 209 boolean changed = false; 206 210 for (Iterator<Command> it = commands.iterator(); it.hasNext();) { 207 if (it.next(). invalidBecauselayerRemoved(layer)) {211 if (it.next().getAffectedDataSet() == dataSet) { 208 212 it.remove(); 209 213 changed = true; … … 211 215 } 212 216 for (Iterator<Command> it = redoCommands.iterator(); it.hasNext();) { 213 if (it.next(). invalidBecauselayerRemoved(layer)) {217 if (it.next().getAffectedDataSet() == dataSet) { 214 218 it.remove(); 215 219 changed = true; … … 219 223 fireCommandsChanged(); 220 224 } 221 }222 223 @Override224 public void layerRemoving(LayerRemoveEvent e) {225 clean(e.getRemovedLayer());226 }227 228 @Override229 public void layerAdded(LayerAddEvent e) {230 // Do nothing231 }232 233 @Override234 public void layerOrderChanged(LayerOrderChangeEvent e) {235 // Do nothing236 225 } 237 226 -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r12672 r12718 169 169 private final List<AbstractDatasetChangedEvent> cachedEvents = new ArrayList<>(); 170 170 171 private String name; 171 172 private UploadPolicy uploadPolicy; 172 173 … … 1360 1361 } 1361 1362 1363 /** 1364 * Returns the name of this data set (optional). 1365 * @return the name of this data set. Can be {@code null} 1366 * @since 12718 1367 */ 1368 public String getName() { 1369 return name; 1370 } 1371 1372 /** 1373 * Sets the name of this data set. 1374 * @param name the new name of this data set. Can be {@code null} to reset it 1375 * @since 12718 1376 */ 1377 public void setName(String name) { 1378 this.name = name; 1379 } 1380 1362 1381 /* --------------------------------------------------------------------------------- */ 1363 1382 /* interface ProjectionChangeListner */ -
trunk/src/org/openstreetmap/josm/data/validation/Test.java
r12667 r12718 23 23 import org.openstreetmap.josm.data.osm.search.SearchCompiler.NotOutsideDataSourceArea; 24 24 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 25 import org.openstreetmap.josm.gui.MainApplication;26 25 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 27 26 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 331 330 } 332 331 if (!primitivesToDelete.isEmpty()) { 333 return DeleteCommand.delete( MainApplication.getLayerManager().getEditLayer(),primitivesToDelete);332 return DeleteCommand.delete(primitivesToDelete); 334 333 } else { 335 334 return null; -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12695 r12718 72 72 import org.openstreetmap.josm.data.Bounds; 73 73 import org.openstreetmap.josm.data.UndoRedoHandler; 74 import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener; 74 75 import org.openstreetmap.josm.data.Version; 75 76 import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder; … … 84 85 import org.openstreetmap.josm.gui.io.SaveLayersDialog; 85 86 import org.openstreetmap.josm.gui.layer.AutosaveTask; 87 import org.openstreetmap.josm.gui.layer.Layer; 88 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; 89 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener; 90 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 91 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 86 92 import org.openstreetmap.josm.gui.layer.MainLayerManager; 87 import org.openstreetmap.josm.gui.layer.OsmDataLayer .CommandQueueListener;93 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 88 94 import org.openstreetmap.josm.gui.layer.TMSLayer; 89 95 import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; … … 187 193 /** 188 194 * The commands undo/redo handler. 189 * @since 12641 (as a replacement to {@code Main.main.undoRedo})190 */ 191 public static final UndoRedoHandler undoRedo = new UndoRedoHandler(); // Must be declared after layerManager195 * @since 12641 196 */ 197 public static UndoRedoHandler undoRedo; 192 198 193 199 /** … … 213 219 public MainApplication(MainFrame mainFrame) { 214 220 this.mainFrame = mainFrame; 221 undoRedo = super.undoRedo; 222 getLayerManager().addLayerChangeListener(new LayerChangeListener() { 223 @Override 224 public void layerRemoving(LayerRemoveEvent e) { 225 Layer layer = e.getRemovedLayer(); 226 if (layer instanceof OsmDataLayer) { 227 undoRedo.clean(((OsmDataLayer) layer).data); 228 } 229 } 230 231 @Override 232 public void layerOrderChanged(LayerOrderChangeEvent e) { 233 // Do nothing 234 } 235 236 @Override 237 public void layerAdded(LayerAddEvent e) { 238 // Do nothing 239 } 240 }); 215 241 } 216 242 … … 405 431 public DataSet getEditDataSet() { 406 432 return getLayerManager().getEditDataSet(); 433 } 434 435 @Override 436 public void setEditDataSet(DataSet ds) { 437 Optional<OsmDataLayer> layer = getLayerManager().getLayersOfType(OsmDataLayer.class).stream() 438 .filter(l -> l.data.equals(ds)).findFirst(); 439 if (layer.isPresent()) { 440 getLayerManager().setActiveLayer(layer.get()); 441 } 442 } 443 444 @Override 445 public boolean containsDataSet(DataSet ds) { 446 return getLayerManager().getLayersOfType(OsmDataLayer.class).stream().anyMatch(l -> l.data.equals(ds)); 407 447 } 408 448 -
trunk/src/org/openstreetmap/josm/gui/datatransfer/importers/PrimitiveDataPaster.java
r12641 r12718 83 83 } 84 84 } 85 return new AddPrimitivesCommand(bufferCopy, toSelect, layer );85 return new AddPrimitivesCommand(bufferCopy, toSelect, layer.data); 86 86 } 87 87 -
trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
r12641 r12718 39 39 import org.openstreetmap.josm.command.Command; 40 40 import org.openstreetmap.josm.command.PseudoCommand; 41 import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener; 41 42 import org.openstreetmap.josm.data.osm.DataSet; 42 43 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 44 45 import org.openstreetmap.josm.gui.SideButton; 45 46 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 46 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;47 47 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 48 48 import org.openstreetmap.josm.tools.GBC; -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/RefreshAction.java
r12641 r12718 11 11 12 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener; 13 14 import org.openstreetmap.josm.data.osm.Relation; 14 15 import org.openstreetmap.josm.gui.HelpAwareOptionPane; … … 19 20 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel; 20 21 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 21 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;22 22 import org.openstreetmap.josm.gui.tagging.TagEditorModel; 23 23 import org.openstreetmap.josm.tools.ImageProvider; -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java
r12663 r12718 73 73 if (newRelation.getMembersCount() == 0 && !newRelation.hasKeys()) 74 74 return; 75 MainApplication.undoRedo.add(new AddCommand(layer , newRelation));75 MainApplication.undoRedo.add(new AddCommand(layer.data, newRelation)); 76 76 77 77 // make sure everybody is notified about the changes … … 95 95 memberTableModel.applyToRelation(editedRelation); 96 96 Conflict<Relation> conflict = new Conflict<>(editor.getRelation(), editedRelation); 97 MainApplication.undoRedo.add(new ConflictAddCommand(layer , conflict));97 MainApplication.undoRedo.add(new ConflictAddCommand(layer.data, conflict)); 98 98 } 99 99 -
trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
r12170 r12718 339 339 * @param name the name. If null, the name is set to the empty string. 340 340 */ 341 public finalvoid setName(String name) {341 public void setName(String name) { 342 342 if (this.name != null) { 343 343 removeColorPropertyListener(); -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r12675 r12718 295 295 296 296 /** 297 * A listener that gets notified of command queue (undo/redo) size changes.298 */299 @FunctionalInterface300 public interface CommandQueueListener {301 /**302 * Notifies the listener about the new queue size303 * @param queueSize Undo stack size304 * @param redoSize Redo stack size305 */306 void commandChanged(int queueSize, int redoSize);307 }308 309 /**310 297 * Listener called when a state of this layer has changed. 311 298 * @since 10600 (functional interface) … … 401 388 CheckParameterUtil.ensureParameterNotNull(data, "data"); 402 389 this.data = data; 390 this.data.setName(name); 403 391 this.setAssociatedFile(associatedFile); 404 392 data.addDataSetListener(new DataSetListenerAdapter(this)); … … 603 591 return; 604 592 605 MainApplication.undoRedo.clean( this);593 MainApplication.undoRedo.clean(data); 606 594 607 595 // if uploaded, clean the modified flags as well … … 1146 1134 invalidate(); 1147 1135 } 1136 1137 @Override 1138 public void setName(String name) { 1139 if (data != null) { 1140 data.setName(name); 1141 } 1142 super.setName(name); 1143 } 1148 1144 } -
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r12713 r12718 37 37 import org.openstreetmap.josm.gui.MainApplication; 38 38 import org.openstreetmap.josm.gui.MapFrame; 39 import org.openstreetmap.josm.gui.layer.OsmDataLayer;40 39 41 40 /** … … 103 102 } 104 103 105 OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();106 104 DataSet dataset = ways.get(0).getDataSet(); 107 105 … … 210 208 211 209 if (intNode == newNode) { 212 cmds.add( layer != null ? new AddCommand(layer, intNode) :new AddCommand(dataset, intNode));210 cmds.add(new AddCommand(dataset, intNode)); 213 211 } 214 212 } -
trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java
r12688 r12718 104 104 } 105 105 // Purge all other ways and relations so dataset only contains lefthand traffic data 106 PurgeCommand.build( null,toPurge, null).executeCommand();106 PurgeCommand.build(toPurge, null).executeCommand(); 107 107 // Combine adjacent countries into a single polygon 108 108 Collection<Way> optimizedWays = new ArrayList<>(); -
trunk/test/unit/org/openstreetmap/josm/command/CommandTest.java
r12636 r12718 2 2 package org.openstreetmap.josm.command; 3 3 4 import static org.junit.Assert.assertFalse;5 4 import static org.junit.Assert.assertSame; 6 import static org.junit.Assert.assertTrue;7 5 8 6 import java.util.Arrays; … … 50 48 51 49 /** 52 * Test {@link Command#invalidBecauselayerRemoved(org.openstreetmap.josm.gui.layer.Layer)} 50 * Test {@link Command#getLayer()} 51 * @deprecated to be removed end of 2017 53 52 */ 54 53 @Test 55 public void testInvalidBecauselayerRemoved() { 56 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "test", null); 57 58 Command command = new NopCommand(); 59 assertFalse(command.invalidBecauselayerRemoved(layer2)); 60 assertTrue(command.invalidBecauselayerRemoved(testData.layer)); 61 62 Command command2 = new NopCommand(layer2); 63 assertTrue(command2.invalidBecauselayerRemoved(layer2)); 64 assertFalse(command2.invalidBecauselayerRemoved(testData.layer)); 65 } 66 67 /** 68 * Test {@link Command#getLayer()} 69 */ 70 @Test 54 @Deprecated 71 55 public void testGetLayer() { 72 56 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "test", null); 73 57 Command command = new NopCommand(); 74 Command command2 = new NopCommand(layer2 );58 Command command2 = new NopCommand(layer2.data); 75 59 assertSame(testData.layer, command.getLayer()); 76 60 assertSame(layer2, command2.getLayer()); … … 98 82 } 99 83 100 NopCommand( OsmDataLayer layer) {101 super( layer);84 NopCommand(DataSet dataset) { 85 super(dataset); 102 86 } 103 87
Note:
See TracChangeset
for help on using the changeset viewer.