Changeset 29 in josm
- Timestamp:
- 2005-12-02T07:40:16+01:00 (19 years ago)
- Files:
-
- 2 added
- 10 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r24 r29 16 16 import org.openstreetmap.josm.actions.AboutAction; 17 17 import org.openstreetmap.josm.actions.ExitAction; 18 import org.openstreetmap.josm.actions.Open GpxAction;18 import org.openstreetmap.josm.actions.OpenAction; 19 19 import org.openstreetmap.josm.actions.OpenOsmServerAction; 20 20 import org.openstreetmap.josm.actions.PreferencesAction; 21 21 import org.openstreetmap.josm.actions.SaveAction; 22 22 import org.openstreetmap.josm.actions.SaveGpxAction; 23 import org.openstreetmap.josm.actions.UndoAction; 23 24 import org.openstreetmap.josm.data.Preferences; 24 25 import org.openstreetmap.josm.data.Preferences.PreferencesException; … … 76 77 // creating actions 77 78 OpenOsmServerAction openServerAction = new OpenOsmServerAction(); 78 Open GpxAction openGpxAction = new OpenGpxAction();79 OpenAction openAction = new OpenAction(); 79 80 SaveAction saveAction = new SaveAction(); 80 81 SaveGpxAction saveGpxAction = new SaveGpxAction(); 81 82 ExitAction exitAction = new ExitAction(); 83 UndoAction undoAction = new UndoAction(); 82 84 PreferencesAction preferencesAction = new PreferencesAction(); 83 85 AboutAction aboutAction = new AboutAction(); … … 89 91 JMenu fileMenu = new JMenu("Files"); 90 92 fileMenu.setMnemonic('F'); 91 fileMenu.add(open GpxAction);93 fileMenu.add(openAction); 92 94 fileMenu.add(saveAction); 93 95 fileMenu.add(saveGpxAction); … … 95 97 fileMenu.add(exitAction); 96 98 mainMenu.add(fileMenu); 99 97 100 98 101 JMenu connectionMenu = new JMenu("Connection"); … … 103 106 JMenu editMenu = new JMenu("Edit"); 104 107 editMenu.setMnemonic('E'); 108 //editMenu.add(undoAction); 109 editMenu.addSeparator(); 105 110 editMenu.add(preferencesAction); 106 111 mainMenu.add(editMenu); … … 116 121 toolBar.setFloatable(false); 117 122 toolBar.add(openServerAction); 118 toolBar.add(open GpxAction);123 toolBar.add(openAction); 119 124 toolBar.add(saveAction); 120 125 toolBar.add(saveGpxAction); 126 toolBar.addSeparator(); 127 //toolBar.add(undoAction); 121 128 toolBar.addSeparator(); 122 129 toolBar.add(preferencesAction); -
src/org/openstreetmap/josm/actions/OpenAction.java
r27 r29 32 32 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer; 33 33 import org.openstreetmap.josm.io.GpxReader; 34 import org.openstreetmap.josm.io.OsmReader; 34 35 import org.openstreetmap.josm.io.RawGpsReader; 35 36 … … 40 41 * @author imi 41 42 */ 42 public class Open GpxAction extends AbstractAction {43 public class OpenAction extends AbstractAction { 43 44 44 45 /** 45 46 * Create an open action. The name is "Open GPX". 46 47 */ 47 public OpenGpxAction() { 48 super("Open GPX", ImageProvider.get("opengpx")); 49 putValue(ACCELERATOR_KEY, KeyStroke.getAWTKeyStroke(KeyEvent.VK_O, 50 InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); 48 public OpenAction() { 49 super("Open", ImageProvider.get("open")); 50 putValue(ACCELERATOR_KEY, KeyStroke.getAWTKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK)); 51 51 putValue(MNEMONIC_KEY, KeyEvent.VK_O); 52 putValue(SHORT_DESCRIPTION, "Open a file in GPX format.");52 putValue(SHORT_DESCRIPTION, "Open a file."); 53 53 } 54 54 … … 68 68 // additional options 69 69 JCheckBox rawGps = new JCheckBox("Raw GPS data", true); 70 rawGps.setToolTipText("Check this, if the data are obtained from a gps device.");70 rawGps.setToolTipText("Check this, if the data were obtained from a gps device."); 71 71 JCheckBox newLayer = new JCheckBox("As Layer", true); 72 72 newLayer.setToolTipText("Open as a new layer or replace all current layers."); … … 86 86 return; 87 87 88 File gpxFile = fc.getSelectedFile();89 if ( gpxFile == null)88 File filename = fc.getSelectedFile(); 89 if (filename == null) 90 90 return; 91 91 92 92 try { 93 93 Layer layer; 94 94 if (rawGps.isSelected()) { 95 Collection<Collection<GeoPoint>> data = new RawGpsReader(new FileReader( gpxFile)).parse();96 layer = new RawGpsDataLayer(data, gpxFile.getName());95 Collection<Collection<GeoPoint>> data = new RawGpsReader(new FileReader(filename)).parse(); 96 layer = new RawGpsDataLayer(data, filename.getName()); 97 97 } else { 98 DataSet dataSet = new GpxReader(new FileReader(gpxFile)).parse(); 98 DataSet dataSet = filename.getName().toLowerCase().endsWith("gpx") ? 99 new GpxReader(new FileReader(filename)).parse() : 100 new OsmReader(new FileReader(filename)).parse(); 99 101 Collection<OsmPrimitive> l = Main.main.ds.mergeFrom(dataSet); 100 layer = new OsmDataLayer(l, gpxFile.getName());102 layer = new OsmDataLayer(l, filename.getName()); 101 103 } 102 104 103 105 if (Main.main.getMapFrame() == null || !newLayer.isSelected()) 104 Main.main.setMapFrame( gpxFile.getName(), new MapFrame(layer));106 Main.main.setMapFrame(filename.getName(), new MapFrame(layer)); 105 107 else 106 108 Main.main.getMapFrame().mapView.addLayer(layer); 107 109 108 110 } catch (JDOMException x) { 109 111 x.printStackTrace(); … … 111 113 } catch (IOException x) { 112 114 x.printStackTrace(); 113 JOptionPane.showMessageDialog(Main.main, "Could not read '"+ gpxFile.getName()+"'\n"+x.getMessage());115 JOptionPane.showMessageDialog(Main.main, "Could not read '"+filename.getName()+"'\n"+x.getMessage()); 114 116 } 115 117 } -
src/org/openstreetmap/josm/gui/MapView.java
r24 r29 141 141 for (LayerChangeListener l : listeners) 142 142 l.layerRemoved(layer); 143 if (layer == editLayer) 144 editLayer = null; 143 145 } 144 146 -
src/org/openstreetmap/josm/gui/dialogs/LayerList.java
r23 r29 24 24 25 25 import org.openstreetmap.josm.Main; 26 import org.openstreetmap.josm.data.osm.DataSet; 26 27 import org.openstreetmap.josm.gui.ImageProvider; 27 28 import org.openstreetmap.josm.gui.MapFrame; … … 154 155 if (model.size() == 1) { 155 156 Main.main.setMapFrame(null, null); 157 Main.main.ds = new DataSet(); 156 158 } else { 157 159 int sel = layers.getSelectedIndex(); -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r28 r29 13 13 import java.awt.event.WindowFocusListener; 14 14 import java.util.Collection; 15 import java.util.HashMap; 15 16 import java.util.Iterator; 16 17 import java.util.TreeMap; … … 292 293 data.setRowCount(0); 293 294 TreeMap<String, Collection<String>> props = new TreeMap<String, Collection<String>>(); 295 HashMap<String, Integer> valueCounts = new HashMap<String, Integer>(); 294 296 for (OsmPrimitive osm : newSelection) { 295 297 if (osm.keys != null) { … … 301 303 } 302 304 value.add(e.getValue()); 305 306 Integer count = valueCounts.get(e.getValue()); 307 if (count == null) 308 count = 0; 309 valueCounts.put(e.getValue(), count+1); 303 310 } 304 311 } 305 312 } 313 int selCount = newSelection.size(); 306 314 for (Entry<String, Collection<String>> e : props.entrySet()) { 307 315 JComboBox value = new JComboBox(e.getValue().toArray()); 308 316 value.setEditable(true); 309 if (e.getValue().size() > 1 )317 if (e.getValue().size() > 1 || valueCounts.get(e.getValue().iterator().next()) != selCount) 310 318 value.getEditor().setItem("<different>"); 311 319 data.addRow(new Object[]{e.getKey(), value}); -
src/org/openstreetmap/josm/gui/layer/EditLayer.java
r23 r29 42 42 * All commands that were made on the dataset. 43 43 */ 44 public Collection<Command> commands = new LinkedList<Command>();44 public LinkedList<Command> commands = new LinkedList<Command>(); 45 45 46 46 /** -
src/org/openstreetmap/josm/io/GpxReader.java
r24 r29 34 34 * The OSM namespace used (for extensions). 35 35 */ 36 private static final Namespace OSM = Namespace.getNamespace("osm" );36 private static final Namespace OSM = Namespace.getNamespace("osm", "http://www.openstreetmap.org"); 37 37 38 38 /** … … 115 115 private void parseTrack(Element e, DataSet ds) { 116 116 Track track = new Track(); 117 boolean pendingLS = false; // is this track just a fake? 118 117 119 for (Object o : e.getChildren()) { 118 120 Element child = (Element)o; … … 127 129 else { 128 130 LineSegment lineSegment = new LineSegment(start, node); 129 parseKeyValueExtensions(lineSegment, ((Element)w).getChild("extensions", GPX));131 parseKeyValueExtensions(lineSegment, child.getChild("extensions", GPX)); 130 132 track.add(lineSegment); 131 133 start = null; 132 134 } 133 135 } 134 } else if (child.getName().equals("extensions")) 136 } else if (child.getName().equals("extensions")) { 135 137 parseKeyValueExtensions(track, child); 136 else if (child.getName().equals("link")) 138 if (child.getChild("segment", OSM) != null) 139 pendingLS = true; 140 } else if (child.getName().equals("link")) 137 141 parseKeyValueLink(track, child); 138 142 else 139 143 parseKeyValueTag(track, child); 140 144 } 141 ds.tracks.add(track); 145 if (pendingLS && track.segments.size() == 1) 146 ds.pendingLineSegments.add(track.segments.get(0)); 147 else 148 ds.tracks.add(track); 142 149 } 143 150 … … 175 182 private void parseKeyValueExtensions(OsmPrimitive osm, Element e) { 176 183 if (e != null) { 177 if (osm.keys == null)178 osm.keys = new HashMap<Key, String>();179 184 for (Object o : e.getChildren("property", OSM)) { 185 if (osm.keys == null) 186 osm.keys = new HashMap<Key, String>(); 180 187 Element child = (Element)o; 181 Key key = Key.get(child.getAttributeValue("name")); 182 osm.keys.put(key, child.getAttributeValue("value")); 188 String keyname = child.getAttributeValue("key"); 189 if (keyname != null) { 190 Key key = Key.get(keyname); 191 String value = child.getAttributeValue("value"); 192 if (value == null) 193 value = ""; 194 osm.keys.put(key, value); 195 } 183 196 } 184 197 } -
src/org/openstreetmap/josm/io/GpxWriter.java
r25 r29 100 100 // line segments 101 101 for (LineSegment ls : t.segments) { 102 Element lsElem = new Element("trkseg", GPX); 103 if (ls.keys != null) 104 addPropertyExtensions(lsElem, ls.keys); 105 lsElem.getChildren().add(parseWaypoint(ls.start, "trkpt")); 106 lsElem.getChildren().add(parseWaypoint(ls.end, "trkpt")); 102 tElem.getChildren().add(parseLineSegment(ls)); 107 103 nodes.remove(ls.start); 108 104 nodes.remove(ls.end); 109 tElem.getChildren().add(lsElem);110 105 } 106 111 107 e.getChildren().add(tElem); 112 108 } 113 109 110 // encode pending line segments as tracks 111 for (LineSegment ls : Main.main.ds.pendingLineSegments) { 112 Element t = new Element("trk", GPX); 113 t.getChildren().add(parseLineSegment(ls)); 114 nodes.remove(ls.start); 115 nodes.remove(ls.end); 116 Element ext = new Element("extensions", GPX); 117 ext.getChildren().add(new Element("segment", OSM)); 118 t.getChildren().add(ext); 119 e.getChildren().add(t); 120 } 121 114 122 // waypoints (missing nodes) 115 123 for (Node n : nodes) … … 117 125 118 126 return e; 127 } 128 129 130 /** 131 * Parse a line segment and store it into a JDOM-Element. Return that element. 132 */ 133 @SuppressWarnings("unchecked") 134 private Element parseLineSegment(LineSegment ls) { 135 Element lsElem = new Element("trkseg", GPX); 136 if (ls.keys != null) 137 addPropertyExtensions(lsElem, ls.keys); 138 lsElem.getChildren().add(parseWaypoint(ls.start, "trkpt")); 139 lsElem.getChildren().add(parseWaypoint(ls.end, "trkpt")); 140 return lsElem; 119 141 } 120 142 … … 213 235 if (keys.isEmpty()) 214 236 return; 215 Element extensions = e.getChild("extensions" );237 Element extensions = e.getChild("extensions", GPX); 216 238 if (extensions == null) 217 239 e.getChildren().add(extensions = new Element("extensions", GPX)); -
src/org/openstreetmap/josm/io/OsmReader.java
r28 r29 47 47 Element root = builder.build(source).getRootElement(); 48 48 return parseDataSet(root); 49 } catch (NumberFormatException nfe) { 50 throw new JDOMException("NumberFormatException. Probably a tag is missing.", nfe); 49 51 } catch (NullPointerException npe) { 50 52 throw new JDOMException("NullPointerException. Probably a tag name mismatch.", npe); … … 96 98 String token = t.nextToken(); 97 99 if (!" ".equals(token)) 98 data.keys.put(Key.get(token), " yes");100 data.keys.put(Key.get(token), ""); 99 101 } 100 102 } -
src/org/openstreetmap/josm/io/OsmServerReader.java
r27 r29 49 49 */ 50 50 public Collection<Collection<GeoPoint>> parseRawGps() throws IOException, JDOMException { 51 String url = urlStr+"trackpoints?bbox="+l at1+","+lon1+","+lat2+","+lon2+"&page=";51 String url = urlStr+"trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page="; 52 52 Collection<Collection<GeoPoint>> data = new LinkedList<Collection<GeoPoint>>(); 53 53 Collection<GeoPoint> list = new LinkedList<GeoPoint>(); -
src/org/openstreetmap/josm/io/RawGpsReader.java
r23 r29 9 9 import org.jdom.Element; 10 10 import org.jdom.JDOMException; 11 import org.jdom.Namespace; 11 12 import org.jdom.input.SAXBuilder; 12 13 import org.openstreetmap.josm.data.GeoPoint; … … 34 35 35 36 /** 37 * The gpx namespace. 38 */ 39 private Namespace GPX = Namespace.getNamespace("http://www.topografix.com/GPX/1/0"); 40 41 /** 36 42 * Parse and return the read data 37 43 */ … … 52 58 Collection<Collection<GeoPoint>> data = new LinkedList<Collection<GeoPoint>>(); 53 59 54 for (Object o : root.getChildren("wpt", GpxReader.GPX)) { 60 // workaround for bug where the server adds /gpx.asd to the namespace 61 GPX = Namespace.getNamespace(root.getNamespaceURI()); 62 63 for (Object o : root.getChildren("wpt", GPX)) { 55 64 Collection<GeoPoint> line = new LinkedList<GeoPoint>(); 56 65 line.add(new GeoPoint( … … 59 68 data.add(line); 60 69 } 61 for (Object o : root.getChildren("rte", G pxReader.GPX)) {62 Collection<GeoPoint> line = parseLine(((Element)o).getChildren("rtept", G pxReader.GPX));70 for (Object o : root.getChildren("rte", GPX)) { 71 Collection<GeoPoint> line = parseLine(((Element)o).getChildren("rtept", GPX)); 63 72 if (!line.isEmpty()) 64 73 data.add(line); 65 74 } 66 for (Object o : root.getChildren("trk", G pxReader.GPX)) {67 for (Object seg : ((Element)o).getChildren("trkseg", G pxReader.GPX)) {68 Collection<GeoPoint> line = parseLine(((Element)seg).getChildren("trkpt", G pxReader.GPX));75 for (Object o : root.getChildren("trk", GPX)) { 76 for (Object seg : ((Element)o).getChildren("trkseg", GPX)) { 77 Collection<GeoPoint> line = parseLine(((Element)seg).getChildren("trkpt", GPX)); 69 78 if (!line.isEmpty()) 70 79 data.add(line);
Note:
See TracChangeset
for help on using the changeset viewer.