source: subversion/applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/IntersectedWaysAction.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 IntersectedWaysAction extends JosmAction {
26
27    public IntersectedWaysAction() {
28        super(tr("Intersecting ways"), "intway", tr("Select intersecting ways"),
29                Shortcut.registerShortcut("tools:intway", tr("Tool: {0}", "Intersecting ways"),
30                        KeyEvent.VK_I, Shortcut.DIRECT), true);
31        putValue("help", ht("/Action/SelectIntersectingWays"));
32    }
33
34    @Override
35    public void actionPerformed(ActionEvent e) {
36        DataSet ds = getLayerManager().getEditDataSet();
37        Collection<Way> selectedWays = ds.getSelectedWays();
38
39        // select ways attached to already selected ways
40        if (!selectedWays.isEmpty()) {
41            Set<Way> newWays = new HashSet<>();
42            NodeWayUtils.addWaysIntersectingWays(
43                    ds.getWays(),
44                    selectedWays, newWays);
45            ds.addSelected(newWays);
46            return;
47        } else {
48            new Notification(
49                    tr("Please select some ways to find connected and intersecting ways!")
50                    ).setIcon(JOptionPane.WARNING_MESSAGE).show();
51        }
52    }
53
54    @Override
55    protected void updateEnabledState() {
56        updateEnabledStateOnCurrentSelection();
57    }
58
59    @Override
60    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
61        if (selection == null) {
62            setEnabled(false);
63            return;
64        }
65        setEnabled(!selection.isEmpty());
66    }
67}
Note: See TracBrowser for help on using the repository browser.