source: osm/applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/IntersectedWaysAction.java

Last change on this file was 35674, checked in by GerdP, 3 years ago
  • simplify updateEnabledState
  • minor performance improvements
  • checkstyle or sonarling issues, javadoc corrections
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 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("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}
Note: See TracBrowser for help on using the repository browser.