Changeset 33 in josm


Ignore:
Timestamp:
2005-12-22T01:32:33+01:00 (18 years ago)
Author:
imi
Message:
  • prepared for uploading.
  • fixed gpx export/import with uid and modified flag
Files:
6 added
10 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/Main.java

    r31 r33  
    1717import org.openstreetmap.josm.actions.ExitAction;
    1818import org.openstreetmap.josm.actions.OpenAction;
    19 import org.openstreetmap.josm.actions.OpenOsmServerAction;
     19import org.openstreetmap.josm.actions.DownloadAction;
    2020import org.openstreetmap.josm.actions.PreferencesAction;
    2121import org.openstreetmap.josm.actions.RedoAction;
    2222import org.openstreetmap.josm.actions.SaveAction;
    2323import org.openstreetmap.josm.actions.UndoAction;
     24import org.openstreetmap.josm.actions.UploadAction;
    2425import org.openstreetmap.josm.data.Preferences;
    2526import org.openstreetmap.josm.data.Preferences.PreferencesException;
     
    7980               
    8081                // creating actions
    81                 OpenOsmServerAction openServerAction = new OpenOsmServerAction();
     82                DownloadAction downloadAction = new DownloadAction();
     83                UploadAction uploadAction = new UploadAction();
    8284                OpenAction openAction = new OpenAction();
    8385                SaveAction saveAction = new SaveAction();
     
    103105                JMenu connectionMenu = new JMenu("Connection");
    104106                connectionMenu.setMnemonic('C');
    105                 connectionMenu.add(openServerAction);
     107                connectionMenu.add(downloadAction);
     108                connectionMenu.add(uploadAction);
    106109                mainMenu.add(connectionMenu);
    107110               
     
    123126                JToolBar toolBar = new JToolBar();
    124127                toolBar.setFloatable(false);
    125                 toolBar.add(openServerAction);
     128                toolBar.add(downloadAction);
     129                toolBar.add(uploadAction);
    126130                toolBar.add(openAction);
    127131                toolBar.add(saveAction);
  • src/org/openstreetmap/josm/actions/DownloadAction.java

    r32 r33  
    3636
    3737/**
    38  * Action that opens a connection to the osm server.
     38 * Action that opens a connection to the osm server and download map data.
    3939 *
    4040 * An dialog is displayed asking the user to specify a rectangle to grab.
     
    4343 * @author imi
    4444 */
    45 public class OpenOsmServerAction extends JosmAction {
     45public class DownloadAction extends JosmAction {
    4646
    4747        JTextField[] latlon = new JTextField[]{
     
    5252        JCheckBox rawGps = new JCheckBox("Open as raw gps data", false);
    5353
    54         public OpenOsmServerAction() {
    55                 super("Connect to OSM", "connectosm", "Open a connection to the OSM server.", KeyEvent.VK_C,
    56                                 KeyStroke.getAWTKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK));
     54        public DownloadAction() {
     55                super("Download from OSM", "download", "Download map data from the OSM server.", KeyEvent.VK_D,
     56                                KeyStroke.getAWTKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK));
    5757        }
    5858
  • src/org/openstreetmap/josm/actions/ExtensionFileFilter.java

    r32 r33  
    2121                //new ExtensionFileFilter(".josm", "JOSM Savefiles (.josm)")
    2222        };
    23        
     23
    2424        /**
    2525         * Construct an extension file filter by giving the extension to check after.
  • src/org/openstreetmap/josm/command/ChangeKeyValueCommand.java

    r32 r33  
    5656                        oldProperties.add(osm.keys == null ? null : new HashMap<Key, String>(osm.keys));
    5757                        oldModified.add(osm.modified);
     58                        osm.modified = true;
    5859                }
    59                        
     60
    6061                if (value == null) {
    6162                        for (OsmPrimitive osm : objects) {
  • src/org/openstreetmap/josm/data/Preferences.java

    r30 r33  
    5050         */
    5151        private boolean forceRawGpsLines = false;
    52         /**
    53          * Whether nodes on the same place should be considered identical.
    54          */
    55         public boolean mergeNodes = true;
    5652
    5753        /**
     
    132128                                osmDataPassword = osmServer.getChildText("password");
    133129                        }
    134                         mergeNodes = root.getChild("mergeNodes") != null;
    135130                        drawRawGpsLines = root.getChild("drawRawGpsLines") != null;
    136131                        forceRawGpsLines = root.getChild("forceRawGpsLines") != null;
     
    153148                children.add(new Element("laf").setText(laf.getClassName()));
    154149                children.add(new Element("projection").setText(getProjection().getClass().getName()));
    155                 if (mergeNodes)
    156                         children.add(new Element("mergeNodes"));
    157150                if (drawRawGpsLines)
    158151                        children.add(new Element("drawRawGpsLines"));
  • src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r32 r33  
    1515abstract public class OsmPrimitive {
    1616
    17         private static int idcount = 0;
    18         public OsmPrimitive() {
    19                 id = ++idcount;
    20         }
    21        
    2217        /**
    2318         * The key/value list for this primitive.
     
    4338         * If set to true, this object is currently selected.
    4439         */
    45         transient private boolean selected = false;
     40        private boolean selected = false;
    4641
    4742        /**
     
    6055         * @return      True, if the keysets are mergable
    6156         */
    62         public boolean keyPropertiesMergable(OsmPrimitive other) {
     57        final public boolean keyPropertiesMergable(OsmPrimitive other) {
    6358                if ((keys == null) != (other.keys == null))
    6459                        return false;
     
    8075         * @param selected Whether the primitive should be selected or not.
    8176         */
    82         public void setSelected(boolean selected) {
     77        final public void setSelected(boolean selected) {
    8378                if (selected != this.selected)
    8479                        Main.main.ds.fireSelectionChanged();
     
    8984         * @return Return whether the primitive is selected on screen.
    9085         */
    91         public boolean isSelected() {
     86        final public boolean isSelected() {
    9287                return selected;
    9388        }
  • src/org/openstreetmap/josm/gui/PreferenceDialog.java

    r31 r33  
    5454                        projection.commitConfigurationPanel();
    5555                        Main.pref.setProjection(projection);
    56                         Main.pref.mergeNodes = mergeNodes.isSelected();
    5756                        Main.pref.osmDataServer = osmDataServer.getText();
    5857                        Main.pref.osmDataUsername = osmDataUsername.getText();
     
    125124         */
    126125        JCheckBox forceRawGpsLines = new JCheckBox("Force lines if no line segments imported.");
    127         /**
    128          * The checkbox stating whether nodes should be merged together.
    129          */
    130         JCheckBox mergeNodes = new JCheckBox("Merge nodes with equal latitude/longitude.");
    131126
    132127        /**
     
    198193                forceRawGpsLines.setSelected(Main.pref.isForceRawGpsLines());
    199194                forceRawGpsLines.setEnabled(drawRawGpsLines.isSelected());
    200                 mergeNodes.setToolTipText("When importing GPX data, all nodes with exact the same lat/lon are merged.");
    201                 mergeNodes.setSelected(Main.pref.mergeNodes);
    202195
    203196                osmDataServer.setText(Main.pref.osmDataServer);
     
    238231                map.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
    239232                map.add(projectionDetail, GBC.eop());
    240                
    241                 map.add(new JLabel("GPX import / export"), GBC.eol());
    242                 map.add(mergeNodes, GBC.eol().insets(20,0,0,0));
    243233                map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
    244234
  • src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r30 r33  
    22
    33import java.awt.BorderLayout;
    4 import java.awt.Component;
    54import java.awt.Dimension;
    65import java.awt.event.ActionEvent;
     
    98import java.util.Collection;
    109
    11 import javax.swing.DefaultListCellRenderer;
    1210import javax.swing.DefaultListModel;
    1311import javax.swing.JButton;
    14 import javax.swing.JLabel;
    1512import javax.swing.JList;
    1613import javax.swing.JScrollPane;
     
    2017import org.openstreetmap.josm.data.SelectionChangedListener;
    2118import org.openstreetmap.josm.data.osm.OsmPrimitive;
    22 import org.openstreetmap.josm.data.osm.visitor.SelectionComponentVisitor;
    2319import org.openstreetmap.josm.gui.ImageProvider;
    2420import org.openstreetmap.josm.gui.MapFrame;
     21import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
    2522
    2623/**
     
    4946                super("Current Selection", "Selection List", "selectionlist", KeyEvent.VK_E, "Open a selection list window.");
    5047                setPreferredSize(new Dimension(320,150));
    51                 displaylist.setCellRenderer(new DefaultListCellRenderer(){
    52                         private SelectionComponentVisitor visitor = new SelectionComponentVisitor();
    53                         @Override
    54                         public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    55                                 Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    56                                 if (c instanceof JLabel && value != null) {
    57                                         ((OsmPrimitive)value).visit(visitor);
    58                                         ((JLabel)c).setText(visitor.name);
    59                                         ((JLabel)c).setIcon(visitor.icon);
    60                                 }
    61                                 return c;
    62                         }
    63                 });
     48                displaylist.setCellRenderer(new OsmPrimitivRenderer());
    6449                displaylist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    6550
  • src/org/openstreetmap/josm/io/GpxReader.java

    r32 r33  
    11package org.openstreetmap.josm.io;
     2
     3import static org.openstreetmap.josm.io.GpxWriter.GPX;
     4import static org.openstreetmap.josm.io.GpxWriter.OSM;
     5import static org.openstreetmap.josm.io.GpxWriter.JOSM;
    26
    37import java.io.IOException;
     
    711import org.jdom.Element;
    812import org.jdom.JDOMException;
    9 import org.jdom.Namespace;
    1013import org.jdom.input.SAXBuilder;
    11 import org.openstreetmap.josm.Main;
    1214import org.openstreetmap.josm.data.GeoPoint;
    1315import org.openstreetmap.josm.data.osm.DataSet;
     
    2628 */
    2729public class GpxReader {
    28 
    29         /**
    30          * The GPX namespace used.
    31          */
    32         public static final Namespace GPX = Namespace.getNamespace("http://www.topografix.com/GPX/1/0");
    33         /**
    34          * The OSM namespace used (for extensions).
    35          */
    36         private static final Namespace OSM = Namespace.getNamespace("osm", "http://www.openstreetmap.org");
    3730
    3831        /**
     
    136129                        } else if (child.getName().equals("extensions")) {
    137130                                parseKeyValueExtensions(track, child);
    138                                 if (child.getChild("segment", OSM) != null)
     131                                if (child.getChild("segment", JOSM) != null)
    139132                                        realLineSegment = true;
    140133                        } else if (child.getName().equals("link"))
     
    162155         */
    163156        private Node addNode(DataSet data, Node node) {
    164                 if (Main.pref.mergeNodes)
    165                         for (Node n : data.nodes)
    166                                 if (node.coor.equalsLatLon(n.coor))
    167                                         return n;
     157                for (Node n : data.nodes)
     158                        if (node.coor.equalsLatLon(n.coor))
     159                                return n;
    168160                data.nodes.add(node);
    169161                return node;
     
    194186                                }
    195187                        }
     188                        Element idElement = e.getChild("uid", JOSM);
     189                        if (idElement != null)
     190                                osm.id = Long.parseLong(idElement.getText());
     191                        osm.modified = e.getChild("modified", JOSM) != null;
    196192                }
    197193        }
  • src/org/openstreetmap/josm/io/GpxWriter.java

    r32 r33  
    1818import org.openstreetmap.josm.data.osm.LineSegment;
    1919import org.openstreetmap.josm.data.osm.Node;
     20import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2021import org.openstreetmap.josm.data.osm.Track;
    2122
     
    3435        /**
    3536         * The GPX namespace used.
    36          * TODO unify with GpxReader
    37          */
    38         private static final Namespace GPX = Namespace.getNamespace("http://www.topografix.com/GPX/1/0");
     37         */
     38        public static final Namespace GPX = Namespace.getNamespace("http://www.topografix.com/GPX/1/0");
    3939        /**
    4040         * The OSM namespace used (for extensions).
    41          * TODO unify with GpxReader
    42          */
    43         private static final Namespace OSM = Namespace.getNamespace("osm", "http://www.openstreetmap.org");
     41         */
     42        public static final Namespace OSM = Namespace.getNamespace("osm", "http://www.openstreetmap.org");
     43        /**
     44         * The JOSM namespace (for JOSM-extensions).
     45         */
     46        public static final Namespace JOSM = Namespace.getNamespace("josm", "http://wiki.eigenheimstrasse.de/wiki/JOSM");
    4447
    4548        /**
     
    6669                Element root = parseDataSet();
    6770                root.addNamespaceDeclaration(OSM);
     71                root.addNamespaceDeclaration(JOSM);
    6872                Document d = new Document(root);
    6973                XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
     
    8993                for (Track t : Main.main.ds.tracks) {
    9094                        Element tElem = new Element("trk", GPX);
     95                        HashMap<Key, String> keys = null;
    9196                        if (t.keys != null) {
    92                                 HashMap<Key, String> keys = new HashMap<Key, String>(t.keys);
     97                                keys = new HashMap<Key, String>(t.keys);
    9398                                addAndRemovePropertyTag("name", tElem, keys);
    9499                                addAndRemovePropertyTag("cmt", tElem, keys);
     
    98103                                addAndRemovePropertyTag("number", tElem, keys);
    99104                                addAndRemovePropertyTag("type", tElem, keys);
    100                                 addPropertyExtensions(tElem, keys);
    101105                        }
     106                        addPropertyExtensions(tElem, keys, t);
     107
    102108                        // line segments
    103109                        for (LineSegment ls : t.segments) {
     
    118124                        unrefNodes.remove(ls.end);
    119125                        Element ext = new Element("extensions", GPX);
    120                         ext.getChildren().add(new Element("segment", OSM));
     126                        ext.getChildren().add(new Element("segment", JOSM));
    121127                        t.getChildren().add(ext);
    122128                        e.getChildren().add(t);
     
    137143        private Element parseLineSegment(LineSegment ls) {
    138144                Element lsElem = new Element("trkseg", GPX);
    139                 if (ls.keys != null)
    140                 addPropertyExtensions(lsElem, ls.keys);
     145                addPropertyExtensions(lsElem, ls.keys, ls);
    141146                lsElem.getChildren().add(parseWaypoint(ls.start, "trkpt"));
    142147                lsElem.getChildren().add(parseWaypoint(ls.end, "trkpt"));
     
    156161                e.setAttribute("lat", Double.toString(n.coor.lat));
    157162                e.setAttribute("lon", Double.toString(n.coor.lon));
     163                HashMap<Key, String> keys = null;
    158164                if (n.keys != null) {
    159                         HashMap<Key, String> keys = new HashMap<Key, String>(n.keys);
     165                        keys = new HashMap<Key, String>(n.keys);
    160166                        addAndRemovePropertyTag("ele", e, keys);
    161167                        addAndRemovePropertyTag("time", e, keys);
     
    176182                        addAndRemovePropertyTag("ageofdgpsdata", e, keys);
    177183                        addAndRemovePropertyTag("dgpsid", e, keys);
    178                         addPropertyExtensions(e, keys);
    179                 }
     184                }
     185                addPropertyExtensions(e, keys, n);
    180186                return e;
    181187        }
     
    235241         */
    236242        @SuppressWarnings("unchecked")
    237         private void addPropertyExtensions(Element e, Map<Key, String> keys) {
    238                 if (keys.isEmpty())
     243        private void addPropertyExtensions(Element e, Map<Key, String> keys, OsmPrimitive osm) {
     244                if ((keys == null || keys.isEmpty()) && osm.id == 0 && !osm.modified)
    239245                        return;
    240246                Element extensions = e.getChild("extensions", GPX);
    241247                if (extensions == null)
    242248                        e.getChildren().add(extensions = new Element("extensions", GPX));
    243                 for (Entry<Key, String> prop : keys.entrySet()) {
    244                         Element propElement = new Element("property", OSM);
    245                         propElement.setAttribute("key", prop.getKey().name);
    246                         propElement.setAttribute("value", prop.getValue());
     249                if (keys != null && !keys.isEmpty()) {
     250                        for (Entry<Key, String> prop : keys.entrySet()) {
     251                                Element propElement = new Element("property", OSM);
     252                                propElement.setAttribute("key", prop.getKey().name);
     253                                propElement.setAttribute("value", prop.getValue());
     254                                extensions.getChildren().add(propElement);
     255                        }
     256                }
     257                // id
     258                if (osm.id != 0) {
     259                        Element propElement = new Element("uid", JOSM);
     260                        propElement.setText(""+osm.id);
    247261                        extensions.getChildren().add(propElement);
    248262                }
     263                // modified
     264                if (osm.modified) {
     265                        Element modElement = new Element("modified", JOSM);
     266                        extensions.getChildren().add(modElement);
     267                }
    249268        }
    250269}
  • src/org/openstreetmap/josm/io/OsmReader.java

    r32 r33  
    1010import org.jdom.JDOMException;
    1111import org.jdom.input.SAXBuilder;
    12 import org.openstreetmap.josm.Main;
    1312import org.openstreetmap.josm.data.GeoPoint;
    1413import org.openstreetmap.josm.data.osm.DataSet;
     
    1817import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1918import org.openstreetmap.josm.data.osm.Track;
     19import org.openstreetmap.josm.data.osm.visitor.AddVisitor;
    2020
    2121/**
     
    7777
    7878        /**
     79         * Parse any (yet unknown) object and return it.
     80         */
     81        private OsmPrimitive parseObject(Element e, DataSet data) throws JDOMException {
     82                if (e.getName().equals("node"))
     83                        return parseNode(e);
     84                else if (e.getName().equals("segment"))
     85                        return parseLineSegment(e, data);
     86                else if (e.getName().equals("track"))
     87                        return parseTrack(e, data);
     88                else if (e.getName().equals("property")) {
     89                        parseProperty(e, data);
     90                        return null;
     91                }
     92                throw new JDOMException("unknown tag: "+e.getName());
     93        }
     94       
     95        /**
     96         * Read a data set from the element.
     97         * @param e     The element to parse
     98         * @return              The DataSet read from the element
     99         * @throws JDOMException In case of a parsing error.
     100         */
     101        private DataSet parseDataSet(Element e) throws JDOMException {
     102                DataSet data = new DataSet();
     103                AddVisitor visitor = new AddVisitor(data);
     104                for (Object o : e.getChildren()) {
     105                        Element child = (Element)o;
     106                        if (child.getName().equals("deleted"))
     107                                for (Object delObj : child.getChildren())
     108                                        data.deleted.add(parseObject((Element)delObj, data));
     109                        else {
     110                                OsmPrimitive osm = parseObject(child, data);
     111                                if (osm != null)
     112                                        osm.visit(visitor);
     113                        }
     114                }
     115
     116                return data;
     117        }
     118
     119        /**
     120         * Parse and return an line segment. The node information of the "from" and
     121         * "to" attributes must already be in the dataset.
     122         * @param e             The line segment element to parse.
     123         * @param data  The dataset to obtain the node information from.
     124         * @return The parsed line segment.
     125         * @throws JDOMException In case of parsing errors.
     126         */
     127        private LineSegment parseLineSegment(Element e, DataSet data) throws JDOMException {
     128                long startId = Long.parseLong(e.getAttributeValue("from"));
     129                long endId = Long.parseLong(e.getAttributeValue("to"));
     130               
     131                Node start = null, end = null;
     132                for (Node n : data.nodes) {
     133                        if (n.id == startId)
     134                                start = n;
     135                        if (n.id == endId)
     136                                end = n;
     137                }
     138                if (start == null || end == null)
     139                        throw new JDOMException("The 'from' or 'to' object has not been transfered before.");
     140                LineSegment ls = new LineSegment(start, end);
     141                parseCommon(ls, e);
     142                return ls;
     143        }
     144
     145        /**
     146         * Parse and read a track from the element.
     147         *
     148         * @param e             The element that contain the track.
     149         * @param data  The DataSet to get segment information from.
     150         * @return              The parsed track.
     151         * @throws JDOMException In case of a parsing error.
     152         */
     153        private Track parseTrack(Element e, DataSet data) throws JDOMException {
     154                Track track = new Track();
     155                parseCommon(track, e);
     156                for (Object o : e.getChildren("segment")) {
     157                        Element child = (Element)o;
     158                        long id = Long.parseLong(child.getAttributeValue("uid"));
     159                        LineSegment ls = findLineSegment(data.lineSegments, id);
     160                        track.segments.add(ls);
     161                }
     162                return track;
     163        }
     164       
     165        /**
    79166         * Parse the common part (properties and uid) of the element.
    80167         * @param data  To store the data in.
     
    82169         * @throws JDOMException In case of a parsing error
    83170         */
    84         private void parseCommon(OsmPrimitive data, Element e) throws JDOMException {
    85                 data.id = Long.parseLong(e.getAttributeValue("uid"));
    86                 if (data.id == 0)
    87                         throw new JDOMException("Object has illegal or no id.");
     171        private void parseCommon(OsmPrimitive data, Element e) {
     172                String suid = e.getAttributeValue("uid");
     173                if (suid != null)
     174                        data.id = Long.parseLong(suid);
     175                if (data.id < 0)
     176                        data.id = 0;
    88177               
    89178                String propStr = e.getAttributeValue("tags");
     
    105194
    106195        /**
    107          * Read a data set from the element.
    108          * @param e     The element to parse
    109          * @return              The DataSet read from the element
    110          * @throws JDOMException In case of a parsing error.
    111          */
    112         private DataSet parseDataSet(Element e) throws JDOMException {
    113                 DataSet data = new DataSet();
    114                 for (Object o : e.getChildren()) {
    115                         Element child = (Element)o;
    116                         if (child.getName().equals("node"))
    117                                 addNode(data, parseNode(child));
    118                         else if (child.getName().equals("segment")) {
    119                                 LineSegment ls = parseLineSegment(child, data);
    120                                 if (data.lineSegments.contains(ls))
    121                                         throw new JDOMException("Double segment definition "+ls.id);
    122                                 data.lineSegments.add(ls);
    123                         } else if (child.getName().equals("track")) {
    124                                 Track track = parseTrack(child, data);
    125                                 if (data.tracks.contains(track))
    126                                         throw new JDOMException("Double track definition "+track.id);
    127                                 data.tracks.add(track);
    128                         }
    129                 }
    130 
    131                 return data;
    132         }
    133 
    134         /**
    135          * Parse and return an line segment. The node information of the "from" and
    136          * "to" attributes must already be in the dataset.
    137          * @param e             The line segment element to parse.
    138          * @param data  The dataset to obtain the node information from.
    139          * @return The parsed line segment.
    140          * @throws JDOMException In case of parsing errors.
    141          */
    142         private LineSegment parseLineSegment(Element e, DataSet data) throws JDOMException {
    143                 long startId = Long.parseLong(e.getAttributeValue("from"));
    144                 long endId = Long.parseLong(e.getAttributeValue("to"));
    145                
    146                 Node start = null, end = null;
    147                 for (Node n : data.nodes) {
    148                         if (n.id == startId)
    149                                 start = n;
    150                         if (n.id == endId)
    151                                 end = n;
    152                 }
    153                 if (start == null || end == null)
    154                         throw new JDOMException("The 'from' or 'to' object has not been transfered before.");
    155                 LineSegment ls = new LineSegment(start, end);
    156                 parseCommon(ls, e);
    157                 return ls;
    158         }
    159 
    160         /**
    161          * Parse and read a track from the element.
    162          *
    163          * @param e             The element that contain the track.
    164          * @param data  The DataSet to get segment information from.
    165          * @return              The parsed track.
    166          * @throws JDOMException In case of a parsing error.
    167          */
    168         private Track parseTrack(Element e, DataSet data) throws JDOMException {
    169                 Track track = new Track();
    170                 parseCommon(track, e);
    171                 for (Object o : e.getChildren("segment")) {
    172                         Element child = (Element)o;
    173                         long id = Long.parseLong(child.getAttributeValue("uid"));
    174                         LineSegment ls = findLineSegment(data.lineSegments, id);
    175                         track.segments.add(ls);
    176                 }
    177                 return track;
    178         }
    179        
     196         * Parse a property tag and assign the property to a previous found object.
     197         */
     198        private void parseProperty(Element e, DataSet data) throws JDOMException {
     199                long id = Long.parseLong(e.getAttributeValue("uid"));
     200                OsmPrimitive osm = findObject(data, id);
     201                Key key = Key.get(e.getAttributeValue("key"));
     202                String value =e.getAttributeValue("value");
     203                if (value != null) {
     204                        if (osm.keys == null)
     205                                osm.keys = new HashMap<Key, String>();
     206                        osm.keys.put(key, value);
     207                }
     208        }
     209
     210        /**
     211         * Search for an object in the dataset by comparing the id.
     212         */
     213        private OsmPrimitive findObject(DataSet data, long id) throws JDOMException {
     214                for (OsmPrimitive osm : data.nodes)
     215                        if (osm.id == id)
     216                                return osm;
     217                for (OsmPrimitive osm : data.lineSegments)
     218                        if (osm.id == id)
     219                                return osm;
     220                for (OsmPrimitive osm : data.tracks)
     221                        if (osm.id == id)
     222                                return osm;
     223                for (OsmPrimitive osm : data.deleted)
     224                        if (osm.id == id)
     225                                return osm;
     226                throw new JDOMException("Unknown object reference: "+id);
     227        }
     228
    180229        /**
    181230         * Search for a segment in a collection by comparing the id.
     
    187236                throw new JDOMException("Unknown line segment reference: "+id);
    188237        }
    189        
    190         /**
    191          * Adds the node to allNodes if it is not already listed. Does respect the
    192          * preference setting "mergeNodes". Return the node in the list that correspond
    193          * to the node in the list (either the new added or the old found).
    194          *
    195          * If reading raw gps data, mergeNodes are always on (To save memory. You
    196          * can't edit raw gps nodes anyway.)
    197          *
    198          * @param data The DataSet to add the node to.
    199          * @param node The node that should be added.
    200          * @return Either the parameter node or the old node found in the dataset.
    201          */
    202         private Node addNode(DataSet data, Node node) {
    203                 if (Main.pref.mergeNodes)
    204                         for (Node n : data.nodes)
    205                                 if (node.coor.equalsLatLon(n.coor))
    206                                         return n;
    207                 data.nodes.add(node);
    208                 return node;
    209         }
    210238}
Note: See TracChangeset for help on using the changeset viewer.