Changeset 26792 in osm for applications/editors
- Timestamp:
- 2011-10-07T07:56:35+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPlugin2.java
r26644 r26792 10 10 11 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.actions.JosmAction;13 12 import org.openstreetmap.josm.gui.MainMenu; 14 13 import org.openstreetmap.josm.gui.MapFrame; … … 43 42 JMenuItem selModifiedNodes; 44 43 JMenuItem selModifiedWays; 44 JMenuItem selectHighway; 45 45 46 46 JMenuItem selectURL; … … 78 78 selModifiedWays = MainMenu.add(selectionMenu, new SelectModWaysAction()); 79 79 undoSelection = MainMenu.add(selectionMenu, new UndoSelectionAction()); 80 selectHighway = MainMenu.add(selectionMenu, new SelectHighwayAction()); 80 81 81 82 selectURL = MainMenu.add(toolsMenu, new ChooseURLAction()); -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/SelectHighwayAction.java
r26791 r26792 1 // License: GPL. Copyright 2011 by Alexei Kasatkin1 // License: PD 2 2 package utilsplugin2.selection; 3 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;5 4 import static org.openstreetmap.josm.tools.I18n.tr; 6 5 7 6 import java.awt.event.ActionEvent; 8 7 import java.awt.event.KeyEvent; 9 import java.util. Collection;10 import java .util.HashSet;11 import java.util.Set;8 import java.util.*; 9 import javax.swing.JOptionPane; 10 import org.openstreetmap.josm.Main; 12 11 import org.openstreetmap.josm.actions.JosmAction; 13 12 import org.openstreetmap.josm.data.osm.*; 14 15 13 import org.openstreetmap.josm.tools.Shortcut; 16 14 17 15 /** 18 * Extends current selection by selecting nodes on all touched ways 16 * Select all connected ways for a street if one way is selected (determine by name/ref), 17 * select highway ways between two selected ways. 18 * 19 * @author zverik 19 20 */ 20 public class ConnectedWaysAction extends JosmAction {21 public class SelectHighwayAction extends JosmAction { 21 22 22 public ConnectedWaysAction() { 23 super(tr("All connected ways"), "adjwaysall", tr("Select all connected ways"), 24 Shortcut.registerShortcut("tools:adjwaysall", tr("Tool: {0}","All connected ways"), 25 KeyEvent.VK_E, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), true); 26 putValue("help", ht("/Action/SelectConnectedWays")); 23 public SelectHighwayAction() { 24 super(tr("Select Highway"), "selecthighway", tr("Select highway for the name/ref given"), 25 Shortcut.registerShortcut("tools:selecthighway", tr("Tool: {0}","Select Highway"), 26 KeyEvent.VK_W, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), true); 27 27 } 28 28 29 @Override 29 30 public void actionPerformed(ActionEvent e) { 30 31 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 31 Set<Node> selectedNodes = OsmPrimitive.getFilteredSet(selection, Node.class); 32 Set<Way> selectedWays = OsmPrimitive.getFilteredSet(getCurrentDataSet().getSelected(), Way.class); 33 32 List<Way> selectedWays = OsmPrimitive.getFilteredList(getCurrentDataSet().getSelected(), Way.class); 34 33 Set<Way> newWays = new HashSet<Way>(); 35 34 36 // selecting ways attached to selected nodes 37 if(!selectedNodes.isEmpty()) { 38 NodeWayUtils.addWaysConnectedToNodes(selectedNodes, newWays); 35 if( selectedWays.size() == 1 ) { 36 Way firstWay = selectedWays.get(0); 37 String key = firstWay.hasKey("name") ? "name" : "ref"; 38 if( !firstWay.hasKey(key) ) { 39 JOptionPane.showMessageDialog(Main.parent, "The selected way should have either name or ref tag.", "Select Highway", JOptionPane.ERROR_MESSAGE); 40 return; 41 } 42 String value = firstWay.get(key); 43 44 Queue<Node> nodeQueue = new LinkedList<Node>(); 45 nodeQueue.add(firstWay.firstNode()); 46 47 while( !nodeQueue.isEmpty() ) { 48 Node node = nodeQueue.remove(); 49 for( Way p : OsmPrimitive.getFilteredList(node.getReferrers(), Way.class) ) { 50 if( !newWays.contains(p) && p.hasKey(key) && p.get(key).equals(value) ) { 51 newWays.add(p); 52 nodeQueue.add(p.firstNode().equals(node) ? p.lastNode() : p.firstNode()); 53 } 54 } 55 } 56 } else if( selectedWays.size() == 2 ) { 57 JOptionPane.showMessageDialog(Main.parent, "Sorry, two ways are not supported yet", "Select Highway", JOptionPane.ERROR_MESSAGE); 58 return; 59 } else { 60 JOptionPane.showMessageDialog(Main.parent, "Please select exactly one way for this action", "Select Highway", JOptionPane.ERROR_MESSAGE); 61 return; 39 62 } 40 63 41 // select ways attached to already selected ways42 newWays.addAll(selectedWays);43 NodeWayUtils.addWaysConnectedToWaysRecursively(selectedWays, newWays);44 45 // System.out.printf("%d ways added to selection\n",newWays.size()-selectedWays.size());46 64 getCurrentDataSet().setSelected(newWays); 47 48 65 } 49 66 50 67 @Override 51 68 protected void updateEnabledState() { 52 if (getCurrentDataSet() == null) {69 if (getCurrentDataSet() == null) 53 70 setEnabled(false); 54 } else {71 else 55 72 updateEnabledState(getCurrentDataSet().getSelected()); 56 }57 73 } 58 74 … … 63 79 return; 64 80 } 65 setEnabled(!selection.isEmpty()); 81 int count = 0; 82 for( OsmPrimitive p : selection ) 83 if( p instanceof Way ) 84 count++; 85 setEnabled(count == 1); // todo: or 2 66 86 } 67 68 69 87 }
Note:
See TracChangeset
for help on using the changeset viewer.