- Timestamp:
- 2005-10-04T20:14:54+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/SaveGpxAction.java
r1 r10 4 4 import java.awt.event.KeyEvent; 5 5 import java.io.File; 6 import java.io.FileWriter; 7 import java.io.IOException; 6 8 7 9 import javax.swing.AbstractAction; 8 10 import javax.swing.ImageIcon; 9 11 import javax.swing.JFileChooser; 12 import javax.swing.JOptionPane; 10 13 11 14 import org.openstreetmap.josm.gui.Main; 15 import org.openstreetmap.josm.io.GpxWriter; 12 16 13 17 /** … … 29 33 30 34 @SuppressWarnings("unchecked") 31 public void actionPerformed(ActionEvent e) { 35 public void actionPerformed(ActionEvent event) { 36 if (Main.main.getMapFrame() == null) { 37 JOptionPane.showMessageDialog(Main.main, "No document open so nothing to save."); 38 return; 39 } 32 40 JFileChooser fc = new JFileChooser("data"); 33 41 fc.showSaveDialog(Main.main); … … 35 43 if (gpxFile == null) 36 44 return; 45 46 try { 47 FileWriter fileWriter = new FileWriter(gpxFile); 48 GpxWriter out = new GpxWriter(fileWriter, Main.main.getMapFrame().mapView.dataSet); 49 out.output(); 50 fileWriter.close(); 51 } catch (IOException e) { 52 e.printStackTrace(); 53 JOptionPane.showMessageDialog(Main.main, "An error occoured while saving.\n"+e.getMessage()); 54 } 37 55 } 38 56 -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r9 r10 66 66 return true; 67 67 } 68 68 69 69 /** 70 70 * Mark the primitive as selected or not selected and fires a selection -
src/org/openstreetmap/josm/io/GpxReader.java
r9 r10 92 92 93 93 /** 94 * Read a data set from the element. 95 * @param e The element to parse 96 * @return The DataSet read from the element 97 */ 98 private DataSet parseDataSet(Element e) { 99 DataSet data = new DataSet(); 100 // read waypoints not contained in tracks or areas 101 for (Object o : e.getChildren("wpt", GPX)) 102 addNode(data, parseWaypoint((Element)o)); 103 104 // read tracks 105 for (Object trackElement : e.getChildren("trk", GPX)) 106 parseTrack((Element)trackElement, data); 107 108 return data; 109 } 110 111 /** 112 * Parse and read a track from the element. Store it in the dataSet, as well 113 * as all nodes in it. 114 * 115 * @param e The element that contain the track. 116 * @param ds The DataSet to store the data in. 117 */ 118 private void parseTrack(Element e, DataSet ds) { 119 Track track = new Track(); 120 for (Object o : e.getChildren()) { 121 Element child = (Element)o; 122 if (child.getName().equals("extensions")) 123 parseKeyValueExtensions(track, child); 124 else if (child.getName().equals("link")) 125 parseKeyValueLink(track, child); 126 else if (child.getName().equals("trkseg")) { 127 Node start = null; 128 for (Object w : child.getChildren("trkpt", GPX)) { 129 Node node = parseWaypoint((Element)w); 130 node = addNode(ds, node); 131 if (start == null) 132 start = node; 133 else { 134 LineSegment lineSegment = new LineSegment(start, node); 135 parseKeyValueExtensions(lineSegment, ((Element)w).getChild("extensions", GPX)); 136 track.add(lineSegment); 137 start = null; 138 } 139 } 140 } else 141 parseKeyValueTag(track, child); 142 } 143 ds.addTrack(track); 144 } 145 146 147 /** 148 * Adds the node to allNodes if it is not already listed. Does respect the 149 * preference setting "mergeNodes". Return the node in the list that correspond 150 * to the node in the list (either the new added or the old found). 151 * 152 * @param data The DataSet to add the node to. 153 * @param node The node that should be added. 154 * @return Either the parameter node or the old node found in the dataset. 155 */ 156 private Node addNode (DataSet data, Node node) { 157 if (Main.pref.mergeNodes) 158 for (Node n : data.nodes) 159 if (node.coor.lat == n.coor.lat && node.coor.lon == n.coor.lon) 160 return n; 161 data.nodes.add(node); 162 return node; 163 } 164 165 /** 94 166 * Parse the extensions tag and add all properties found as key/value. 95 167 * <code>osm.keys</code> may be <code>null</code>, in which case it is … … 138 210 * The format stored is: mimetype;url 139 211 * Example: text/html;http://www.openstreetmap.org 212 * 140 213 * @param osm The osm primitive to store the data in. 141 214 * @param e The element in gpx:linkType - format. 142 215 */ 143 private void parseKeyValueLink( Node osm, Element e) {216 private void parseKeyValueLink(OsmPrimitive osm, Element e) { 144 217 if (e != null) { 145 218 if (osm.keys == null) … … 149 222 } 150 223 } 151 152 /**153 * Read a data set from the element.154 * @param e The element to parse155 * @return The DataSet read from the element156 */157 private DataSet parseDataSet(Element e) {158 DataSet data = new DataSet();159 // read waypoints not contained in tracks or areas160 for (Object o : e.getChildren("wpt", GPX))161 addNode(data, parseWaypoint((Element)o));162 163 // read tracks164 for (Object trackElement : e.getChildren("trk", GPX)) {165 Track track = new Track();166 for (Object trackSegmentElement : ((Element)trackElement).getChildren("trkseg", GPX)) {167 Node start = null;168 for (Object w : ((Element)trackSegmentElement).getChildren("trkpt", GPX)) {169 Node node = parseWaypoint((Element)w);170 node = addNode(data, node);171 if (start == null)172 start = node;173 else {174 LineSegment lineSegment = new LineSegment(start, node);175 track.add(lineSegment);176 start = null;177 }178 }179 }180 data.addTrack(track);181 }182 183 return data;184 }185 186 /**187 * Adds the node to allNodes if it is not already listed. Does respect the188 * preference setting "mergeNodes". Return the node in the list that correspond189 * to the node in the list (either the new added or the old found).190 *191 * @param data The DataSet to add the node to.192 * @param node The node that should be added.193 * @return Either the parameter node or the old node found in the dataset.194 */195 private Node addNode (DataSet data, Node node) {196 if (Main.pref.mergeNodes)197 for (Node n : data.nodes)198 if (node.coor.lat == n.coor.lat && node.coor.lon == n.coor.lon)199 return n;200 data.nodes.add(node);201 return node;202 }203 224 }
Note:
See TracChangeset
for help on using the changeset viewer.