Changeset 5953 in josm for trunk/src/org/openstreetmap/josm/command
- Timestamp:
- 2013-05-10T17:13:24+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java
r5926 r5953 16 16 import org.openstreetmap.josm.data.osm.PrimitiveData; 17 17 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 18 import org.openstreetmap.josm.tools.CheckParameterUtil; 18 19 19 20 /** 20 21 * Add primitives to a data layer. 21 * 22 * @since 2305 22 23 */ 23 24 public class AddPrimitivesCommand extends Command { 24 25 25 26 private List<PrimitiveData> data = new ArrayList<PrimitiveData>(); 27 private Collection<PrimitiveData> toSelect = new ArrayList<PrimitiveData>(); 26 28 27 29 // only filled on undo 28 30 private List<OsmPrimitive> createdPrimitives = null; 31 private Collection<OsmPrimitive> createdPrimitivesToSelect = null; 29 32 33 /** 34 * Constructs a new {@code AddPrimitivesCommand} to add data to the current edit layer. 35 * @param data The OSM primitives data to add. Must not be {@code null} 36 */ 30 37 public AddPrimitivesCommand(List<PrimitiveData> data) { 31 this.data.addAll(data); 38 this(data, data); 39 } 40 41 /** 42 * Constructs a new {@code AddPrimitivesCommand} to add data to the current edit layer. 43 * @param data The OSM primitives to add. Must not be {@code null} 44 * @param toSelect The OSM primitives to select at the end. Can be {@code null} 45 * @since 5953 46 */ 47 public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect) { 48 init(data, toSelect); 49 } 50 51 /** 52 * Constructs a new {@code AddPrimitivesCommand} to add data to the given layer. 53 * @param data The OSM primitives data to add. Must not be {@code null} 54 * @param toSelect The OSM primitives to select at the end. Can be {@code null} 55 * @param layer The target data layer. Must not be {@code null} 56 */ 57 public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect, OsmDataLayer layer) { 58 super(layer); 59 init(data, toSelect); 32 60 } 33 61 34 p ublic AddPrimitivesCommand(List<PrimitiveData> data, OsmDataLayer layer) {35 super(layer);62 private final void init(List<PrimitiveData> data, List<PrimitiveData> toSelect) { 63 CheckParameterUtil.ensureParameterNotNull(data, "data"); 36 64 this.data.addAll(data); 65 if (toSelect != null) { 66 this.toSelect.addAll(toSelect); 67 } 37 68 } 38 69 39 @SuppressWarnings("null")40 70 @Override public boolean executeCommand() { 41 List<OsmPrimitive> newPrimitives;71 Collection<OsmPrimitive> primitivesToSelect; 42 72 if (createdPrimitives == null) { // first time execution 43 newPrimitives = new ArrayList<OsmPrimitive>(data.size()); 73 List<OsmPrimitive> newPrimitives = new ArrayList<OsmPrimitive>(data.size()); 74 primitivesToSelect = new ArrayList<OsmPrimitive>(toSelect.size()); 44 75 45 76 for (PrimitiveData pd : data) { … … 56 87 } 57 88 newPrimitives.add(primitive); 89 if (toSelect.contains(pd)) { 90 primitivesToSelect.add(primitive); 91 } 58 92 } 59 93 60 // Then load ways and relations94 // Then load ways and relations 61 95 for (int i=0; i<newPrimitives.size(); i++) { 62 96 if (!(newPrimitives.get(i) instanceof Node)) { … … 70 104 getLayer().data.addPrimitive(osm); 71 105 } 72 newPrimitives = createdPrimitives;106 primitivesToSelect = createdPrimitivesToSelect; 73 107 } 74 108 75 getLayer().data.setSelected( newPrimitives);109 getLayer().data.setSelected(primitivesToSelect); 76 110 return true; 77 111 } … … 82 116 if (createdPrimitives == null) { 83 117 createdPrimitives = new ArrayList<OsmPrimitive>(data.size()); 118 createdPrimitivesToSelect = new ArrayList<OsmPrimitive>(toSelect.size()); 84 119 85 for (PrimitiveData p : data) { 86 createdPrimitives.add(ds.getPrimitiveById(p)); 120 for (PrimitiveData pd : data) { 121 OsmPrimitive p = ds.getPrimitiveById(pd); 122 createdPrimitives.add(p); 123 if (toSelect.contains(pd)) { 124 createdPrimitivesToSelect.add(p); 125 } 87 126 } 88 127 createdPrimitives = PurgeCommand.topoSort(createdPrimitives); … … 92 131 } 93 132 data = null; 133 toSelect = null; 94 134 95 135 } else {
Note:
See TracChangeset
for help on using the changeset viewer.