source: josm/trunk/src/org/openstreetmap/josm/actions/DuplicateAction.java@ 10604

Last change on this file since 10604 was 10604, checked in by Don-vip, 8 years ago

fix #12478, fix #12565, fix #11114 - Use ​Swing Copy/Paste instead of CopyAction/PasteAction with custom buffer (patch by michael2402, modified) - gsoc-core

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2// Author: David Earl
3package org.openstreetmap.josm.actions;
4
5import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
6import static org.openstreetmap.josm.tools.I18n.tr;
7
8import java.awt.event.ActionEvent;
9import java.awt.event.KeyEvent;
10import java.util.Collection;
11
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler;
15import org.openstreetmap.josm.gui.datatransfer.PrimitiveTransferable;
16import org.openstreetmap.josm.gui.datatransfer.data.PrimitiveTransferData;
17import org.openstreetmap.josm.tools.Shortcut;
18
19/**
20 * An action that dupplicates the given nodes. They are not added to the clipboard.
21 */
22public final class DuplicateAction extends JosmAction {
23
24 /**
25 * Constructs a new {@code DuplicateAction}.
26 */
27 public DuplicateAction() {
28 super(tr("Duplicate"), "duplicate",
29 tr("Duplicate selection."),
30 Shortcut.registerShortcut("system:duplicate", tr("Edit: {0}", tr("Duplicate")), KeyEvent.VK_D, Shortcut.CTRL), true);
31 putValue("help", ht("/Action/Duplicate"));
32 }
33
34 @Override
35 public void actionPerformed(ActionEvent e) {
36 PrimitiveTransferData data = PrimitiveTransferData.getDataWithReferences(getLayerManager().getEditDataSet().getSelected());
37 new OsmTransferHandler().pasteOn(Main.getLayerManager().getEditLayer(), data.getCenter(), new PrimitiveTransferable(data));
38 }
39
40 @Override
41 protected void updateEnabledState() {
42 updateEnabledStateOnCurrentSelection();
43 }
44
45 @Override
46 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
47 setEnabled(selection != null && !selection.isEmpty());
48 }
49}
Note: See TracBrowser for help on using the repository browser.