source: subversion/applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/MiddleNodesAction.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 javax.swing.JOptionPane;
14
15import org.openstreetmap.josm.actions.JosmAction;
16import org.openstreetmap.josm.data.osm.Node;
17import org.openstreetmap.josm.data.osm.OsmPrimitive;
18import org.openstreetmap.josm.gui.Notification;
19import org.openstreetmap.josm.tools.Shortcut;
20
21/**
22 * Selects nodes between two selected
23 */
24public class MiddleNodesAction extends JosmAction {
25
26    public static final boolean treeMode = false;
27
28    public MiddleNodesAction() {
29        super(tr("Middle nodes"), "midnodes", tr("Select middle nodes"),
30                Shortcut.registerShortcut("tools:midnodes", tr("Tool: {0}", "Middle nodes"), KeyEvent.VK_E, Shortcut.ALT_SHIFT), true);
31        putValue("help", ht("/Action/MiddleNodes"));
32    }
33
34    @Override
35    public void actionPerformed(ActionEvent e) {
36        Set<Node> selectedNodes = new HashSet<>(getLayerManager().getEditDataSet().getSelectedNodes());
37
38        // if no 2 nodes and no ways are selected, do nothing
39        if (selectedNodes.size() != 2) {
40            new Notification(
41                    tr("Please select two nodes connected by way!")
42                    ).setIcon(JOptionPane.WARNING_MESSAGE).show();
43            return;
44        }
45
46        Set<Node> newNodes = new HashSet<>();
47        NodeWayUtils.addMiddle(selectedNodes, newNodes);
48
49        // select only newly found nodes
50        newNodes.removeAll(selectedNodes);
51        getLayerManager().getEditDataSet().addSelected(newNodes);
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.