1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.ActionEvent;
|
---|
7 | import java.awt.event.KeyEvent;
|
---|
8 | import javax.swing.JComponent;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
12 | import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
|
---|
13 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
14 |
|
---|
15 | public class UnselectAllAction extends JosmAction implements LayerChangeListener {
|
---|
16 |
|
---|
17 | public UnselectAllAction() {
|
---|
18 | super(tr("Unselect All"), "unselectall", tr("Unselect all objects."),
|
---|
19 | Shortcut.registerShortcut("edit:unselectall", tr("Edit: {0}", tr("Unselect All")), KeyEvent.VK_U, Shortcut.GROUP_EDIT), true);
|
---|
20 | // this is not really GROUP_EDIT, but users really would complain if the yhad to reconfigure because we put
|
---|
21 | // the correct group in
|
---|
22 |
|
---|
23 | // Add extra shortcut C-S-a
|
---|
24 | Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
|
---|
25 | Shortcut.registerShortcut("edit:unselectallfocus", tr("Edit: {0}", tr("Unselect All (Focus)")),
|
---|
26 | KeyEvent.VK_A, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT).getKeyStroke(),
|
---|
27 | tr("Unselect All"));
|
---|
28 |
|
---|
29 | // Add extra shortcut ESCAPE
|
---|
30 | /*
|
---|
31 | * FIXME: this isn't optimal. In a better world the mapmode actions
|
---|
32 | * would be able to capture keyboard events and react accordingly. But
|
---|
33 | * for now this is a reasonable approximation.
|
---|
34 | */
|
---|
35 | Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
|
---|
36 | Shortcut.registerShortcut("edit:unselectallescape", tr("Edit: {0}", tr("Unselect All (Escape)")),
|
---|
37 | KeyEvent.VK_ESCAPE, Shortcut.GROUP_DIRECT).getKeyStroke(),
|
---|
38 | tr("Unselect All"));
|
---|
39 | Layer.listeners.add(this);
|
---|
40 | refreshEnabled();
|
---|
41 | }
|
---|
42 |
|
---|
43 | public void actionPerformed(ActionEvent e) {
|
---|
44 | if (!isEnabled())
|
---|
45 | return;
|
---|
46 | getCurrentDataSet().setSelected();
|
---|
47 | }
|
---|
48 | /**
|
---|
49 | * Refreshes the enabled state
|
---|
50 | *
|
---|
51 | */
|
---|
52 | protected void refreshEnabled() {
|
---|
53 | setEnabled(getEditLayer() != null);
|
---|
54 | }
|
---|
55 |
|
---|
56 | /* ---------------------------------------------------------------------------------- */
|
---|
57 | /* Interface LayerChangeListener */
|
---|
58 | /* ---------------------------------------------------------------------------------- */
|
---|
59 | public void activeLayerChange(Layer oldLayer, Layer newLayer) {
|
---|
60 | refreshEnabled();
|
---|
61 | }
|
---|
62 |
|
---|
63 | public void layerAdded(Layer newLayer) {
|
---|
64 | refreshEnabled();
|
---|
65 | }
|
---|
66 |
|
---|
67 | public void layerRemoved(Layer oldLayer) {
|
---|
68 | refreshEnabled();
|
---|
69 | }
|
---|
70 | }
|
---|