Changeset 22 in josm
- Timestamp:
- 2005-10-23T22:13:33+02:00 (19 years ago)
- Files:
-
- 7 added
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r21 r22 4 4 import java.awt.BorderLayout; 5 5 import java.awt.Container; 6 import java.util.Collection; 7 import java.util.LinkedList; 6 8 7 9 import javax.swing.JFrame; … … 20 22 import org.openstreetmap.josm.actions.PreferencesAction; 21 23 import org.openstreetmap.josm.actions.SaveGpxAction; 24 import org.openstreetmap.josm.command.Command; 25 import org.openstreetmap.josm.command.DataSet; 22 26 import org.openstreetmap.josm.data.Preferences; 23 27 import org.openstreetmap.josm.data.Preferences.PreferencesException; … … 26 30 27 31 /** 28 * Main window class consisting of the mainframe MDIapplication.32 * Main window class application. 29 33 * 30 34 * @author imi … … 41 45 */ 42 46 public final static Preferences pref = new Preferences(); 47 48 /** 49 * The global command queue since last save. So if you reload the data from disk 50 * (or from OSM server, if nothing changed on server) and reapply the commands, 51 * you should get the same result as currently displaying. 52 */ 53 public Collection<Command> commands = new LinkedList<Command>(); 54 55 /** 56 * The global dataset. 57 */ 58 public DataSet ds = new DataSet(); 43 59 44 60 /** … … 105 121 // creating toolbar 106 122 JToolBar toolBar = new JToolBar(); 107 toolBar.setFloatable( false);123 toolBar.setFloatable(true); 108 124 toolBar.add(openServerAction); 109 125 toolBar.add(openGpxAction); -
src/org/openstreetmap/josm/actions/OpenOsmServerAction.java
r21 r22 44 44 public class OpenOsmServerAction extends AbstractAction { 45 45 46 privateJTextField[] latlon = new JTextField[]{46 JTextField[] latlon = new JTextField[]{ 47 47 new JTextField(9), 48 48 new JTextField(9), 49 49 new JTextField(9), 50 50 new JTextField(9)}; 51 privateJCheckBox rawGps = new JCheckBox("Open as raw gps data", false);51 JCheckBox rawGps = new JCheckBox("Open as raw gps data", false); 52 52 53 53 public OpenOsmServerAction() { … … 178 178 * checkbox. 179 179 */ 180 privateBookmark readBookmark() {180 Bookmark readBookmark() { 181 181 try { 182 182 Bookmark b = new Bookmark(); -
src/org/openstreetmap/josm/actions/SaveGpxAction.java
r21 r22 47 47 try { 48 48 FileWriter fileWriter = new FileWriter(gpxFile); 49 GpxWriter out = new GpxWriter(fileWriter , Main.main.getMapFrame().mapView.getActiveDataSet());49 GpxWriter out = new GpxWriter(fileWriter); 50 50 out.output(); 51 51 fileWriter.close(); -
src/org/openstreetmap/josm/actions/mapmode/AddLineSegmentAction.java
r21 r22 11 11 12 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.command.DataSet; 13 import org.openstreetmap.josm.command.AddCommand; 14 import org.openstreetmap.josm.command.Command; 14 15 import org.openstreetmap.josm.data.osm.LineSegment; 15 16 import org.openstreetmap.josm.data.osm.Node; … … 130 131 131 132 if (start != end) { 132 DataSet ds = mv.getActiveDataSet();133 134 133 // try to find a line segment 135 for (Track t : ds.tracks())134 for (Track t : Main.main.ds.tracks()) 136 135 for (LineSegment ls : t.segments()) 137 136 if (start == ls.getStart() && end == ls.getEnd()) { … … 141 140 142 141 LineSegment ls = new LineSegment(start, end); 143 boolean foundTrack = false; 144 145 if (((e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0)) { 146 // find a track for the new line segment 147 for (Track t : ds.tracks()) { 148 if (t.getEndingNode() == start) { 149 t.add(ls); 150 foundTrack = true; 151 } 152 } 153 if (!foundTrack) { 154 for (Track t : ds.tracks()) { 155 if (t.getStartingNode() == end) { 156 t.addStart(ls); 157 foundTrack = true; 158 } 159 } 160 } 161 } 162 if (!foundTrack) 163 ds.addPendingLineSegment(ls); 142 Command c = new AddCommand(ls); 143 c.executeCommand(); 144 Main.main.commands.add(c); 164 145 } 165 146 -
src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java
r17 r22 4 4 import java.awt.event.MouseEvent; 5 5 6 import org.openstreetmap.josm.Main; 7 import org.openstreetmap.josm.command.AddCommand; 8 import org.openstreetmap.josm.command.Command; 6 9 import org.openstreetmap.josm.data.osm.Node; 7 10 import org.openstreetmap.josm.gui.MapFrame; … … 48 51 Node node = new Node(); 49 52 node.coor = mv.getPoint(e.getX(), e.getY(), true); 50 mv.getActiveDataSet().nodes.add(node); 53 Command c = new AddCommand(node); 54 c.executeCommand(); 55 Main.main.commands.add(c); 51 56 mv.repaint(); 52 57 } -
src/org/openstreetmap/josm/actions/mapmode/AddTrackAction.java
r21 r22 6 6 import java.util.LinkedList; 7 7 8 import org.openstreetmap.josm.command.DataSet; 8 import org.openstreetmap.josm.Main; 9 import org.openstreetmap.josm.command.AddCommand; 10 import org.openstreetmap.josm.command.Command; 9 11 import org.openstreetmap.josm.data.osm.LineSegment; 10 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 76 78 return; // not allowed together 77 79 78 DataSet ds = mv.getActiveDataSet();79 80 80 if (!ctrl && !shift) 81 ds.clearSelection(); // new selection will replace the old.81 Main.main.ds.clearSelection(); // new selection will replace the old. 82 82 83 83 Collection<OsmPrimitive> selectionList = selectionManager.getObjectsInRectangle(r,alt); 84 84 for (OsmPrimitive osm : selectionList) 85 osm.setSelected(!ctrl , ds);85 osm.setSelected(!ctrl); 86 86 87 87 mv.repaint(); // from now on, the map has to be repainted. … … 90 90 return; // no new track yet. 91 91 92 Collection<OsmPrimitive> selection = ds.getSelected();92 Collection<OsmPrimitive> selection = Main.main.ds.getSelected(); 93 93 if (selection.isEmpty()) 94 94 return; … … 104 104 Track t = new Track(); 105 105 for (LineSegment ls : lineSegments) 106 ds.assignPendingLineSegment(ls, t, true); 107 ds.addTrack(t); 108 ds.clearSelection(); 106 t.add(ls); 107 Command c = new AddCommand(t); 108 c.executeCommand(); 109 Main.main.commands.add(c); 110 Main.main.ds.clearSelection(); 109 111 } 110 112 -
src/org/openstreetmap/josm/actions/mapmode/CombineAction.java
r21 r22 10 10 11 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.command.DataSet; 12 import org.openstreetmap.josm.command.CombineCommand; 13 import org.openstreetmap.josm.command.Command; 13 14 import org.openstreetmap.josm.data.osm.LineSegment; 14 15 import org.openstreetmap.josm.data.osm.Node; … … 83 84 mv.addMouseListener(this); 84 85 mv.addMouseMotionListener(this); 85 mv.getActiveDataSet().clearSelection();86 Main.main.ds.clearSelection(); 86 87 } 87 88 … … 147 148 if (first instanceof LineSegment && second instanceof LineSegment) 148 149 JOptionPane.showMessageDialog(Main.main, "Cannot combine two line segments. To create tracks use 'Add Track'."); 149 else if (first instanceof LineSegment && second instanceof Track) 150 combine((LineSegment)first, (Track)second); 151 else if (first instanceof Track && second instanceof LineSegment) 152 combine((LineSegment)second, (Track)first); 153 else if (first instanceof Track && second instanceof Track) { 154 if (!first.keyPropertiesMergable(second)) 155 JOptionPane.showMessageDialog(Main.main, "Cannot combine because of different properties."); 156 else { 157 Track t1 = (Track)first; 158 Track t2 = (Track)second; 159 if (t1.getStartingNode() == t2.getEndingNode()) { 160 t1 = t2; 161 t2 = (Track)first; 162 } 163 t1.addAll(t2.segments()); 164 if (t1.keys == null) 165 t1.keys = t2.keys; 166 else 167 t1.keys.putAll(t2.keys); 168 mv.getActiveDataSet().removeTrack(t2); 169 } 150 else if (first instanceof Track && second instanceof Track && !first.keyPropertiesMergable(second)) 151 JOptionPane.showMessageDialog(Main.main, "Cannot combine because of different properties."); 152 else { 153 Command c = new CombineCommand(first, second); 154 c.executeCommand(); 155 Main.main.commands.add(c); 170 156 } 171 157 mv.repaint(); 172 }173 174 175 /**176 * Add the line segment to the track and remove it from the pending segments.177 * @param ls The line segment to add178 * @param t The track to add the line segment to179 */180 private void combine(LineSegment ls, Track t) {181 DataSet ds = mv.getActiveDataSet();182 if (!ds.pendingLineSegments().contains(ls))183 throw new IllegalStateException("Should not be able to select non-pending line segments.");184 185 ds.assignPendingLineSegment(ls, t, t.getStartingNode() != ls.getEnd());186 158 } 187 159 … … 218 190 Point start = mv.getScreenPoint(ls.getStart().coor); 219 191 Point end = mv.getScreenPoint(ls.getEnd().coor); 220 if ( mv.getActiveDataSet().pendingLineSegments().contains(osm) && g.getColor() == Color.GRAY)192 if (Main.main.ds.pendingLineSegments().contains(osm) && g.getColor() == Color.GRAY) 221 193 g.drawLine(start.x, start.y, end.x, end.y); 222 194 else -
src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r21 r22 11 11 12 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.command.DataSet;14 13 import org.openstreetmap.josm.data.osm.Key; 15 14 import org.openstreetmap.josm.data.osm.LineSegment; … … 94 93 return; 95 94 96 DataSet ds = mv.getActiveDataSet();97 98 95 if ((e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) != 0) 99 deleteWithReferences(sel , ds);96 deleteWithReferences(sel); 100 97 else 101 delete(sel , ds);98 delete(sel); 102 99 103 100 mv.repaint(); … … 129 126 * @param osm The object to delete. 130 127 */ 131 private void deleteWithReferences(OsmPrimitive osm , DataSet ds) {128 private void deleteWithReferences(OsmPrimitive osm) { 132 129 // collect all tracks, areas and pending line segments that should be deleted 133 130 ArrayList<Track> tracksToDelete = new ArrayList<Track>(); … … 136 133 if (osm instanceof Node) { 137 134 // delete any track and line segment the node is in. 138 for (Track t : ds.tracks())135 for (Track t : Main.main.ds.tracks()) 139 136 for (LineSegment ls : t.segments()) 140 137 if (ls.getStart() == osm || ls.getEnd() == osm) 141 138 tracksToDelete.add(t); 142 for (LineSegment ls : ds.pendingLineSegments())139 for (LineSegment ls : Main.main.ds.pendingLineSegments()) 143 140 if (ls.getStart() == osm || ls.getEnd() == osm) 144 141 lineSegmentsToDelete.add(ls); … … 147 144 LineSegment lineSegment = (LineSegment)osm; 148 145 lineSegmentsToDelete.add(lineSegment); 149 for (Track t : ds.tracks())146 for (Track t : Main.main.ds.tracks()) 150 147 for (LineSegment ls : t.segments()) 151 148 if (lineSegment == ls) … … 169 166 // delete tracks and areas 170 167 for (Track t : tracksToDelete) 171 ds.removeTrack(t);168 Main.main.ds.removeTrack(t); 172 169 for (LineSegment ls : lineSegmentsToDelete) 173 ds.destroyPendingLineSegment(ls);170 Main.main.ds.destroyPendingLineSegment(ls); 174 171 175 172 // removing all unreferenced nodes 176 173 for (Node n : checkUnreferencing) { 177 if (!isReferenced(n , ds))178 ds.nodes.remove(n);174 if (!isReferenced(n)) 175 Main.main.ds.nodes.remove(n); 179 176 } 180 177 // now, all references are killed. Delete the node (if it was a node) 181 178 if (osm instanceof Node) 182 ds.nodes.remove(osm);179 Main.main.ds.nodes.remove(osm); 183 180 } 184 181 … … 190 187 * @param osm The object to delete. 191 188 */ 192 private void delete(OsmPrimitive osm , DataSet ds) {189 private void delete(OsmPrimitive osm) { 193 190 if (osm instanceof Node) { 194 191 Node n = (Node)osm; 195 if (isReferenced(n , ds)) {196 String combined = combine(n , ds);192 if (isReferenced(n)) { 193 String combined = combine(n); 197 194 if (combined != null) { 198 195 JOptionPane.showMessageDialog(Main.main, combined); … … 201 198 } 202 199 // now, the node isn't referenced anymore, so delete it. 203 ds.nodes.remove(n);200 Main.main.ds.nodes.remove(n); 204 201 } else if (osm instanceof LineSegment) { 205 202 LinkedList<Track> tracksToDelete = new LinkedList<Track>(); 206 for (Track t : ds.tracks()) {203 for (Track t : Main.main.ds.tracks()) { 207 204 t.remove((LineSegment)osm); 208 205 if (t.segments().isEmpty()) … … 210 207 } 211 208 for (Track t : tracksToDelete) 212 ds.removeTrack(t);213 ds.destroyPendingLineSegment((LineSegment)osm);209 Main.main.ds.removeTrack(t); 210 Main.main.ds.destroyPendingLineSegment((LineSegment)osm); 214 211 } else if (osm instanceof Track) { 215 ds.removeTrack((Track)osm);212 Main.main.ds.removeTrack((Track)osm); 216 213 for (LineSegment ls : ((Track)osm).segments()) 217 ds.addPendingLineSegment(ls);214 Main.main.ds.addPendingLineSegment(ls); 218 215 } 219 216 } … … 225 222 * @return Whether the node is used by a track or area. 226 223 */ 227 private boolean isReferenced(Node n , DataSet ds) {228 for (Track t : ds.tracks())224 private boolean isReferenced(Node n) { 225 for (Track t : Main.main.ds.tracks()) 229 226 for (LineSegment ls : t.segments()) 230 227 if (ls.getStart() == n || ls.getEnd() == n) 231 228 return true; 232 for (LineSegment ls : ds.pendingLineSegments())229 for (LineSegment ls : Main.main.ds.pendingLineSegments()) 233 230 if (ls.getStart() == n || ls.getEnd() == n) 234 231 return true; … … 246 243 * are problems combining the node. 247 244 */ 248 private String combine(Node n , DataSet ds) {245 private String combine(Node n) { 249 246 // first, check for pending line segments 250 for (LineSegment ls : ds.pendingLineSegments())247 for (LineSegment ls : Main.main.ds.pendingLineSegments()) 251 248 if (n == ls.getStart() || n == ls.getEnd()) 252 249 return "Node used by a line segment which is not part of any track. Remove this first."; … … 261 258 HashMap<ArrayList<LineSegment>, Track> lineSegments = new HashMap<ArrayList<LineSegment>, Track>(); 262 259 263 for (Track t : ds.tracks()) {260 for (Track t : Main.main.ds.tracks()) { 264 261 ArrayList<LineSegment> current = new ArrayList<LineSegment>(); 265 262 for (LineSegment ls : t.segments()) … … 284 281 // try to combine tracks 285 282 ArrayList<Track> tracks = new ArrayList<Track>(); 286 for (Track t : ds.tracks())283 for (Track t : Main.main.ds.tracks()) 287 284 if (t.getStartingNode() == n || t.getEndingNode() == n) 288 285 tracks.add(t); … … 349 346 // move the remaining line segments to first track. 350 347 first.addAll(second.segments()); 351 ds.removeTrack(second);348 Main.main.ds.removeTrack(second); 352 349 } 353 350 -
src/org/openstreetmap/josm/actions/mapmode/MapMode.java
r17 r22 87 87 mapFrame.selectMapMode(this); 88 88 } 89 89 90 90 /** 91 91 * Does nothing. Only to subclass. -
src/org/openstreetmap/josm/actions/mapmode/MoveAction.java
r21 r22 6 6 import java.awt.event.MouseEvent; 7 7 import java.util.Collection; 8 import java.util.HashSet;9 8 10 import org.openstreetmap.josm.command.DataSet; 11 import org.openstreetmap.josm.data.osm.Node; 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.command.Command; 11 import org.openstreetmap.josm.command.MoveCommand; 12 import org.openstreetmap.josm.data.GeoPoint; 12 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 14 import org.openstreetmap.josm.gui.MapFrame; … … 75 76 } 76 77 77 int dx = e.getX() - mousePos.x; 78 int dy = e.getY() - mousePos.y; 78 GeoPoint mouseGeo = mv.getPoint(e.getX(), e.getY(), false); 79 GeoPoint mouseStartGeo = mv.getPoint(mousePos.x, mousePos.y, false); 80 double dx = mouseGeo.x - mouseStartGeo.x; 81 double dy = mouseGeo.y - mouseStartGeo.y; 79 82 if (dx == 0 && dy == 0) 80 83 return; 81 84 82 Collection<OsmPrimitive> selection = mv.getActiveDataSet().getSelected(); 83 // creating a list of all nodes that should be moved. 84 Collection<Node> movingNodes = new HashSet<Node>(); 85 for (OsmPrimitive osm : selection) 86 movingNodes.addAll(osm.getAllNodes()); 87 88 for (Node n : movingNodes) { 89 Point pos = mv.getScreenPoint(n.coor); 90 pos.x += dx; 91 pos.y += dy; 92 n.coor = mv.getPoint(pos.x, pos.y, true); 93 } 85 Collection<OsmPrimitive> selection = Main.main.ds.getSelected(); 86 Command c = new MoveCommand(selection, dx, dy); 87 c.executeCommand(); 88 Main.main.commands.add(c); 89 94 90 mv.repaint(); 95 96 91 mousePos = e.getPoint(); 97 92 } … … 111 106 return; 112 107 113 DataSet ds = mv.getActiveDataSet(); 114 115 if (ds.getSelected().size() == 0) { 108 if (Main.main.ds.getSelected().size() == 0) { 116 109 OsmPrimitive osm = mv.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0); 117 110 if (osm != null) 118 osm.setSelected(true , ds);111 osm.setSelected(true); 119 112 singleOsmPrimitive = osm; 120 113 mv.repaint(); … … 134 127 mv.setCursor(oldCursor); 135 128 if (singleOsmPrimitive != null) { 136 singleOsmPrimitive.setSelected(false , mv.getActiveDataSet());129 singleOsmPrimitive.setSelected(false); 137 130 mv.repaint(); 138 131 } -
src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java
r21 r22 5 5 import java.util.Collection; 6 6 7 import org.openstreetmap.josm. command.DataSet;7 import org.openstreetmap.josm.Main; 8 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 9 import org.openstreetmap.josm.gui.MapFrame; … … 87 87 return; // not allowed together 88 88 89 DataSet ds = mv.getActiveDataSet();90 91 89 if (!ctrl && !shift) 92 ds.clearSelection(); // new selection will replace the old.90 Main.main.ds.clearSelection(); // new selection will replace the old. 93 91 94 92 Collection<OsmPrimitive> selectionList = selectionManager.getObjectsInRectangle(r,alt); 95 93 for (OsmPrimitive osm : selectionList) 96 osm.setSelected(!ctrl , ds);94 osm.setSelected(!ctrl); 97 95 mv.repaint(); 98 96 } -
src/org/openstreetmap/josm/command/AddCommand.java
r21 r22 2 2 3 3 import java.awt.Component; 4 import java.util.Collection; 4 5 import java.util.Iterator; 5 6 6 7 import javax.swing.JLabel; 7 8 9 import org.openstreetmap.josm.Main; 8 10 import org.openstreetmap.josm.data.osm.Key; 9 11 import org.openstreetmap.josm.data.osm.LineSegment; … … 26 28 */ 27 29 private final OsmPrimitive osm; 28 /**29 * The dataset to add the primitive to.30 */31 private final DataSet ds;32 30 33 31 /** 34 32 * Create the command and specify the element to add. 35 33 */ 36 public AddCommand(OsmPrimitive osm , DataSet dataSet) {34 public AddCommand(OsmPrimitive osm) { 37 35 this.osm = osm; 38 this.ds = dataSet;39 36 } 40 37 … … 42 39 osm.visit(this); 43 40 } 44 41 45 42 public Component commandDescription() { 46 43 SelectionComponentVisitor v = new SelectionComponentVisitor(); 47 44 osm.visit(v); 48 45 return new JLabel(v.name, v.icon, JLabel.LEADING); 46 } 47 48 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 49 if (!added.contains(osm)) 50 added.add(osm); 49 51 } 50 52 … … 54 56 */ 55 57 public void visit(Node n) { 56 ds.nodes.add(n);58 Main.main.ds.nodes.add(n); 57 59 } 58 60 … … 62 64 */ 63 65 public void visit(LineSegment ls) { 64 ds.pendingLineSegments.add(ls);66 Main.main.ds.pendingLineSegments.add(ls); 65 67 } 66 68 … … 70 72 */ 71 73 public void visit(Track t) { 72 ds.addTrack(t);73 for (Iterator<LineSegment> it = ds.pendingLineSegments.iterator(); it.hasNext();)74 Main.main.ds.tracks.add(t); 75 for (Iterator<LineSegment> it = Main.main.ds.pendingLineSegments.iterator(); it.hasNext();) 74 76 if (t.segments().contains(it.next())) 75 77 it.remove(); -
src/org/openstreetmap/josm/command/Command.java
r21 r22 2 2 3 3 import java.awt.Component; 4 import java.util.Collection; 5 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 4 7 5 8 6 9 /** 7 10 * Classes implementing Command modify a dataset in a specific way. A command is 8 * one atomic action on a dataset, such as move or delete.11 * one atomic action on a specific dataset, such as move or delete. 9 12 * 10 13 * @author imi … … 16 19 */ 17 20 void executeCommand(); 18 21 19 22 /** 20 23 * Give a description of the command as component to draw 21 24 */ 22 25 Component commandDescription(); 26 27 /** 28 * Fill in the changed data this command operates on (for sending to the server). 29 * Add to the lists, don't clear them. 30 * @param modified The modified primitives 31 * @param deleted The deleted primitives 32 * @param added The added primitives 33 */ 34 void fillModifiedData(Collection<OsmPrimitive> modified, 35 Collection<OsmPrimitive> deleted, 36 Collection<OsmPrimitive> added); 23 37 } -
src/org/openstreetmap/josm/command/DataSet.java
r21 r22 205 205 */ 206 206 public void mergeFrom(DataSet ds, boolean mergeEqualNodes) { 207 System.out.println(nodes.size()+" "+pendingLineSegments.size()+" "+tracks.size()); 208 if (mergeEqualNodes) { 207 if (mergeEqualNodes && !nodes.isEmpty()) { 209 208 Map<Node, Node> mergeMap = new HashMap<Node, Node>(); 210 209 Set<Node> nodesToAdd = new HashSet<Node>(); … … 247 246 pendingLineSegments.addAll(ds.pendingLineSegments); 248 247 } 249 System.out.println(nodes.size()+" "+pendingLineSegments.size()+" "+tracks.size());250 248 } 251 249 … … 258 256 return; 259 257 for (OsmPrimitive osm : list) { 260 osm.setSelected(false , this);258 osm.setSelected(false); 261 259 if (osm.keys != null) 262 260 clearSelection(osm.keys.keySet()); -
src/org/openstreetmap/josm/command/MoveCommand.java
r21 r22 63 63 return new JLabel("Move "+objects.size()+" primitives "+xstr+" "+ystr); 64 64 } 65 66 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 67 for (OsmPrimitive osm : objects) 68 if (!modified.contains(osm)) 69 modified.add(osm); 70 } 65 71 } -
src/org/openstreetmap/josm/data/SelectionTracker.java
r8 r22 59 59 * @author imi 60 60 */ 61 private enum SelectionEventState {WAITING, COLLECTING, PURGING} ;61 private enum SelectionEventState {WAITING, COLLECTING, PURGING} 62 62 63 63 /** 64 64 * The state, regarding to the selection changing that we are in. 65 65 */ 66 transient privateSelectionEventState state = SelectionEventState.WAITING;66 transient SelectionEventState state = SelectionEventState.WAITING; 67 67 68 68 /** 69 69 * A list of listeners to selection changed events. 70 70 */ 71 transient privateCollection<SelectionChangedListener> listeners = new LinkedList<SelectionChangedListener>();71 transient Collection<SelectionChangedListener> listeners = new LinkedList<SelectionChangedListener>(); 72 72 73 73 -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r21 r22 4 4 import java.util.Map; 5 5 6 import org.openstreetmap.josm. command.DataSet;6 import org.openstreetmap.josm.Main; 7 7 import org.openstreetmap.josm.data.osm.visitor.Visitor; 8 8 … … 72 72 * changed later, if the value actualy changed. 73 73 * @param selected Whether the primitive should be selected or not. 74 * @param ds The dataSet, this primitive is in.75 74 */ 76 public void setSelected(boolean selected , DataSet ds) {75 public void setSelected(boolean selected) { 77 76 if (selected != this.selected) 78 ds.fireSelectionChanged();77 Main.main.ds.fireSelectionChanged(); 79 78 this.selected = selected; 80 79 } -
src/org/openstreetmap/josm/data/projection/Projection.java
r21 r22 8 8 import javax.swing.event.ChangeListener; 9 9 10 import org.openstreetmap.josm.command.DataSet;11 10 import org.openstreetmap.josm.data.GeoPoint; 12 11 … … 81 80 * This implementation does nothing. It is provided only for subclasses 82 81 * to initialize their data members. 83 *84 * @param dataSet85 * The dataset, which will be displayed on screen. Later, all86 * projections should be relative to the given dataset. Any87 * reverse projections (xy2latlon) can be assumed to be in near88 * distance to nodes of this dataset (that means, it is ok, if89 * there is a conversion error, if the requested x/y to xy2latlon90 * is far away from any coordinate in the dataset)91 82 */ 92 public void init( DataSet dataSet) {}83 public void init() {} 93 84 94 85 /** -
src/org/openstreetmap/josm/data/projection/UTM.java
r21 r22 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.command.DataSet;19 18 import org.openstreetmap.josm.data.Bounds; 20 19 import org.openstreetmap.josm.data.GeoPoint; … … 80 79 }; 81 80 82 private enum Hemisphere {north, south} ;81 private enum Hemisphere {north, south} 83 82 84 83 /** … … 102 101 * Spinner with all possible zones for the configuration panel 103 102 */ 104 privateJSpinner zoneSpinner;103 JSpinner zoneSpinner; 105 104 /** 106 105 * Hemisphere combo for the configuration panel 107 106 */ 108 privateJComboBox hemisphereCombo;107 JComboBox hemisphereCombo; 109 108 110 109 … … 193 192 /** 194 193 * Try to autodetect the zone and hemisphere from the dataset. 195 * @param dataSet The dataset to extrakt zone information from.196 194 * @return The zone data extrakted from the dataset. 197 195 */ 198 private ZoneData autoDetect(DataSet dataSet) {196 ZoneData autoDetect() { 199 197 ZoneData zd = new ZoneData(); 200 198 201 Bounds b = dataSet.getBoundsLatLon();199 Bounds b = Main.main.ds.getBoundsLatLon(); 202 200 if (b == null) 203 201 return zd; … … 234 232 */ 235 233 @Override 236 public void init( DataSet dataSet) {234 public void init() { 237 235 if (zone == 0) { 238 ZoneData zd = autoDetect( dataSet);236 ZoneData zd = autoDetect(); 239 237 zone = zd.zone; 240 238 hemisphere = zd.hemisphere; … … 274 272 public void actionPerformed(ActionEvent e) { 275 273 if (Main.main.getMapFrame() != null) { 276 DataSet ds = Main.main.getMapFrame().mapView.getActiveDataSet(); 277 ZoneData zd = autoDetect(ds); 274 ZoneData zd = autoDetect(); 278 275 if (zd.zone == 0) 279 276 JOptionPane.showMessageDialog(Main.main, "Autodetection failed. Maybe the data set contain too few information."); -
src/org/openstreetmap/josm/gui/ImageProvider.java
r21 r22 25 25 * @author imi 26 26 */ 27 public enum OverlayPosition {NORTHWEST, NORTHEAST, SOUTHWEST, SOUTHEAST} ;27 public enum OverlayPosition {NORTHWEST, NORTHEAST, SOUTHWEST, SOUTHEAST} 28 28 29 29 /** -
src/org/openstreetmap/josm/gui/MapStatus.java
r17 r22 47 47 * The position of the mouse cursor. 48 48 */ 49 privateJTextField positionText = new JTextField("-000.00000000000000 -000.00000000000000".length());49 JTextField positionText = new JTextField("-000.00000000000000 -000.00000000000000".length()); 50 50 /** 51 51 * The field holding the name of the object under the mouse. 52 52 */ 53 privateJTextField nameText = new JTextField(30);53 JTextField nameText = new JTextField(30); 54 54 55 55 /** … … 147 147 * The last sent mouse movement event. 148 148 */ 149 privateMouseState mouseState = new MouseState();149 MouseState mouseState = new MouseState(); 150 150 151 151 /** -
src/org/openstreetmap/josm/gui/MapView.java
r21 r22 32 32 * provide the MapMode's enough capabilities to operate. 33 33 * 34 * MapView holds the map data, organize it, convert it, provide access to it.35 *36 34 * MapView hold meta-data about the data set currently displayed, as scale level, 37 35 * center point viewed, what scrolling mode or editing mode is selected or with … … 87 85 */ 88 86 public MapView(Layer layer) { 89 if (layer.dataSet == null)90 throw new IllegalArgumentException("Initial layer must have a dataset.");91 92 87 addComponentListener(new ComponentAdapter(){ 93 88 @Override … … 118 113 // initialize the projection if it was the first layer 119 114 if (layers.size() == 1) 120 Main.pref.getProjection().init( layer.dataSet);115 Main.pref.getProjection().init(); 121 116 122 117 // initialize the dataset in the new layer … … 231 226 OsmPrimitive minPrimitive = null; 232 227 233 // calculate the object based on the current active dataset.234 DataSet ds = getActiveDataSet();235 236 228 // nodes 237 for (Node n : ds.nodes) {229 for (Node n : Main.main.ds.nodes) { 238 230 Point sp = getScreenPoint(n.coor); 239 231 double dist = p.distanceSq(sp); … … 247 239 248 240 // pending line segments 249 for (LineSegment ls : ds.pendingLineSegments()) {241 for (LineSegment ls : Main.main.ds.pendingLineSegments()) { 250 242 Point A = getScreenPoint(ls.getStart().coor); 251 243 Point B = getScreenPoint(ls.getEnd().coor); … … 262 254 // tracks & line segments 263 255 minDistanceSq = Double.MAX_VALUE; 264 for (Track t : ds.tracks()) {256 for (Track t : Main.main.ds.tracks()) { 265 257 for (LineSegment ls : t.segments()) { 266 258 Point A = getScreenPoint(ls.getStart().coor); … … 375 367 376 368 /** 377 * Return the dataSet for the current selected layer. If the active layer378 * does not have a dataset, return the DataSet from the next layer a.s.o.379 *380 * @return The DataSet of the current active layer.381 */382 public DataSet getActiveDataSet() {383 if (activeLayer.dataSet != null)384 return activeLayer.dataSet;385 for (Layer l : layers)386 if (l.dataSet != null)387 return l.dataSet;388 throw new IllegalStateException("No dataset found.");389 }390 391 /**392 369 * Change to the new projection. Recalculate the dataset and zoom, if autoZoom 393 370 * is active. … … 422 399 h = 20; 423 400 424 Bounds bounds = getActiveDataSet().getBoundsXY();401 Bounds bounds = Main.main.ds.getBoundsXY(); 425 402 426 403 boolean oldAutoScale = autoScale; -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r21 r22 91 91 * Indicate, that the application has to be restarted for the settings to take effect. 92 92 */ 93 privateboolean requiresRestart = false;93 boolean requiresRestart = false; 94 94 /** 95 95 * ComboBox with all look and feels. 96 96 */ 97 privateJComboBox lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels());97 JComboBox lafCombo = new JComboBox(UIManager.getInstalledLookAndFeels()); 98 98 /** 99 99 * Combobox with all projections available 100 100 */ 101 privateJComboBox projectionCombo = new JComboBox(Preferences.allProjections.clone());101 JComboBox projectionCombo = new JComboBox(Preferences.allProjections.clone()); 102 102 /** 103 103 * The main tab panel. … … 108 108 * Editfield for the Base url to the REST API from OSM. 109 109 */ 110 privateJTextField osmDataServer = new JTextField(20);110 JTextField osmDataServer = new JTextField(20); 111 111 /** 112 112 * Editfield for the username to the OSM account. 113 113 */ 114 privateJTextField osmDataUsername = new JTextField(20);114 JTextField osmDataUsername = new JTextField(20); 115 115 /** 116 116 * Passwordfield for the userpassword of the REST API. 117 117 */ 118 privateJPasswordField osmDataPassword = new JPasswordField(20);118 JPasswordField osmDataPassword = new JPasswordField(20); 119 119 /** 120 120 * The checkbox stating whether nodes should be merged together. 121 121 */ 122 privateJCheckBox drawRawGpsLines = new JCheckBox("Draw lines between raw gps points.");122 JCheckBox drawRawGpsLines = new JCheckBox("Draw lines between raw gps points."); 123 123 /** 124 124 * The checkbox stating whether raw gps lines should be forced. 125 125 */ 126 privateJCheckBox forceRawGpsLines = new JCheckBox("Force lines if no line segments imported.");126 JCheckBox forceRawGpsLines = new JCheckBox("Force lines if no line segments imported."); 127 127 /** 128 128 * The checkbox stating whether nodes should be merged together. 129 129 */ 130 privateJCheckBox mergeNodes = new JCheckBox("Merge nodes with equal latitude/longitude.");130 JCheckBox mergeNodes = new JCheckBox("Merge nodes with equal latitude/longitude."); 131 131 132 132 /** -
src/org/openstreetmap/josm/gui/SelectionManager.java
r21 r22 15 15 import java.util.LinkedList; 16 16 17 import org.openstreetmap.josm. command.DataSet;17 import org.openstreetmap.josm.Main; 18 18 import org.openstreetmap.josm.data.osm.LineSegment; 19 19 import org.openstreetmap.josm.data.osm.Node; … … 272 272 } else { 273 273 // nodes 274 DataSet ds = mv.getActiveDataSet(); 275 for (Node n : ds.nodes) { 274 for (Node n : Main.main.ds.nodes) { 276 275 if (r.contains(mv.getScreenPoint(n.coor))) 277 276 selection.add(n); … … 279 278 280 279 // pending line segments 281 for (LineSegment ls : ds.pendingLineSegments())280 for (LineSegment ls : Main.main.ds.pendingLineSegments()) 282 281 if (rectangleContainLineSegment(r, alt, ls)) 283 282 selection.add(ls); 284 283 285 284 // tracks 286 for (Track t : ds.tracks()) {285 for (Track t : Main.main.ds.tracks()) { 287 286 boolean wholeTrackSelected = !t.segments().isEmpty(); 288 287 for (LineSegment ls : t.segments()) -
src/org/openstreetmap/josm/gui/dialogs/LayerList.java
r21 r22 8 8 import java.awt.event.ActionListener; 9 9 import java.awt.event.KeyEvent; 10 import java.io.IOException; 10 11 import java.util.Collection; 11 12 … … 16 17 import javax.swing.JLabel; 17 18 import javax.swing.JList; 19 import javax.swing.JOptionPane; 18 20 import javax.swing.JPanel; 19 21 import javax.swing.JScrollPane; … … 30 32 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 31 33 import org.openstreetmap.josm.gui.layer.Layer; 34 import org.openstreetmap.josm.io.OsmWriter; 32 35 33 36 /** … … 42 45 * The data model for the list component. 43 46 */ 44 privateDefaultListModel model = new DefaultListModel();47 DefaultListModel model = new DefaultListModel(); 45 48 /** 46 49 * The list component holding all layers. 47 50 */ 48 privateJList layers = new JList(model);51 JList layers = new JList(model); 49 52 /** 50 53 * The invisible icon blended over invisible layers. 51 54 */ 52 privatestatic final Icon invisible = ImageProvider.get("layer", "invisible");55 static final Icon invisible = ImageProvider.get("layer", "invisible"); 53 56 54 57 /** … … 69 72 */ 70 73 private JButton deleteButton = new JButton(ImageProvider.get("dialogs", "delete")); 71 74 /** 75 * Button for connecting disconnecting to the server. 76 */ 77 private JButton uploadButton = new JButton(ImageProvider.get("dialogs", "condiscon")); 78 72 79 /** 73 80 * Create an layerlist and attach it to the given mapView. … … 89 96 icon = ImageProvider.overlay(icon, invisible, ImageProvider.OverlayPosition.SOUTHEAST); 90 97 label.setIcon(icon); 91 98 92 99 DataSet ds = layer.dataSet; 93 100 if (ds != null) { … … 100 107 101 108 final MapView mapView = mapFrame.mapView; 102 109 103 110 Collection<Layer> data = mapView.getAllLayers(); 104 111 for (Layer l : data) … … 115 122 }); 116 123 mapView.addLayerChangeListener(this); 117 124 118 125 // Buttons 119 126 JPanel buttonPanel = new JPanel(new GridLayout(1, 5)); … … 173 180 mergeButton.setToolTipText("Merge the selected layer into the layer directly below."); 174 181 mergeButton.addActionListener(new ActionListener(){ 175 public void actionPerformed(ActionEvent e) { 176 Layer lFrom = (Layer)layers.getSelectedValue(); 177 DataSet dsFrom = lFrom.dataSet; 178 Layer lTo = (Layer)model.get(layers.getSelectedIndex()+1); 179 DataSet dsTo = lTo.dataSet; 180 dsTo.mergeFrom(dsFrom, Main.pref.mergeNodes); 181 layers.setSelectedValue(lTo, true); 182 mapView.removeLayer(lFrom); 182 public void actionPerformed(ActionEvent e) { 183 Layer lFrom = (Layer)layers.getSelectedValue(); 184 DataSet dsFrom = lFrom.dataSet; 185 Layer lTo = (Layer)model.get(layers.getSelectedIndex()+1); 186 DataSet dsTo = lTo.dataSet; 187 dsTo.mergeFrom(dsFrom, Main.pref.mergeNodes); 188 layers.setSelectedValue(lTo, true); 189 mapView.removeLayer(lFrom); 190 } 191 }); 192 buttonPanel.add(mergeButton); 193 194 uploadButton.setToolTipText("Upload changes to the server."); 195 uploadButton.addActionListener(new ActionListener(){ 196 public void actionPerformed(ActionEvent e) { 197 OsmWriter con = new OsmWriter(Main.pref.osmDataServer, Main.main.commands); 198 try { 199 con.output(); 200 } catch (IOException x) { 201 x.printStackTrace(); 202 JOptionPane.showMessageDialog(Main.main, "Not all changes could be uploaded."); 183 203 } 184 }); 185 buttonPanel.add(mergeButton); 186 204 } 205 }); 206 buttonPanel.add(uploadButton); 207 187 208 add(buttonPanel, BorderLayout.SOUTH); 188 209 … … 193 214 * Updates the state of the Buttons. 194 215 */ 195 privatevoid updateButtonEnabled() {216 void updateButtonEnabled() { 196 217 int sel = layers.getSelectedIndex(); 197 218 Layer l = (Layer)layers.getSelectedValue(); -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r21 r22 17 17 18 18 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.command.DataSet;20 19 import org.openstreetmap.josm.data.SelectionChangedListener; 21 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 23 22 import org.openstreetmap.josm.gui.ImageProvider; 24 23 import org.openstreetmap.josm.gui.MapFrame; 25 import org.openstreetmap.josm.gui.MapView;26 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;27 import org.openstreetmap.josm.gui.layer.Layer;28 24 29 25 /** … … 34 30 * @author imi 35 31 */ 36 public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener , LayerChangeListener{32 public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener { 37 33 38 34 /** … … 44 40 */ 45 41 private JList displaylist = new JList(list); 46 /**47 * The dataset, all selections are part of.48 */49 private final MapView mapView;50 42 51 43 /** … … 55 47 public SelectionListDialog(MapFrame mapFrame) { 56 48 super(mapFrame, "Current Selection", "Selection List", "selectionlist", KeyEvent.VK_E, "Open a selection list window."); 57 this.mapView = mapFrame.mapView;58 49 setLayout(new BorderLayout()); 59 50 setSize(300,400); … … 84 75 getContentPane().add(button, BorderLayout.SOUTH); 85 76 86 selectionChanged( mapView.getActiveDataSet().getSelected());77 selectionChanged(Main.main.ds.getSelected()); 87 78 } 88 79 … … 90 81 public void setVisible(boolean b) { 91 82 if (b) { 92 mapView.addLayerChangeListener(this); 93 mapView.getActiveDataSet().addSelectionChangedListener(this); 94 selectionChanged(mapView.getActiveDataSet().getSelected()); 83 Main.main.ds.addSelectionChangedListener(this); 84 selectionChanged(Main.main.ds.getSelected()); 95 85 } else { 96 mapView.removeLayerChangeListener(this); 97 mapView.getActiveDataSet().removeSelectionChangedListener(this); 86 Main.main.ds.removeSelectionChangedListener(this); 98 87 } 99 88 super.setVisible(b); … … 118 107 */ 119 108 public void updateMap() { 120 DataSet ds = mapView.getActiveDataSet(); 121 ds.clearSelection(); 109 Main.main.ds.clearSelection(); 122 110 for (int i = 0; i < list.getSize(); ++i) 123 111 if (displaylist.isSelectedIndex(i)) 124 ((OsmPrimitive)list.get(i)).setSelected(true , ds);112 ((OsmPrimitive)list.get(i)).setSelected(true); 125 113 Main.main.getMapFrame().repaint(); 126 114 } 127 128 public void activeLayerChange(Layer oldLayer, Layer newLayer) {129 DataSet ds = oldLayer.dataSet;130 if (ds != null)131 ds.removeSelectionChangedListener(this);132 ds = newLayer.dataSet;133 if (ds != null)134 ds.addSelectionChangedListener(this);135 }136 137 /**138 * Does nothing. Only to satisfy LayerChangeListener139 */140 public void layerAdded(Layer newLayer) {}141 /**142 * Does nothing. Only to satisfy LayerChangeListener143 */144 public void layerRemoved(Layer oldLayer) {}145 115 } -
src/org/openstreetmap/josm/gui/layer/Layer.java
r21 r22 5 5 import javax.swing.Icon; 6 6 7 import org.openstreetmap.josm.command.DataSet;8 import org.openstreetmap.josm.data.osm.LineSegment;9 import org.openstreetmap.josm.data.osm.Node;10 import org.openstreetmap.josm.data.osm.Track;11 7 import org.openstreetmap.josm.gui.MapView; 12 import org.openstreetmap.josm.gui.engine.Engine;13 8 14 9 /** … … 34 29 public boolean visible = true; 35 30 /** 36 * The dataSet this layer operates on, if any. Not all layer may have a37 * dataset associated.38 */39 public final DataSet dataSet;40 /**41 31 * The name of this layer. 42 32 */ 43 33 public final String name; 44 /**45 * The engine used to draw the data.46 */47 private final Engine engine;48 34 49 35 /** 50 36 * Create the layer and fill in the necessary components. 51 * @param dataSet The DataSet, this layer operates on. Can be <code>null</code>.52 37 */ 53 public Layer(DataSet dataSet, Engine engine, String name) { 54 if (engine == null || name == null) 55 throw new NullPointerException(); 56 this.dataSet = dataSet; 38 public Layer(String name) { 57 39 this.name = name; 58 this.engine = engine;59 40 } 60 41 … … 63 44 * @param mv The object that can translate GeoPoints to screen coordinates. 64 45 */ 65 public final void paint(Graphics g, MapView mv) { 66 engine.init(g, mv); 67 68 for (Track t : dataSet.tracks()) 69 engine.drawTrack(t); 70 for (LineSegment ls : dataSet.pendingLineSegments()) 71 engine.drawPendingLineSegment(ls); 72 for (Node n : dataSet.nodes) 73 engine.drawNode(n); 74 } 75 46 abstract public void paint(Graphics g, MapView mv); 76 47 /** 77 48 * Return a representative small image for this layer. The image must not -
src/org/openstreetmap/josm/gui/layer/LayerFactory.java
r21 r22 19 19 */ 20 20 public static Layer create(DataSet dataSet, String name, boolean rawGps) { 21 Layer layer = rawGps ? new RawGpsDataLayer(dataSet, name) : new OsmDataLayer( dataSet,name);21 Layer layer = rawGps ? new RawGpsDataLayer(dataSet, name) : new OsmDataLayer(name); 22 22 return layer; 23 23 } -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r21 r22 1 1 package org.openstreetmap.josm.gui.layer; 2 3 import java.awt.Color; 4 import java.awt.Graphics; 5 import java.awt.Point; 6 import java.util.Collection; 7 import java.util.HashSet; 2 8 3 9 import javax.swing.Icon; 4 10 5 import org.openstreetmap.josm.command.DataSet; 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.data.osm.Key; 13 import org.openstreetmap.josm.data.osm.LineSegment; 14 import org.openstreetmap.josm.data.osm.Node; 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.data.osm.Track; 17 import org.openstreetmap.josm.data.osm.visitor.Visitor; 6 18 import org.openstreetmap.josm.gui.ImageProvider; 7 import org.openstreetmap.josm.gui. engine.SimpleEngine;19 import org.openstreetmap.josm.gui.MapView; 8 20 9 21 /** … … 14 26 * @author imi 15 27 */ 16 public class OsmDataLayer extends Layer {28 public class OsmDataLayer extends Layer implements Visitor { 17 29 18 30 private static Icon icon; 31 private final static Color darkblue = new Color(0,0,128); 32 private final static Color darkgreen = new Color(0,128,0); 33 34 /** 35 * The data behind this layer. A list of primitives which are also in Main.main.ds. 36 */ 37 private final Collection<OsmPrimitive> data; 38 39 /** 40 * The mapview we are currently drawing on. 41 */ 42 private MapView mv; 43 /** 44 * The graphic environment we are drawing with. 45 */ 46 private Graphics g; 19 47 20 48 /** 21 49 * Construct a OsmDataLayer. 22 50 */ 23 protected OsmDataLayer(DataSet dataSet, String name) { 24 super(dataSet, new SimpleEngine(), name); 51 protected OsmDataLayer(Collection<OsmPrimitive> data, String name) { 52 super(name); 53 this.data = data; 25 54 } 26 55 … … 40 69 return true; 41 70 } 71 72 @Override 73 public void paint(Graphics g, MapView mv) { 74 this.mv = mv; 75 this.g = g; 76 for (OsmPrimitive osm : data) 77 osm.visit(this); 78 } 79 80 /** 81 * Draw a small rectangle. 82 * 83 * - White if selected (as always) 84 * - Yellow, if not used by any tracks or areas. 85 * - Green, if only used by pending line segments. 86 * - Darkblue, if used in tracks but are only as inbound node. Inbound are 87 * all nodes, that have only line segments of the same track and 88 * at least two different line segments attached. 89 * - Red otherwise (means, this is a dead end or is part of more than 90 * one track). 91 * 92 * @param n The node to draw. 93 */ 94 public void visit(Node n) { 95 if (n.isSelected()) { 96 drawNode(n, Color.WHITE); // selected 97 return; 98 } 99 100 Collection<LineSegment> lineSegments = n.getParentSegments(); 101 if (lineSegments.isEmpty()) { 102 drawNode(n, Color.YELLOW); // single waypoint only 103 return; 104 } 105 106 HashSet<Track> tracks = new HashSet<Track>(); 107 for (LineSegment ls : lineSegments) 108 tracks.addAll(ls.getParents()); 109 if (tracks.isEmpty()) { 110 drawNode(n, Color.GREEN); // pending line 111 return; 112 } 113 if (tracks.size() > 1) { 114 drawNode(n, Color.RED); // more than one track 115 return; 116 } 117 int segmentUsed = 0; 118 for (LineSegment ls : tracks.iterator().next().segments()) 119 if (n == ls.getStart() || n == ls.getEnd()) 120 ++segmentUsed; 121 drawNode(n, segmentUsed > 1 ? darkblue : Color.RED); 122 } 123 124 public void visit(LineSegment ls) { 125 g.setColor(ls.isSelected() ? Color.WHITE : darkblue); 126 if (Main.main.ds.pendingLineSegments().contains(ls)) 127 g.setColor(darkgreen); 128 Point p1 = mv.getScreenPoint(ls.getStart().coor); 129 Point p2 = mv.getScreenPoint(ls.getEnd().coor); 130 g.drawLine(p1.x, p1.y, p2.x, p2.y); 131 } 132 133 /** 134 * Draw a darkblue line for all line segments. 135 * @param t The track to draw. 136 */ 137 public void visit(Track t) { 138 for (LineSegment ls : t.segments()) 139 ls.visit(this); 140 } 141 142 public void visit(Key k) { 143 } 144 145 /** 146 * Draw the node as small rectangle with the given color. 147 * 148 * @param n The node to draw. 149 * @param color The color of the node. 150 */ 151 private void drawNode(Node n, Color color) { 152 Point p = mv.getScreenPoint(n.coor); 153 g.setColor(color); 154 g.drawRect(p.x-1, p.y-1, 2, 2); 155 } 42 156 } -
src/org/openstreetmap/josm/gui/layer/RawGpsDataLayer.java
r21 r22 5 5 import org.openstreetmap.josm.command.DataSet; 6 6 import org.openstreetmap.josm.gui.ImageProvider; 7 import org.openstreetmap.josm.gui.engine.RawGpsEngine;8 7 9 8 /** … … 18 17 19 18 protected RawGpsDataLayer(DataSet dataSet, String name) { 20 super( dataSet, new RawGpsEngine(),name);19 super(name); 21 20 } 22 21 -
src/org/openstreetmap/josm/io/GpxWriter.java
r21 r22 14 14 import org.jdom.output.Format; 15 15 import org.jdom.output.XMLOutputter; 16 import org.openstreetmap.josm. command.DataSet;16 import org.openstreetmap.josm.Main; 17 17 import org.openstreetmap.josm.data.osm.Key; 18 18 import org.openstreetmap.josm.data.osm.LineSegment; … … 47 47 */ 48 48 private Writer out; 49 /**50 * The DataSet this outputter operates on.51 */52 private final DataSet ds;53 49 54 50 /** … … 57 53 * 58 54 * @param out The Writer to store the result data in. 59 * @param ds The dataset to store. 60 */ 61 public GpxWriter(Writer out, DataSet ds) { 62 this.ds = ds; 55 */ 56 public GpxWriter(Writer out) { 63 57 this.out = out; 64 58 } … … 88 82 e.setAttribute("creator", "JOSM Beta"); 89 83 // for getting all unreferenced waypoints in the wpt-list 90 LinkedList<Node> nodes = new LinkedList<Node>( ds.nodes);84 LinkedList<Node> nodes = new LinkedList<Node>(Main.main.ds.nodes); 91 85 92 86 // tracks 93 for (Track t : ds.tracks()) {87 for (Track t : Main.main.ds.tracks()) { 94 88 Element tElem = new Element("trk", GPX); 95 89 if (t.keys != null) { -
src/org/openstreetmap/josm/io/OsmReader.java
r21 r22 1 1 package org.openstreetmap.josm.io; 2 2 3 import java.awt.Font;4 import java.awt.GridBagLayout;5 3 import java.io.IOException; 6 4 import java.io.InputStreamReader; 7 5 import java.io.Reader; 8 import java.net.Authenticator;9 6 import java.net.HttpURLConnection; 10 import java.net.PasswordAuthentication;11 7 import java.net.URL; 12 8 13 import javax.swing.JLabel;14 import javax.swing.JOptionPane;15 import javax.swing.JPanel;16 import javax.swing.JPasswordField;17 import javax.swing.JTextField;18 19 import org.openstreetmap.josm.Main;20 9 import org.openstreetmap.josm.command.DataSet; 21 import org.openstreetmap.josm.gui.GBC;22 10 23 11 /** … … 26 14 * @author imi 27 15 */ 28 public class OsmReader implements DataReader {16 public class OsmReader extends OsmConnection implements DataReader { 29 17 30 18 /** … … 36 24 */ 37 25 private boolean rawGps; 38 /** 39 * Whether the user cancelled the password dialog 40 */ 41 private boolean cancelled = false; 42 /** 43 * Set to true, when the autenticator tried the password once. 44 */ 45 private boolean passwordtried = false; 46 26 47 27 /** 48 28 * Construct the reader and store the information for attaching … … 52 32 this.rawGps = rawGps; 53 33 urlStr = server.endsWith("/") ? server : server+"/"; 54 urlStr += rawGps?"trackpoints" : "map";55 urlStr += "?bbox="+lon1+","+lat1+","+lon2+","+lat2;56 34 if (rawGps) 57 urlStr += "&page="; 58 59 HttpURLConnection.setFollowRedirects(true); 60 Authenticator.setDefault(new Authenticator(){ 61 @Override 62 protected PasswordAuthentication getPasswordAuthentication() { 63 String username = Main.pref.osmDataUsername; 64 String password = Main.pref.osmDataPassword; 65 if (passwordtried || "".equals(username) || password == null || "".equals(password)) { 66 JPanel p = new JPanel(new GridBagLayout()); 67 p.add(new JLabel("Username"), GBC.std().insets(0,0,10,0)); 68 JTextField usernameField = new JTextField("".equals(username) ? "" : username, 20); 69 p.add(usernameField, GBC.eol()); 70 p.add(new JLabel("Password"), GBC.std().insets(0,0,10,0)); 71 JPasswordField passwordField = new JPasswordField(password == null ? "" : password, 20); 72 p.add(passwordField, GBC.eol()); 73 JLabel warning = new JLabel("Warning: The password is transferred unencrypted."); 74 warning.setFont(warning.getFont().deriveFont(Font.ITALIC)); 75 p.add(warning, GBC.eol()); 76 int choice = JOptionPane.showConfirmDialog(Main.main, p, "Enter Password", JOptionPane.OK_CANCEL_OPTION); 77 if (choice == JOptionPane.CANCEL_OPTION) { 78 cancelled = true; 79 return null; 80 } 81 username = usernameField.getText(); 82 password = String.valueOf(passwordField.getPassword()); 83 if ("".equals(username)) 84 return null; 85 } 86 passwordtried = true; 87 return new PasswordAuthentication(username, password.toCharArray()); 88 } 89 }); 35 urlStr += "trackpoints?bbox="+lat1+","+lon1+","+lat2+","+lon2+"&page="; 36 else 37 urlStr += "map?bbox="+lon1+","+lat1+","+lon2+","+lat2; 90 38 } 91 39 … … 93 41 public DataSet parse() throws ParseException, ConnectionException { 94 42 Reader in; 43 initAuthentication(); 95 44 try { 96 45 if (rawGps) { … … 98 47 for (int i = 0;;++i) { 99 48 URL url = new URL(urlStr+i); 49 System.out.println(url); 100 50 HttpURLConnection con = (HttpURLConnection)url.openConnection(); 101 51 con.setConnectTimeout(20000); 102 if (con.getResponseCode() == 401 && cancelled)52 if (con.getResponseCode() == 401 && isCancelled()) 103 53 return null; 104 54 in = new InputStreamReader(con.getInputStream()); … … 112 62 HttpURLConnection con = (HttpURLConnection)url.openConnection(); 113 63 con.setConnectTimeout(20000); 114 if (con.getResponseCode() == 401 && cancelled)64 if (con.getResponseCode() == 401 && isCancelled()) 115 65 return null; 116 66 in = new InputStreamReader(con.getInputStream());
Note:
See TracChangeset
for help on using the changeset viewer.