diff --git a/src/org/openstreetmap/josm/actions/CopyAction.java b/src/org/openstreetmap/josm/actions/CopyAction.java
index cc6cb5b..681c8ba 100644
|
a
|
b
|
|
| 5 | 5 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht; |
| 6 | 6 | import static org.openstreetmap.josm.tools.I18n.tr; |
| 7 | 7 | |
| | 8 | import java.awt.Toolkit; |
| 8 | 9 | import java.awt.event.ActionEvent; |
| 9 | 10 | import java.awt.event.KeyEvent; |
| 10 | 11 | import java.util.Collection; |
| … |
… |
|
| 14 | 15 | import org.openstreetmap.josm.Main; |
| 15 | 16 | import org.openstreetmap.josm.data.osm.OsmPrimitive; |
| 16 | 17 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType; |
| | 18 | import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy; |
| | 19 | import org.openstreetmap.josm.gui.datatransfer.PrimitiveTransferable; |
| 17 | 20 | import org.openstreetmap.josm.gui.layer.OsmDataLayer; |
| 18 | 21 | import org.openstreetmap.josm.tools.Shortcut; |
| 19 | | import org.openstreetmap.josm.tools.Utils; |
| 20 | 22 | |
| 21 | 23 | /** |
| 22 | 24 | * Copy OSM primitives to clipboard in order to paste them, or their tags, somewhere else. |
| … |
… |
public void actionPerformed(ActionEvent e) {
|
| 56 | 58 | */ |
| 57 | 59 | public static void copy(OsmDataLayer source, Collection<OsmPrimitive> primitives) { |
| 58 | 60 | /* copy ids to the clipboard */ |
| 59 | | String ids = getCopyString(primitives); |
| 60 | | Utils.copyToClipboard(ids); |
| 61 | | |
| 62 | | Main.pasteBuffer.makeCopy(primitives); |
| 63 | | Main.pasteSource = source; |
| | 61 | final PrimitiveTransferable transferable = new PrimitiveTransferable(new PrimitiveDeepCopy(primitives).getAll(), true); |
| | 62 | Toolkit.getDefaultToolkit().getSystemClipboard().setContents(transferable, null); |
| 64 | 63 | } |
| 65 | 64 | |
| 66 | 65 | public static String getCopyString(Collection<? extends OsmPrimitive> primitives) { |
diff --git a/src/org/openstreetmap/josm/actions/DuplicateAction.java b/src/org/openstreetmap/josm/actions/DuplicateAction.java
index 6c0d1d9..677868b 100644
|
a
|
b
|
public DuplicateAction() {
|
| 28 | 28 | |
| 29 | 29 | @Override |
| 30 | 30 | public void actionPerformed(ActionEvent e) { |
| 31 | | Main.main.menu.paste.pasteData(new PrimitiveDeepCopy(getCurrentDataSet().getSelected()), getEditLayer(), e); |
| | 31 | // Main.main.menu.paste.pasteData(new PrimitiveDeepCopy(getCurrentDataSet().getSelected()), getEditLayer(), e); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | @Override |
diff --git a/src/org/openstreetmap/josm/actions/PasteAction.java b/src/org/openstreetmap/josm/actions/PasteAction.java
index 96e5873..8509eaa 100644
|
a
|
b
|
|
| 7 | 7 | |
| 8 | 8 | import java.awt.MouseInfo; |
| 9 | 9 | import java.awt.Point; |
| | 10 | import java.awt.Toolkit; |
| | 11 | import java.awt.datatransfer.UnsupportedFlavorException; |
| 10 | 12 | import java.awt.event.ActionEvent; |
| 11 | 13 | import java.awt.event.KeyEvent; |
| | 14 | import java.io.IOException; |
| 12 | 15 | import java.util.ArrayList; |
| 13 | 16 | import java.util.HashMap; |
| 14 | 17 | import java.util.List; |
| … |
… |
|
| 26 | 29 | import org.openstreetmap.josm.data.osm.RelationMemberData; |
| 27 | 30 | import org.openstreetmap.josm.data.osm.WayData; |
| 28 | 31 | import org.openstreetmap.josm.gui.ExtendedDialog; |
| | 32 | import org.openstreetmap.josm.gui.datatransfer.PrimitiveTransferable; |
| 29 | 33 | import org.openstreetmap.josm.gui.layer.Layer; |
| 30 | 34 | import org.openstreetmap.josm.tools.Shortcut; |
| 31 | 35 | |
| … |
… |
public PasteAction() {
|
| 48 | 52 | Main.pasteBuffer.addPasteBufferChangedListener(this); |
| 49 | 53 | } |
| 50 | 54 | |
| | 55 | @SuppressWarnings("unchecked") |
| 51 | 56 | @Override |
| 52 | 57 | public void actionPerformed(ActionEvent e) { |
| 53 | | if (!isEnabled()) |
| 54 | | return; |
| 55 | | pasteData(Main.pasteBuffer, Main.pasteSource, e); |
| | 58 | try { |
| | 59 | pasteData((Iterable<PrimitiveData>) Toolkit.getDefaultToolkit().getSystemClipboard().getData(PrimitiveTransferable.PRIMITIVE_DATA), Main.pasteSource, e); |
| | 60 | } catch (UnsupportedFlavorException | IOException e1) { |
| | 61 | e1.printStackTrace(); |
| | 62 | } |
| 56 | 63 | } |
| 57 | 64 | |
| 58 | 65 | /** |
| 59 | 66 | * Paste OSM primitives from the given paste buffer and OSM data layer source to the current edit layer. |
| 60 | | * @param pasteBuffer The paste buffer containing primitive ids to copy |
| | 67 | * @param paste The primitive ids to paste |
| 61 | 68 | * @param source The OSM data layer used to look for primitive ids |
| 62 | 69 | * @param e The ActionEvent that triggered this operation |
| 63 | 70 | */ |
| 64 | | public void pasteData(PrimitiveDeepCopy pasteBuffer, Layer source, ActionEvent e) { |
| | 71 | public void pasteData(Iterable<PrimitiveData> paste, Layer source, ActionEvent e) { |
| 65 | 72 | /* Find the middle of the pasteBuffer area */ |
| 66 | 73 | double maxEast = -1E100, minEast = 1E100, maxNorth = -1E100, minNorth = 1E100; |
| 67 | 74 | boolean incomplete = false; |
| 68 | | for (PrimitiveData data : pasteBuffer.getAll()) { |
| | 75 | for (PrimitiveData data : paste) { |
| 69 | 76 | if (data instanceof NodeData) { |
| 70 | 77 | NodeData n = (NodeData) data; |
| 71 | 78 | if (n.getEastNorth() != null) { |
| … |
… |
public void pasteData(PrimitiveDeepCopy pasteBuffer, Layer source, ActionEvent e
|
| 118 | 125 | Map<Long, Long> newNodeIds = new HashMap<>(); |
| 119 | 126 | Map<Long, Long> newWayIds = new HashMap<>(); |
| 120 | 127 | Map<Long, Long> newRelationIds = new HashMap<>(); |
| 121 | | for (PrimitiveData data: pasteBuffer.getAll()) { |
| | 128 | for (PrimitiveData data: paste) { |
| 122 | 129 | if (data.isIncomplete()) { |
| 123 | 130 | continue; |
| 124 | 131 | } |
| … |
… |
public void pasteData(PrimitiveDeepCopy pasteBuffer, Layer source, ActionEvent e
|
| 132 | 139 | newRelationIds.put(data.getUniqueId(), copy.getUniqueId()); |
| 133 | 140 | } |
| 134 | 141 | bufferCopy.add(copy); |
| 135 | | if (pasteBuffer.getDirectlyAdded().contains(data)) { |
| 136 | | toSelect.add(copy); |
| 137 | | } |
| | 142 | // if (pasteBuffer.getDirectlyAdded().contains(data)) { |
| | 143 | // toSelect.add(copy); |
| | 144 | // } |
| 138 | 145 | } |
| 139 | 146 | |
| 140 | 147 | // Update references in copied buffer |
| … |
… |
protected boolean confirmDeleteIncomplete() {
|
| 196 | 203 | |
| 197 | 204 | @Override |
| 198 | 205 | protected void updateEnabledState() { |
| 199 | | if (getCurrentDataSet() == null || Main.pasteBuffer == null) { |
| 200 | | setEnabled(false); |
| 201 | | return; |
| 202 | | } |
| 203 | | setEnabled(!Main.pasteBuffer.isEmpty()); |
| | 206 | setEnabled(Toolkit.getDefaultToolkit().getSystemClipboard().isDataFlavorAvailable(PrimitiveTransferable.PRIMITIVE_DATA)); |
| 204 | 207 | } |
| 205 | 208 | |
| 206 | 209 | @Override |
diff --git a/src/org/openstreetmap/josm/gui/datatransfer/PrimitiveTransferable.java b/src/org/openstreetmap/josm/gui/datatransfer/PrimitiveTransferable.java
index c01e5c7..2f25945 100644
|
a
|
b
|
|
| 6 | 6 | import java.awt.datatransfer.UnsupportedFlavorException; |
| 7 | 7 | import java.util.ArrayList; |
| 8 | 8 | import java.util.Collection; |
| | 9 | import java.util.Collections; |
| 9 | 10 | |
| 10 | 11 | import org.openstreetmap.josm.data.osm.OsmPrimitive; |
| 11 | 12 | import org.openstreetmap.josm.data.osm.PrimitiveData; |
| … |
… |
|
| 22 | 23 | */ |
| 23 | 24 | public static final DataFlavor PRIMITIVE_DATA = new DataFlavor(PrimitiveData.class, PrimitiveData.class.getName()); |
| 24 | 25 | private final Collection<? extends OsmPrimitive> primitives; |
| | 26 | private final Collection<? extends PrimitiveData> primitiveData; |
| 25 | 27 | |
| 26 | 28 | /** |
| 27 | 29 | * Constructs a new {@code PrimitiveTransferable}. |
| … |
… |
|
| 29 | 31 | */ |
| 30 | 32 | public PrimitiveTransferable(Collection<? extends OsmPrimitive> primitives) { |
| 31 | 33 | this.primitives = primitives; |
| | 34 | this.primitiveData = Collections.emptyList(); |
| | 35 | } |
| | 36 | |
| | 37 | public PrimitiveTransferable(Collection<? extends PrimitiveData> primitiveData, boolean marker) { |
| | 38 | this.primitives = Collections.emptyList(); |
| | 39 | this.primitiveData = primitiveData; |
| 32 | 40 | } |
| 33 | 41 | |
| 34 | 42 | @Override |
| … |
… |
protected String getStringData() {
|
| 59 | 67 | sb.append(" # ").append(primitive.getDisplayName(DefaultNameFormatter.getInstance())); |
| 60 | 68 | sb.append("\n"); |
| 61 | 69 | } |
| | 70 | for (PrimitiveData data : primitiveData) { |
| | 71 | sb.append(data.getType()); |
| | 72 | sb.append(" ").append(data.getUniqueId()); |
| | 73 | sb.append("\n"); |
| | 74 | } |
| 62 | 75 | return sb.toString().replace("\u200E", "").replace("\u200F", ""); |
| 63 | 76 | } |
| 64 | 77 | |
| 65 | 78 | protected Collection<PrimitiveData> getRelationMemberData() { |
| 66 | | final Collection<PrimitiveData> r = new ArrayList<>(primitives.size()); |
| | 79 | final Collection<PrimitiveData> r = new ArrayList<>(primitives.size() + primitiveData.size()); |
| 67 | 80 | for (OsmPrimitive primitive : primitives) { |
| 68 | 81 | r.add(primitive.save()); |
| 69 | 82 | } |
| | 83 | r.addAll(primitiveData); |
| 70 | 84 | return r; |
| 71 | 85 | } |
| 72 | 86 | } |