- Timestamp:
- 2006-04-01T13:01:41+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 3 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r77 r78 15 15 import java.util.StringTokenizer; 16 16 17 import javax.swing.Action; 17 18 import javax.swing.JFrame; 18 19 import javax.swing.JMenu; … … 27 28 import org.openstreetmap.josm.actions.DownloadAction; 28 29 import org.openstreetmap.josm.actions.ExitAction; 30 import org.openstreetmap.josm.actions.GpxExportAction; 29 31 import org.openstreetmap.josm.actions.OpenAction; 30 32 import org.openstreetmap.josm.actions.PreferencesAction; … … 80 82 public final RedoAction redoAction; 81 83 82 /**83 * This directory is used for all disc IO access as starting directory. Should84 * be set accordingly after the IO action.85 */86 public File currentDirectory = new File(".");87 88 84 private OpenAction openAction; 89 85 … … 104 100 105 101 downloadAction = new DownloadAction(); 106 UploadAction uploadAction = new UploadAction();102 Action uploadAction = new UploadAction(); 107 103 openAction = new OpenAction(); 108 SaveAction saveAction = new SaveAction(); 109 ExitAction exitAction = new ExitAction(); 104 Action saveAction = new SaveAction(); 105 Action gpxExportAction = new GpxExportAction(null); 106 Action exitAction = new ExitAction(); 110 107 undoAction = new UndoAction(); 111 108 redoAction = new RedoAction(); 112 PreferencesAction preferencesAction = new PreferencesAction();113 A boutAction aboutAction = new AboutAction();109 Action preferencesAction = new PreferencesAction(); 110 Action aboutAction = new AboutAction(); 114 111 115 112 // creating menu … … 121 118 fileMenu.add(openAction); 122 119 fileMenu.add(saveAction); 120 fileMenu.add(gpxExportAction); 123 121 fileMenu.addSeparator(); 124 122 fileMenu.add(exitAction); … … 151 149 toolBar.add(downloadAction); 152 150 toolBar.add(uploadAction); 151 toolBar.addSeparator(); 153 152 toolBar.add(openAction); 154 153 toolBar.add(saveAction); 154 toolBar.add(gpxExportAction); 155 155 toolBar.addSeparator(); 156 156 toolBar.add(undoAction); -
src/org/openstreetmap/josm/actions/OpenAction.java
r71 r78 16 16 import org.jdom.JDOMException; 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.coor.LatLon;19 18 import org.openstreetmap.josm.data.osm.DataSet; 20 19 import org.openstreetmap.josm.gui.MapFrame; … … 22 21 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 23 22 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer; 23 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer.GpsPoint; 24 24 import org.openstreetmap.josm.io.GpxReader; 25 25 import org.openstreetmap.josm.io.OsmReader; … … 35 35 * @author imi 36 36 */ 37 public class OpenAction extends JosmAction {37 public class OpenAction extends DiskAccessAction { 38 38 39 39 /** … … 45 45 46 46 public void actionPerformed(ActionEvent e) { 47 JFileChooser fc = new JFileChooser(Main.main.currentDirectory); 48 for (int i = 0; i < ExtensionFileFilter.filters.length; ++i) 49 fc.addChoosableFileFilter(ExtensionFileFilter.filters[i]); 50 fc.setAcceptAllFileFilterUsed(true); 51 52 if (fc.showOpenDialog(Main.main) != JFileChooser.APPROVE_OPTION) 47 JFileChooser fc = createAndOpenFileChooser(true, true); 48 if (fc == null) 53 49 return; 54 55 Main.main.currentDirectory = fc.getCurrentDirectory(); 56 57 File filename = fc.getSelectedFile(); 58 if (filename == null) 59 return; 60 61 openFile(filename); 50 File[] files = fc.getSelectedFiles(); 51 for (int i = files.length; i > 0; --i) 52 openFile(files[i-1]); 62 53 } 63 54 … … 71 62 72 63 if (asRawData(fn)) { 73 Collection<Collection< LatLon>> data;64 Collection<Collection<GpsPoint>> data; 74 65 if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) { 75 66 data = new RawGpsReader(new FileReader(filename)).parse(); 76 67 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 77 data = new LinkedList<Collection< LatLon>>();68 data = new LinkedList<Collection<GpsPoint>>(); 78 69 data.add(new RawCsvReader(new FileReader(filename)).parse()); 79 70 } else … … 82 73 } else { 83 74 DataSet dataSet; 84 if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) 75 if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) { 76 JOptionPane.showMessageDialog(Main.main, "Warning: Soon, it will be no longer possible to open GPX files as osm data. Please convert your files to .osm format."); 85 77 dataSet = new GpxReader(new FileReader(filename)).parse(); 86 else if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) {78 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) { 87 79 try { 88 80 // temporary allow loading of old xml format. … … 91 83 if (x.getMessage().equals("Unknown version: null")) { 92 84 int answer = JOptionPane.showConfirmDialog(Main.main, 93 "Thisseems to be an old 0.2 API XML file.\n" +85 fn+" seems to be an old 0.2 API XML file.\n" + 94 86 "JOSM can try to open it with the old parser. This option\n" + 95 87 "will not be available in future JOSM version. You should\n" + … … 104 96 } 105 97 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 106 JOptionPane.showMessageDialog(Main.main, "CSV Data import for non-GPS data is not implemented yet.");98 JOptionPane.showMessageDialog(Main.main, fn+": CSV Data import for non-GPS data is not implemented yet."); 107 99 return; 108 100 } else { 109 JOptionPane.showMessageDialog(Main.main, "Unknown file extension: "+fn.substring(filename.getName().lastIndexOf('.')+1));101 JOptionPane.showMessageDialog(Main.main, fn+": Unknown file extension: "+fn.substring(filename.getName().lastIndexOf('.')+1)); 110 102 return; 111 103 } … … 140 132 return false; 141 133 return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog( 142 Main.main, "Do you want to open the fileas raw gps data?",134 Main.main, "Do you want to open "+fn+" as raw gps data?", 143 135 "Open as raw data?", JOptionPane.YES_NO_OPTION); 144 136 } -
src/org/openstreetmap/josm/actions/SaveAction.java
r71 r78 15 15 import org.openstreetmap.josm.Main; 16 16 import org.openstreetmap.josm.data.osm.LineSegment; 17 import org.openstreetmap.josm.data.osm.OsmPrimitive;18 17 import org.openstreetmap.josm.io.GpxWriter; 19 18 import org.openstreetmap.josm.io.OsmWriter; … … 24 23 * @author imi 25 24 */ 26 public class SaveAction extends JosmAction {25 public class SaveAction extends DiskAccessAction { 27 26 28 27 /** 29 28 * Construct the action with "Save" as label. 29 * @param layer Save only this layer. If <code>null</code>, save the whole Main 30 * data set. 30 31 */ 31 32 public SaveAction() { … … 41 42 return; 42 43 43 JFileChooser fc = new JFileChooser(Main.main.currentDirectory); 44 for (int i = 0; i < ExtensionFileFilter.filters.length; ++i) 45 fc.addChoosableFileFilter(ExtensionFileFilter.filters[i]); 46 fc.setAcceptAllFileFilterUsed(true); 47 fc.showSaveDialog(Main.main); 44 JFileChooser fc = createAndOpenFileChooser(false, false); 45 if (fc == null) 46 return; 47 48 48 File file = fc.getSelectedFile(); 49 if (file == null)50 return;51 Main.main.currentDirectory = fc.getCurrentDirectory();52 if (file.exists() && JOptionPane.YES_OPTION !=53 JOptionPane.showConfirmDialog(Main.main, "File exists. Overwrite?", "Overwrite", JOptionPane.YES_NO_OPTION))54 return;55 49 56 50 try { … … 58 52 if (fn.indexOf('.') == -1) { 59 53 FileFilter ff = fc.getFileFilter(); 60 if (ff instanceof ExtensionFileFilter) { 61 fn = fn + "." + ((ExtensionFileFilter)ff).defaultExtension; 62 file = new File(fn); 63 } 54 if (ff instanceof ExtensionFileFilter) 55 fn = "." + ((ExtensionFileFilter)ff).defaultExtension; 56 else 57 fn += ".osm"; 58 file = new File(fn); 64 59 } 65 60 FileWriter fileWriter; … … 88 83 } 89 84 } 90 91 /**92 * Check the data set if it would be empty on save. It is empty, if it contains93 * no objects (after all objects that are created and deleted without beeing94 * transfered to the server have been removed).95 *96 * @return <code>true</code>, if a save result in an empty data set.97 */98 private boolean isDataSetEmpty() {99 for (OsmPrimitive osm : Main.main.ds.allPrimitives())100 if (!osm.isDeleted() || osm.id > 0)101 return false;102 return true;103 }104 105 85 } -
src/org/openstreetmap/josm/data/Bounds.java
r73 r78 39 39 return "Bounds["+min.lat()+","+min.lon()+","+max.lat()+","+max.lon()+"]"; 40 40 } 41 42 /** 43 * Extend the bounds if necessary to include the given point. 44 */ 45 public void extend(LatLon ll) { 46 if (ll.lat() < min.lat() || ll.lon() < min.lon()) 47 min = new LatLon(Math.min(ll.lat(), min.lat()), Math.min(ll.lon(), min.lon())); 48 if (ll.lat() > max.lat() || ll.lon() > max.lon()) 49 max = new LatLon(Math.max(ll.lat(), max.lat()), Math.max(ll.lon(), max.lon())); 50 } 41 51 } -
src/org/openstreetmap/josm/data/Preferences.java
r77 r78 73 73 } 74 74 synchronized public boolean getBoolean(String key) { 75 return properties.containsKey(key) ? Boolean.parseBoolean(properties.get(key)) : false; 75 return getBoolean(key, false); 76 } 77 synchronized public boolean getBoolean(String key, boolean def) { 78 return properties.containsKey(key) ? Boolean.parseBoolean(properties.get(key)) : def; 76 79 } 77 80 -
src/org/openstreetmap/josm/data/coor/Coordinate.java
r71 r78 52 52 @Override 53 53 public boolean equals(Object obj) { 54 return obj instanceof EastNorth ? x == ((EastNorth)obj).x && ((EastNorth)obj).y == y : false;54 return obj instanceof Coordinate ? x == ((Coordinate)obj).x && ((Coordinate)obj).y == y : false; 55 55 } 56 56 -
src/org/openstreetmap/josm/data/osm/DataSet.java
r71 r78 8 8 9 9 /** 10 * DataSet is the data behind the application. It can consist of only a few10 * DataSet is the data behind the application. It can consists of only a few 11 11 * points up to the whole osm database. DataSet's can be merged together, 12 12 * saved, (up/down/disk)loaded etc. -
src/org/openstreetmap/josm/data/osm/visitor/SelectionComponentVisitor.java
r71 r78 42 42 name = ls.id+" ("+ls.from.coor.lat()+","+ls.from.coor.lon()+") -> ("+ls.to.coor.lat()+","+ls.to.coor.lon()+")"; 43 43 } 44 icon = ImageProvider.get("data", " linesegment");44 icon = ImageProvider.get("data", "segment"); 45 45 } 46 46 -
src/org/openstreetmap/josm/data/projection/Projection.java
r74 r78 12 12 public interface Projection { 13 13 14 public static double MAX_LAT = 85 ;14 public static double MAX_LAT = 85.05112877980659; // Mercator squares the world 15 15 public static double MAX_LON = 180; 16 16 public static final double MAX_SERVER_PRECISION = 1e12; -
src/org/openstreetmap/josm/gui/MapView.java
r77 r78 17 17 import org.openstreetmap.josm.data.osm.DataSet; 18 18 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 19 import org.openstreetmap.josm.data.projection.Projection; 19 20 import org.openstreetmap.josm.gui.layer.Layer; 20 21 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 214 215 215 216 if (v.min == null || v.max == null) { 216 // no bounds means standard scale and center 217 center = Main.proj.latlon2eastNorth(new LatLon(51.526447, -0.14746371)); 218 scale = 10; 217 // no bounds means whole world 218 center = getProjection().latlon2eastNorth(new LatLon(0,0)); 219 EastNorth world = getProjection().latlon2eastNorth(new LatLon(Projection.MAX_LAT,Projection.MAX_LON)); 220 double scaleX = world.east()*2/w; 221 double scaleY = world.north()*2/h; 222 scale = Math.max(scaleX, scaleY); // minimum scale to see all of the screen 223 219 224 } else { 220 225 center = new EastNorth(v.min.east()/2+v.max.east()/2, v.min.north()/2+v.max.north()/2); -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r77 r78 176 176 // projection combo box 177 177 for (int i = 0; i < projectionCombo.getItemCount(); ++i) { 178 if (projectionCombo.getItemAt(i). toString().equals(Main.pref.get("projection"))) {178 if (projectionCombo.getItemAt(i).getClass().getName().equals(Main.pref.get("projection"))) { 179 179 projectionCombo.setSelectedIndex(i); 180 180 break; … … 258 258 osmDataUsername.setToolTipText("Login name (email) to the OSM account."); 259 259 osmDataPassword.setToolTipText("Login password to the OSM account. Leave blank to not store any password."); 260 csvImportString.setToolTipText("<html>Import string specification. Currently, only lat/lon pairsare imported.<br>" +260 csvImportString.setToolTipText("<html>Import string specification. lat/lon and time are imported.<br>" + 261 261 "<b>lat</b>: The latitude coordinate<br>" + 262 262 "<b>lon</b>: The longitude coordinate<br>" + 263 "<b>time</b>: The measured time as string<br>" + 263 264 "<b>ignore</b>: Skip this field<br>" + 264 265 "An example: \"ignore ignore lat lon\" will use ' ' as delimiter, skip the first two values and read then lat/lon.<br>" + -
src/org/openstreetmap/josm/gui/dialogs/LayerList.java
r77 r78 2 2 3 3 import java.awt.BorderLayout; 4 import java.awt.Color;5 4 import java.awt.Component; 6 5 import java.awt.Dimension; … … 17 16 import javax.swing.Icon; 18 17 import javax.swing.JButton; 19 import javax.swing.JColorChooser;20 18 import javax.swing.JLabel; 21 19 import javax.swing.JList; 22 import javax.swing.JMenuItem;23 import javax.swing.JOptionPane;24 20 import javax.swing.JPanel; 25 import javax.swing.JPopupMenu;26 21 import javax.swing.JScrollPane; 27 22 import javax.swing.ListSelectionModel; … … 36 31 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 37 32 import org.openstreetmap.josm.gui.layer.Layer; 38 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer;39 import org.openstreetmap.josm.tools.ColorHelper;40 33 import org.openstreetmap.josm.tools.ImageProvider; 41 34 import org.openstreetmap.josm.tools.ImageProvider.OverlayPosition; … … 122 115 layers.addMouseListener(new MouseAdapter(){ 123 116 private void openPopup(MouseEvent e) { 124 final int index = layers.locationToIndex(e.getPoint()); 125 final Layer layer = (Layer)layers.getModel().getElementAt(index); 126 if (!(layer instanceof RawGpsDataLayer)) 127 return; // currently only options for raw layers. 128 JPopupMenu menu = new JPopupMenu(); 129 JMenuItem color = new JMenuItem("Customize Color"); 130 color.addActionListener(new ActionListener(){ 131 public void actionPerformed(ActionEvent e) { 132 String col = Main.pref.get("color.layer "+layer.name, Main.pref.get("color.gps point", ColorHelper.color2html(Color.gray))); 133 JColorChooser c = new JColorChooser(ColorHelper.html2color(col)); 134 Object[] options = new Object[]{"OK", "Cancel", "Default"}; 135 int answer = JOptionPane.showOptionDialog(Main.main, c, "Choose a color", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); 136 switch (answer) { 137 case 0: 138 Main.pref.put("color.layer "+layer.name, ColorHelper.color2html(c.getColor())); 139 break; 140 case 1: 141 return; 142 case 2: 143 Main.pref.put("color.layer "+layer.name, null); 144 break; 145 } 146 Main.main.repaint(); 147 } 148 }); 149 menu.add(color); 117 int index = layers.locationToIndex(e.getPoint()); 118 Layer layer = (Layer)layers.getModel().getElementAt(index); 119 LayerListPopup menu = new LayerListPopup(layer); 150 120 menu.show(LayerList.this, e.getX(), e.getY()); 151 121 } -
src/org/openstreetmap/josm/gui/layer/Layer.java
r77 r78 78 78 */ 79 79 abstract public void visitBoundingBox(BoundingXYVisitor v); 80 81 abstract public Object getInfoComponent(); 80 82 } -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r77 r78 2 2 3 3 import java.awt.Graphics; 4 import java.awt.GridBagLayout; 4 5 import java.util.Collection; 5 6 import java.util.HashSet; … … 10 11 11 12 import javax.swing.Icon; 13 import javax.swing.JLabel; 14 import javax.swing.JPanel; 12 15 13 16 import org.openstreetmap.josm.Main; … … 21 24 import org.openstreetmap.josm.data.osm.visitor.MergeVisitor; 22 25 import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor; 26 import org.openstreetmap.josm.data.osm.visitor.Visitor; 23 27 import org.openstreetmap.josm.gui.MapView; 28 import org.openstreetmap.josm.tools.GBC; 24 29 import org.openstreetmap.josm.tools.ImageProvider; 25 30 … … 279 284 return size; 280 285 } 286 287 @Override 288 public Object getInfoComponent() { 289 final int[] normal = new int[3]; 290 final int[] deleted = new int[3]; 291 final String[] names = {"node", "segment", "way"}; 292 Visitor counter = new Visitor(){ 293 private void inc(OsmPrimitive osm, int i) { 294 normal[i]++; 295 if (osm.isDeleted()) 296 deleted[i]++; 297 } 298 public void visit(Node n) { 299 inc(n, 0); 300 } 301 public void visit(LineSegment ls) { 302 inc(ls, 1); 303 } 304 public void visit(Way w) { 305 inc(w, 2); 306 } 307 }; 308 for (OsmPrimitive osm : data.allPrimitives()) 309 osm.visit(counter); 310 311 JPanel p = new JPanel(new GridBagLayout()); 312 p.add(new JLabel(name+" consists of:"), GBC.eol()); 313 for (int i = 0; i < normal.length; ++i) { 314 String s = normal[i]+" "+names[i]+(normal[i] != 1 ?"s":""); 315 if (deleted[i] > 0) 316 s += " ("+deleted[i]+" deleted)"; 317 p.add(new JLabel(s, ImageProvider.get("data", names[i]), JLabel.HORIZONTAL), GBC.eol().insets(15,0,0,0)); 318 } 319 return p; 320 } 281 321 } -
src/org/openstreetmap/josm/gui/layer/RawGpsDataLayer.java
r77 r78 5 5 import java.awt.Point; 6 6 import java.util.Collection; 7 import java.util.LinkedList;8 7 9 8 import javax.swing.Icon; … … 28 27 private static Icon icon; 29 28 29 public static class GpsPoint { 30 public final LatLon latlon; 31 public final EastNorth eastNorth; 32 public final String time; 33 public GpsPoint(LatLon ll, String t) { 34 latlon = ll; 35 eastNorth = Main.proj.latlon2eastNorth(ll); 36 time = t; 37 } 38 } 39 30 40 /** 31 41 * A list of ways which containing a list of points. 32 42 */ 33 private final Collection<Collection<LatLon>> data; 34 private Collection<Collection<EastNorth>> eastNorth; 43 public final Collection<Collection<GpsPoint>> data; 35 44 36 public RawGpsDataLayer(Collection<Collection< LatLon>> data, String name) {45 public RawGpsDataLayer(Collection<Collection<GpsPoint>> data, String name) { 37 46 super(name); 38 47 this.data = data; 39 40 eastNorth = new LinkedList<Collection<EastNorth>>();41 for (Collection<LatLon> c : data) {42 Collection<EastNorth> eastNorthList = new LinkedList<EastNorth>();43 for (LatLon ll : c)44 eastNorthList.add(Main.proj.latlon2eastNorth(ll));45 this.eastNorth.add(eastNorthList);46 }47 48 48 Main.pref.addPreferenceChangedListener(new PreferenceChangedListener(){ 49 49 public void preferenceChanged(String key, String newValue) { … … 75 75 g.setColor(Color.GRAY); 76 76 Point old = null; 77 for (Collection< EastNorth> c : eastNorth) {77 for (Collection<GpsPoint> c : data) { 78 78 if (!Main.pref.getBoolean("forceRawGpsLines")) 79 79 old = null; 80 for ( EastNorth eastNorth: c) {81 Point screen = mv.getPoint( eastNorth);80 for (GpsPoint p : c) { 81 Point screen = mv.getPoint(p.eastNorth); 82 82 if (Main.pref.getBoolean("drawRawGpsLines") && old != null) 83 83 g.drawLine(old.x, old.y, screen.x, screen.y); … … 92 92 public String getToolTipText() { 93 93 int points = 0; 94 for (Collection< LatLon> c : data)94 for (Collection<GpsPoint> c : data) 95 95 points += c.size(); 96 return data.size()+" ways, "+points+" points.";96 return data.size()+" tracks, "+points+" points."; 97 97 } 98 98 … … 110 110 @Override 111 111 public void visitBoundingBox(BoundingXYVisitor v) { 112 for (Collection<EastNorth> c : eastNorth) 113 for (EastNorth eastNorth : c) 114 v.visit(eastNorth); 112 for (Collection<GpsPoint> c : data) 113 for (GpsPoint p : c) 114 v.visit(p.eastNorth); 115 } 116 117 @Override 118 public Object getInfoComponent() { 119 StringBuilder b = new StringBuilder(); 120 int points = 0; 121 for (Collection<GpsPoint> c : data) { 122 b.append(" a track with "+c.size()+" points<br>"); 123 points += c.size(); 124 } 125 b.append("</html>"); 126 return "<html>"+name+" consists of "+data.size()+" tracks ("+points+" points)<br>"+b.toString(); 115 127 } 116 128 } -
src/org/openstreetmap/josm/io/GpxWriter.java
r71 r78 2 2 3 3 import java.io.IOException; 4 import java.io.PrintWriter; 4 5 import java.io.Writer; 5 6 import java.util.Collection; … … 15 16 import org.jdom.output.Format; 16 17 import org.jdom.output.XMLOutputter; 18 import org.openstreetmap.josm.data.Bounds; 19 import org.openstreetmap.josm.data.coor.LatLon; 17 20 import org.openstreetmap.josm.data.osm.DataSet; 18 21 import org.openstreetmap.josm.data.osm.LineSegment; … … 20 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 21 24 import org.openstreetmap.josm.data.osm.Way; 25 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer.GpsPoint; 26 import org.openstreetmap.josm.tools.XmlWriter; 22 27 23 28 /** … … 49 54 * This is the output writer to store the resulting data in. 50 55 */ 51 private Writer out;56 private PrintWriter out; 52 57 /** 53 58 * The dataset beeing processed. … … 73 78 */ 74 79 public GpxWriter(Writer out, DataSet ds) { 75 this.out = out;80 this.out = new PrintWriter(out); 76 81 this.ds = ds; 77 82 } … … 318 323 ext.getChildren().addAll(extensions); 319 324 } 325 326 327 public GpxWriter(Writer writer, String name, String desc, String author, String email, String copyright, String year, String keywords) { 328 out = writer instanceof PrintWriter ? (PrintWriter)writer : new PrintWriter(writer); 329 out.println(XmlWriter.header()); 330 out.println("<gpx version='1.1' creator='JOSM' xmlns='http://www.topografix.com/GPX/1/1'>"); 331 out.println(" <metadata>"); 332 if (!name.equals("")) 333 out.println(" <name>"+XmlWriter.encode(name)+"</name>"); 334 if (!desc.equals("")) 335 out.println(" <desc>"+XmlWriter.encode(desc)+"</desc>"); 336 if (!author.equals("")) { 337 out.println(" <author>"); 338 out.println(" <name>"+XmlWriter.encode(author)+"</name>"); 339 if (!email.equals("")) 340 out.println(" <email>"+XmlWriter.encode(email)+"</email>"); 341 out.println(" </author>"); 342 if (!copyright.equals("")) { 343 out.println(" <copyright author='"+XmlWriter.encode(author)+"'>"); 344 if (!year.equals("")) 345 out.println(" <year>"+XmlWriter.encode(year)+"</year>"); 346 out.println(" <license>"+XmlWriter.encode(copyright)+"</license>"); 347 out.println(" </copyright>"); 348 } 349 } 350 if (!keywords.equals("")) { 351 out.println(" <keywords>"+XmlWriter.encode(keywords)+"</keywords>"); 352 } 353 // don't finish here, to give output functions the chance to add <bounds> 354 } 355 356 /** 357 * Export the dataset to gpx. Only the physical line segment structure is 358 * exported. To do this, the list of ways is processed. If a way span a 359 * sequence of line segments, this is added as one trkseg. 360 * Then, all remaining line segments are added in one extra trk. Finally, 361 * all remaining nodes are added as wpt. 362 */ 363 public void output(DataSet data) { 364 Collection<OsmPrimitive> all = data.allNonDeletedPrimitives(); 365 if (all.isEmpty()) { 366 out.println(" </metadata>"); 367 out.println("</gpx>"); 368 return; 369 } 370 // calculate bounds 371 Bounds b = new Bounds(new LatLon(Double.MAX_VALUE, Double.MAX_VALUE), new LatLon(Double.MIN_VALUE, Double.MIN_VALUE)); 372 for (Node n : data.nodes) 373 if (!n.isDeleted()) 374 b.extend(n.coor); 375 out.println(" <bounds minlat='"+b.min.lat()+"' minlon='"+b.min.lon()+"' maxlat='"+b.max.lat()+"' maxlon='"+b.max.lon()+"' />"); 376 out.println(" </metadata>"); 377 378 // add ways 379 for (Way w : data.ways) { 380 if (w.isDeleted()) 381 continue; 382 out.println(" <trk>"); 383 LineSegment oldLs = null; 384 for (LineSegment ls : w.segments) { 385 // end old segemnt, if no longer match a chain 386 if (oldLs != null && !oldLs.to.coor.equals(ls.from.coor)) { 387 out.println(" </trkseg>"); 388 outputNode(oldLs.to, false); 389 all.remove(oldLs.to); 390 oldLs = null; 391 } 392 // start new segment if necessary 393 if (oldLs == null) 394 out.println(" <trkseg>"); 395 outputNode(ls.from, false); 396 all.remove(ls.from); 397 oldLs = ls; 398 all.remove(ls); 399 } 400 // write last node if there 401 if (oldLs != null) { 402 outputNode(oldLs.to, false); 403 all.remove(oldLs.to); 404 out.println(" </trkseg>"); 405 } 406 out.println(" </trk>"); 407 all.remove(w); 408 } 409 410 // add remaining line segments 411 Collection<LineSegment> lineSegments = new LinkedList<LineSegment>(); 412 for (OsmPrimitive osm : all) 413 if (osm instanceof LineSegment) 414 lineSegments.add((LineSegment)osm); 415 if (!lineSegments.isEmpty()) { 416 out.println(" <trk>"); 417 for (LineSegment ls : lineSegments) { 418 out.println(" <trkseg>"); 419 outputNode(ls.from, false); 420 all.remove(ls.from); 421 outputNode(ls.to, false); 422 all.remove(ls.to); 423 out.println(" </trkseg>"); 424 all.remove(ls); 425 } 426 out.println(" </trk>"); 427 } 428 429 // finally add the remaining nodes 430 for (OsmPrimitive osm : all) { 431 outputNode((Node)osm, true); 432 } 433 434 out.println("</gpx>"); 435 } 436 437 438 /** 439 * Export the collection structure to gpx. The gpx will consists of only one 440 * trk with as many trkseg as there are collections in the outer collection. 441 */ 442 public void output(Collection<Collection<GpsPoint>> data) { 443 if (data.size() == 0) { 444 out.println(" </metadata>"); 445 out.println("</gpx>"); 446 return; 447 } 448 // calculate bounds 449 Bounds b = new Bounds(new LatLon(Double.MAX_VALUE, Double.MAX_VALUE), new LatLon(Double.MIN_VALUE, Double.MIN_VALUE)); 450 for (Collection<GpsPoint> c : data) 451 for (GpsPoint p : c) 452 b.extend(p.latlon); 453 out.println(" <bounds minlat='"+b.min.lat()+"' minlon='"+b.min.lon()+"' maxlat='"+b.max.lat()+"' maxlon='"+b.max.lon()+"' />"); 454 out.println(" </metadata>"); 455 456 out.println(" <trk>"); 457 for (Collection<GpsPoint> c : data) { 458 out.println(" <trkseg>"); 459 LatLon last = null; 460 for (GpsPoint p : c) { 461 // skip double entries 462 if (p.latlon.equals(last)) 463 continue; 464 last = p.latlon; 465 LatLon ll = p.latlon; 466 out.print(" <trkpt lat='"+ll.lat()+"' lon='"+ll.lon()+"'"); 467 if (p.time != null && !p.time.isEmpty()) { 468 out.println(">"); 469 out.println(" <time>"+p.time+"</time>"); 470 out.println(" </trkpt>"); 471 } else 472 out.println(" />"); 473 } 474 out.println(" </trkseg>"); 475 } 476 out.println(" </trk>"); 477 out.println("</gpx>"); 478 } 479 480 private void outputNode(Node n, boolean wpt) { 481 out.print((wpt?" <wpt":" <trkpt")+" lat='"+n.coor.lat()+"' lon='"+n.coor.lon()+"'"); 482 if (n.keys == null) { 483 out.println(" />"); 484 return; 485 } 486 boolean found = false; 487 String[] possibleKeys = {"ele", "time", "magvar", "geoidheight", "name", 488 "cmt", "desc", "src", "link", "sym", "type", "fix", "sat", 489 "hdop", "vdop", "pdop", "ageofgpsdata", "dgpsid"}; 490 Collection<String> keys = n.keySet(); 491 for (String k : possibleKeys) { 492 if (keys.contains(k)) { 493 if (!found) { 494 found = true; 495 out.println(">"); 496 } 497 if (k.equals("link")) { 498 out.println(" <link>"); 499 out.println(" <text>"+XmlWriter.encode(n.get(k))+"</text>"); 500 out.println(" </link>"); 501 } else 502 out.println(" <"+k+">"+XmlWriter.encode(n.get(k))+"</"+k+">"); 503 } 504 } 505 if (found) 506 out.println(wpt?" </wpt>":" </trkpt>"); 507 else 508 out.println(" />"); 509 } 320 510 } -
src/org/openstreetmap/josm/io/OsmServerReader.java
r75 r78 11 11 import org.jdom.JDOMException; 12 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.data.coor.LatLon;14 13 import org.openstreetmap.josm.data.osm.DataSet; 14 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer.GpsPoint; 15 15 import org.xml.sax.SAXException; 16 16 … … 47 47 * ways. 48 48 */ 49 public Collection<Collection< LatLon>> parseRawGps() throws IOException, JDOMException {49 public Collection<Collection<GpsPoint>> parseRawGps() throws IOException, JDOMException { 50 50 String url = Main.pref.get("osm-server.url")+"/0.3/trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page="; 51 Collection<Collection< LatLon>> data = new LinkedList<Collection<LatLon>>();52 Collection< LatLon> list = new LinkedList<LatLon>();51 Collection<Collection<GpsPoint>> data = new LinkedList<Collection<GpsPoint>>(); 52 Collection<GpsPoint> list = new LinkedList<GpsPoint>(); 53 53 54 54 for (int i = 0;;++i) { … … 57 57 break; 58 58 RawGpsReader gpsReader = new RawGpsReader(r); 59 Collection<Collection< LatLon>> allWays = gpsReader.parse();59 Collection<Collection<GpsPoint>> allWays = gpsReader.parse(); 60 60 boolean foundSomething = false; 61 for (Collection< LatLon> t : allWays) {61 for (Collection<GpsPoint> t : allWays) { 62 62 if (!t.isEmpty()) { 63 63 foundSomething = true; -
src/org/openstreetmap/josm/io/OsmServerWriter.java
r75 r78 66 66 public void visit(Node n) { 67 67 if (n.id == 0 && !n.isDeleted()) { 68 n.put("created_by", "JOSM");69 68 sendRequest("PUT", "node", n, true); 70 69 } else if (n.isDeleted()) { … … 81 80 public void visit(LineSegment ls) { 82 81 if (ls.id == 0 && !ls.isDeleted()) { 83 ls.put("created_by", "JOSM");84 82 sendRequest("PUT", "segment", ls, true); 85 83 } else if (ls.isDeleted()) { … … 96 94 public void visit(Way w) { 97 95 if (w.id == 0 && !w.isDeleted()) { 98 w.put("created_by", "JOSM");99 96 sendRequest("PUT", "way", w, true); 100 97 } else if (w.isDeleted()) { -
src/org/openstreetmap/josm/io/RawCsvReader.java
r74 r78 12 12 import org.openstreetmap.josm.Main; 13 13 import org.openstreetmap.josm.data.coor.LatLon; 14 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer.GpsPoint; 14 15 15 16 /** … … 28 29 } 29 30 30 public Collection< LatLon> parse() throws JDOMException, IOException {31 Collection< LatLon> data = new LinkedList<LatLon>();31 public Collection<GpsPoint> parse() throws JDOMException, IOException { 32 Collection<GpsPoint> data = new LinkedList<GpsPoint>(); 32 33 String formatStr = Main.pref.get("csvImportString"); 33 34 if (formatStr == null) … … 63 64 StringTokenizer st = new StringTokenizer(line, delim); 64 65 double lat = 0, lon = 0; 66 String time = null; 65 67 for (String token : format) { 66 68 if (token.equals("lat")) … … 68 70 else if (token.equals("lon")) 69 71 lon = Double.parseDouble(st.nextToken()); 72 else if (token.equals("time")) 73 time = (time == null?"":(time+" ")) + st.nextToken(); 70 74 else if (token.equals("ignore")) 71 75 st.nextToken(); … … 73 77 throw new JDOMException("Unknown data type: '"+token+"'."+(Main.pref.get("csvImportString").equals("") ? " Maybe add an format string in preferences." : "")); 74 78 } 75 data.add(new LatLon(lat, lon));79 data.add(new GpsPoint(new LatLon(lat, lon), time)); 76 80 } 77 81 } catch (RuntimeException e) { -
src/org/openstreetmap/josm/io/RawGpsReader.java
r71 r78 5 5 import java.util.Collection; 6 6 import java.util.LinkedList; 7 import java.util.List;8 7 9 8 import org.jdom.Element; … … 12 11 import org.jdom.input.SAXBuilder; 13 12 import org.openstreetmap.josm.data.coor.LatLon; 13 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer.GpsPoint; 14 14 15 15 /** … … 42 42 * Parse and return the read data 43 43 */ 44 public Collection<Collection< LatLon>> parse() throws JDOMException, IOException {44 public Collection<Collection<GpsPoint>> parse() throws JDOMException, IOException { 45 45 final SAXBuilder builder = new SAXBuilder(); 46 46 builder.setValidation(false); … … 55 55 */ 56 56 @SuppressWarnings("unchecked") 57 private Collection<Collection< LatLon>> parseData(Element root) throws JDOMException {58 Collection<Collection< LatLon>> data = new LinkedList<Collection<LatLon>>();57 private Collection<Collection<GpsPoint>> parseData(Element root) throws JDOMException { 58 Collection<Collection<GpsPoint>> data = new LinkedList<Collection<GpsPoint>>(); 59 59 60 60 // workaround for bug where the server adds /gpx.asd to the namespace … … 62 62 63 63 for (Object o : root.getChildren("wpt", GPX)) { 64 Collection<LatLon> line = new LinkedList<LatLon>(); 65 line.add(new LatLon(parseDouble((Element)o, LatLonAttr.lat), parseDouble((Element)o, LatLonAttr.lon))); 64 Collection<GpsPoint> line = new LinkedList<GpsPoint>(); 65 line.add(new GpsPoint( 66 new LatLon(parseDouble((Element)o, LatLonAttr.lat), parseDouble((Element)o, LatLonAttr.lon)), 67 ((Element)o).getChildText("time", GPX))); 66 68 data.add(line); 67 }68 for (Object o : root.getChildren("rte", GPX)) {69 Collection<LatLon> line = parseLine(((Element)o).getChildren("rtept", GPX));70 if (!line.isEmpty())71 data.add(line);72 69 } 73 70 for (Object o : root.getChildren("trk", GPX)) { 74 71 for (Object seg : ((Element)o).getChildren("trkseg", GPX)) { 75 Collection<LatLon> line = parseLine(((Element)seg).getChildren("trkpt", GPX)); 72 Collection<GpsPoint> data1 = new LinkedList<GpsPoint>(); 73 for (Object trkObj : ((Element)seg).getChildren("trkpt", GPX)) { 74 data1.add(new GpsPoint( 75 new LatLon(parseDouble((Element)trkObj, LatLonAttr.lat), parseDouble((Element)trkObj, LatLonAttr.lon)), 76 ((Element)trkObj).getChildText("time", GPX))); 77 } 78 Collection<GpsPoint> line = data1; 76 79 if (!line.isEmpty()) 77 80 data.add(line); … … 94 97 return d; 95 98 } 96 97 /**98 * Parse the list of waypoint - elements and return a collection with the99 * points read.100 */101 private Collection<LatLon> parseLine(List<Element> wpt) throws JDOMException {102 Collection<LatLon> data = new LinkedList<LatLon>();103 for (Element e : wpt)104 data.add(new LatLon(parseDouble(e, LatLonAttr.lat), parseDouble(e, LatLonAttr.lon)));105 return data;106 }107 99 }
Note:
See TracChangeset
for help on using the changeset viewer.