Changeset 11240 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-11-12T14:52:32+01:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
r10755 r11240 43 43 import org.openstreetmap.josm.gui.Notification; 44 44 import org.openstreetmap.josm.gui.conflict.tags.CombinePrimitiveResolverDialog; 45 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 45 46 import org.openstreetmap.josm.tools.Geometry; 46 47 import org.openstreetmap.josm.tools.Pair; … … 541 542 * @throws UserCancelException if user cancels the operation 542 543 */ 543 p rivateJoinAreasResult joinAreas(List<Multipolygon> areas) throws UserCancelException {544 public JoinAreasResult joinAreas(List<Multipolygon> areas) throws UserCancelException { 544 545 545 546 JoinAreasResult result = new JoinAreasResult(); … … 1296 1297 * @return list of polygons, or null if too complex relation encountered. 1297 1298 */ 1298 p rivatestatic List<Multipolygon> collectMultipolygons(Collection<Way> selectedWays) {1299 public static List<Multipolygon> collectMultipolygons(Collection<Way> selectedWays) { 1299 1300 1300 1301 List<Multipolygon> result = new ArrayList<>(); … … 1404 1405 private RelationRole addOwnMultipolygonRelation(Collection<Way> inner) { 1405 1406 if (inner.isEmpty()) return null; 1407 OsmDataLayer layer = Main.getLayerManager().getEditLayer(); 1406 1408 // Create new multipolygon relation and add all inner ways to it 1407 1409 Relation newRel = new Relation(); … … 1410 1412 newRel.addMember(new RelationMember("inner", w)); 1411 1413 } 1412 cmds.add(new AddCommand(newRel)); 1414 cmds.add(layer != null ? new AddCommand(layer, newRel) : 1415 new AddCommand(inner.iterator().next().getDataSet(), newRel)); 1413 1416 addedRelations.add(newRel); 1414 1417 … … 1426 1429 List<RelationRole> result = new ArrayList<>(); 1427 1430 1428 for (Relation r : Main.getLayerManager().getEditDataSet().getRelations()) {1431 for (Relation r : osm.getDataSet().getRelations()) { 1429 1432 if (r.isDeleted()) { 1430 1433 continue; … … 1480 1483 } 1481 1484 1485 OsmDataLayer layer = Main.getLayerManager().getEditLayer(); 1482 1486 Relation newRel; 1483 1487 switch (multiouters.size()) { … … 1508 1512 } 1509 1513 newRel.addMember(new RelationMember("outer", outer)); 1510 cmds.add( new AddCommand(newRel));1514 cmds.add(layer != null ? new AddCommand(layer, newRel) : new AddCommand(outer.getDataSet(), newRel)); 1511 1515 } 1512 1516 } -
trunk/src/org/openstreetmap/josm/actions/PurgeAction.java
r10619 r11240 93 93 return; 94 94 95 Collection<OsmPrimitive> sel = getLayerManager().getEditDataSet().getAllSelected(); 95 doPurge(getLayerManager().getEditDataSet().getAllSelected(), true); 96 } 97 98 /** 99 * Performs purge on selected OSM primitives. 100 * @param sel selected OSM primitives 101 * @param confirm asks user confirmation through a popup dialog 102 * @since 11240 103 */ 104 public void doPurge(Collection<OsmPrimitive> sel, boolean confirm) { 96 105 layer = Main.getLayerManager().getEditLayer(); 97 106 … … 205 214 boolean clearUndoRedo = false; 206 215 207 if (!GraphicsEnvironment.isHeadless() ) {216 if (!GraphicsEnvironment.isHeadless() && confirm) { 208 217 final boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog( 209 218 "purge", Main.parent, buildPanel(modified), tr("Confirm Purging"), … … 216 225 } 217 226 218 Main.main.undoRedo.add(new PurgeCommand(Main.getLayerManager().getEditLayer(), toPurgeChecked, makeIncomplete)); 227 Main.main.undoRedo.add(layer != null ? new PurgeCommand(layer, toPurgeChecked, makeIncomplete) : 228 new PurgeCommand(toPurgeChecked.iterator().next().getDataSet(), toPurgeChecked, makeIncomplete)); 219 229 220 230 if (clearUndoRedo) { -
trunk/src/org/openstreetmap/josm/actions/SelectByInternalPointAction.java
r10448 r11240 30 30 31 31 /** 32 * Returns the surrounding polygons/multipolygons 33 * ordered by their area size (from small to large) 32 * Returns the surrounding polygons/multipolygons ordered by their area size (from small to large) 34 33 * which contain the internal point. 35 34 * … … 38 37 */ 39 38 public static Collection<OsmPrimitive> getSurroundingObjects(EastNorth internalPoint) { 40 final DataSet ds = Main.getLayerManager().getEditDataSet(); 39 return getSurroundingObjects(Main.getLayerManager().getEditDataSet(), internalPoint); 40 } 41 42 /** 43 * Returns the surrounding polygons/multipolygons ordered by their area size (from small to large) 44 * which contain the internal point. 45 * 46 * @param ds the data set 47 * @param internalPoint the internal point. 48 * @return the surrounding polygons/multipolygons 49 * @since 11240 50 */ 51 public static Collection<OsmPrimitive> getSurroundingObjects(DataSet ds, EastNorth internalPoint) { 41 52 if (ds == null) { 42 53 return Collections.emptySet(); -
trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
r10775 r11240 539 539 final Way changedWay = new Way(way); 540 540 changedWay.setNodes(wayToKeep.getNodes()); 541 commandList.add( new ChangeCommand(way, changedWay));541 commandList.add(layer != null ? new ChangeCommand(layer, way, changedWay) : new ChangeCommand(way.getDataSet(), way, changedWay)); 542 542 if (!newSelection.contains(way)) { 543 543 newSelection.add(way); … … 548 548 newSelection.addAll(newWays); 549 549 for (Way wayToAdd : newWays) { 550 commandList.add( new AddCommand(layer, wayToAdd));550 commandList.add(layer != null ? new AddCommand(layer, wayToAdd) : new AddCommand(way.getDataSet(), wayToAdd)); 551 551 } 552 552 … … 678 678 679 679 if (c != null) { 680 commandList.add( new ChangeCommand(layer, r, c));680 commandList.add(layer != null ? new ChangeCommand(layer, r, c) : new ChangeCommand(r.getDataSet(), r, c)); 681 681 } 682 682 } -
trunk/src/org/openstreetmap/josm/command/AddCommand.java
r11140 r11240 11 11 import javax.swing.Icon; 12 12 13 import org.openstreetmap.josm.data.osm.DataSet; 13 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 15 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; … … 47 48 public AddCommand(OsmDataLayer layer, OsmPrimitive osm) { 48 49 super(layer); 50 this.osm = Objects.requireNonNull(osm, "osm"); 51 } 52 53 /** 54 * Creates the command and specify the element to add in the context of the given data set. 55 * @param data The data set. Must not be {@code null} 56 * @param osm The primitive to add 57 * @since 11240 58 */ 59 public AddCommand(DataSet data, OsmPrimitive osm) { 60 super(data); 49 61 this.osm = Objects.requireNonNull(osm, "osm"); 50 62 } -
trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java
r10804 r11240 106 106 // a subsequent command (e.g. MoveCommand) cannot be redone. 107 107 for (OsmPrimitive osm : createdPrimitives) { 108 get Layer().data.addPrimitive(osm);108 getAffectedDataSet().addPrimitive(osm); 109 109 } 110 110 primitivesToSelect = createdPrimitivesToSelect; 111 111 } 112 112 113 get Layer().data.setSelected(primitivesToSelect);113 getAffectedDataSet().setSelected(primitivesToSelect); 114 114 return true; 115 115 } -
trunk/src/org/openstreetmap/josm/command/ChangeCommand.java
r10216 r11240 10 10 import javax.swing.Icon; 11 11 12 import org.openstreetmap.josm.data.osm.DataSet; 12 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 14 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; … … 47 48 public ChangeCommand(OsmDataLayer layer, OsmPrimitive osm, OsmPrimitive newOsm) { 48 49 super(layer); 50 this.osm = osm; 51 this.newOsm = newOsm; 52 sanityChecks(); 53 } 54 55 /** 56 * Constructs a new {@code ChangeCommand} in the context of a given data set. 57 * @param data The data set 58 * @param osm The existing primitive to modify 59 * @param newOsm The new primitive 60 * @since 11240 61 */ 62 public ChangeCommand(DataSet data, OsmPrimitive osm, OsmPrimitive newOsm) { 63 super(data); 49 64 this.osm = osm; 50 65 this.newOsm = newOsm; -
trunk/src/org/openstreetmap/josm/command/Command.java
r10970 r11240 137 137 private final OsmDataLayer layer; 138 138 139 /** the dataset which this command is applied to */ 140 private final DataSet data; 141 139 142 /** 140 143 * Creates a new command in the context of the current edit layer, if any … … 142 145 public Command() { 143 146 this.layer = Main.getLayerManager().getEditLayer(); 147 this.data = layer != null ? layer.data : null; 144 148 } 145 149 … … 153 157 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 154 158 this.layer = layer; 159 this.data = layer.data; 160 } 161 162 /** 163 * Creates a new command in the context of a specific data set, without data layer 164 * 165 * @param data the data set. Must not be null. 166 * @throws IllegalArgumentException if data is null 167 * @since 11240 168 */ 169 public Command(DataSet data) { 170 CheckParameterUtil.ensureParameterNotNull(data, "data"); 171 this.layer = null; 172 this.data = data; 155 173 } 156 174 … … 226 244 */ 227 245 public DataSet getAffectedDataSet() { 228 return layer == null ? null : layer.data;246 return data; 229 247 } 230 248 … … 331 349 Command command = (Command) obj; 332 350 return Objects.equals(cloneMap, command.cloneMap) && 333 Objects.equals(layer, command.layer); 351 Objects.equals(layer, command.layer) && 352 Objects.equals(data, command.data); 334 353 } 335 354 -
trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
r10663 r11240 29 29 import org.openstreetmap.josm.actions.SplitWayAction; 30 30 import org.openstreetmap.josm.actions.SplitWayAction.SplitWayResult; 31 import org.openstreetmap.josm.data.osm.DataSet; 31 32 import org.openstreetmap.josm.data.osm.Node; 32 33 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 131 132 public DeleteCommand(OsmDataLayer layer, Collection<? extends OsmPrimitive> data) { 132 133 super(layer); 134 CheckParameterUtil.ensureParameterNotNull(data, "data"); 135 this.toDelete = data; 136 checkConsistency(); 137 } 138 139 /** 140 * Constructor for a collection of data to be deleted in the context of 141 * a specific data set 142 * 143 * @param dataset the dataset context for deleting these primitives. Must not be null. 144 * @param data the primitives to delete. Must neither be null nor empty. 145 * @throws IllegalArgumentException if dataset is null 146 * @throws IllegalArgumentException if data is null or empty 147 * @since 11240 148 */ 149 public DeleteCommand(DataSet dataset, Collection<? extends OsmPrimitive> data) { 150 super(dataset); 133 151 CheckParameterUtil.ensureParameterNotNull(data, "data"); 134 152 this.toDelete = data; … … 448 466 // 449 467 if (!primitivesToDelete.isEmpty()) { 450 cmds.add(new DeleteCommand(layer, primitivesToDelete)); 468 cmds.add(layer != null ? new DeleteCommand(layer, primitivesToDelete) : 469 new DeleteCommand(primitivesToDelete.iterator().next().getDataSet(), primitivesToDelete)); 451 470 } 452 471 -
trunk/src/org/openstreetmap/josm/command/PurgeCommand.java
r10378 r11240 43 43 protected final ConflictCollection purgedConflicts = new ConflictCollection(); 44 44 45 protected final DataSet ds;46 47 45 /** 46 * Constructs a new {@code PurgeCommand} (handles conflicts). 48 47 * This command relies on a number of consistency conditions: 49 48 * - makeIncomplete must be a subset of toPurge. 50 * - Each primitive, that is in toPurge but not in makeIncomplete, must 51 * have all its referrers in toPurge. 52 * - Each element of makeIncomplete must not be new and must have only 53 * referrers that are either a relation or included in toPurge. 49 * - Each primitive, that is in toPurge but not in makeIncomplete, must have all its referrers in toPurge. 50 * - Each element of makeIncomplete must not be new and must have only referrers that are either a relation or included in toPurge. 54 51 * @param layer OSM data layer 55 52 * @param toPurge primitives to purge … … 58 55 public PurgeCommand(OsmDataLayer layer, Collection<OsmPrimitive> toPurge, Collection<OsmPrimitive> makeIncomplete) { 59 56 super(layer); 60 this.ds = layer.data; 57 init(toPurge, makeIncomplete); 58 } 59 60 /** 61 * Constructs a new {@code PurgeCommand} (does not handle conflicts). 62 * This command relies on a number of consistency conditions: 63 * - makeIncomplete must be a subset of toPurge. 64 * - Each primitive, that is in toPurge but not in makeIncomplete, must have all its referrers in toPurge. 65 * - Each element of makeIncomplete must not be new and must have only referrers that are either a relation or included in toPurge. 66 * @param data OSM data set 67 * @param toPurge primitives to purge 68 * @param makeIncomplete primitives to make incomplete 69 * @since 11240 70 */ 71 public PurgeCommand(DataSet data, Collection<OsmPrimitive> toPurge, Collection<OsmPrimitive> makeIncomplete) { 72 super(data); 73 init(toPurge, makeIncomplete); 74 } 75 76 private void init(Collection<OsmPrimitive> toPurge, Collection<OsmPrimitive> makeIncomplete) { 61 77 /** 62 78 * The topological sort is to avoid missing way nodes and missing … … 82 98 @Override 83 99 public boolean executeCommand() { 84 ds.beginUpdate();100 getAffectedDataSet().beginUpdate(); 85 101 try { 86 102 purgedConflicts.get().clear(); … … 105 121 osm.load(empty); 106 122 } else { 107 ds.removePrimitive(osm); 108 Conflict<?> conflict = getLayer().getConflicts().getConflictForMy(osm); 109 if (conflict != null) { 110 purgedConflicts.add(conflict); 111 getLayer().getConflicts().remove(conflict); 123 getAffectedDataSet().removePrimitive(osm); 124 if (getLayer() != null) { 125 Conflict<?> conflict = getLayer().getConflicts().getConflictForMy(osm); 126 if (conflict != null) { 127 purgedConflicts.add(conflict); 128 getLayer().getConflicts().remove(conflict); 129 } 112 130 } 113 131 } 114 132 } 115 133 } finally { 116 ds.endUpdate();134 getAffectedDataSet().endUpdate(); 117 135 } 118 136 return true; … … 121 139 @Override 122 140 public void undoCommand() { 123 if ( ds== null)141 if (getAffectedDataSet() == null) 124 142 return; 125 143 … … 127 145 PrimitiveData data = makeIncompleteDataByPrimId.get(osm); 128 146 if (data != null) { 129 if ( ds.getPrimitiveById(osm) != osm)147 if (getAffectedDataSet().getPrimitiveById(osm) != osm) 130 148 throw new AssertionError( 131 149 String.format("Primitive %s has been made incomplete when purging, but it cannot be found on undo.", osm)); 132 150 osm.load(data); 133 151 } else { 134 if ( ds.getPrimitiveById(osm) != null)152 if (getAffectedDataSet().getPrimitiveById(osm) != null) 135 153 throw new AssertionError(String.format("Primitive %s was removed when purging, but is still there on undo", osm)); 136 ds.addPrimitive(osm);154 getAffectedDataSet().addPrimitive(osm); 137 155 } 138 156 } … … 279 297 @Override 280 298 public int hashCode() { 281 return Objects.hash(super.hashCode(), toPurge, makeIncompleteData, makeIncompleteDataByPrimId, purgedConflicts, ds);299 return Objects.hash(super.hashCode(), toPurge, makeIncompleteData, makeIncompleteDataByPrimId, purgedConflicts, getAffectedDataSet()); 282 300 } 283 301 … … 291 309 Objects.equals(makeIncompleteData, that.makeIncompleteData) && 292 310 Objects.equals(makeIncompleteDataByPrimId, that.makeIncompleteDataByPrimId) && 293 Objects.equals(purgedConflicts, that.purgedConflicts) && 294 Objects.equals(ds, that.ds); 311 Objects.equals(purgedConflicts, that.purgedConflicts); 295 312 } 296 313 } -
trunk/src/org/openstreetmap/josm/command/conflict/DeletedStateConflictResolveCommand.java
r9371 r11240 74 74 75 75 private void deleteMy() { 76 Set<OsmPrimitive> referrers = get Layer().data.unlinkReferencesToPrimitive(conflict.getMy());76 Set<OsmPrimitive> referrers = getAffectedDataSet().unlinkReferencesToPrimitive(conflict.getMy()); 77 77 for (OsmPrimitive p : referrers) { 78 78 if (!p.isNew() && !p.isDeleted()) { -
trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java
r10467 r11240 107 107 return; 108 108 DataSet ds = Main.getLayerManager().getEditDataSet(); 109 Collection<? extends OsmPrimitive> oldSelection = ds.getSelected(); 110 ds.beginUpdate(); 109 Collection<? extends OsmPrimitive> oldSelection = null; 110 if (ds != null) { 111 oldSelection = ds.getSelected(); 112 ds.beginUpdate(); 113 } 111 114 try { 112 115 for (int i = 1; i <= num; ++i) { … … 120 123 } 121 124 } finally { 122 ds.endUpdate(); 123 } 124 fireCommandsChanged(); 125 fireIfSelectionChanged(ds, oldSelection); 125 if (ds != null) { 126 ds.endUpdate(); 127 } 128 } 129 fireCommandsChanged(); 130 if (ds != null) { 131 fireIfSelectionChanged(ds, oldSelection); 132 } 126 133 } 127 134
Note:
See TracChangeset
for help on using the changeset viewer.