[6380] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[626] | 2 | // Author: David Earl
|
---|
| 3 | package org.openstreetmap.josm.actions;
|
---|
| 4 |
|
---|
[9059] | 5 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
[626] | 6 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 7 |
|
---|
| 8 | import java.awt.event.ActionEvent;
|
---|
| 9 | import java.awt.event.KeyEvent;
|
---|
[2256] | 10 | import java.util.Collection;
|
---|
[9059] | 11 |
|
---|
[3969] | 12 | import org.openstreetmap.josm.Main;
|
---|
[2256] | 13 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
[10604] | 14 | import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler;
|
---|
| 15 | import org.openstreetmap.josm.gui.datatransfer.PrimitiveTransferable;
|
---|
| 16 | import org.openstreetmap.josm.gui.datatransfer.data.PrimitiveTransferData;
|
---|
[1084] | 17 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
[626] | 18 |
|
---|
[10604] | 19 | /**
|
---|
[10606] | 20 | * An action that duplicates the given nodes. They are not added to the clipboard.
|
---|
[10604] | 21 | */
|
---|
[9059] | 22 | public final class DuplicateAction extends JosmAction {
|
---|
[626] | 23 |
|
---|
[9059] | 24 | /**
|
---|
| 25 | * Constructs a new {@code DuplicateAction}.
|
---|
| 26 | */
|
---|
[626] | 27 | public DuplicateAction() {
|
---|
[1169] | 28 | super(tr("Duplicate"), "duplicate",
|
---|
[10604] | 29 | tr("Duplicate selection."),
|
---|
[4982] | 30 | Shortcut.registerShortcut("system:duplicate", tr("Edit: {0}", tr("Duplicate")), KeyEvent.VK_D, Shortcut.CTRL), true);
|
---|
[2323] | 31 | putValue("help", ht("/Action/Duplicate"));
|
---|
[626] | 32 | }
|
---|
| 33 |
|
---|
[6084] | 34 | @Override
|
---|
[1169] | 35 | public void actionPerformed(ActionEvent e) {
|
---|
[10604] | 36 | PrimitiveTransferData data = PrimitiveTransferData.getDataWithReferences(getLayerManager().getEditDataSet().getSelected());
|
---|
| 37 | new OsmTransferHandler().pasteOn(Main.getLayerManager().getEditLayer(), data.getCenter(), new PrimitiveTransferable(data));
|
---|
[626] | 38 | }
|
---|
[1023] | 39 |
|
---|
[1820] | 40 | @Override
|
---|
| 41 | protected void updateEnabledState() {
|
---|
[10409] | 42 | updateEnabledStateOnCurrentSelection();
|
---|
[1814] | 43 | }
|
---|
[2256] | 44 |
|
---|
| 45 | @Override
|
---|
| 46 | protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
|
---|
| 47 | setEnabled(selection != null && !selection.isEmpty());
|
---|
| 48 | }
|
---|
[626] | 49 | }
|
---|