source: subversion/applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/ConnectedWaysAction.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.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;
10import java.util.HashSet;
11import java.util.Set;
12
13import org.openstreetmap.josm.actions.JosmAction;
14import org.openstreetmap.josm.data.osm.DataSet;
15import org.openstreetmap.josm.data.osm.Node;
16import org.openstreetmap.josm.data.osm.OsmPrimitive;
17import org.openstreetmap.josm.data.osm.Way;
18import org.openstreetmap.josm.tools.Shortcut;
19
20/**
21 * Extends current selection by selecting nodes on all touched ways
22 */
23public class ConnectedWaysAction extends JosmAction {
24
25    public ConnectedWaysAction() {
26        super(tr("All connected ways"), "adjwaysall", tr("Select all connected ways"),
27                Shortcut.registerShortcut("tools:adjwaysall", tr("Tool: {0}", "All connected ways"),
28                        KeyEvent.VK_E, Shortcut.CTRL_SHIFT), true);
29        putValue("help", ht("/Action/SelectConnectedWays"));
30    }
31
32    @Override
33    public void actionPerformed(ActionEvent e) {
34        DataSet ds = getLayerManager().getEditDataSet();
35        Collection<Node> selectedNodes = ds.getSelectedNodes();
36        Collection<Way> selectedWays = ds.getSelectedWays();
37
38        Set<Way> newWays = new HashSet<>();
39
40        // selecting ways attached to selected nodes
41        if (!selectedNodes.isEmpty()) {
42            NodeWayUtils.addWaysConnectedToNodes(selectedNodes, newWays);
43        }
44
45        // select ways attached to already selected ways
46        newWays.addAll(selectedWays);
47        NodeWayUtils.addWaysConnectedToWaysRecursively(selectedWays, newWays);
48
49        ds.setSelected(newWays);
50    }
51
52    @Override
53    protected void updateEnabledState() {
54        updateEnabledStateOnCurrentSelection();
55    }
56
57    @Override
58    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
59        if (selection == null) {
60            setEnabled(false);
61            return;
62        }
63        setEnabled(!selection.isEmpty());
64    }
65}
Note: See TracBrowser for help on using the repository browser.