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

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

fix #13203 - Ctrl-D (Duplicate) places new object on top of source object (patch by michael2402) - 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 duplicates 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(),
38 PasteAction.computePastePosition(e, getValue(NAME)), new PrimitiveTransferable(data));
39 }
40
41 @Override
42 protected void updateEnabledState() {
43 updateEnabledStateOnCurrentSelection();
44 }
45
46 @Override
47 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
48 setEnabled(selection != null && !selection.isEmpty());
49 }
50}
Note: See TracBrowser for help on using the repository browser.