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 |
|
---|
9 | import javax.swing.JComponent;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
13 |
|
---|
14 | public class UnselectAllAction extends JosmAction {
|
---|
15 |
|
---|
16 | public UnselectAllAction() {
|
---|
17 | super(tr("Unselect All"), "unselectall", tr("Unselect all objects."),
|
---|
18 | Shortcut.registerShortcut("edit:unselectall", tr("Edit: {0}", tr("Unselect All")), KeyEvent.VK_U, Shortcut.GROUP_EDIT), true);
|
---|
19 | // this is not really GROUP_EDIT, but users really would complain if the yhad to reconfigure because we put
|
---|
20 | // the correct group in
|
---|
21 |
|
---|
22 | // Add extra shortcut C-S-a
|
---|
23 | Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
|
---|
24 | Shortcut.registerShortcut("edit:unselectallfocus", tr("Edit: {0}", tr("Unselect All (Focus)")),
|
---|
25 | KeyEvent.VK_A, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT).getKeyStroke(),
|
---|
26 | tr("Unselect All"));
|
---|
27 |
|
---|
28 | // Add extra shortcut ESCAPE
|
---|
29 | /*
|
---|
30 | * FIXME: this isn't optimal. In a better world the mapmode actions
|
---|
31 | * would be able to capture keyboard events and react accordingly. But
|
---|
32 | * for now this is a reasonable approximation.
|
---|
33 | */
|
---|
34 | Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
|
---|
35 | Shortcut.registerShortcut("edit:unselectallescape", tr("Edit: {0}", tr("Unselect All (Escape)")),
|
---|
36 | KeyEvent.VK_ESCAPE, Shortcut.GROUP_DIRECT).getKeyStroke(),
|
---|
37 | tr("Unselect All"));
|
---|
38 | }
|
---|
39 |
|
---|
40 | public void actionPerformed(ActionEvent e) {
|
---|
41 | if (!isEnabled())
|
---|
42 | return;
|
---|
43 | getCurrentDataSet().setSelected();
|
---|
44 | }
|
---|
45 | /**
|
---|
46 | * Refreshes the enabled state
|
---|
47 | *
|
---|
48 | */
|
---|
49 | @Override
|
---|
50 | protected void updateEnabledState() {
|
---|
51 | setEnabled(getEditLayer() != null);
|
---|
52 | }
|
---|
53 | }
|
---|