Changeset 40 in josm for src/org/openstreetmap
- Timestamp:
- 2006-01-11T23:39:36+01:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 2 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r33 r40 15 15 16 16 import org.openstreetmap.josm.actions.AboutAction; 17 import org.openstreetmap.josm.actions.DownloadAction; 17 18 import org.openstreetmap.josm.actions.ExitAction; 18 19 import org.openstreetmap.josm.actions.OpenAction; 19 import org.openstreetmap.josm.actions.DownloadAction;20 20 import org.openstreetmap.josm.actions.PreferencesAction; 21 21 import org.openstreetmap.josm.actions.RedoAction; … … 26 26 import org.openstreetmap.josm.data.Preferences.PreferencesException; 27 27 import org.openstreetmap.josm.data.osm.DataSet; 28 import org.openstreetmap.josm.gui.BugReportExceptionHandler; 28 29 import org.openstreetmap.josm.gui.ImageProvider; 29 30 import org.openstreetmap.josm.gui.MapFrame; … … 144 145 */ 145 146 public static void main(String[] args) { 147 setupExceptionHandler(); 146 148 setupUiDefaults(); 147 149 … … 217 219 UIManager.put("OptionPane.noIcon", UIManager.get("OptionPane.cancelIcon")); 218 220 } 221 222 /** 223 * Setup an exception handler that displays a sorry message and the possibility 224 * to do a bug report. 225 */ 226 private static void setupExceptionHandler() { 227 Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler()); 228 } 219 229 } -
src/org/openstreetmap/josm/actions/DownloadAction.java
r37 r40 77 77 GeoPoint bottomLeft = mv.getPoint(0, h, true); 78 78 GeoPoint topRight = mv.getPoint(w, 0, true); 79 if (bottomLeft.isOutSideWorld()) 80 bottomLeft = new GeoPoint(-89.999, -179.999); // do not use the Projection constants, since this look better. 81 if (topRight.isOutSideWorld()) 82 topRight = new GeoPoint(89.999, 179.999); 79 83 latlon[0].setText(""+bottomLeft.lat); 80 84 latlon[1].setText(""+bottomLeft.lon); -
src/org/openstreetmap/josm/actions/OpenAction.java
r38 r40 1 1 package org.openstreetmap.josm.actions; 2 2 3 import java.awt.GridBagLayout;4 3 import java.awt.event.ActionEvent; 5 4 import java.awt.event.InputEvent; … … 8 7 import java.io.FileReader; 9 8 import java.io.IOException; 10 import java.io.Reader;11 9 import java.util.Collection; 12 10 import java.util.LinkedList; 13 11 14 import javax.swing.Box;15 import javax.swing.JCheckBox;16 12 import javax.swing.JFileChooser; 17 import javax.swing.JLabel;18 13 import javax.swing.JOptionPane; 19 import javax.swing.JPanel;20 14 import javax.swing.KeyStroke; 21 15 … … 24 18 import org.openstreetmap.josm.data.GeoPoint; 25 19 import org.openstreetmap.josm.data.osm.DataSet; 26 import org.openstreetmap.josm.gui.GBC;27 20 import org.openstreetmap.josm.gui.MapFrame; 28 21 import org.openstreetmap.josm.gui.layer.Layer; … … 55 48 fc.setAcceptAllFileFilterUsed(true); 56 49 57 // additional options58 JCheckBox rawGps = new JCheckBox("Raw GPS data", true);59 rawGps.setToolTipText("Check this, if the data were obtained from a gps device.");60 61 JPanel p = new JPanel(new GridBagLayout());62 p.add(new JLabel("Options"), GBC.eop());63 p.add(rawGps, GBC.eol());64 p.add(Box.createVerticalGlue(), GBC.eol().fill());65 fc.setAccessory(p);66 67 50 if (fc.showOpenDialog(Main.main) != JFileChooser.APPROVE_OPTION) 68 51 return; … … 74 57 try { 75 58 Layer layer; 76 Reader in = new FileReader(filename);77 59 String extension = filename.getName().toLowerCase().substring(filename.getName().lastIndexOf('.')+1); 78 if (rawGps.isSelected()) { 60 61 if (asRawData(extension)) { 79 62 Collection<Collection<GeoPoint>> data; 80 if (extension.equals("gpx")) 81 data = new RawGpsReader(in).parse(); 82 else if (extension.equals("xml") || extension.equals("osm")) { 83 JOptionPane.showMessageDialog(Main.main, "Osm server data import for GPS data is not supported."); 84 return; 63 if (extension.equals("gpx")) { 64 data = new RawGpsReader(new FileReader(filename)).parse(); 85 65 } else if (extension.equals("csv") || extension.equals("txt")) { 86 66 data = new LinkedList<Collection<GeoPoint>>(); 87 data.add(new RawCsvReader(in).parse()); 88 } else { 89 JOptionPane.showMessageDialog(Main.main, "Unknown file extension: "+extension); 90 return; 91 } 67 data.add(new RawCsvReader(new FileReader(filename)).parse()); 68 } else 69 throw new IllegalStateException(); 92 70 layer = new RawGpsDataLayer(data, filename.getName()); 93 71 } else { 94 72 DataSet dataSet; 95 73 if (extension.equals("gpx")) 96 dataSet = new GpxReader( in).parse();74 dataSet = new GpxReader(new FileReader(filename)).parse(); 97 75 else if (extension.equals("xml") || extension.equals("osm")) 98 dataSet = new OsmReader( in).parse();76 dataSet = new OsmReader(new FileReader(filename)).parse(); 99 77 else if (extension.equals("csv") || extension.equals("txt")) { 100 78 JOptionPane.showMessageDialog(Main.main, "CSV Data import for non-GPS data is not implemented yet."); … … 120 98 } 121 99 } 100 101 /** 102 * @return Return whether the file should be opened as raw gps data. May ask the 103 * user, if unsure. 104 */ 105 private boolean asRawData(String extension) { 106 if (extension.equals("csv") || extension.equals("txt")) 107 return true; 108 if (!extension.equals("gpx")) 109 return false; 110 return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog( 111 Main.main, "Do you want to open the file as raw gps data?", 112 "Open as raw data?", JOptionPane.YES_NO_OPTION); 113 } 122 114 } -
src/org/openstreetmap/josm/actions/SaveAction.java
r39 r40 13 13 14 14 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 16 import org.openstreetmap.josm.io.GpxWriter; 16 17 import org.openstreetmap.josm.io.OsmWriter; … … 37 38 return; 38 39 } 40 if (isDataSetEmpty() && JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(Main.main, "The document contains no data. Save anyway?", "Empty document", JOptionPane.YES_NO_OPTION)) 41 return; 42 39 43 JFileChooser fc = new JFileChooser("data"); 40 44 for (int i = 0; i < ExtensionFileFilter.filters.length; ++i) … … 45 49 if (file == null) 46 50 return; 47 51 48 52 try { 49 FileWriter fileWriter = new FileWriter(file);50 53 String fn = file.getName(); 54 FileWriter fileWriter; 51 55 if (fn.endsWith(".gpx")) 52 new GpxWriter(fileWriter ).output();56 new GpxWriter(fileWriter = new FileWriter(file)).output(); 53 57 else if (fn.endsWith(".xml") || fn.endsWith(".osm")) 54 new OsmWriter(fileWriter , Main.main.ds).output();58 new OsmWriter(fileWriter = new FileWriter(file), Main.main.ds).output(); 55 59 else if (fn.endsWith(".txt") || fn.endsWith(".csv")) { 56 60 JOptionPane.showMessageDialog(Main.main, "CSV output not supported yet."); … … 60 64 return; 61 65 } 62 63 66 fileWriter.close(); 64 67 } catch (IOException e) { … … 68 71 } 69 72 73 /** 74 * Check the data set if it would be empty on save. It is empty, if it contains 75 * no objects (after all objects that are created and deleted without beeing 76 * transfered to the server have been removed). 77 * 78 * @return <code>true</code>, if a save result in an empty data set. 79 */ 80 private boolean isDataSetEmpty() { 81 for (OsmPrimitive osm : Main.main.ds.allPrimitives()) 82 if (!osm.isDeleted() || osm.id > 0) 83 return false; 84 return true; 85 } 86 70 87 } -
src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java
r30 r40 3 3 import java.awt.event.KeyEvent; 4 4 import java.awt.event.MouseEvent; 5 6 import javax.swing.JOptionPane; 5 7 6 8 import org.openstreetmap.josm.Main; … … 50 52 Node node = new Node(); 51 53 node.coor = mv.getPoint(e.getX(), e.getY(), true); 54 if (node.coor.isOutSideWorld()) { 55 JOptionPane.showMessageDialog(Main.main, "Can not add a node outside of the world."); 56 return; 57 } 52 58 mv.editLayer().add(new AddCommand(Main.main.ds, node)); 53 59 mv.repaint(); -
src/org/openstreetmap/josm/actions/mapmode/MoveAction.java
r31 r40 7 7 import java.util.Collection; 8 8 9 import javax.swing.JOptionPane; 10 9 11 import org.openstreetmap.josm.Main; 10 12 import org.openstreetmap.josm.command.Command; 11 13 import org.openstreetmap.josm.command.MoveCommand; 12 14 import org.openstreetmap.josm.data.GeoPoint; 15 import org.openstreetmap.josm.data.osm.Node; 13 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 17 import org.openstreetmap.josm.gui.MapFrame; … … 84 87 85 88 Collection<OsmPrimitive> selection = Main.main.ds.getSelected(); 89 Collection<Node> affectedNodes = MoveCommand.getAffectedNodes(selection); 90 91 // check if any coordinate would be outside the world 92 for (OsmPrimitive osm : affectedNodes) { 93 if (osm instanceof Node && ((Node)osm).coor.isOutSideWorld()) { 94 JOptionPane.showMessageDialog(Main.main, "Cannot move objects outside of the world."); 95 return; 96 } 97 } 98 86 99 Command c = mv.editLayer().lastCommand(); 87 if (c instanceof MoveCommand && MoveCommand.getAffectedNodes(selection).equals(((MoveCommand)c).objects))100 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand)c).objects)) 88 101 ((MoveCommand)c).moveAgain(dx,dy); 89 102 else -
src/org/openstreetmap/josm/command/AddCommand.java
r35 r40 6 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 7 import org.openstreetmap.josm.data.osm.visitor.AddVisitor; 8 import org.openstreetmap.josm.data.osm.visitor.DeleteVisitor; 8 9 9 10 /** … … 38 39 39 40 public void undoCommand() { 40 osm. setDeleted(true);41 osm.visit(new DeleteVisitor(ds)); 41 42 } 42 43 -
src/org/openstreetmap/josm/command/DeleteCommand.java
r35 r40 6 6 import org.openstreetmap.josm.data.osm.DataSet; 7 7 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 import org.openstreetmap.josm.data.osm.visitor.AddVisitor;9 8 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 10 import org.openstreetmap.josm.data.osm.visitor.Visitor;11 9 12 10 /** … … 39 37 40 38 public void undoCommand() { 41 Visitor v = new AddVisitor(ds);42 39 for (OsmPrimitive osm : data) 43 osm. visit(v);40 osm.setDeleted(false); 44 41 } 45 42 -
src/org/openstreetmap/josm/data/Bounds.java
r23 r40 1 1 package org.openstreetmap.josm.data; 2 3 import org.openstreetmap.josm.Main; 4 import org.openstreetmap.josm.data.projection.Projection; 2 5 3 6 /** … … 45 48 this.max = max; 46 49 } 47 50 51 /** 52 * Construct bounds that span the whole world. 53 */ 54 public Bounds() { 55 min = new GeoPoint(-Projection.MAX_LAT, -Projection.MAX_LON); 56 Main.pref.getProjection().latlon2xy(min); 57 max = new GeoPoint(Projection.MAX_LAT, Projection.MAX_LON); 58 Main.pref.getProjection().latlon2xy(max); 59 } 60 48 61 /** 49 62 * @return The bounding rectangle that covers <code>this</code> and … … 59 72 return new Bounds(nmin, nmax); 60 73 } 61 74 62 75 /** 63 76 * @return The bounding rectangle that covers <code>this</code> and -
src/org/openstreetmap/josm/data/GeoPoint.java
r18 r40 1 1 package org.openstreetmap.josm.data; 2 3 import org.openstreetmap.josm.data.projection.Projection; 2 4 3 5 … … 66 68 !Double.isNaN(lat) && !Double.isNaN(lon); 67 69 } 70 71 /** 72 * @return <code>true</code>, if the coordinate is outside the world, compared 73 * by using lat/lon. 74 */ 75 public boolean isOutSideWorld() { 76 return lat < -Projection.MAX_LAT || lat > Projection.MAX_LAT || 77 lon < -Projection.MAX_LON || lon > Projection.MAX_LON; 78 } 68 79 } -
src/org/openstreetmap/josm/data/osm/DataSet.java
r35 r40 50 50 o.addAll(lineSegments); 51 51 o.addAll(tracks); 52 return o; 53 } 54 55 /** 56 * @return A collection containing all not-deleted primitives (except keys). 57 */ 58 public Collection<OsmPrimitive> allNonDeletedPrimitives() { 59 Collection<OsmPrimitive> o = new LinkedList<OsmPrimitive>(); 60 for (OsmPrimitive osm : allPrimitives()) 61 if (!osm.isDeleted()) 62 o.add(osm); 52 63 return o; 53 64 } -
src/org/openstreetmap/josm/data/osm/visitor/AddVisitor.java
r35 r40 26 26 public void visit(Node n) { 27 27 ds.nodes.add(n); 28 n.setDeleted(false);29 28 } 30 29 public void visit(LineSegment ls) { 31 30 ds.lineSegments.add(ls); 32 ls.setDeleted(false);33 31 } 34 32 public void visit(Track t) { 35 33 ds.tracks.add(t); 36 t.setDeleted(false);37 34 } 38 35 public void visit(Key k) {} -
src/org/openstreetmap/josm/data/osm/visitor/CollectBackReferencesVisitor.java
r31 r40 14 14 * Helper that collect all line segments a node is part of, all tracks 15 15 * a node or line segment is part of and all areas a node is part of. 16 * 17 * Deleted objects are not collected. 18 * 16 19 * @author imi 17 20 */ … … 25 28 public final Collection<OsmPrimitive> data = new HashSet<OsmPrimitive>(); 26 29 30 31 /** 32 * Construct a back reference counter. 33 * @param ds The dataset to operate on. 34 */ 27 35 public CollectBackReferencesVisitor(DataSet ds) { 28 36 this.ds = ds; … … 31 39 public void visit(Node n) { 32 40 for (Track t : ds.tracks) { 41 if (t.isDeleted()) 42 continue; 33 43 for (LineSegment ls : t.segments) { 34 44 if (ls.start == n || ls.end == n) { … … 38 48 } 39 49 } 40 for (LineSegment ls : ds.lineSegments) 50 for (LineSegment ls : ds.lineSegments) { 51 if (ls.isDeleted()) 52 continue; 41 53 if (ls.start == n || ls.end == n) 42 54 data.add(ls); 55 } 43 56 } 44 57 public void visit(LineSegment ls) { 45 for (Track t : ds.tracks) 58 for (Track t : ds.tracks) { 59 if (t.isDeleted()) 60 continue; 46 61 if (t.segments.contains(ls)) 47 62 data.add(t); 63 } 48 64 } 49 65 public void visit(Track t) {} -
src/org/openstreetmap/josm/data/projection/Projection.java
r23 r40 18 18 */ 19 19 abstract public class Projection implements Cloneable { 20 21 public static double MAX_LAT = 85; // yep - JOSM cannot cartograph the poles. 22 public static double MAX_LON = 179.99999; 20 23 21 24 /** -
src/org/openstreetmap/josm/data/projection/UTM.java
r35 r40 195 195 ZoneData autoDetect(Bounds b) { 196 196 ZoneData zd = new ZoneData(); 197 if (b == null)198 return zd;199 197 GeoPoint center = b.centerLatLon(); 200 198 double lat = center.lat; -
src/org/openstreetmap/josm/gui/MapView.java
r39 r40 394 394 l.paint(g, this); 395 395 } 396 397 // draw world borders 398 g.setColor(Color.DARK_GRAY); 399 Bounds b = new Bounds(); 400 Point min = getScreenPoint(b.min); 401 Point max = getScreenPoint(b.max); 402 int x1 = Math.min(min.x, max.x); 403 int y1 = Math.min(min.y, max.y); 404 int x2 = Math.max(min.x, max.x); 405 int y2 = Math.max(min.y, max.y); 406 g.drawRect(x1, y1, x2-x1+1, y2-y1+1); 396 407 } 397 408 -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r39 r40 2 2 3 3 import java.awt.Graphics; 4 import java.util.Collection; 4 5 import java.util.Iterator; 5 6 import java.util.LinkedList; … … 90 91 @Override 91 92 public String getToolTipText() { 92 return data.nodes.size()+" nodes, "+data.lineSegments.size()+" segments, "+data.tracks.size()+" streets."; 93 return undeletedSize(data.nodes)+" nodes, "+ 94 undeletedSize(data.lineSegments)+" segments, "+ 95 undeletedSize(data.tracks)+" streets."; 93 96 } 94 97 … … 110 113 for (Node n : data.nodes) 111 114 b.visit(n); 112 return b.bounds ;115 return b.bounds != null ? b.bounds : new Bounds(); 113 116 } 114 117 … … 118 121 for (Node n : data.nodes) 119 122 b.visit(n); 120 return b.bounds ;123 return b.bounds != null ? b.bounds : new Bounds(); 121 124 } 122 125 … … 197 200 it.remove(); 198 201 } 202 203 /** 204 * @return The number of not-deleted primitives in the list. 205 */ 206 private int undeletedSize(Collection<? extends OsmPrimitive> list) { 207 int size = 0; 208 for (OsmPrimitive osm : list) 209 if (!osm.isDeleted()) 210 size++; 211 return size; 212 } 199 213 } -
src/org/openstreetmap/josm/io/OsmWriter.java
r35 r40 63 63 List<Element> list = root.getChildren(); 64 64 properties = new LinkedList<Element>(); 65 for (OsmPrimitive osm : ds.allPrimitives()) { 66 if (!osm.isDeleted()) { 67 osm.visit(this); 68 list.add(element); 69 } 65 for (OsmPrimitive osm : ds.allNonDeletedPrimitives()) { 66 osm.visit(this); 67 list.add(element); 70 68 } 71 69 list.addAll(properties); -
src/org/openstreetmap/josm/io/RawGpsReader.java
r29 r40 55 55 */ 56 56 @SuppressWarnings("unchecked") 57 private Collection<Collection<GeoPoint>> parseData(Element root) {57 private Collection<Collection<GeoPoint>> parseData(Element root) throws JDOMException { 58 58 Collection<Collection<GeoPoint>> data = new LinkedList<Collection<GeoPoint>>(); 59 59 … … 63 63 for (Object o : root.getChildren("wpt", GPX)) { 64 64 Collection<GeoPoint> line = new LinkedList<GeoPoint>(); 65 line.add(new GeoPoint( 66 Float.parseFloat(((Element)o).getAttributeValue("lat")), 67 Float.parseFloat(((Element)o).getAttributeValue("lon")))); 65 line.add(new GeoPoint(parseFloat((Element)o, LatLon.lat), parseFloat((Element)o, LatLon.lon))); 68 66 data.add(line); 69 67 } … … 83 81 } 84 82 83 enum LatLon {lat, lon} 84 /** 85 * Return a parsed float value from the element behind the object o. 86 * @param o An object of dynamic type org.jdom.Element (will be casted). 87 * @param attr The name of the attribute. 88 * @throws JDOMException If the absolute of the value is out of bound. 89 */ 90 private float parseFloat(Element e, LatLon attr) throws JDOMException { 91 float f = Float.parseFloat(e.getAttributeValue(attr.toString())); 92 if (Math.abs(f) > (attr == LatLon.lat ? 90 : 180)) 93 throw new JDOMException("Data error: "+attr+" value '"+f+"' is out of bound."); 94 return f; 95 } 96 85 97 /** 86 98 * Parse the list of trackpoint - elements and return a collection with the 87 99 * points read. 88 100 */ 89 private Collection<GeoPoint> parseLine(List<Element> wpt) {101 private Collection<GeoPoint> parseLine(List<Element> wpt) throws JDOMException { 90 102 Collection<GeoPoint> data = new LinkedList<GeoPoint>(); 91 103 for (Element e : wpt) 92 data.add(new GeoPoint( 93 Float.parseFloat(e.getAttributeValue("lat")), 94 Float.parseFloat(e.getAttributeValue("lon")))); 104 data.add(new GeoPoint(parseFloat(e, LatLon.lat), parseFloat(e, LatLon.lon))); 95 105 return data; 96 106 }
Note:
See TracChangeset
for help on using the changeset viewer.