[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 |
|
---|
[2256] | 12 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
[10604] | 13 | import org.openstreetmap.josm.gui.datatransfer.PrimitiveTransferable;
|
---|
| 14 | import org.openstreetmap.josm.gui.datatransfer.data.PrimitiveTransferData;
|
---|
[1084] | 15 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
[626] | 16 |
|
---|
[10604] | 17 | /**
|
---|
[10606] | 18 | * An action that duplicates the given nodes. They are not added to the clipboard.
|
---|
[10604] | 19 | */
|
---|
[10766] | 20 | public final class DuplicateAction extends AbstractPasteAction {
|
---|
[626] | 21 |
|
---|
[9059] | 22 | /**
|
---|
| 23 | * Constructs a new {@code DuplicateAction}.
|
---|
| 24 | */
|
---|
[626] | 25 | public DuplicateAction() {
|
---|
[1169] | 26 | super(tr("Duplicate"), "duplicate",
|
---|
[10604] | 27 | tr("Duplicate selection."),
|
---|
[4982] | 28 | Shortcut.registerShortcut("system:duplicate", tr("Edit: {0}", tr("Duplicate")), KeyEvent.VK_D, Shortcut.CTRL), true);
|
---|
[2323] | 29 | putValue("help", ht("/Action/Duplicate"));
|
---|
[626] | 30 | }
|
---|
| 31 |
|
---|
[6084] | 32 | @Override
|
---|
[1169] | 33 | public void actionPerformed(ActionEvent e) {
|
---|
[10604] | 34 | PrimitiveTransferData data = PrimitiveTransferData.getDataWithReferences(getLayerManager().getEditDataSet().getSelected());
|
---|
[10766] | 35 | doPaste(e, new PrimitiveTransferable(data));
|
---|
[626] | 36 | }
|
---|
[1023] | 37 |
|
---|
[1820] | 38 | @Override
|
---|
| 39 | protected void updateEnabledState() {
|
---|
[10409] | 40 | updateEnabledStateOnCurrentSelection();
|
---|
[1814] | 41 | }
|
---|
[2256] | 42 |
|
---|
| 43 | @Override
|
---|
| 44 | protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
|
---|
| 45 | setEnabled(selection != null && !selection.isEmpty());
|
---|
| 46 | }
|
---|
[626] | 47 | }
|
---|