source: josm/trunk/src/org/openstreetmap/josm/actions/CopyAction.java@ 2667

Last change on this file since 2667 was 2323, checked in by Gubaer, 14 years ago

Added explicit help topics
See also current list of help topics with links to source files and to help pages

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2// Author: David Earl
3package org.openstreetmap.josm.actions;
4
5import static org.openstreetmap.josm.tools.I18n.tr;
6import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
7
8import java.awt.event.ActionEvent;
9import java.awt.event.KeyEvent;
10import java.util.Collection;
11import java.util.LinkedList;
12
13import javax.swing.JOptionPane;
14
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.data.osm.OsmPrimitive;
17import org.openstreetmap.josm.tools.Shortcut;
18
19public final class CopyAction extends JosmAction {
20
21 private LinkedList<JosmAction> listeners;
22
23 public CopyAction() {
24 super(tr("Copy"), "copy",
25 tr("Copy selected objects to paste buffer."),
26 Shortcut.registerShortcut("system:copy", tr("Edit: {0}", tr("Copy")), KeyEvent.VK_C, Shortcut.GROUP_MENU), true);
27 putValue("help", ht("/Action/Copy"));
28 listeners = new LinkedList<JosmAction>();
29 }
30
31 @Override public void addListener(JosmAction a) {
32 listeners.add(a);
33 }
34
35 public void actionPerformed(ActionEvent e) {
36 if(isEmptySelection()) return;
37
38 Main.pasteBuffer.makeCopy(getCurrentDataSet().getSelected());
39 Main.pasteSource = getEditLayer();
40 Main.main.menu.paste.setEnabled(true); /* now we have a paste buffer we can make paste available */
41
42 for(JosmAction a : listeners) {
43 a.pasteBufferChanged(Main.pasteBuffer);
44 }
45 }
46
47 @Override
48 protected void updateEnabledState() {
49 if (getCurrentDataSet() == null) {
50 setEnabled(false);
51 } else {
52 updateEnabledState(getCurrentDataSet().getSelected());
53 }
54 }
55
56 @Override
57 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
58 setEnabled(selection != null && !selection.isEmpty());
59 }
60
61 private boolean isEmptySelection() {
62 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected();
63 if (sel.isEmpty()) {
64 JOptionPane.showMessageDialog(
65 Main.parent,
66 tr("Please select something to copy."),
67 tr("Information"),
68 JOptionPane.INFORMATION_MESSAGE
69 );
70 return true;
71 }
72 return false;
73 }
74}
Note: See TracBrowser for help on using the repository browser.