| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.actions;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
|---|
| 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 6 |
|
|---|
| 7 | import java.awt.event.ActionEvent;
|
|---|
| 8 | import java.awt.event.KeyEvent;
|
|---|
| 9 |
|
|---|
| 10 | import org.openstreetmap.josm.data.osm.OsmData;
|
|---|
| 11 | import org.openstreetmap.josm.tools.Shortcut;
|
|---|
| 12 |
|
|---|
| 13 | /**
|
|---|
| 14 | * User action to invert the selection in the current dataset.
|
|---|
| 15 | */
|
|---|
| 16 | public class InvertSelectionAction extends JosmAction {
|
|---|
| 17 |
|
|---|
| 18 | /**
|
|---|
| 19 | * Constructs a new {@code SelectAllAction}.
|
|---|
| 20 | */
|
|---|
| 21 | public InvertSelectionAction() {
|
|---|
| 22 | super(tr("Invert Selection"), "invert_selection", tr("Invert Selection"),
|
|---|
| 23 | Shortcut.registerShortcut("selection:invertselection",
|
|---|
| 24 | tr("Selection: {0}", tr("Invert Selection")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), true);
|
|---|
| 25 | setHelpId(ht("/Action/InvertSelection"));
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | @Override
|
|---|
| 29 | public void actionPerformed(ActionEvent e) {
|
|---|
| 30 | if (!isEnabled())
|
|---|
| 31 | return;
|
|---|
| 32 | OsmData<?, ?, ?, ?> ds = getLayerManager().getActiveData();
|
|---|
| 33 | ds.setSelected(ds.getPrimitives(t -> !t.isSelected()));
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | @Override
|
|---|
| 37 | protected boolean listenToSelectionChange() {
|
|---|
| 38 | return false;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | @Override
|
|---|
| 42 | protected void updateEnabledState() {
|
|---|
| 43 | setEnabled(getLayerManager().getActiveData() != null);
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|