001 // License: GPL. Copyright 2007 by Immanuel Scholz and others
002 // Author: David Earl
003 package org.openstreetmap.josm.actions;
004
005 import static org.openstreetmap.josm.tools.I18n.tr;
006 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
007
008 import java.awt.event.ActionEvent;
009 import java.awt.event.KeyEvent;
010 import java.util.Collection;
011 import org.openstreetmap.josm.Main;
012
013 import org.openstreetmap.josm.data.osm.OsmPrimitive;
014 import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy;
015 import org.openstreetmap.josm.tools.Shortcut;
016
017 public final class DuplicateAction extends JosmAction{
018
019 public DuplicateAction() {
020 super(tr("Duplicate"), "duplicate",
021 tr("Duplicate selection by copy and immediate paste."),
022 Shortcut.registerShortcut("system:duplicate", tr("Edit: {0}", tr("Duplicate")), KeyEvent.VK_D, Shortcut.CTRL), true);
023 putValue("help", ht("/Action/Duplicate"));
024 }
025
026 public void actionPerformed(ActionEvent e) {
027 Main.main.menu.paste.pasteData(new PrimitiveDeepCopy(getCurrentDataSet().getSelected()), getEditLayer(), e);
028 }
029
030 @Override
031 protected void updateEnabledState() {
032 if (getCurrentDataSet() == null) {
033 setEnabled(false);
034 } else {
035 updateEnabledState(getCurrentDataSet().getSelected());
036 }
037 }
038
039 @Override
040 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
041 setEnabled(selection != null && !selection.isEmpty());
042 }
043 }