Ticket #13036: commands-layerv2.patch
File commands-layerv2.patch, 73.8 KB (added by , 7 years ago) |
---|
-
src/org/openstreetmap/josm/Main.java
136 136 /** 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 /** 142 142 * The main menu bar at top of screen. … … 629 629 } 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 xxx 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 xxx 650 */ 651 public abstract boolean containsDataSet(DataSet ds); 652 653 /** 654 * This needs to be called whenever the content of the data set was invalidated. 655 * It triggers a repaint of the components that display it. 656 * @param ds the data set to invalidate 657 * @since xxx 658 */ 659 public abstract void invalidateDataSet(DataSet ds); 639 660 640 661 /** 641 662 * Registers a {@code JosmAction} and its shortcut. -
src/org/openstreetmap/josm/actions/JoinAreasAction.java
692 692 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); 698 698 commitCommands(marktr("Delete Ways that are not part of an inner multipolygon")); … … 1017 1017 List<List<Node>> chunks = buildNodeChunks(way, nodes); 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 1023 1023 if (split != null) { … … 1466 1466 for (Way w : inner) { 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); 1472 1472 … … 1537 1537 cmds.add(new ChangeCommand(r.rel, newRel)); 1538 1538 } 1539 1539 1540 OsmDataLayer layer = getLayerManager().getEditLayer();1541 1540 Relation newRel; 1542 1541 switch (multiouters.size()) { 1543 1542 case 0: … … 1566 1565 relationsToDelete.add(r.rel); 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 } 1572 1571 -
src/org/openstreetmap/josm/actions/PurgeAction.java
117 117 public PurgeCommand getPurgeCommand(Collection<OsmPrimitive> sel) { 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; 123 123 } -
src/org/openstreetmap/josm/actions/RedoAction.java
8 8 import java.awt.event.KeyEvent; 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 16 16 /** … … 18 18 * 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 /** 24 24 * Construct the action with "Redo" as label. -
src/org/openstreetmap/josm/actions/SplitWayAction.java
213 213 } 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()) { 219 219 getLayerManager().getEditDataSet().setSelected(result.getNewSelection()); … … 293 293 super.buttonAction(buttonIndex, evt); 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()) { 300 299 MainApplication.getLayerManager().getEditDataSet().setSelected(result.getNewSelection()); … … 497 496 * @param wayChunks the list of way chunks into the way is split. Must not be null. 498 497 * @param selection The list of currently selected primitives 499 498 * @return the result from the split operation 499 * @deprecated to be removed end of 2017. Use {@link #splitWay(Way, List, Collection)} instead 500 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 xxx 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 506 526 /** … … 520 540 * @param splitStrategy The strategy used to determine which way chunk should reuse the old id and its history 521 541 * @return the result from the split operation 522 542 * @since 8954 543 * @deprecated to be removed end of 2017. Use {@link #splitWay(Way, List, Collection, Strategy)} instead 523 544 */ 545 @Deprecated 524 546 public static SplitWayResult splitWay(OsmDataLayer layer, Way way, List<List<Node>> wayChunks, 525 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 xxx 567 */ 568 public static SplitWayResult splitWay(Way way, List<List<Node>> wayChunks, 569 Collection<? extends OsmPrimitive> selection, Strategy splitStrategy) { 526 570 // build a list of commands, and also a new selection list 527 571 final List<OsmPrimitive> newSelection = new ArrayList<>(selection.size() + wayChunks.size()); 528 572 newSelection.addAll(selection); … … 533 577 // Determine which part reuses the existing way 534 578 final Way wayToKeep = splitStrategy.determineWayToKeep(newWays); 535 579 536 return wayToKeep != null ? doSplitWay( layer,way, wayToKeep, newWays, newSelection) : null;580 return wayToKeep != null ? doSplitWay(way, wayToKeep, newWays, newSelection) : null; 537 581 } 538 582 539 static SplitWayResult doSplitWay(OsmDataLayer layer, Way way, Way wayToKeep, List<Way> newWays, 540 List<OsmPrimitive> newSelection) { 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()); 543 586 Collection<String> nowarnroles = Main.pref.getCollection("way.split.roles.nowarn", … … 549 592 // Change the original way 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); 555 598 } … … 560 603 newSelection.addAll(newWays); 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 566 609 boolean warnmerole = false; … … 687 730 } 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 } 693 736 if (warnmerole) { … … 740 783 * @param atNodes the list of nodes where the way is split. Must not be null. 741 784 * @param selection The list of currently selected primitives 742 785 * @return the result from the split operation 786 * @deprecated to be removed end of 2017. Use {@link #split(Way, List, Collection) instead} 743 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 xxx 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 749 814 @Override -
src/org/openstreetmap/josm/actions/UndoAction.java
8 8 import java.awt.event.KeyEvent; 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 16 16 /** … … 18 18 * 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 /** 24 24 * Construct the action with "Undo" as label. -
src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
150 150 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. 158 158 if (c != null) { … … 351 351 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 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 357 357 MainApplication.undoRedo.add(cmd); … … 403 403 */ 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; 422 421 } -
src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java
487 487 nodes.remove(candidateNode); 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); 493 493 } … … 499 499 tr("Cannot delete node that has tags"), 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); 505 505 } -
src/org/openstreetmap/josm/actions/relation/RecentRelationsAction.java
18 18 import javax.swing.plaf.basic.BasicArrowButton; 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; 23 24 import org.openstreetmap.josm.gui.MainApplication; 24 25 import org.openstreetmap.josm.gui.SideButton; 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; 30 30 -
src/org/openstreetmap/josm/command/AddCommand.java
44 44 * Creates the command and specify the element to add in the context of the given data layer. 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); 50 52 this.osm = Objects.requireNonNull(osm, "osm"); -
src/org/openstreetmap/josm/command/AddPrimitivesCommand.java
58 58 * @param data The OSM primitives data to add. Must not be {@code null} 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 * @deprecated to be removed end of 2017. Use {@link #AddPrimitivesCommand(List, List, DataSet)} instead 61 62 */ 63 @Deprecated 62 64 public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect, OsmDataLayer layer) { 63 65 super(layer); 64 66 init(data, toSelect); 65 67 } 66 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 xxx 75 */ 76 public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect, DataSet ds) { 77 super(ds); 78 init(data, toSelect); 79 } 80 67 81 private void init(List<PrimitiveData> data, List<PrimitiveData> toSelect) { 68 82 CheckParameterUtil.ensureParameterNotNull(data, "data"); 69 83 this.data = new ArrayList<>(data); -
src/org/openstreetmap/josm/command/ChangeCommand.java
44 44 * @param layer The data layer 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); 50 52 this.osm = osm; -
src/org/openstreetmap/josm/command/Command.java
34 34 * Classes implementing Command modify a dataset in a specific way. A command is 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 40 40 * @since 21 (creation) … … 134 134 /** the map of OsmPrimitives in the original state to OsmPrimitives in cloned state */ 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 140 144 /** the dataset which this command is applied to */ … … 145 149 */ 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 151 155 /** … … 153 157 * 154 158 * @param layer the data layer. Must not be null. 155 159 * @throws IllegalArgumentException if layer is null 160 * @deprecated to be removed end of 2017. Use {@link #Command(DataSet)} instead 156 161 */ 162 @Deprecated 157 163 public Command(OsmDataLayer layer) { 158 164 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 159 165 this.layer = layer; … … 215 221 * 216 222 * @param oldLayer the old layer that was removed 217 223 * @return true if this command is invalid after that layer is removed. 224 * @deprecated to be removed end of 2017. Use {@link #invalidBecauseDatasetRemoved} instead 218 225 */ 226 @Deprecated 219 227 public boolean invalidBecauselayerRemoved(Layer oldLayer) { 220 228 return layer == oldLayer; 221 229 } 222 230 223 231 /** 232 * Called when a dataset has been removed to have the command remove itself from 233 * any buffer if it is not longer applicable to it (e.g. it was part of 234 * the removed dataset) 235 * 236 * @param oldDataset the old data set that was removed 237 * @return true if this command is invalid after that data set is removed. 238 * @since xxx 239 */ 240 public boolean invalidBecauseDatasetRemoved(DataSet oldDataset) { 241 return data == oldDataset; 242 } 243 244 /** 224 245 * Lets other commands access the original version 225 246 * of the object. Usually for undoing. 226 247 * @param osm The requested OSM object … … 233 254 /** 234 255 * Replies the layer this command is (or was) applied to. 235 256 * @return the layer this command is (or was) applied to 257 * @deprecated to be removed end of 2017. Use {@link #getAffectedDataSet} instead 236 258 */ 259 @Deprecated 237 260 protected OsmDataLayer getLayer() { 238 261 return layer; 239 262 } … … 370 393 /** 371 394 * Invalidate all layers that were affected by this command. 372 395 * @see Layer#invalidate() 396 * @deprecated to be removed end of 2017. Use {@link #invalidateAffectedDataSet} instead 373 397 */ 398 @Deprecated 374 399 public void invalidateAffectedLayers() { 375 400 OsmDataLayer layer = getLayer(); 376 401 if (layer != null) { 377 402 layer.invalidate(); 378 403 } 379 404 } 405 406 /** 407 * Invalidate data set that was affected by this command. 408 * @see Main#invalidateDataSet 409 * @since xxx 410 */ 411 public void invalidateAffectedDataSet() { 412 Main.main.invalidateDataSet(data); 413 } 380 414 } -
src/org/openstreetmap/josm/command/DeleteCommand.java
107 107 } 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. 114 113 * @param data the primitive to delete. Must not be null. 115 114 * @throws IllegalArgumentException if data is null 116 115 * @throws IllegalArgumentException if layer is null 116 * @deprecated to be removed end of 2017. Use {@link #DeleteCommand(DataSet, OsmPrimitive)} instead 117 117 */ 118 @Deprecated 118 119 public DeleteCommand(OsmDataLayer layer, OsmPrimitive data) { 119 120 this(layer, Collections.singleton(data)); 120 121 } 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 xxx 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. 127 140 * @param data the primitives to delete. Must neither be null nor empty. 128 141 * @throws IllegalArgumentException if layer is null 129 142 * @throws IllegalArgumentException if data is null or empty 143 * @deprecated to be removed end of 2017. Use {@link #DeleteCommand(DataSet, Collection)} instead 130 144 */ 145 @Deprecated 131 146 public DeleteCommand(OsmDataLayer layer, Collection<? extends OsmPrimitive> data) { 132 147 super(layer); 133 148 CheckParameterUtil.ensureParameterNotNull(data, "data"); … … 136 151 } 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. 143 157 * @param data the primitives to delete. Must neither be null nor empty. … … 285 299 * @param silent Set to true if the user should not be bugged with additional dialogs 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 302 * @deprecated to be removed end of 2017. Use {@link #deleteWithReferences(Collection, boolean)} instead 288 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 xxx 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); 293 325 parents.addAll(selection); … … 296 328 return null; 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 302 334 /** … … 306 338 * If a way is deleted, all relations the way is member of are also deleted. 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 345 * @deprecated to be removed end of 2017. Use {@link #deleteWithReferences(Collection)} instead 313 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 xxx 363 */ 364 public static Command deleteWithReferences(Collection<? extends OsmPrimitive> selection) { 365 return deleteWithReferences(selection, false); 316 366 } 317 367 318 368 /** … … 324 374 * If this would cause ways with less than 2 nodes to be created, delete these ways instead. If 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. 380 * @deprecated to be removed end of 2017. Use {@link #delete(Collection)} instead 330 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 xxx 399 */ 400 public static Command delete(Collection<? extends OsmPrimitive> selection) { 401 return delete(selection, true, false); 333 402 } 334 403 335 404 /** … … 375 444 * If this would cause ways with less than 2 nodes to be created, delete these ways instead. If 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. 451 * @deprecated to be removed end of 2017. Use {@link #delete(Collection, boolean)} instead 382 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); 457 } 458 459 /** 460 * Try to delete all given primitives. 461 * 462 * If a node is used by a way, it's removed from that way. If a node or a way is used by a 463 * relation, inform the user and do not delete. 464 * 465 * If this would cause ways with less than 2 nodes to be created, delete these ways instead. If 466 * they are part of a relation, inform the user and do not delete. 467 * 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 xxx 472 */ 473 public static Command delete(Collection<? extends OsmPrimitive> selection, boolean alsoDeleteNodesInWay) { 474 return delete(selection, alsoDeleteNodesInWay, false /* not silent */); 386 475 } 387 476 388 477 /** … … 394 483 * If this would cause ways with less than 2 nodes to be created, delete these ways instead. If 395 484 * they are part of a relation, inform the user and do not delete. 396 485 * 397 * @param layer the {@link OsmDataLayer} in whose context the primitives are deleted486 * @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. 491 * @deprecated to be removed end of 2017. Use {@link #delete(Collection, boolean, boolean)} instead 402 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 xxx 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; 407 517 … … 459 569 // build the delete command 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 466 575 return new SequenceCommand(tr("Delete"), cmds); … … 468 577 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. 583 * @deprecated to be removed end of 2017. Use {@link #deleteWaySegment(WaySegment)} instead 474 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 xxx 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()) { 480 601 // If the way is circular (first and last nodes are the same), the way shouldn't be splitted … … 505 626 wnew.setNodes(n1); 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 } 511 632 } -
src/org/openstreetmap/josm/command/PurgeCommand.java
53 53 * @param layer OSM data layer 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); 59 61 init(toPurge, makeIncomplete); … … 318 320 * @param toPurgeAdditionally optional list that will be filled with primitives to be purged that have not been in the selection 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 xxx 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 325 340 Set<OsmPrimitive> toPurgeChecked = new HashSet<>(); … … 422 437 } 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 429 443 private static boolean hasOnlyIncompleteMembers( -
src/org/openstreetmap/josm/command/SequenceCommand.java
11 11 import javax.swing.Icon; 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; 16 17 … … 135 136 this.sequenceComplete = sequenceComplete; 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. Use {@link #invalidateAffectedDataSet} instead 143 */ 138 144 @Override 145 @Deprecated 139 146 public void invalidateAffectedLayers() { 140 147 super.invalidateAffectedLayers(); 141 148 for (Command c : sequence) { … … 144 151 } 145 152 146 153 @Override 154 public void invalidateAffectedDataSet() { 155 super.invalidateAffectedDataSet(); 156 for (Command c : sequence) { 157 c.invalidateAffectedDataSet(); 158 } 159 } 160 161 @Override 147 162 public int hashCode() { 148 163 return Objects.hash(super.hashCode(), Arrays.hashCode(sequence), sequenceComplete, name, continueOnError); 149 164 } -
src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java
15 15 import org.openstreetmap.josm.data.osm.DataSet; 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; 21 20 import org.openstreetmap.josm.tools.Logging; … … 32 31 * Constructs a new {@code ConflictAddCommand}. 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); 38 39 this.conflict = conflict; … … 55 56 tr("<html>Layer ''{0}'' already has a conflict for object<br>" 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 ), 61 62 tr("Double conflict"), … … 76 77 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 89 91 @Override -
src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java
5 5 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; 15 15 … … 23 23 */ 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 /** 29 29 * Constructs a new {@code ConflictResolveCommand} in the context of the current edit layer, if any. 30 30 */ 31 31 public ConflictResolveCommand() { 32 super(); 33 resolvedConflicts = new ConflictCollection(); 32 // Do nothing 34 33 } 35 34 36 35 /** 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 45 53 /** … … 55 63 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 */ 61 69 protected void reconstituteConflicts() { … … 71 79 public void undoCommand() { 72 80 super.undoCommand(); 73 81 74 if (MainApplication.isDisplayingMapView()) { 75 if (!MainApplication.getLayerManager().containsLayer(getLayer())) { 76 Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more", 77 this.toString(), 78 getLayer().toString() 79 )); 80 return; 81 } 82 83 MainApplication.getLayerManager().setActiveLayer(getLayer()); 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; 84 89 } 90 91 Main.main.setEditDataSet(ds); 85 92 reconstituteConflicts(); 86 93 } 87 94 -
src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java
9 9 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; 14 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 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; 21 20 … … 71 70 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 87 85 // -
src/org/openstreetmap/josm/data/UndoRedoHandler.java
10 10 import org.openstreetmap.josm.command.Command; 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 /** 31 23 * All commands that were made on the dataset. Don't write from outside! … … 44 36 * Constructs a new {@code UndoRedoHandler}. 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 xxx (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 50 56 /** … … 91 97 oldSelection = ds.getSelected(); 92 98 } 93 99 addNoRedraw(c); 94 c.invalidateAffected Layers();100 c.invalidateAffectedDataSet(); 95 101 afterAdd(); 96 102 97 103 // the command may have changed the selection so tell the listeners about the current situation … … 124 130 for (int i = 1; i <= num; ++i) { 125 131 final Command c = commands.removeLast(); 126 132 c.undoCommand(); 127 c.invalidateAffected Layers();133 c.invalidateAffectedDataSet(); 128 134 redoCommands.addFirst(c); 129 135 if (commands.isEmpty()) { 130 136 break; … … 160 166 for (int i = 0; i < num; ++i) { 161 167 final Command c = redoCommands.removeFirst(); 162 168 c.executeCommand(); 163 c.invalidateAffected Layers();169 c.invalidateAffectedDataSet(); 164 170 commands.add(c); 165 171 if (redoCommands.isEmpty()) { 166 172 break; … … 196 202 } 197 203 198 204 /** 199 * Resets all commands that affect the given layer. 200 * @param layer The layer that was affected. 205 * Resets all commands that affect the given dataset. 206 * @param dataSet The data set that was affected. 207 * @since xxx 201 208 */ 202 public void clean( Layer layer) {203 if ( layer== null)209 public void clean(DataSet dataSet) { 210 if (dataSet == null) 204 211 return; 205 212 boolean changed = false; 206 213 for (Iterator<Command> it = commands.iterator(); it.hasNext();) { 207 if (it.next().invalidBecause layerRemoved(layer)) {214 if (it.next().invalidBecauseDatasetRemoved(dataSet)) { 208 215 it.remove(); 209 216 changed = true; 210 217 } 211 218 } 212 219 for (Iterator<Command> it = redoCommands.iterator(); it.hasNext();) { 213 if (it.next().invalidBecause layerRemoved(layer)) {220 if (it.next().invalidBecauseDatasetRemoved(dataSet)) { 214 221 it.remove(); 215 222 changed = true; 216 223 } … … 220 227 } 221 228 } 222 229 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 }237 238 230 /** 239 231 * Removes a command queue listener. 240 232 * @param l The command queue listener to remove -
src/org/openstreetmap/josm/data/osm/DataSet.java
168 168 // Events that occurred while dataset was locked but should be fired after write lock is released 169 169 private final List<AbstractDatasetChangedEvent> cachedEvents = new ArrayList<>(); 170 170 171 private String name; 171 172 private UploadPolicy uploadPolicy; 172 173 173 174 private final ReadWriteLock lock = new ReentrantReadWriteLock(); … … 1359 1360 return conflicts; 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 xxx 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 xxx 1376 */ 1377 public void setName(String name) { 1378 this.name = name; 1379 } 1380 1362 1381 /* --------------------------------------------------------------------------------- */ 1363 1382 /* interface ProjectionChangeListner */ 1364 1383 /* --------------------------------------------------------------------------------- */ -
src/org/openstreetmap/josm/data/validation/Test.java
22 22 import org.openstreetmap.josm.data.osm.Way; 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; 28 27 import org.openstreetmap.josm.tools.GBC; … … 330 329 } 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; 336 335 } -
src/org/openstreetmap/josm/gui/MainApplication.java
39 39 import java.util.concurrent.ExecutorService; 40 40 import java.util.concurrent.Executors; 41 41 import java.util.concurrent.Future; 42 import java.util.function.Consumer; 42 43 import java.util.logging.Level; 43 44 import java.util.stream.Collectors; 44 45 import java.util.stream.Stream; … … 71 72 import org.openstreetmap.josm.actions.search.SearchAction; 72 73 import org.openstreetmap.josm.data.Bounds; 73 74 import org.openstreetmap.josm.data.UndoRedoHandler; 75 import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener; 74 76 import org.openstreetmap.josm.data.Version; 75 77 import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder; 76 78 import org.openstreetmap.josm.data.osm.DataSet; … … 83 85 import org.openstreetmap.josm.gui.io.CustomConfigurator.XMLCommandProcessor; 84 86 import org.openstreetmap.josm.gui.io.SaveLayersDialog; 85 87 import org.openstreetmap.josm.gui.layer.AutosaveTask; 88 import org.openstreetmap.josm.gui.layer.Layer; 89 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; 90 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener; 91 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 92 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 86 93 import org.openstreetmap.josm.gui.layer.MainLayerManager; 87 import org.openstreetmap.josm.gui.layer.OsmDataLayer .CommandQueueListener;94 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 88 95 import org.openstreetmap.josm.gui.layer.TMSLayer; 89 96 import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; 90 97 import org.openstreetmap.josm.gui.preferences.display.LafPreference; … … 186 193 187 194 /** 188 195 * The commands undo/redo handler. 189 * @since 12641 (as a replacement to {@code Main.main.undoRedo})196 * @since 12641 190 197 */ 191 public static final UndoRedoHandler undoRedo = new UndoRedoHandler(); // Must be declared after layerManager198 public static UndoRedoHandler undoRedo; 192 199 193 200 /** 194 201 * Listener that sets the enabled state of undo/redo menu entries. … … 212 219 */ 213 220 public MainApplication(MainFrame mainFrame) { 214 221 this.mainFrame = mainFrame; 222 undoRedo = super.undoRedo; 223 getLayerManager().addLayerChangeListener(new LayerChangeListener() { 224 @Override 225 public void layerRemoving(LayerRemoveEvent e) { 226 Layer layer = e.getRemovedLayer(); 227 if (layer instanceof OsmDataLayer) { 228 undoRedo.clean(((OsmDataLayer) layer).data); 229 } 230 } 231 232 @Override 233 public void layerOrderChanged(LayerOrderChangeEvent e) { 234 // Do nothing 235 } 236 237 @Override 238 public void layerAdded(LayerAddEvent e) { 239 // Do nothing 240 } 241 }); 215 242 } 216 243 217 244 /** … … 406 433 return getLayerManager().getEditDataSet(); 407 434 } 408 435 436 @Override 437 public void setEditDataSet(DataSet ds) { 438 consumeDataSet(ds, l -> getLayerManager().setActiveLayer(l)); 439 } 440 441 @Override 442 public boolean containsDataSet(DataSet ds) { 443 return getLayerManager().getLayersOfType(OsmDataLayer.class).stream().anyMatch(l -> l.data.equals(ds)); 444 } 445 446 @Override 447 public void invalidateDataSet(DataSet ds) { 448 consumeDataSet(ds, OsmDataLayer::invalidate); 449 } 450 451 private static void consumeDataSet(DataSet ds, Consumer<OsmDataLayer> consumer) { 452 Optional<OsmDataLayer> layer = getLayerManager().getLayersOfType(OsmDataLayer.class).stream() 453 .filter(l -> l.data.equals(ds)).findFirst(); 454 if (layer.isPresent()) { 455 consumer.accept(layer.get()); 456 } 457 } 458 409 459 /** 410 460 * Returns the command-line arguments used to run the application. 411 461 * @return the command-line arguments used to run the application -
src/org/openstreetmap/josm/gui/datatransfer/importers/PrimitiveDataPaster.java
82 82 throw BugReport.intercept(e).put("data", data); 83 83 } 84 84 } 85 return new AddPrimitivesCommand(bufferCopy, toSelect, layer );85 return new AddPrimitivesCommand(bufferCopy, toSelect, layer.data); 86 86 } 87 87 88 88 private static EnumMap<OsmPrimitiveType, Map<Long, Long>> generateNewPrimitives(PrimitiveTransferData pasteBuffer, -
src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
38 38 import org.openstreetmap.josm.actions.AutoScaleAction; 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; 43 44 import org.openstreetmap.josm.gui.MainApplication; 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; 49 49 import org.openstreetmap.josm.tools.ImageProvider; -
src/org/openstreetmap/josm/gui/dialogs/relation/actions/RefreshAction.java
10 10 import javax.swing.JOptionPane; 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; 15 16 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; … … 18 19 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable; 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; 24 24 import org.openstreetmap.josm.tools.Shortcut; -
src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java
72 72 // tags, don't add an empty relation 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 78 78 // … … 94 94 tagEditorModel.applyToPrimitive(editedRelation); 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 100 100 /** -
src/org/openstreetmap/josm/gui/layer/Layer.java
338 338 * 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(); 344 344 } -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
294 294 } 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) 312 299 */ … … 400 387 super(name); 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)); 405 393 data.addDataSetListener(MultipolygonCache.getInstance()); … … 602 590 if (processed == null || processed.isEmpty()) 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 608 596 data.cleanupDeletedPrimitives(); … … 1145 1133 public void highlightUpdated(HighlightUpdateEvent e) { 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 } -
src/org/openstreetmap/josm/tools/Geometry.java
36 36 import org.openstreetmap.josm.data.projection.Projections; 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 /** 42 41 * Some tools for geometry related tasks. … … 102 101 changedWays[pos] = false; 103 102 } 104 103 105 OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();106 104 DataSet dataset = ways.get(0).getDataSet(); 107 105 108 106 //iterate over all way pairs and introduce the intersections … … 209 207 intersectionNodes.add(intNode); 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 } 215 213 } else if (test && !intersectionNodes.isEmpty()) -
src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java
103 103 w.removeAll(); 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<>(); 109 109 List<Multipolygon> areas = JoinAreasAction.collectMultipolygons(ways); -
test/unit/org/openstreetmap/josm/command/CommandTest.java
49 49 } 50 50 51 51 /** 52 * Test {@link Command#invalidBecause layerRemoved(org.openstreetmap.josm.gui.layer.Layer)}52 * Test {@link Command#invalidBecauseDatasetRemoved} 53 53 */ 54 54 @Test 55 public void testInvalidBecause layerRemoved() {55 public void testInvalidBecauseDatasetRemoved() { 56 56 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "test", null); 57 57 58 58 Command command = new NopCommand(); 59 assertFalse(command.invalidBecause layerRemoved(layer2));60 assertTrue(command.invalidBecause layerRemoved(testData.layer));59 assertFalse(command.invalidBecauseDatasetRemoved(layer2.data)); 60 assertTrue(command.invalidBecauseDatasetRemoved(testData.layer.data)); 61 61 62 Command command2 = new NopCommand(layer2 );63 assertTrue(command2.invalidBecause layerRemoved(layer2));64 assertFalse(command2.invalidBecause layerRemoved(testData.layer));62 Command command2 = new NopCommand(layer2.data); 63 assertTrue(command2.invalidBecauseDatasetRemoved(layer2.data)); 64 assertFalse(command2.invalidBecauseDatasetRemoved(testData.layer.data)); 65 65 } 66 66 67 67 /** 68 68 * Test {@link Command#getLayer()} 69 * @deprecated to be removed end of 2017 69 70 */ 70 71 @Test 72 @Deprecated 71 73 public void testGetLayer() { 72 74 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "test", null); 73 75 Command command = new NopCommand(); 74 Command command2 = new NopCommand(layer2 );76 Command command2 = new NopCommand(layer2.data); 75 77 assertSame(testData.layer, command.getLayer()); 76 78 assertSame(layer2, command2.getLayer()); 77 79 } … … 97 99 super(); 98 100 } 99 101 100 NopCommand( OsmDataLayer layer) {101 super( layer);102 NopCommand(DataSet dataset) { 103 super(dataset); 102 104 } 103 105 104 106 @Override