source: subversion/applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectAllInsideAction.java

Last change on this file was 33212, checked in by Dirk Stoecker, 2 years ago

fix #josm14597

File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.plugins.utilsplugin2.selection;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.awt.event.KeyEvent;
9import java.util.Collection;
10
11import javax.swing.JOptionPane;
12
13import org.openstreetmap.josm.actions.JosmAction;
14import org.openstreetmap.josm.data.osm.DataSet;
15import org.openstreetmap.josm.data.osm.OsmPrimitive;
16import org.openstreetmap.josm.gui.Notification;
17import org.openstreetmap.josm.tools.Shortcut;
18import org.openstreetmap.josm.tools.SubclassFilteredCollection;
19
20/**
21 * Extends current selection by selecting nodes on all touched ways
22 */
23public class SelectAllInsideAction extends JosmAction {
24
25    public SelectAllInsideAction() {
26        super(tr("All inside [testing]"), "selinside", tr("Select all inside selected polygons"),
27                Shortcut.registerShortcut("tools:selinside", tr("Tool: {0}", "All inside"),
28                        KeyEvent.VK_I, Shortcut.ALT_SHIFT), true);
29        putValue("help", ht("/Action/SelectAllInside"));
30    }
31
32    @Override
33    public void actionPerformed(ActionEvent e) {
34        DataSet ds = getLayerManager().getEditDataSet();
35        Collection<OsmPrimitive> insideSelected = NodeWayUtils.selectAllInside(ds.getSelected(), ds, true);
36
37        if (!insideSelected.isEmpty()) {
38            ds.addSelected(insideSelected);
39            ds.setSelected(new SubclassFilteredCollection<>(ds.getSelected(), OsmPrimitive::isSelectable));
40        } else {
41            new Notification(
42                    tr("Nothing found. Please select some closed ways or multipolygons to find all primitives inside them!"))
43            .setIcon(JOptionPane.WARNING_MESSAGE)
44            .show();
45        }
46    }
47
48    @Override
49    protected void updateEnabledState() {
50        updateEnabledStateOnCurrentSelection();
51    }
52
53    @Override
54    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
55        if (selection == null) {
56            setEnabled(false);
57            return;
58        }
59        setEnabled(!selection.isEmpty());
60    }
61}
Note: See TracBrowser for help on using the repository browser.