Ticket #6367: JOSM.patch
File JOSM.patch, 5.6 KB (added by , 12 years ago) |
---|
-
src/org/openstreetmap/josm/actions/FollowLineAction.java
7 7 import java.awt.event.KeyEvent; 8 8 import java.util.Collection; 9 9 import java.util.Iterator; 10 import java.util.LinkedList; 10 11 import java.util.List; 11 12 import java.util.Set; 12 13 13 14 import org.openstreetmap.josm.Main; 14 15 import org.openstreetmap.josm.actions.mapmode.DrawAction; 15 16 import org.openstreetmap.josm.command.ChangeCommand; 17 import org.openstreetmap.josm.command.Command; 18 import org.openstreetmap.josm.command.SelectCommand; 19 import org.openstreetmap.josm.command.SequenceCommand; 16 20 import org.openstreetmap.josm.data.osm.Node; 17 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 22 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; … … 38 42 "followline.png", 39 43 tr("Continues drawing a line that shares nodes with another line."), 40 44 Shortcut.registerShortcut("tools:followline", tr( 41 "Tool: {0}", tr("Follow")),42 KeyEvent.VK_F, Shortcut.GROUP_EDIT), true);45 "Tool: {0}", tr("Follow")), 46 KeyEvent.VK_F, Shortcut.GROUP_EDIT), true); 43 47 } 44 48 45 49 @Override … … 62 66 if (osmLayer == null) 63 67 return; 64 68 if (!(Main.map.mapMode instanceof DrawAction)) return; // We are not on draw mode 65 69 66 70 Collection<Node> selectedPoints = osmLayer.data.getSelectedNodes(); 67 71 Collection<Way> selectedLines = osmLayer.data.getSelectedWays(); 68 72 if ((selectedPoints.size() > 1) || (selectedLines.size() != 1)) // Unsuitable selection 69 73 return; 70 74 71 75 Node last = ((DrawAction) Main.map.mapMode).getCurrentBaseNode(); 72 76 if (last == null) 73 77 return; … … 82 86 } 83 87 List<OsmPrimitive> referrers = last.getReferrers(); 84 88 if (referrers.size() < 2) return; // There's nothing to follow 85 86 Node newPoint = null; 89 90 Node newPoint = null; 87 91 Iterator<OsmPrimitive> i = referrers.iterator(); 88 92 while (i.hasNext()) { 89 93 OsmPrimitive referrer = i.next(); … … 95 99 continue; 96 100 } 97 101 Set<Node> points = toFollow.getNeighbours(last); 98 if (!points.remove(prev) || (points.size() == 0)) 102 if (!points.remove(prev) || (points.size() == 0)) { 99 103 continue; 104 } 100 105 if (points.size() > 1) // Ambiguous junction? 101 106 return; 102 107 … … 114 119 } else { 115 120 newFollower.addNode(newPoint); 116 121 } 117 Main.main.undoRedo.add(new ChangeCommand(follower, newFollower)); 118 osmLayer.data.clearSelection(); 119 osmLayer.data.addSelected(newFollower); 120 osmLayer.data.addSelected(newPoint); 121 // "viewport following" mode for tracing long features 122 // from aerial imagery or GPS tracks. 122 123 Collection<OsmPrimitive> newSelection = new LinkedList<OsmPrimitive>(); 124 125 newSelection.add(newFollower); 126 newSelection.add(newPoint); 127 128 Collection<Command> cmds = new LinkedList<Command>(); 129 130 cmds.add(new ChangeCommand(follower, newFollower)); 131 cmds.add(new SelectCommand(newSelection)); 132 133 Main.main.undoRedo.add(new SequenceCommand(tr("Follow line"), cmds)); 134 135 // "viewport following" mode for tracing long features 136 // from aerial imagery or GPS tracks. 123 137 if (Main.map.mapView.viewportFollowing) { 124 138 Main.map.mapView.smoothScrollTo(newPoint.getEastNorth()); 125 139 }; -
src/org/openstreetmap/josm/command/SelectCommand.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.command; 3 4 import static org.openstreetmap.josm.tools.I18n.trn; 5 6 import java.util.Collection; 7 8 import javax.swing.JLabel; 9 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 13 /** 14 * Command that selects OSM primitives 15 * 16 * @author Landwirt 17 */ 18 public class SelectCommand extends Command { 19 20 private final Collection<OsmPrimitive> osm; 21 22 private Collection<OsmPrimitive> oldSelection; 23 24 public SelectCommand(Collection<OsmPrimitive> osm) { 25 this.osm = osm; 26 } 27 28 @Override 29 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 30 Collection<OsmPrimitive> added) { 31 } 32 33 @Override 34 public void undoCommand() { 35 Main.map.mapView.getEditLayer().data.setSelected(oldSelection); 36 } 37 38 @Override public boolean executeCommand() { 39 oldSelection = Main.map.mapView.getEditLayer().data.getSelected(); 40 41 Main.map.mapView.getEditLayer().data.setSelected(osm); 42 return true; 43 } 44 45 @Override public JLabel getDescription() { 46 int size = osm != null ? osm.size() : 0; 47 return new JLabel(trn("Selected {0} object", "Selected {0} objects", size, size), null, 48 JLabel.HORIZONTAL 49 ); 50 } 51 }