1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.plugins.utilsplugin2.selection;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.KeyEvent;
|
---|
9 | import java.util.Collection;
|
---|
10 | import java.util.HashSet;
|
---|
11 | import java.util.Set;
|
---|
12 |
|
---|
13 | import javax.swing.JOptionPane;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
16 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
17 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
18 | import org.openstreetmap.josm.data.osm.Way;
|
---|
19 | import org.openstreetmap.josm.gui.Notification;
|
---|
20 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Extends current selection by selecting nodes on all touched ways
|
---|
24 | */
|
---|
25 | public class IntersectedWaysAction extends JosmAction {
|
---|
26 |
|
---|
27 | public IntersectedWaysAction() {
|
---|
28 | super(tr("Intersecting ways"), "intway", tr("Select intersecting ways"),
|
---|
29 | Shortcut.registerShortcut("tools:intway", tr("Selection: {0}", tr("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().getActiveDataSet();
|
---|
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 | } else {
|
---|
47 | new Notification(
|
---|
48 | tr("Please select some ways to find 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 | setEnabled(selection != null && !selection.isEmpty());
|
---|
61 | }
|
---|
62 | }
|
---|