source: josm/trunk/src/org/openstreetmap/josm/actions/InvertSelectionAction.java@ 16701

Last change on this file since 16701 was 16701, checked in by simon04, 4 years ago

fix #18586 - Add invert selection action for experts

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