Changeset 8990 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
r8988 r8990 48 48 import org.openstreetmap.josm.tools.GBC; 49 49 import org.openstreetmap.josm.tools.Shortcut; 50 import org.openstreetmap.josm.tools.Utils;51 50 52 51 /** … … 248 247 public void valueChanged(ListSelectionEvent e) { 249 248 final Way selected = list.getSelectedValue(); 250 if (Main.isDisplayingMapView() && selected != null) { 251 final List<WaySegment> segments = Utils.transform(selected.getNodes().subList(0, selected.getNodesCount() - 1), 252 new Utils.Function<Node, WaySegment>() { 253 @Override 254 public WaySegment apply(Node x) { 255 return new WaySegment(selectedWay, selectedWay.getNodes().indexOf(x)); 256 } 257 }); 249 if (Main.isDisplayingMapView() && selected != null && selected.getNodesCount() > 1) { 250 final Collection<WaySegment> segments = new ArrayList<>(selected.getNodesCount() - 1); 251 final Iterator<Node> it = selected.getNodes().iterator(); 252 Node previousNode = it.next(); 253 while (it.hasNext()) { 254 final Node node = it.next(); 255 segments.add(WaySegment.forNodePair(selectedWay, previousNode, node)); 256 previousNode = node; 257 } 258 258 setHighlightedWaySegments(segments); 259 259 } -
trunk/src/org/openstreetmap/josm/data/osm/WaySegment.java
r8846 r8990 44 44 public Node getSecondNode() { 45 45 return way.getNode(lowerIndex + 1); 46 } 47 48 /** 49 * Determines and returns the way segment for the given way and node pair. 50 * @throws IllegalArgumentException if the node pair is not part of way 51 */ 52 public static WaySegment forNodePair(Way way, Node first, Node second) { 53 int endIndex = way.getNodesCount() - 1; 54 while (endIndex > 0) { 55 final int indexOfFirst = way.getNodes().subList(0, endIndex).lastIndexOf(first); 56 if (second.equals(way.getNode(indexOfFirst + 1))) { 57 return new WaySegment(way, indexOfFirst); 58 } 59 endIndex--; 60 } 61 throw new IllegalArgumentException("Node pair is not part of way!"); 46 62 } 47 63
Note:
See TracChangeset
for help on using the changeset viewer.