Changeset 10452 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-06-21T23:41:42+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/Command.java
r10413 r10452 148 148 * Executes the command on the dataset. This implementation will remember all 149 149 * primitives returned by fillModifiedData for restoring them on undo. 150 * <p> 151 * The layer should be invalidated after execution so that it can be re-painted. 150 152 * @return true 153 * @see #invalidateAffectedLayers() 151 154 */ 152 155 public boolean executeCommand() { … … 300 303 Objects.equals(layer, command.layer); 301 304 } 305 306 /** 307 * Invalidate all layers that were affected by this command. 308 * @see Layer#invalidate() 309 */ 310 public void invalidateAffectedLayers() { 311 OsmDataLayer layer = getLayer(); 312 if (layer != null) { 313 layer.invalidate(); 314 } 315 } 302 316 } -
trunk/src/org/openstreetmap/josm/command/SequenceCommand.java
r9377 r10452 126 126 127 127 @Override 128 public void invalidateAffectedLayers() { 129 super.invalidateAffectedLayers(); 130 for (Command c : sequence) { 131 c.invalidateAffectedLayers(); 132 } 133 } 134 135 @Override 128 136 public int hashCode() { 129 137 return Objects.hash(super.hashCode(), Arrays.hashCode(sequence), sequenceComplete, name, continueOnError); -
trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java
r10446 r10452 15 15 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 16 16 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 17 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 17 18 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener; 18 19 import org.openstreetmap.josm.tools.CheckParameterUtil; 19 20 21 /** 22 * This is the global undo/redo handler for all {@link OsmDataLayer}s. 23 * <p> 24 * 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. 25 */ 20 26 public class UndoRedoHandler implements LayerChangeListener { 21 27 … … 45 51 CheckParameterUtil.ensureParameterNotNull(c, "c"); 46 52 c.executeCommand(); 53 c.invalidateAffectedLayers(); 47 54 commands.add(c); 48 55 // Limit the number of commands in the undo list. … … 55 62 } 56 63 64 /** 65 * Fires a commands change event after adding a command. 66 */ 57 67 public void afterAdd() { 58 68 fireCommandsChanged(); 59 60 // the command may have changed the selection so tell the listeners about the current situation61 DataSet ds = Main.getLayerManager().getEditDataSet();62 if (ds != null) {63 ds.fireSelectionChanged();64 }65 69 } 66 70 … … 70 74 */ 71 75 public synchronized void add(final Command c) { 76 DataSet ds = Main.getLayerManager().getEditDataSet(); 77 Collection<? extends OsmPrimitive> oldSelection = ds.getSelected(); 72 78 addNoRedraw(c); 73 79 afterAdd(); 80 81 // the command may have changed the selection so tell the listeners about the current situation 82 fireIfSelectionChanged(ds, oldSelection); 74 83 } 75 84 … … 88 97 if (commands.isEmpty()) 89 98 return; 90 Collection<? extends OsmPrimitive> oldSelection = Main.getLayerManager().getEditDataSet().getSelected(); 91 Main.getLayerManager().getEditDataSet().beginUpdate(); 99 DataSet ds = Main.getLayerManager().getEditDataSet(); 100 Collection<? extends OsmPrimitive> oldSelection = ds.getSelected(); 101 ds.beginUpdate(); 92 102 try { 93 103 for (int i = 1; i <= num; ++i) { 94 104 final Command c = commands.removeLast(); 95 105 c.undoCommand(); 106 c.invalidateAffectedLayers(); 96 107 redoCommands.addFirst(c); 97 108 if (commands.isEmpty()) { … … 100 111 } 101 112 } finally { 102 Main.getLayerManager().getEditDataSet().endUpdate(); 103 } 104 fireCommandsChanged(); 105 Collection<? extends OsmPrimitive> newSelection = Main.getLayerManager().getEditDataSet().getSelected(); 106 if (!oldSelection.equals(newSelection)) { 107 Main.getLayerManager().getEditDataSet().fireSelectionChanged(); 108 } 113 ds.endUpdate(); 114 } 115 fireCommandsChanged(); 116 fireIfSelectionChanged(ds, oldSelection); 109 117 } 110 118 … … 123 131 if (redoCommands.isEmpty()) 124 132 return; 125 Collection<? extends OsmPrimitive> oldSelection = Main.getLayerManager().getEditDataSet().getSelected(); 133 DataSet ds = Main.getLayerManager().getEditDataSet(); 134 Collection<? extends OsmPrimitive> oldSelection = ds.getSelected(); 126 135 for (int i = 0; i < num; ++i) { 127 136 final Command c = redoCommands.removeFirst(); 128 137 c.executeCommand(); 138 c.invalidateAffectedLayers(); 129 139 commands.add(c); 130 140 if (redoCommands.isEmpty()) { … … 133 143 } 134 144 fireCommandsChanged(); 135 Collection<? extends OsmPrimitive> newSelection = Main.getLayerManager().getEditDataSet().getSelected(); 145 fireIfSelectionChanged(ds, oldSelection); 146 } 147 148 private static void fireIfSelectionChanged(DataSet ds, Collection<? extends OsmPrimitive> oldSelection) { 149 Collection<? extends OsmPrimitive> newSelection = ds.getSelected(); 136 150 if (!oldSelection.equals(newSelection)) { 137 Main.getLayerManager().getEditDataSet().fireSelectionChanged(); 138 } 139 } 140 141 public void fireCommandsChanged() { 151 ds.fireSelectionChanged(); 152 } 153 } 154 155 /** 156 * Fires a command change to all listeners. 157 */ 158 private void fireCommandsChanged() { 142 159 for (final CommandQueueListener l : listenerCommands) { 143 160 l.commandChanged(commands.size(), redoCommands.size()); … … 145 162 } 146 163 164 /** 165 * Resets the undo/redo list. 166 */ 147 167 public void clean() { 148 168 redoCommands.clear(); … … 151 171 } 152 172 173 /** 174 * Resets all commands that affect the given layer. 175 * @param layer The layer that was affected. 176 */ 153 177 public void clean(Layer layer) { 154 178 if (layer == null) -
trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
r10446 r10452 608 608 609 609 @Override 610 protected void realRun() throws SAXException, IOException, 611 OsmTransferException { 610 protected void realRun() throws SAXException, IOException, OsmTransferException { 612 611 ProgressMonitor monitor = getProgressMonitor(); 613 612 try { 614 613 monitor.setTicksCount(testErrors.size()); 614 final DataSet ds = Main.getLayerManager().getEditDataSet(); 615 615 int i = 0; 616 616 SwingUtilities.invokeAndWait(new Runnable() { 617 617 @Override 618 618 public void run() { 619 Main.getLayerManager().getEditDataSet().beginUpdate();619 ds.beginUpdate(); 620 620 } 621 621 }); … … 633 633 @Override 634 634 public void run() { 635 Main.getLayerManager().getEditDataSet().endUpdate();635 ds.endUpdate(); 636 636 } 637 637 }); … … 644 644 Main.map.repaint(); 645 645 tree.resetErrors(); 646 Main.getLayerManager().getEditDataSet().fireSelectionChanged();646 ds.fireSelectionChanged(); 647 647 } 648 648 });
Note:
See TracChangeset
for help on using the changeset viewer.