- Timestamp:
- 2006-05-03T22:21:02+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r100 r101 37 37 import org.openstreetmap.josm.actions.UndoAction; 38 38 import org.openstreetmap.josm.actions.UploadAction; 39 import org.openstreetmap.josm.actions.mapmode.MapMode; 39 40 import org.openstreetmap.josm.data.Bounds; 40 41 import org.openstreetmap.josm.data.Preferences; … … 186 187 final MapFrame mapFrame = new MapFrame(layer); 187 188 setMapFrame(mapFrame); 189 mapFrame.selectMapMode((MapMode)mapFrame.getDefaultButtonAction()); 188 190 mapFrame.setVisible(true); 189 191 mapFrame.setVisibleDialogs(); -
src/org/openstreetmap/josm/actions/DownloadAction.java
r100 r101 135 135 136 136 public void actionPerformed(ActionEvent e) { 137 String osmDataServer = Main.pref.get("osm-server.url");138 //TODO: Remove this in later versions (temporary only)139 if (osmDataServer.endsWith("/0.2") || osmDataServer.endsWith("/0.2/")) {140 int answer = JOptionPane.showConfirmDialog(Main.parent,141 "You seem to have an outdated server entry in your preferences.\n" +142 "\n" +143 "As of JOSM Release 1.2, you must no longer specify the API version in\n" +144 "the osm url. For the OSM standard server, use http://www.openstreetmap.org/api" +145 "\n" +146 "Fix settings and continue?", "Outdated server url detected.", JOptionPane.YES_NO_OPTION);147 if (answer != JOptionPane.YES_OPTION)148 return;149 int cutPos = osmDataServer.endsWith("/0.2") ? 4 : 5;150 Main.pref.put("osm-server.url", osmDataServer.substring(0, osmDataServer.length()-cutPos));151 }152 153 137 JPanel dlg = new JPanel(new GridBagLayout()); 154 138 -
src/org/openstreetmap/josm/actions/GroupAction.java
r99 r101 45 45 46 46 this.current = current; 47 putValue(SMALL_ICON, ImageProvider.overlay((Icon)actions.get(current).getValue(SMALL_ICON), "right", OverlayPosition.SOUTHEAST)); 47 putValue(SMALL_ICON, ImageProvider.overlay((Icon)actions.get(current).getValue(SMALL_ICON), "overlay/right", OverlayPosition.SOUTHEAST)); 48 48 Object tooltip = actions.get(current).getValue(SHORT_DESCRIPTION); 49 49 putValue(SHORT_DESCRIPTION, "<html>"+tooltip+" <font size='-2'>"+shortCutName+"</font> </html>"); -
src/org/openstreetmap/josm/actions/OpenAction.java
r99 r101 75 75 try { 76 76 // temporary allow loading of old xml format. 77 dataSet = OsmReader.parseDataSet(new FileReader(filename)); 77 dataSet = OsmReader.parseDataSet(new FileReader(filename), null, null); 78 78 } catch (SAXException x) { 79 79 if (x.getMessage().equals("Unknown version null")) { -
src/org/openstreetmap/josm/actions/UploadAction.java
r99 r101 44 44 } 45 45 46 String osmDataServer = Main.pref.get("osm-server.url");47 //TODO: Remove this in later versions (temporary only)48 if (osmDataServer.endsWith("/0.2") || osmDataServer.endsWith("/0.2/")) {49 int answer = JOptionPane.showConfirmDialog(Main.parent,50 "You seem to have an outdated server entry in your preferences.\n" +51 "\n" +52 "As of JOSM Release 1.2, you must no longer specify the API version in\n" +53 "the osm url. For the OSM standard server, use http://www.openstreetmap.org/api" +54 "\n" +55 "Fix settings and continue?", "Outdated server url detected.", JOptionPane.YES_NO_OPTION);56 if (answer != JOptionPane.YES_OPTION)57 return;58 int cutPos = osmDataServer.endsWith("/0.2") ? 4 : 5;59 Main.pref.put("osm-server.url", osmDataServer.substring(0, osmDataServer.length()-cutPos));60 }61 62 46 if (!Main.map.conflictDialog.conflicts.isEmpty()) { 63 47 JOptionPane.showMessageDialog(Main.parent, "There are unresolved conflicts. You have to resolve these first."); -
src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java
r100 r101 21 21 import org.openstreetmap.josm.data.osm.Way; 22 22 import org.openstreetmap.josm.gui.MapFrame; 23 import org.openstreetmap.josm.tools.ImageProvider; 23 24 24 25 /** … … 47 48 48 49 public AddNodeAction(MapFrame mapFrame, String name, Mode mode, String desc) { 49 super(name, "node/"+mode, desc, mapFrame); 50 super(name, "node/"+mode, desc, mapFrame, ImageProvider.getCursor("crosshair", "node")); 50 51 this.mode = mode; 51 52 } -
src/org/openstreetmap/josm/actions/mapmode/AddSegmentAction.java
r98 r101 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 16 import org.openstreetmap.josm.gui.MapFrame; 17 import org.openstreetmap.josm.tools.ImageProvider; 17 18 18 19 /** … … 46 47 */ 47 48 public AddSegmentAction(MapFrame mapFrame) { 48 super("Add segment", "addsegment", "Add a segment between two nodes.", "G", KeyEvent.VK_G, mapFrame); 49 super("Add segment", 50 "addsegment", 51 "Add a segment between two nodes.", 52 "G", 53 KeyEvent.VK_G, 54 mapFrame, 55 ImageProvider.getCursor("normal", "segment")); 49 56 } 50 57 -
src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java
r100 r101 20 20 import org.openstreetmap.josm.data.osm.Way; 21 21 import org.openstreetmap.josm.gui.MapFrame; 22 import org.openstreetmap.josm.tools.ImageProvider; 22 23 23 24 /** … … 56 57 */ 57 58 public AddWayAction(MapFrame mapFrame) { 58 super("Add Way", "addway", "Add a new way to the data.", "W", KeyEvent.VK_W, mapFrame); 59 super("Add Way", "addway", "Add a new way to the data.", "W", KeyEvent.VK_W, mapFrame, ImageProvider.getCursor("normal", "way")); 59 60 60 61 Main.ds.addSelectionChangedListener(this); -
src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r100 r101 24 24 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 25 25 import org.openstreetmap.josm.gui.MapFrame; 26 import org.openstreetmap.josm.tools.ImageProvider; 26 27 27 28 /** … … 50 51 */ 51 52 public DeleteAction(MapFrame mapFrame) { 52 super("Delete", "delete", "Delete nodes, streets or segments.", "Delete", KeyEvent.VK_DELETE, mapFrame); 53 super("Delete", 54 "delete", 55 "Delete nodes, streets or segments.", 56 "D", 57 KeyEvent.VK_D, 58 mapFrame, 59 ImageProvider.getCursor("normal", "delete")); 53 60 } 54 61 -
src/org/openstreetmap/josm/actions/mapmode/MapMode.java
r98 r101 1 1 package org.openstreetmap.josm.actions.mapmode; 2 2 3 import java.awt.Cursor; 3 4 import java.awt.event.ActionEvent; 4 5 import java.awt.event.MouseEvent; … … 23 24 abstract public class MapMode extends JosmAction implements MouseListener, MouseMotionListener { 24 25 26 // private final Cursor cursor; 27 // private Cursor oldCursor; 28 25 29 /** 26 30 * Constructor for mapmodes without an menu 27 31 */ 28 public MapMode(String name, String iconName, String tooltip, String keyname, int keystroke, MapFrame mapFrame) { 32 public MapMode(String name, String iconName, String tooltip, String keyname, int keystroke, MapFrame mapFrame, Cursor cursor) { 29 33 super(name, "mapmode/"+iconName, tooltip, keyname, KeyStroke.getKeyStroke(keystroke, 0)); 34 // this.cursor = cursor; 30 35 putValue("active", false); 31 36 } … … 34 39 * Constructor for mapmodes with an menu (no shortcut will be registered) 35 40 */ 36 public MapMode(String name, String iconName, String tooltip, MapFrame mapFrame) { 41 public MapMode(String name, String iconName, String tooltip, MapFrame mapFrame, Cursor cursor) { 37 42 putValue(NAME, name); 38 43 putValue(SMALL_ICON, ImageProvider.get("mapmode", iconName)); 39 44 putValue(SHORT_DESCRIPTION, tooltip); 45 // this.cursor = cursor; 40 46 } 41 47 42 48 public void enterMode() { 43 49 putValue("active", true); 50 // oldCursor = Main.map.mapView.getCursor(); 51 // Main.map.mapView.setCursor(cursor); 52 44 53 } 45 54 public void exitMode() { 46 55 putValue("active", false); 56 // Main.map.mapView.setCursor(oldCursor); 47 57 } 48 58 -
src/org/openstreetmap/josm/actions/mapmode/MoveAction.java
r98 r101 17 17 import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor; 18 18 import org.openstreetmap.josm.gui.MapFrame; 19 import org.openstreetmap.josm.tools.ImageProvider; 19 20 20 21 /** … … 48 49 */ 49 50 public MoveAction(MapFrame mapFrame) { 50 super("Move", "move", "Move selected objects around.", "M", KeyEvent.VK_M, mapFrame); 51 super("Move", 52 "move", 53 "Move selected objects around.", 54 "M", 55 KeyEvent.VK_M, 56 mapFrame, 57 ImageProvider.getCursor("normal", "move")); 51 58 } 52 59 -
src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java
r98 r101 11 11 import org.openstreetmap.josm.gui.SelectionManager; 12 12 import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded; 13 import org.openstreetmap.josm.tools.ImageProvider; 13 14 14 15 /** … … 64 65 */ 65 66 public SelectionAction(MapFrame mapFrame) { 66 super("Selection", "selection", "Select objects by dragging or clicking.", "S", KeyEvent.VK_S, mapFrame); 67 super("Selection", 68 "selection", 69 "Select objects by dragging or clicking.", 70 "S", 71 KeyEvent.VK_S, 72 mapFrame, 73 ImageProvider.getCursor("normal", "selection")); 67 74 this.selectionManager = new SelectionManager(this, false, mapFrame.mapView); 68 75 } -
src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java
r94 r101 9 9 import org.openstreetmap.josm.gui.SelectionManager; 10 10 import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded; 11 import org.openstreetmap.josm.tools.ImageProvider; 11 12 12 13 /** … … 41 42 */ 42 43 public ZoomAction(MapFrame mapFrame) { 43 super("Zoom", "zoom", "Zoom in by dragging.", "Z", KeyEvent.VK_Z, mapFrame); 44 super("Zoom", "zoom", "Zoom in by dragging. (Ctrl+up,left,down,right,+,-)", "Z", KeyEvent.VK_Z, mapFrame, ImageProvider.getCursor("normal", "zoom")); 44 45 mv = mapFrame.mapView; 45 46 selectionManager = new SelectionManager(this, true, mv); -
src/org/openstreetmap/josm/data/ServerSidePreferences.java
r98 r101 1 1 package org.openstreetmap.josm.data; 2 2 3 import java.io.IOException;4 3 import java.net.URL; 5 4 … … 24 23 } 25 24 26 @Override public void load() throws IOException{25 @Override public void load() { 27 26 resetToDefault(); 28 27 } -
src/org/openstreetmap/josm/gui/MapFrame.java
r99 r101 10 10 11 11 import javax.swing.AbstractButton; 12 import javax.swing.Action; 12 13 import javax.swing.BoxLayout; 13 14 import javax.swing.ButtonGroup; … … 92 93 toolGroup.add((AbstractButton)c); 93 94 toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true); 94 selectMapMode((MapMode)((AbstractButton)toolBarActions.getComponent(0)).getAction());95 95 96 96 // autoScale … … 128 128 statusLine = new MapStatus(this); 129 129 } 130 131 public Action getDefaultButtonAction() { 132 return ((AbstractButton)toolBarActions.getComponent(0)).getAction(); 133 } 130 134 131 135 /** -
src/org/openstreetmap/josm/gui/MapMover.java
r100 r101 2 2 3 3 import java.awt.Cursor; 4 import java.awt.event.ActionEvent; 5 import java.awt.event.KeyEvent; 4 6 import java.awt.event.MouseAdapter; 5 7 import java.awt.event.MouseEvent; … … 8 10 import java.awt.event.MouseWheelListener; 9 11 12 import javax.swing.AbstractAction; 13 import javax.swing.JComponent; 14 import javax.swing.KeyStroke; 15 16 import org.openstreetmap.josm.Main; 10 17 import org.openstreetmap.josm.data.coor.EastNorth; 11 18 … … 17 24 */ 18 25 class MapMover extends MouseAdapter implements MouseMotionListener, MouseWheelListener { 26 27 private final class ZoomerAction extends AbstractAction { 28 private final String action; 29 public ZoomerAction(String action) { 30 this.action = action; 31 } 32 public void actionPerformed(ActionEvent e) { 33 if (action.equals("+") || action.equals("-")) { 34 MouseWheelEvent we = new MouseWheelEvent(nc, e.getID(), e.getWhen(), e.getModifiers(), nc.getMousePosition().x, nc.getMousePosition().y, 0, false, MouseWheelEvent.WHEEL_UNIT_SCROLL, 1, action.equals("+") ? -1 : 1); 35 mouseWheelMoved(we); 36 } else { 37 EastNorth center = nc.getCenter(); 38 EastNorth newcenter = nc.getEastNorth(nc.getWidth()/2+nc.getWidth()/5, nc.getHeight()/2+nc.getHeight()/5); 39 if (action.equals("left")) 40 nc.zoomTo(new EastNorth(2*center.east()-newcenter.east(), center.north()), nc.getScale()); 41 else if (action.equals("right")) 42 nc.zoomTo(new EastNorth(newcenter.east(), center.north()), nc.getScale()); 43 else if (action.equals("up")) 44 nc.zoomTo(new EastNorth(center.east(), 2*center.north()-newcenter.north()), nc.getScale()); 45 else if (action.equals("down")) 46 nc.zoomTo(new EastNorth(center.east(), newcenter.north()), nc.getScale()); 47 } 48 } 49 } 19 50 20 51 /** … … 33 64 34 65 private boolean movementInPlace = false; 35 66 36 67 /** 37 68 * Create a new MapMover … … 42 73 nc.addMouseMotionListener(this); 43 74 nc.addMouseWheelListener(this); 75 76 String[] n = {"+","-","up","right","down","left"}; 77 int[] k = {KeyEvent.VK_PLUS, KeyEvent.VK_MINUS, KeyEvent.VK_UP, KeyEvent.VK_RIGHT, KeyEvent.VK_DOWN, KeyEvent.VK_LEFT}; 78 79 for (int i = 0; i < n.length; ++i) { 80 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(k[i], KeyEvent.CTRL_DOWN_MASK), "MapMover.Zoomer."+n[i]); 81 Main.contentPane.getActionMap().put("MapMover.Zoomer."+n[i], new ZoomerAction(n[i])); 82 } 44 83 } 45 84 46 85 /** 47 86 * If the right (and only the right) mouse button is pressed, move the map … … 92 131 nc.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 93 132 } 94 133 95 134 /** 96 135 * End the movement. Setting back the cursor and clear the movement variables … … 124 163 double centery = e.getY() - (e.getY()-h/2)*newHalfHeight*2/h; 125 164 EastNorth newCenter = nc.getEastNorth((int)centerx, (int)centery); 126 165 127 166 nc.zoomTo(newCenter, nc.getScale()*zoom); 128 167 } -
src/org/openstreetmap/josm/gui/MapView.java
r100 r101 84 84 private final AutoScaleAction autoScaleAction; 85 85 86 86 87 87 private final class Scaler extends JSlider implements PropertyChangeListener, ChangeListener { 88 88 boolean clicked = false; … … 91 91 addMouseListener(new MouseAdapter(){ 92 92 @Override public void mousePressed(MouseEvent e) { 93 94 93 clicked = true; 94 } 95 95 @Override public void mouseReleased(MouseEvent e) { 96 97 96 clicked = false; 97 } 98 98 }); 99 MapView.this.addPropertyChangeListener(this); 99 MapView.this.addPropertyChangeListener("scale", this); 100 100 addChangeListener(this); 101 101 } 102 102 public void propertyChange(PropertyChangeEvent evt) { 103 if ( evt.getPropertyName().equals("scale") &&!getModel().getValueIsAdjusting())103 if (!getModel().getValueIsAdjusting()) 104 104 setValue(zoom()); 105 105 } 106 106 public void stateChanged(ChangeEvent e) { 107 107 if (!clicked) … … 114 114 else 115 115 zoomTo(center, pos.north()*2/(MapView.this.getHeight()-20)); 116 117 } 118 116 } 117 } 118 119 119 public MapView(AutoScaleAction autoScaleAction) { 120 120 this.autoScaleAction = autoScaleAction; … … 154 154 Main.ds = dataLayer.data; 155 155 dataLayer.listenerModified.add(new ModifiedChangedListener(){ 156 157 158 159 156 public void modifiedChanged(boolean value, OsmDataLayer source) { 157 JOptionPane.getFrameForComponent(Main.parent).setTitle((value?"*":"")+"Java Open Street Map - Editor"); 158 } 159 }); 160 160 } 161 161 -
src/org/openstreetmap/josm/gui/dialogs/LayerList.java
r100 r101 128 128 Icon icon = layer.getIcon(); 129 129 if (!layer.visible) 130 icon = ImageProvider.overlay(icon, "invisible", OverlayPosition.SOUTHEAST); 130 icon = ImageProvider.overlay(icon, "overlay/invisible", OverlayPosition.SOUTHEAST); 131 131 label.setIcon(icon); 132 132 label.setToolTipText(layer.getToolTipText()); -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r98 r101 32 32 import javax.swing.ListSelectionModel; 33 33 34 import org.jdom.JDOMException;35 34 import org.openstreetmap.josm.Main; 36 35 import org.openstreetmap.josm.data.SelectionChangedListener; … … 69 68 this.url = u; 70 69 } 71 @Override protected void realRun() throws SAXException, JDOMException, IOException{70 @Override protected void realRun() { 72 71 currentAction.setText("Contact "+url.getHost()+"..."); 73 72 sel = mode != SearchMode.remove ? new LinkedList<OsmPrimitive>() : Main.ds.allNonDeletedPrimitives(); 74 73 try { 75 74 URLConnection con = url.openConnection(); 76 Reader in = new ProgressReader(con, progress); 75 Reader in = new ProgressReader(con, progress, currentAction); 77 76 currentAction.setText("Downloading..."); 78 77 Map<Long, String> ids = idReader.parseIds(in); -
src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java
r100 r101 45 45 import javax.swing.filechooser.FileFilter; 46 46 47 import org.jdom.JDOMException;48 47 import org.openstreetmap.josm.Main; 49 48 import org.openstreetmap.josm.data.coor.EastNorth; … … 57 56 import org.openstreetmap.josm.tools.GBC; 58 57 import org.openstreetmap.josm.tools.ImageProvider; 59 import org.xml.sax.SAXException;60 58 61 59 /** … … 84 82 this.gpsLayer = gpsLayer; 85 83 } 86 @Override protected void realRun() throws SAXException, JDOMException,IOException {84 @Override protected void realRun() throws IOException { 87 85 currentAction.setText("Read GPS..."); 88 86 LinkedList<TimedPoint> gps = new LinkedList<TimedPoint>(); … … 103 101 if (last != null && last.after(d)) 104 102 throw new IOException("Time loop in gps data."); 103 last = d; 105 104 } 106 105 } -
src/org/openstreetmap/josm/io/OsmReader.java
r91 r101 6 6 import java.text.ParseException; 7 7 import java.text.SimpleDateFormat; 8 import java.util.Collection; 8 9 import java.util.HashMap; 10 import java.util.LinkedList; 9 11 import java.util.Map; 12 import java.util.Map.Entry; 13 14 import javax.swing.BoundedRangeModel; 15 import javax.swing.JLabel; 10 16 11 17 import org.openstreetmap.josm.data.coor.LatLon; … … 16 22 import org.openstreetmap.josm.data.osm.Way; 17 23 import org.openstreetmap.josm.data.osm.visitor.AddVisitor; 24 import org.openstreetmap.josm.data.osm.visitor.Visitor; 18 25 import org.xml.sax.Attributes; 19 26 import org.xml.sax.SAXException; … … 24 31 * Parser for the Osm Api. Read from an input stream and construct a dataset out of it. 25 32 * 33 * Reading process takes place in three phases. During the first phase (including xml parse), 34 * all nodes are read and stored. Other information than nodes are stored in a raw list 35 * 36 * The second phase reads from the raw list all segments and create Segment objects. 37 * 38 * The third phase read all ways out of the remaining objects in the raw list. 39 * 26 40 * @author Imi 27 41 */ 28 public class OsmReader extends MinML2{42 public class OsmReader { 29 43 30 44 /** … … 37 51 */ 38 52 private AddVisitor adder = new AddVisitor(ds); 53 54 /** 55 * All read nodes after phase 1. 56 */ 57 private Map<Long, Node> nodes = new HashMap<Long, Node>(); 39 58 40 /**41 * The current processed primitive.42 */43 private OsmPrimitive current; 44 45 /**46 * All read nodes so far.47 */48 private Map<Long, Node> nodes = new HashMap<Long, Node>();49 /**50 * All read segents so far.51 */ 52 private Map<Long, Segment> segments = new HashMap<Long, Segment>();59 private static class OsmPrimitiveData extends OsmPrimitive { 60 @Override public void visit(Visitor visitor) {} 61 public int compareTo(OsmPrimitive o) {return 0;} 62 63 public void copyTo(OsmPrimitive osm) { 64 osm.id = id; 65 osm.keys = keys; 66 osm.modified = modified; 67 osm.selected = selected; 68 osm.deleted = deleted; 69 osm.timestamp = timestamp; 70 } 71 } 53 72 54 73 /** 55 * Parse the given input source and return the dataset. 56 */ 57 public static DataSet parseDataSet(Reader source) throws SAXException, IOException { 58 OsmReader osm = new OsmReader(source); 59 60 // clear all negative ids (new to this file) 61 for (OsmPrimitive o : osm.ds.allPrimitives()) 62 if (o.id < 0) 63 o.id = 0; 64 65 return osm.ds; 66 } 67 68 private OsmReader(Reader source) throws SAXException, IOException { 69 parse(source); 70 } 71 72 @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 73 try { 74 if (qName.equals("osm")) { 75 if (atts == null) 76 throw new SAXException("Unknown version."); 77 if (!"0.3".equals(atts.getValue("version"))) 78 throw new SAXException("Unknown version "+atts.getValue("version")); 79 } else if (qName.equals("node")) { 80 Node n = new Node(new LatLon(getDouble(atts, "lat"), getDouble(atts, "lon"))); 81 current = n; 82 readCommon(atts); 83 current.id = getLong(atts, "id"); 84 nodes.put(n.id, n); 85 } else if (qName.equals("segment")) { 86 Node from = nodes.get(getLong(atts, "from")); 87 Node to = nodes.get(getLong(atts, "to")); 88 if (from == null || to == null) 89 throw new SAXException("Segment "+atts.getValue("id")+" is missing its nodes."); 90 current = new Segment(from, to); 91 readCommon(atts); 92 segments.put(current.id, (Segment)current); 93 } else if (qName.equals("way")) { 94 current = new Way(); 95 readCommon(atts); 96 } else if (qName.equals("seg")) { 97 if (current instanceof Way) { 74 * Data structure for the remaining segment objects 75 * Maps the raw attributes to key/value pairs. 76 */ 77 private Map<OsmPrimitiveData, long[]> segs = new HashMap<OsmPrimitiveData, long[]>(); 78 /** 79 * Data structure for the remaining way objects 80 */ 81 private Map<OsmPrimitiveData, Collection<Long>> ways = new HashMap<OsmPrimitiveData, Collection<Long>>(); 82 83 84 private class Parser extends MinML2 { 85 /** 86 * The current osm primitive to be read. 87 */ 88 private OsmPrimitive current; 89 90 @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 91 try { 92 if (qName.equals("osm")) { 93 if (atts == null) 94 throw new SAXException("Unknown version."); 95 if (!"0.3".equals(atts.getValue("version"))) 96 throw new SAXException("Unknown version "+atts.getValue("version")); 97 } else if (qName.equals("node")) { 98 current = new Node(new LatLon(getDouble(atts, "lat"), getDouble(atts, "lon"))); 99 readCommon(atts, current); 100 nodes.put(current.id, (Node)current); 101 } else if (qName.equals("segment")) { 102 current = new OsmPrimitiveData(); 103 readCommon(atts, current); 104 segs.put((OsmPrimitiveData)current, new long[]{getLong(atts, "from"), getLong(atts, "to")}); 105 } else if (qName.equals("way")) { 106 current = new OsmPrimitiveData(); 107 readCommon(atts, current); 108 ways.put((OsmPrimitiveData)current, new LinkedList<Long>()); 109 } else if (qName.equals("seg")) { 110 Collection<Long> list = ways.get(current); 111 if (list == null) 112 throw new SAXException("Found <seg> tag on non-way."); 98 113 long id = getLong(atts, "id"); 99 114 if (id == 0) 100 115 throw new SAXException("Incomplete segment with id=0"); 101 Segment ls = segments.get(id); 102 if (ls == null) { 103 ls = new Segment(id); // incomplete segment 104 segments.put(id, ls); 105 adder.visit(ls); 106 } 107 ((Way)current).segments.add(ls); 108 } 109 } else if (qName.equals("tag")) 110 current.put(atts.getValue("k"), atts.getValue("v")); 111 } catch (NumberFormatException x) { 112 x.printStackTrace(); // SAXException does not chain correctly 113 throw new SAXException(x.getMessage(), x); 114 } catch (NullPointerException x) { 115 x.printStackTrace(); // SAXException does not chain correctly 116 throw new SAXException("NullPointerException. Possible some missing tags.", x); 117 } 118 } 119 120 121 @Override public void endElement(String namespaceURI, String localName, String qName) { 122 if (qName.equals("node") || qName.equals("segment") || qName.equals("way") || qName.equals("area")) { 123 current.visit(adder); 116 list.add(id); 117 } else if (qName.equals("tag")) 118 current.put(atts.getValue("k"), atts.getValue("v")); 119 } catch (NumberFormatException x) { 120 x.printStackTrace(); // SAXException does not chain correctly 121 throw new SAXException(x.getMessage(), x); 122 } catch (NullPointerException x) { 123 x.printStackTrace(); // SAXException does not chain correctly 124 throw new SAXException("NullPointerException. Possible some missing tags.", x); 125 } 126 } 127 128 private double getDouble(Attributes atts, String value) { 129 return Double.parseDouble(atts.getValue(value)); 124 130 } 125 131 } … … 128 134 * Read out the common attributes from atts and put them into this.current. 129 135 */ 130 privatevoid readCommon(Attributes atts) throws SAXException {136 void readCommon(Attributes atts, OsmPrimitive current) throws SAXException { 131 137 current.id = getLong(atts, "id"); 132 138 if (current.id == 0) 133 139 throw new SAXException("Illegal object with id=0"); 134 140 135 141 String time = atts.getValue("timestamp"); 136 142 if (time != null && time.length() != 0) { 137 143 try { 138 144 DateFormat df = new SimpleDateFormat("y-M-d H:m:s"); 139 140 141 142 143 144 } 145 145 current.timestamp = df.parse(time); 146 } catch (ParseException e) { 147 e.printStackTrace(); 148 throw new SAXException("Couldn't read time format '"+time+"'."); 149 } 150 } 151 146 152 String action = atts.getValue("action"); 147 153 if (action == null) … … 152 158 current.modified = true; 153 159 } 154 155 private double getDouble(Attributes atts, String value) { 156 return Double.parseDouble(atts.getValue(value)); 157 } 158 private long getLong(Attributes atts, String value) { 159 return Long.parseLong(atts.getValue(value)); 160 private long getLong(Attributes atts, String value) throws SAXException { 161 String s = atts.getValue(value); 162 if (s == null) 163 throw new SAXException("Missing required attirbute '"+value+"'"); 164 return Long.parseLong(s); 165 } 166 167 private void createSegments() { 168 for (Entry<OsmPrimitiveData, long[]> e : segs.entrySet()) { 169 Node from = nodes.get(e.getValue()[0]); 170 Node to = nodes.get(e.getValue()[1]); 171 if (from == null || to == null) 172 continue; //TODO: implement support for incomplete nodes. 173 Segment s = new Segment(from, to); 174 e.getKey().copyTo(s); 175 segments.put(s.id, s); 176 adder.visit(s); 177 } 178 } 179 180 private void createWays() { 181 for (Entry<OsmPrimitiveData, Collection<Long>> e : ways.entrySet()) { 182 Way w = new Way(); 183 for (long id : e.getValue()) { 184 Segment s = segments.get(id); 185 if (s == null) 186 s = new Segment(id); // incomplete line segment 187 w.segments.add(s); 188 } 189 e.getKey().copyTo(w); 190 adder.visit(w); 191 } 192 } 193 194 /** 195 * All read segments after phase 2. 196 */ 197 private Map<Long, Segment> segments = new HashMap<Long, Segment>(); 198 199 /** 200 * Parse the given input source and return the dataset. 201 */ 202 public static DataSet parseDataSet(Reader source, JLabel currentAction, BoundedRangeModel progress) throws SAXException, IOException { 203 OsmReader osm = new OsmReader(); 204 205 // phase 1: Parse nodes and read in raw segments and ways 206 osm.new Parser().parse(source); 207 if (progress != null) 208 progress.setValue(0); 209 if (currentAction != null) 210 currentAction.setText("Preparing data..."); 211 for (Node n : osm.nodes.values()) 212 osm.adder.visit(n); 213 214 try { 215 osm.createSegments(); 216 osm.createWays(); 217 } catch (NumberFormatException e) { 218 e.printStackTrace(); 219 throw new SAXException("Illformed Node id"); 220 } 221 222 // clear all negative ids (new to this file) 223 for (OsmPrimitive o : osm.ds.allPrimitives()) 224 if (o.id < 0) 225 o.id = 0; 226 227 return osm.ds; 160 228 } 161 229 } -
src/org/openstreetmap/josm/io/OsmServerReader.java
r99 r101 100 100 return null; 101 101 currentAction.setText("Downloading OSM data..."); 102 final DataSet data = OsmReader.parseDataSet(r); 102 final DataSet data = OsmReader.parseDataSet(r, currentAction, progress); 103 103 r.close(); 104 104 activeConnection = null; … … 134 134 if (isAuthCancelled() && activeConnection.getResponseCode() == 401) 135 135 return null; 136 return new ProgressReader(activeConnection, progress); 136 return new ProgressReader(activeConnection, progress, currentAction); 137 137 } 138 138 } -
src/org/openstreetmap/josm/io/ProgressReader.java
r93 r101 7 7 8 8 import javax.swing.BoundedRangeModel; 9 import javax.swing.JLabel; 9 10 10 11 /** … … 16 17 private final Reader in; 17 18 private final BoundedRangeModel progress; 19 private final JLabel currentAction; 20 private int readSoFar = 0; 18 21 19 public ProgressReader(URLConnection con, BoundedRangeModel progress) throws IOException { 22 public ProgressReader(URLConnection con, BoundedRangeModel progress, JLabel currentAction) throws IOException { 20 23 this.in = new InputStreamReader(con.getInputStream()); 21 24 this.progress = progress; 25 this.currentAction = currentAction; 22 26 int contentLength = con.getContentLength(); 23 27 if (contentLength > 0) 24 28 progress.setMaximum(contentLength); 29 else 30 progress.setMaximum(0); 25 31 progress.setValue(0); 26 32 } … … 32 38 @Override public int read(char[] cbuf, int off, int len) throws IOException { 33 39 int read = in.read(cbuf, off, len); 34 progress.setValue(progress.getValue()+read); 40 readSoFar += read; 41 42 String progStr = " ("+readSoFar+"/"; 43 if (progress.getMaximum() == 0) 44 progStr += "???)"; 45 else 46 progStr += progress.getMaximum()+")"; 47 48 String cur = currentAction.getText(); 49 int i = cur.indexOf(' '); 50 if (i != -1) 51 cur = cur.substring(0, i) + progStr; 52 else 53 cur += progStr; 54 currentAction.setText(cur); 55 progress.setValue(readSoFar); 35 56 return read; 36 57 } -
src/org/openstreetmap/josm/test/GpxWriterTest.java
r86 r101 36 36 } 37 37 38 38 39 39 /** 40 40 * Verify, that new created elements, if and only if they occoure more than once in … … 55 55 } 56 56 assertNotNull("way not found in GPX file", realWay); 57 57 58 58 // the second point of the first segment of the ways has an id 59 59 Element trkseg = (Element)realWay.getChildren("trkseg", GPX).get(0); -
src/org/openstreetmap/josm/tools/ImageProvider.java
r93 r101 1 1 package org.openstreetmap.josm.tools; 2 2 3 import java.awt.Cursor; 3 4 import java.awt.Graphics; 4 5 import java.awt.GraphicsConfiguration; 5 6 import java.awt.GraphicsEnvironment; 6 7 import java.awt.Image; 8 import java.awt.Point; 7 9 import java.awt.Toolkit; 8 10 import java.awt.Transparency; … … 63 65 } 64 66 67 public static Cursor getCursor(String name, String overlay) { 68 ImageIcon img = overlay(get("cursor/"+name), "cursor/modifier/"+overlay, OverlayPosition.SOUTHEAST); 69 Cursor c = Toolkit.getDefaultToolkit().createCustomCursor(img.getImage(), 70 name.equals("crosshair") ? new Point(10,10) : new Point(3,2), "Cursor"); 71 return c; 72 } 73 65 74 /** 66 75 * @return an icon that represent the overlay of the two given icons. The 67 76 * second icon is layed on the first relative to the given position. 68 77 */ 69 public static Icon overlay(Icon ground, String overlayImage, OverlayPosition pos) { 78 public static ImageIcon overlay(Icon ground, String overlayImage, OverlayPosition pos) { 70 79 GraphicsConfiguration conf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); 71 80 int w = ground.getIconWidth(); 72 81 int h = ground.getIconHeight(); 73 ImageIcon overlay = ImageProvider.get( "overlay",overlayImage);82 ImageIcon overlay = ImageProvider.get(overlayImage); 74 83 int wo = overlay.getIconWidth(); 75 84 int ho = overlay.getIconHeight();
Note:
See TracChangeset
for help on using the changeset viewer.