Changeset 101 in josm


Ignore:
Timestamp:
2006-05-03T22:21:02+02:00 (18 years ago)
Author:
imi
Message:
  • added zoom/move around with Ctrl+direction keys / Ctrl +, Ctrl -
  • added progress bar counter of downloaded bytes
  • added support for little-osm (relaxed assumptions about osm/xml input format)
Files:
13 added
30 edited

Legend:

Unmodified
Added
Removed
  • .classpath

    r100 r101  
    77        <classpathentry sourcepath="JUNIT_SRC_HOME/junitsrc.zip" kind="var" path="JUNIT_HOME/junit.jar"/>
    88        <classpathentry kind="lib" path="lib/MinML2.jar"/>
    9         <classpathentry sourcepath="C:/projects/metadata-extractor/src" kind="lib" path="lib/metadata-extractor-2.3.1.jar"/>
     9        <classpathentry kind="lib" path="lib/metadata-extractor-2.3.1.jar"/>
    1010        <classpathentry kind="output" path="bin"/>
    1111</classpath>
  • CONTRIBUTION

    r63 r101  
    11One XML Parser is JDOM 1.0 which comes from www.jdom.org and
    22is licensed under "JDOM license", a modified Apache License
    3 with Aknowledgement removed. The other is MinML2 from
    4 http://www.wilson.co.uk/xml/minml2.htm. The license is
     3with Aknowledgement removed. The other XML Parser is MinML2
     4from http://www.wilson.co.uk/xml/minml2.htm. The license is
    55attached below.
    66
    7 The icons are inspired and stolen from gnome-media package
     7The jpeg metadata extraction code is from Drew Noakes
     8(http://drewnoakes.com/code/exif).
     9
     10Most icons are inspired and stolen from gnome-media package
    811of my local linux installation. The images are licensed
    9 under LGPL but redistributed by me under the terms of GPL 2.0.
     12under LGPL but redistributed by me under the terms of GPL
     132.0. The world image is from onearth.pl.
    1014
    11 The UTM - code is a rewritten version from Ben who had it from
    12 some old C code. Aknowledgments are in the UTM.java file of
    13 the source distribution.
    1415
    15 All the rest are belongs to me.
     16All the rest are belong to me.
     17
    1618
    1719Imi.
  • README

    r63 r101  
    3030deb http://ftp.debian-unofficial.org/debian/ stable non-free
    3131
    32 The package is called sun-j2se5.0-jdk-binary.
     32The package is called sun-j2se5.0-jre-binary.
    3333
    3434For MacOS user: There is an installer for Mac OS X 10.4:
    3535http://www.apple.com/support/downloads/java2se50release1.html
     36
     37Sorry, there is no Version of Java5 for Mac OS X 10.3 available :-(
    3638
    3739
     
    6466
    6567
    66 
    6768And gimme feedback: josm@eigenheimstrasse.de (start your mail subject
    6869with "JOSM", so my spam filter will not eat you)
    6970
    7071
    71 
    7272Ciao, Imi.
  • src/org/openstreetmap/josm/Main.java

    r100 r101  
    3737import org.openstreetmap.josm.actions.UndoAction;
    3838import org.openstreetmap.josm.actions.UploadAction;
     39import org.openstreetmap.josm.actions.mapmode.MapMode;
    3940import org.openstreetmap.josm.data.Bounds;
    4041import org.openstreetmap.josm.data.Preferences;
     
    186187                        final MapFrame mapFrame = new MapFrame(layer);
    187188                        setMapFrame(mapFrame);
     189                        mapFrame.selectMapMode((MapMode)mapFrame.getDefaultButtonAction());
    188190                        mapFrame.setVisible(true);
    189191                        mapFrame.setVisibleDialogs();
  • src/org/openstreetmap/josm/actions/DownloadAction.java

    r100 r101  
    135135
    136136        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 
    153137                JPanel dlg = new JPanel(new GridBagLayout());
    154138
  • src/org/openstreetmap/josm/actions/GroupAction.java

    r99 r101  
    4545
    4646                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));
    4848                Object tooltip = actions.get(current).getValue(SHORT_DESCRIPTION);
    4949                putValue(SHORT_DESCRIPTION, "<html>"+tooltip+" <font size='-2'>"+shortCutName+"</font>&nbsp;</html>");
  • src/org/openstreetmap/josm/actions/OpenAction.java

    r99 r101  
    7575                                        try {
    7676                                                // temporary allow loading of old xml format.
    77                                                 dataSet = OsmReader.parseDataSet(new FileReader(filename));
     77                                                dataSet = OsmReader.parseDataSet(new FileReader(filename), null, null);
    7878                                        } catch (SAXException x) {
    7979                                                if (x.getMessage().equals("Unknown version null")) {
  • src/org/openstreetmap/josm/actions/UploadAction.java

    r99 r101  
    4444                }
    4545               
    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 
    6246                if (!Main.map.conflictDialog.conflicts.isEmpty()) {
    6347                        JOptionPane.showMessageDialog(Main.parent, "There are unresolved conflicts. You have to resolve these first.");
  • src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java

    r100 r101  
    2121import org.openstreetmap.josm.data.osm.Way;
    2222import org.openstreetmap.josm.gui.MapFrame;
     23import org.openstreetmap.josm.tools.ImageProvider;
    2324
    2425/**
     
    4748
    4849        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"));
    5051                this.mode = mode;
    5152        }
  • src/org/openstreetmap/josm/actions/mapmode/AddSegmentAction.java

    r98 r101  
    1515import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1616import org.openstreetmap.josm.gui.MapFrame;
     17import org.openstreetmap.josm.tools.ImageProvider;
    1718
    1819/**
     
    4647         */
    4748        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"));
    4956        }
    5057
  • src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java

    r100 r101  
    2020import org.openstreetmap.josm.data.osm.Way;
    2121import org.openstreetmap.josm.gui.MapFrame;
     22import org.openstreetmap.josm.tools.ImageProvider;
    2223
    2324/**
     
    5657         */
    5758        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"));
    5960               
    6061                Main.ds.addSelectionChangedListener(this);
  • src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java

    r100 r101  
    2424import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;
    2525import org.openstreetmap.josm.gui.MapFrame;
     26import org.openstreetmap.josm.tools.ImageProvider;
    2627
    2728/**
     
    5051         */
    5152        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"));
    5360        }
    5461
  • src/org/openstreetmap/josm/actions/mapmode/MapMode.java

    r98 r101  
    11package org.openstreetmap.josm.actions.mapmode;
    22
     3import java.awt.Cursor;
    34import java.awt.event.ActionEvent;
    45import java.awt.event.MouseEvent;
     
    2324abstract public class MapMode extends JosmAction implements MouseListener, MouseMotionListener {
    2425
     26//      private final Cursor cursor;
     27//      private Cursor oldCursor;
     28
    2529        /**
    2630         * Constructor for mapmodes without an menu
    2731         */
    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) {
    2933                super(name, "mapmode/"+iconName, tooltip, keyname, KeyStroke.getKeyStroke(keystroke, 0));
     34//              this.cursor = cursor;
    3035                putValue("active", false);
    3136        }
     
    3439         * Constructor for mapmodes with an menu (no shortcut will be registered)
    3540         */
    36         public MapMode(String name, String iconName, String tooltip, MapFrame mapFrame) {
     41        public MapMode(String name, String iconName, String tooltip, MapFrame mapFrame, Cursor cursor) {
    3742                putValue(NAME, name);
    3843                putValue(SMALL_ICON, ImageProvider.get("mapmode", iconName));
    3944                putValue(SHORT_DESCRIPTION, tooltip);
     45//              this.cursor = cursor;
    4046        }
    4147
    4248        public void enterMode() {
    4349                putValue("active", true);
     50//              oldCursor = Main.map.mapView.getCursor();
     51//              Main.map.mapView.setCursor(cursor);
     52               
    4453        }
    4554        public void exitMode() {
    4655                putValue("active", false);
     56//              Main.map.mapView.setCursor(oldCursor);
    4757        }
    4858
  • src/org/openstreetmap/josm/actions/mapmode/MoveAction.java

    r98 r101  
    1717import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor;
    1818import org.openstreetmap.josm.gui.MapFrame;
     19import org.openstreetmap.josm.tools.ImageProvider;
    1920
    2021/**
     
    4849         */
    4950        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"));
    5158        }
    5259
  • src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java

    r98 r101  
    1111import org.openstreetmap.josm.gui.SelectionManager;
    1212import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded;
     13import org.openstreetmap.josm.tools.ImageProvider;
    1314
    1415/**
     
    6465         */
    6566        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"));
    6774                this.selectionManager = new SelectionManager(this, false, mapFrame.mapView);
    6875        }
  • src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java

    r94 r101  
    99import org.openstreetmap.josm.gui.SelectionManager;
    1010import org.openstreetmap.josm.gui.SelectionManager.SelectionEnded;
     11import org.openstreetmap.josm.tools.ImageProvider;
    1112
    1213/**
     
    4142         */
    4243        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"));
    4445                mv = mapFrame.mapView;
    4546                selectionManager = new SelectionManager(this, true, mv);
  • src/org/openstreetmap/josm/data/ServerSidePreferences.java

    r98 r101  
    11package org.openstreetmap.josm.data;
    22
    3 import java.io.IOException;
    43import java.net.URL;
    54
     
    2423    }
    2524
    26         @Override public void load() throws IOException {
     25        @Override public void load() {
    2726                resetToDefault();
    2827    }
  • src/org/openstreetmap/josm/gui/MapFrame.java

    r99 r101  
    1010
    1111import javax.swing.AbstractButton;
     12import javax.swing.Action;
    1213import javax.swing.BoxLayout;
    1314import javax.swing.ButtonGroup;
     
    9293                        toolGroup.add((AbstractButton)c);
    9394                toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
    94                 selectMapMode((MapMode)((AbstractButton)toolBarActions.getComponent(0)).getAction());
    9595
    9696                // autoScale
     
    128128                statusLine = new MapStatus(this);
    129129        }
     130
     131        public Action getDefaultButtonAction() {
     132            return ((AbstractButton)toolBarActions.getComponent(0)).getAction();
     133    }
    130134
    131135        /**
  • src/org/openstreetmap/josm/gui/MapMover.java

    r100 r101  
    22
    33import java.awt.Cursor;
     4import java.awt.event.ActionEvent;
     5import java.awt.event.KeyEvent;
    46import java.awt.event.MouseAdapter;
    57import java.awt.event.MouseEvent;
     
    810import java.awt.event.MouseWheelListener;
    911
     12import javax.swing.AbstractAction;
     13import javax.swing.JComponent;
     14import javax.swing.KeyStroke;
     15
     16import org.openstreetmap.josm.Main;
    1017import org.openstreetmap.josm.data.coor.EastNorth;
    1118
     
    1724 */
    1825class 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    }
    1950
    2051        /**
     
    3364
    3465        private boolean movementInPlace = false;
    35        
     66
    3667        /**
    3768         * Create a new MapMover
     
    4273                nc.addMouseMotionListener(this);
    4374                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                }
    4483        }
    45        
     84
    4685        /**
    4786         * If the right (and only the right) mouse button is pressed, move the map
     
    92131                nc.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
    93132        }
    94        
     133
    95134        /**
    96135         * End the movement. Setting back the cursor and clear the movement variables
     
    124163                double centery = e.getY() - (e.getY()-h/2)*newHalfHeight*2/h;
    125164                EastNorth newCenter = nc.getEastNorth((int)centerx, (int)centery);
    126                
     165
    127166                nc.zoomTo(newCenter, nc.getScale()*zoom);
    128167        }
  • src/org/openstreetmap/josm/gui/MapView.java

    r100 r101  
    8484        private final AutoScaleAction autoScaleAction;
    8585
    86        
     86
    8787        private final class Scaler extends JSlider implements PropertyChangeListener, ChangeListener {
    8888                boolean clicked = false;
     
    9191                        addMouseListener(new MouseAdapter(){
    9292                                @Override public void mousePressed(MouseEvent e) {
    93                         clicked = true;
    94                 }
     93                                        clicked = true;
     94                                }
    9595                                @Override public void mouseReleased(MouseEvent e) {
    96                         clicked = false;
    97                 }
     96                                        clicked = false;
     97                                }
    9898                        });
    99                         MapView.this.addPropertyChangeListener(this);
     99                        MapView.this.addPropertyChangeListener("scale", this);
    100100                        addChangeListener(this);
    101         }
     101                }
    102102                public void propertyChange(PropertyChangeEvent evt) {
    103                         if (evt.getPropertyName().equals("scale") && !getModel().getValueIsAdjusting())
     103                        if (!getModel().getValueIsAdjusting())
    104104                                setValue(zoom());
    105         }
     105                }
    106106                public void stateChanged(ChangeEvent e) {
    107107                        if (!clicked)
     
    114114                        else
    115115                                zoomTo(center, pos.north()*2/(MapView.this.getHeight()-20));
    116         }
    117         }
    118        
     116                }
     117        }
     118
    119119        public MapView(AutoScaleAction autoScaleAction) {
    120120                this.autoScaleAction = autoScaleAction;
     
    154154                        Main.ds = dataLayer.data;
    155155                        dataLayer.listenerModified.add(new ModifiedChangedListener(){
    156                 public void modifiedChanged(boolean value, OsmDataLayer source) {
    157                         JOptionPane.getFrameForComponent(Main.parent).setTitle((value?"*":"")+"Java Open Street Map - Editor");
    158                 }
    159             });
     156                                public void modifiedChanged(boolean value, OsmDataLayer source) {
     157                                        JOptionPane.getFrameForComponent(Main.parent).setTitle((value?"*":"")+"Java Open Street Map - Editor");
     158                                }
     159                        });
    160160                }
    161161
  • src/org/openstreetmap/josm/gui/dialogs/LayerList.java

    r100 r101  
    128128                                Icon icon = layer.getIcon();
    129129                                if (!layer.visible)
    130                                         icon = ImageProvider.overlay(icon, "invisible", OverlayPosition.SOUTHEAST);
     130                                        icon = ImageProvider.overlay(icon, "overlay/invisible", OverlayPosition.SOUTHEAST);
    131131                                label.setIcon(icon);
    132132                                label.setToolTipText(layer.getToolTipText());
  • src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r98 r101  
    3232import javax.swing.ListSelectionModel;
    3333
    34 import org.jdom.JDOMException;
    3534import org.openstreetmap.josm.Main;
    3635import org.openstreetmap.josm.data.SelectionChangedListener;
     
    6968            this.url = u;
    7069        }
    71                 @Override protected void realRun() throws SAXException, JDOMException, IOException {
     70                @Override protected void realRun() {
    7271                        currentAction.setText("Contact "+url.getHost()+"...");
    7372                        sel = mode != SearchMode.remove ? new LinkedList<OsmPrimitive>() : Main.ds.allNonDeletedPrimitives();
    7473                        try {
    7574                        URLConnection con = url.openConnection();
    76                         Reader in = new ProgressReader(con, progress);
     75                        Reader in = new ProgressReader(con, progress, currentAction);
    7776                                currentAction.setText("Downloading...");
    7877                                Map<Long, String> ids = idReader.parseIds(in);
  • src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java

    r100 r101  
    4545import javax.swing.filechooser.FileFilter;
    4646
    47 import org.jdom.JDOMException;
    4847import org.openstreetmap.josm.Main;
    4948import org.openstreetmap.josm.data.coor.EastNorth;
     
    5756import org.openstreetmap.josm.tools.GBC;
    5857import org.openstreetmap.josm.tools.ImageProvider;
    59 import org.xml.sax.SAXException;
    6058
    6159/**
     
    8482                        this.gpsLayer = gpsLayer;
    8583                }
    86                 @Override protected void realRun() throws SAXException, JDOMException, IOException {
     84                @Override protected void realRun() throws IOException {
    8785                        currentAction.setText("Read GPS...");
    8886                        LinkedList<TimedPoint> gps = new LinkedList<TimedPoint>();
     
    103101                                                if (last != null && last.after(d))
    104102                                                        throw new IOException("Time loop in gps data.");
     103                                                last = d;
    105104                                        }
    106105                                }
  • src/org/openstreetmap/josm/io/OsmReader.java

    r91 r101  
    66import java.text.ParseException;
    77import java.text.SimpleDateFormat;
     8import java.util.Collection;
    89import java.util.HashMap;
     10import java.util.LinkedList;
    911import java.util.Map;
     12import java.util.Map.Entry;
     13
     14import javax.swing.BoundedRangeModel;
     15import javax.swing.JLabel;
    1016
    1117import org.openstreetmap.josm.data.coor.LatLon;
     
    1622import org.openstreetmap.josm.data.osm.Way;
    1723import org.openstreetmap.josm.data.osm.visitor.AddVisitor;
     24import org.openstreetmap.josm.data.osm.visitor.Visitor;
    1825import org.xml.sax.Attributes;
    1926import org.xml.sax.SAXException;
     
    2431 * Parser for the Osm Api. Read from an input stream and construct a dataset out of it.
    2532 *
     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 *
    2640 * @author Imi
    2741 */
    28 public class OsmReader extends MinML2 {
     42public class OsmReader {
    2943
    3044        /**
     
    3751         */
    3852        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>();
    3958       
    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        }
    5372       
    5473        /**
    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.");
    98113                                        long id = getLong(atts, "id");
    99114                                        if (id == 0)
    100115                                                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));
    124130                }
    125131        }
     
    128134         * Read out the common attributes from atts and put them into this.current.
    129135         */
    130         private void readCommon(Attributes atts) throws SAXException {
     136        void readCommon(Attributes atts, OsmPrimitive current) throws SAXException {
    131137                current.id = getLong(atts, "id");
    132138                if (current.id == 0)
    133139                        throw new SAXException("Illegal object with id=0");
    134                
     140
    135141                String time = atts.getValue("timestamp");
    136142                if (time != null && time.length() != 0) {
    137143                        try {
    138144                                DateFormat df = new SimpleDateFormat("y-M-d H:m:s");
    139                     current.timestamp = df.parse(time);
    140             } catch (ParseException e) {
    141                     e.printStackTrace();
    142                     throw new SAXException("Couldn't read time format '"+time+"'.");
    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
    146152                String action = atts.getValue("action");
    147153                if (action == null)
     
    152158                        current.modified = true;
    153159        }
    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;
    160228        }
    161229}
  • src/org/openstreetmap/josm/io/OsmServerReader.java

    r99 r101  
    100100                                return null;
    101101                        currentAction.setText("Downloading OSM data...");
    102                         final DataSet data = OsmReader.parseDataSet(r);
     102                        final DataSet data = OsmReader.parseDataSet(r, currentAction, progress);
    103103                        r.close();
    104104                        activeConnection = null;
     
    134134                if (isAuthCancelled() && activeConnection.getResponseCode() == 401)
    135135                        return null;
    136                 return new ProgressReader(activeConnection, progress);
     136                return new ProgressReader(activeConnection, progress, currentAction);
    137137        }
    138138}
  • src/org/openstreetmap/josm/io/ProgressReader.java

    r93 r101  
    77
    88import javax.swing.BoundedRangeModel;
     9import javax.swing.JLabel;
    910
    1011/**
     
    1617        private final Reader in;
    1718        private final BoundedRangeModel progress;
     19        private final JLabel currentAction;
     20        private int readSoFar = 0;
    1821
    19         public ProgressReader(URLConnection con, BoundedRangeModel progress) throws IOException {
     22        public ProgressReader(URLConnection con, BoundedRangeModel progress, JLabel currentAction) throws IOException {
    2023                this.in = new InputStreamReader(con.getInputStream());
    2124                this.progress = progress;
     25                this.currentAction = currentAction;
    2226                int contentLength = con.getContentLength();
    2327                if (contentLength > 0)
    2428                        progress.setMaximum(contentLength);
     29                else
     30                        progress.setMaximum(0);
    2531                progress.setValue(0);
    2632    }
     
    3238        @Override public int read(char[] cbuf, int off, int len) throws IOException {
    3339                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);
    3556                return read;
    3657        }
  • src/org/openstreetmap/josm/test/GpxWriterTest.java

    r86 r101  
    3636        }
    3737
    38        
     38
    3939        /**
    4040         * Verify, that new created elements, if and only if they occoure more than once in
     
    5555                }
    5656                assertNotNull("way not found in GPX file", realWay);
    57                
     57
    5858                // the second point of the first segment of the ways has an id
    5959                Element trkseg = (Element)realWay.getChildren("trkseg", GPX).get(0);
  • src/org/openstreetmap/josm/tools/ImageProvider.java

    r93 r101  
    11package org.openstreetmap.josm.tools;
    22
     3import java.awt.Cursor;
    34import java.awt.Graphics;
    45import java.awt.GraphicsConfiguration;
    56import java.awt.GraphicsEnvironment;
    67import java.awt.Image;
     8import java.awt.Point;
    79import java.awt.Toolkit;
    810import java.awt.Transparency;
     
    6365        }
    6466
     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
    6574        /**
    6675         * @return an icon that represent the overlay of the two given icons. The
    6776         * second icon is layed on the first relative to the given position.
    6877         */
    69         public static Icon overlay(Icon ground, String overlayImage, OverlayPosition pos) {
     78        public static ImageIcon overlay(Icon ground, String overlayImage, OverlayPosition pos) {
    7079                GraphicsConfiguration conf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    7180                int w = ground.getIconWidth();
    7281                int h = ground.getIconHeight();
    73                 ImageIcon overlay = ImageProvider.get("overlay",overlayImage);
     82                ImageIcon overlay = ImageProvider.get(overlayImage);
    7483                int wo = overlay.getIconWidth();
    7584                int ho = overlay.getIconHeight();
Note: See TracChangeset for help on using the changeset viewer.