source: subversion/applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/AdjacentWaysAction.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.3 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
22 */
23public class AdjacentWaysAction extends JosmAction {
24
25    public static final boolean treeMode = false;
26
27    public AdjacentWaysAction() {
28        super(tr("Adjacent ways"), "adjways",
29                tr("Adjacent ways will be selected. Nodes will be deselected."),
30                Shortcut.registerShortcut("tools:adjways", tr("Tool: {0}", "Adjacent ways"),
31                        KeyEvent.VK_E, Shortcut.SHIFT), true);
32        putValue("help", ht("/Action/AdjacentWays"));
33    }
34
35    @Override
36    public void actionPerformed(ActionEvent e) {
37        DataSet ds = getLayerManager().getEditDataSet();
38        Collection<Node> selectedNodes = ds.getSelectedNodes();
39        Collection<Way> selectedWays = ds.getSelectedWays();
40
41        // select ways attached to already selected ways
42        Set<Way> newWays = new HashSet<>();
43        NodeWayUtils.addWaysConnectedToWays(selectedWays, newWays);
44        newWays.addAll(selectedWays);
45
46        // selecting ways attached to selected nodes
47        if (!selectedNodes.isEmpty()) {
48            NodeWayUtils.addWaysConnectedToNodes(selectedNodes, newWays);
49        }
50
51        //        System.out.printf("%d ways added to selection\n",newWays.size()-selectedWays.size());
52        ds.setSelected(newWays);
53    }
54
55    @Override
56    protected void updateEnabledState() {
57        updateEnabledStateOnCurrentSelection();
58    }
59
60    @Override
61    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
62        if (selection == null) {
63            setEnabled(false);
64            return;
65        }
66        setEnabled(!selection.isEmpty());
67    }
68}
Note: See TracBrowser for help on using the repository browser.