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

Last change on this file was 34812, checked in by gerdp, 3 months ago

see #17187:

  • Replace deprecated methods
  • Remove dead code
  • Make Shift+Z (Select last modified nodes) work again + Repated Shift+Z cycles through the commands available in the undo tree + Ignore changes in other layers
  • Make Alt+Shift+Z (Select last modified Ways) work again (same logic as with Shift+Z)
  • fix some javadoc errors


File size: 2.2 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;
10import java.util.HashSet;
11import java.util.Set;
12
13import javax.swing.JOptionPane;
14
15import org.openstreetmap.josm.actions.JosmAction;
16import org.openstreetmap.josm.data.osm.DataSet;
17import org.openstreetmap.josm.data.osm.OsmPrimitive;
18import org.openstreetmap.josm.data.osm.Way;
19import org.openstreetmap.josm.gui.Notification;
20import org.openstreetmap.josm.tools.Shortcut;
21
22/**
23 * Extends current selection by selecting nodes on all touched ways
24 */
25public class IntersectedWaysRecursiveAction extends JosmAction {
26
27    public IntersectedWaysRecursiveAction() {
28        super(tr("All intersecting ways"), "intwayall", tr("Select all intersecting ways"),
29                Shortcut.registerShortcut("tools:intwayall", tr("Tool: {0}", "All intersecting ways"),
30                        KeyEvent.VK_MULTIPLY, Shortcut.CTRL), true);
31        putValue("help", ht("/Action/SelectAllIntersectingWays"));
32
33    }
34
35    @Override
36    public void actionPerformed(ActionEvent e) {
37        DataSet ds = getLayerManager().getEditDataSet();
38        Collection<Way> selectedWays = ds.getSelectedWays();
39
40        if (!selectedWays.isEmpty()) {
41            Set<Way> newWays = new HashSet<>();
42            NodeWayUtils.addWaysIntersectingWaysRecursively(
43                    ds.getWays(),
44                    selectedWays, newWays);
45            ds.addSelected(newWays);
46        } else {
47            new Notification(
48                    tr("Please select some ways to find all connected and intersecting ways!")
49                    ).setIcon(JOptionPane.WARNING_MESSAGE).show();
50        }
51    }
52
53    @Override
54    protected void updateEnabledState() {
55        updateEnabledStateOnCurrentSelection();
56    }
57
58    @Override
59    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
60        if (selection == null) {
61            setEnabled(false);
62            return;
63        }
64        setEnabled(!selection.isEmpty());
65    }
66}
Note: See TracBrowser for help on using the repository browser.