[298] | 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
[626] | 2 | package org.openstreetmap.josm.actions;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
[2323] | 5 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
[626] | 6 |
|
---|
| 7 | import java.awt.event.ActionEvent;
|
---|
| 8 | import java.awt.event.KeyEvent;
|
---|
[1865] | 9 |
|
---|
[468] | 10 | import javax.swing.JComponent;
|
---|
| 11 |
|
---|
[626] | 12 | import org.openstreetmap.josm.Main;
|
---|
[1084] | 13 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
[626] | 14 |
|
---|
[1820] | 15 | public class UnselectAllAction extends JosmAction {
|
---|
[626] | 16 |
|
---|
[1169] | 17 | public UnselectAllAction() {
|
---|
| 18 | super(tr("Unselect All"), "unselectall", tr("Unselect all objects."),
|
---|
[1808] | 19 | Shortcut.registerShortcut("edit:unselectall", tr("Edit: {0}", tr("Unselect All")), KeyEvent.VK_U, Shortcut.GROUP_EDIT), true);
|
---|
[1169] | 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
|
---|
[626] | 22 |
|
---|
[1169] | 23 | // Add extra shortcut C-S-a
|
---|
| 24 | Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
|
---|
[1808] | 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"));
|
---|
[626] | 28 |
|
---|
[1169] | 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(
|
---|
[1808] | 36 | Shortcut.registerShortcut("edit:unselectallescape", tr("Edit: {0}", tr("Unselect All (Escape)")),
|
---|
| 37 | KeyEvent.VK_ESCAPE, Shortcut.GROUP_DIRECT).getKeyStroke(),
|
---|
| 38 | tr("Unselect All"));
|
---|
[2323] | 39 |
|
---|
| 40 | putValue("help", ht("/Action/UnselectAll"));
|
---|
[1169] | 41 | }
|
---|
[768] | 42 |
|
---|
[1169] | 43 | public void actionPerformed(ActionEvent e) {
|
---|
[1808] | 44 | if (!isEnabled())
|
---|
| 45 | return;
|
---|
[1814] | 46 | getCurrentDataSet().setSelected();
|
---|
[1169] | 47 | }
|
---|
[1808] | 48 | /**
|
---|
| 49 | * Refreshes the enabled state
|
---|
| 50 | *
|
---|
| 51 | */
|
---|
[1820] | 52 | @Override
|
---|
| 53 | protected void updateEnabledState() {
|
---|
[1814] | 54 | setEnabled(getEditLayer() != null);
|
---|
[1808] | 55 | }
|
---|
[626] | 56 | }
|
---|