- Timestamp:
- 2013-05-10T17:13:24+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CopyAction.java
r4982 r5953 18 18 import org.openstreetmap.josm.tools.Utils; 19 19 20 /** 21 * Copy OSM primitives to clipboard in order to paste them, or their tags, somewhere else. 22 * @since 404 23 */ 20 24 public final class CopyAction extends JosmAction { 21 25 26 /** 27 * Constructs a new {@code CopyAction}. 28 */ 22 29 public CopyAction() { 23 30 super(tr("Copy"), "copy", … … 35 42 } 36 43 44 /** 45 * Copies the given primitive ids to the clipboard. 46 * @param source The OSM data layer source 47 * @param primitives The OSM primitives to copy 48 */ 37 49 public static void copy(OsmDataLayer source, Collection<OsmPrimitive> primitives) { 38 50 /* copy ids to the clipboard */ -
trunk/src/org/openstreetmap/josm/actions/PasteAction.java
r5096 r5953 30 30 import org.openstreetmap.josm.tools.Shortcut; 31 31 32 /** 33 * Paste OSM primitives from clipboard to the current edit layer. 34 * @since 404 35 */ 32 36 public final class PasteAction extends JosmAction implements PasteBufferChangedListener { 33 37 38 /** 39 * Constructs a new {@code PasteAction}. 40 */ 34 41 public PasteAction() { 35 42 super(tr("Paste"), "paste", tr("Paste contents of paste buffer."), … … 45 52 } 46 53 47 public void pasteData(PrimitiveDeepCopy pasteBuffer, Layer source, ActionEvent e) { 54 /** 55 * Paste OSM primitives from the given paste buffer and OSM data layer source to the current edit layer. 56 * @param pasteBuffer The paste buffer containing primitive ids to copy 57 * @param source The OSM data layer used to look for primitive ids 58 * @param e The ActionEvent that triggered this operation 59 */ 60 public void pasteData(PrimitiveDeepCopy pasteBuffer, Layer source, ActionEvent e) { 48 61 /* Find the middle of the pasteBuffer area */ 49 62 double maxEast = -1E100, minEast = 1E100, maxNorth = -1E100, minNorth = 1E100; … … 87 100 // Make a copy of pasteBuffer and map from old id to copied data id 88 101 List<PrimitiveData> bufferCopy = new ArrayList<PrimitiveData>(); 102 List<PrimitiveData> toSelect = new ArrayList<PrimitiveData>(); 89 103 Map<Long, Long> newNodeIds = new HashMap<Long, Long>(); 90 104 Map<Long, Long> newWayIds = new HashMap<Long, Long>(); … … 104 118 } 105 119 bufferCopy.add(copy); 120 if (pasteBuffer.getDirectlyAdded().contains(data)) { 121 toSelect.add(copy); 122 } 106 123 } 107 124 … … 148 165 /* Now execute the commands to add the duplicated contents of the paste buffer to the map */ 149 166 150 Main.main.undoRedo.add(new AddPrimitivesCommand(bufferCopy ));167 Main.main.undoRedo.add(new AddPrimitivesCommand(bufferCopy, toSelect)); 151 168 Main.map.mapView.repaint(); 152 169 } -
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.