001// License: GPL. For details, see LICENSE file. 002// Author: David Earl 003package org.openstreetmap.josm.actions; 004 005import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 006import static org.openstreetmap.josm.tools.I18n.tr; 007 008import java.awt.event.ActionEvent; 009import java.awt.event.KeyEvent; 010import java.util.Collection; 011 012import org.openstreetmap.josm.data.osm.OsmPrimitive; 013import org.openstreetmap.josm.gui.datatransfer.PrimitiveTransferable; 014import org.openstreetmap.josm.gui.datatransfer.data.PrimitiveTransferData; 015import org.openstreetmap.josm.tools.Shortcut; 016 017/** 018 * An action that duplicates the given nodes. They are not added to the clipboard. 019 */ 020public final class DuplicateAction extends AbstractPasteAction { 021 022 /** 023 * Constructs a new {@code DuplicateAction}. 024 */ 025 public DuplicateAction() { 026 super(tr("Duplicate"), "duplicate", 027 tr("Duplicate selection."), 028 Shortcut.registerShortcut("system:duplicate", tr("Edit: {0}", tr("Duplicate")), KeyEvent.VK_D, Shortcut.CTRL), true); 029 putValue("help", ht("/Action/Duplicate")); 030 } 031 032 @Override 033 public void actionPerformed(ActionEvent e) { 034 PrimitiveTransferData data = PrimitiveTransferData.getDataWithReferences(getLayerManager().getEditDataSet().getSelected()); 035 doPaste(e, new PrimitiveTransferable(data)); 036 } 037 038 @Override 039 protected void updateEnabledState() { 040 updateEnabledStateOnCurrentSelection(); 041 } 042 043 @Override 044 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 045 setEnabled(selection != null && !selection.isEmpty()); 046 } 047}