Changeset 18 in josm for src


Ignore:
Timestamp:
2005-10-09T20:06:06+02:00 (19 years ago)
Author:
imi
Message:

added Server connection to osm server.

Location:
src/org/openstreetmap/josm
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/actions/OpenGpxAction.java

    r17 r18  
    3737
    3838        /**
    39          * Create an open action. The name is "&Open GPX".
     39         * Create an open action. The name is "Open GPX".
    4040         */
    4141        public OpenGpxAction() {
  • src/org/openstreetmap/josm/data/GeoPoint.java

    r17 r18  
    5858                return (x-other.x)*(x-other.x)+(y-other.y)*(y-other.y);
    5959        }
    60        
     60
    6161        /**
    6262         * @return <code>true</code>, if the other GeoPoint has the same lat/lon values.
    6363         */
    6464        public boolean equalsLatLon(GeoPoint other) {
    65                 return lat == other.lat && lon == other.lon;
     65                return lat == other.lat && lon == other.lon &&
     66                                !Double.isNaN(lat) && !Double.isNaN(lon);
    6667        }
    6768}
  • src/org/openstreetmap/josm/data/Preferences.java

    r17 r18  
    4545        private boolean drawRawGpsLines = false;
    4646        /**
     47         * Force the drawing of lines between raw gps points if there are no
     48         * lines in the imported document.
     49         */
     50        private boolean forceRawGpsLines = false;
     51        /**
    4752         * Whether nodes on the same place should be considered identical.
    4853         */
    4954        public boolean mergeNodes = true;
    50        
    51        
     55
     56        /**
     57         * Base URL to the osm data server
     58         */
     59        public String osmDataServer = "http://www.openstreetmap.org/api/0.1";
     60        /**
     61         * The username to the osm server
     62         */
     63        public String osmDataUsername = "";
     64        /**
     65         * The stored password or <code>null</code>, if the password should not be
     66         * stored.
     67         */
     68        public String osmDataPassword = null;
    5269
    5370        /**
     
    105122                        }
    106123
     124                        Element osmServer = root.getChild("osm-server");
     125                        if (osmServer != null) {
     126                                osmDataServer = osmServer.getChildText("url");
     127                                osmDataUsername = osmServer.getChildText("username");
     128                                osmDataPassword = osmServer.getChildText("password");
     129                        }
    107130                        mergeNodes = root.getChild("mergeNodes") != null;
    108131                        drawRawGpsLines = root.getChild("drawRawGpsLines") != null;
     
    129152                if (drawRawGpsLines)
    130153                        children.add(new Element("drawRawGpsLines"));
     154                Element osmServer = new Element("osm-server");
     155                osmServer.getChildren().add(new Element("url").setText(osmDataServer));
     156                osmServer.getChildren().add(new Element("username").setText(osmDataUsername));
     157                osmServer.getChildren().add(new Element("password").setText(osmDataPassword));
     158                children.add(osmServer);
    131159
    132160                try {
     
    200228                return drawRawGpsLines;
    201229        }
     230        public void setForceRawGpsLines(boolean forceRawGpsLines) {
     231                boolean old = this.forceRawGpsLines;
     232                this.forceRawGpsLines = forceRawGpsLines;
     233                firePropertyChanged("forceRawGpsLines", old, forceRawGpsLines);
     234        }
     235        public boolean isForceRawGpsLines() {
     236                return forceRawGpsLines;
     237        }
    202238}
  • src/org/openstreetmap/josm/data/osm/DataSet.java

    r17 r18  
    33import java.util.Collection;
    44import java.util.Collections;
     5import java.util.HashMap;
    56import java.util.HashSet;
     7import java.util.Iterator;
    68import java.util.LinkedList;
     9import java.util.Map;
     10import java.util.Set;
    711
    812import org.openstreetmap.josm.data.Bounds;
     
    196200         */
    197201        public void mergeFrom(DataSet ds, boolean mergeEqualNodes) {
     202                System.out.println(nodes.size()+" "+pendingLineSegments.size()+" "+tracks.size());
    198203                if (mergeEqualNodes) {
    199                         LinkedList<Node> nodesToAdd = new LinkedList<Node>();
    200                         for (Node n : ds.nodes)
    201                                 for (Node mynode : nodes) {
    202                                         if (mynode.coor.equalsLatLon(n.coor))
    203                                                 mynode.mergeFrom(n);
    204                                         else
    205                                                 nodesToAdd.add(n);
     204                        Map<Node, Node> mergeMap = new HashMap<Node, Node>();
     205                        Set<Node> nodesToAdd = new HashSet<Node>();
     206                        for (Node n : nodes) {
     207                                for (Iterator<Node> it = ds.nodes.iterator(); it.hasNext();) {
     208                                        Node dsn = it.next();
     209                                        if (n.coor.equalsLatLon(dsn.coor)) {
     210                                                mergeMap.put(dsn, n);
     211                                                n.mergeFrom(dsn);
     212                                                it.remove();
     213                                        } else {
     214                                                nodesToAdd.add(dsn);
     215                                        }
    206216                                }
    207                 } else
     217                        }
     218                        nodes.addAll(nodesToAdd);
     219                        for (Track t : ds.tracks) {
     220                                for (LineSegment ls : t.segments()) {
     221                                        Node n = mergeMap.get(ls.getStart());
     222                                        if (n != null)
     223                                                ls.start = n;
     224                                        n = mergeMap.get(ls.getEnd());
     225                                        if (n != null)
     226                                                ls.end = n;
     227                                }
     228                        }
     229                        tracks.addAll(ds.tracks);
     230                        for (LineSegment ls : ds.pendingLineSegments) {
     231                                Node n = mergeMap.get(ls.getStart());
     232                                if (n != null)
     233                                        ls.start = n;
     234                                n = mergeMap.get(ls.getEnd());
     235                                if (n != null)
     236                                        ls.end = n;
     237                        }
     238                        pendingLineSegments.addAll(ds.pendingLineSegments);
     239                } else {
    208240                        nodes.addAll(ds.nodes);
    209                 tracks.addAll(ds.tracks);
    210                 pendingLineSegments.addAll(ds.pendingLineSegments);
     241                        tracks.addAll(ds.tracks);
     242                        pendingLineSegments.addAll(ds.pendingLineSegments);
     243                }
     244                System.out.println(nodes.size()+" "+pendingLineSegments.size()+" "+tracks.size());
    211245        }
    212246
  • src/org/openstreetmap/josm/data/osm/LineSegment.java

    r9 r18  
    1818         * The starting node of the line segment
    1919         */
    20         private Node start;
     20        Node start;
    2121       
    2222        /**
    2323         * The ending node of the line segment
    2424         */
    25         private Node end;
     25        Node end;
    2626
    2727        /**
  • src/org/openstreetmap/josm/gui/Main.java

    r17 r18  
    1515import org.openstreetmap.josm.actions.ExitAction;
    1616import org.openstreetmap.josm.actions.OpenGpxAction;
     17import org.openstreetmap.josm.actions.OpenOsmServerAction;
    1718import org.openstreetmap.josm.actions.PreferencesAction;
    1819import org.openstreetmap.josm.actions.SaveGpxAction;
     
    6364               
    6465                // creating actions
     66                OpenOsmServerAction openServerAction = new OpenOsmServerAction();
    6567                OpenGpxAction openGpxAction = new OpenGpxAction();
    6668                SaveGpxAction saveGpxAction = new SaveGpxAction();
     
    8082                mainMenu.add(fileMenu);
    8183               
     84                JMenu connectionMenu = new JMenu("Connection");
     85                connectionMenu.setMnemonic('C');
     86                connectionMenu.add(openServerAction);
     87                mainMenu.add(connectionMenu);
     88               
    8289                JMenu editMenu = new JMenu("Edit");
    8390                editMenu.setMnemonic('E');
     
    8895                JToolBar toolBar = new JToolBar();
    8996                toolBar.setFloatable(false);
     97                toolBar.add(openServerAction);
    9098                toolBar.add(openGpxAction);
    9199                toolBar.add(saveGpxAction);
  • src/org/openstreetmap/josm/gui/MapMover.java

    r16 r18  
    5555                        GeoPoint p = new GeoPoint();
    5656                        p.x = mousePosMove.x + center.x - mouseCenter.x; 
    57                         p.y = mousePosMove.y + center.y - mouseCenter.y; 
     57                        p.y = mousePosMove.y + center.y - mouseCenter.y;
    5858                        mv.zoomTo(p, mv.getScale());
    5959                } else
  • src/org/openstreetmap/josm/gui/PreferenceDialog.java

    r17 r18  
    2121import javax.swing.JOptionPane;
    2222import javax.swing.JPanel;
     23import javax.swing.JPasswordField;
    2324import javax.swing.JTabbedPane;
     25import javax.swing.JTextField;
    2426import javax.swing.ListCellRenderer;
    2527import javax.swing.UIManager;
     
    5254                        Main.pref.setProjection(projection);
    5355                        Main.pref.mergeNodes = mergeNodes.isSelected();
     56                        Main.pref.osmDataServer = osmDataServer.getText();
     57                        Main.pref.osmDataUsername = osmDataUsername.getText();
     58                        Main.pref.osmDataPassword = String.valueOf(osmDataPassword.getPassword());
     59                        if (Main.pref.osmDataPassword == "")
     60                                Main.pref.osmDataPassword = null;
    5461                        Main.pref.setDrawRawGpsLines(drawRawGpsLines.isSelected());
     62                        Main.pref.setForceRawGpsLines(forceRawGpsLines.isSelected());
    5563                        try {
    5664                                Main.pref.save();
     
    97105
    98106        /**
     107         * Editfield for the Base url to the REST API from OSM.
     108         */
     109        private JTextField osmDataServer = new JTextField(20);
     110        /**
     111         * Editfield for the username to the OSM account.
     112         */
     113        private JTextField osmDataUsername = new JTextField(20);
     114        /**
     115         * Passwordfield for the userpassword of the REST API.
     116         */
     117        private JPasswordField osmDataPassword = new JPasswordField(20);
     118        /**
    99119         * The checkbox stating whether nodes should be merged together.
    100120         */
    101121        private JCheckBox drawRawGpsLines = new JCheckBox("Draw lines between raw gps points.");
     122        /**
     123         * The checkbox stating whether raw gps lines should be forced.
     124         */
     125        private JCheckBox forceRawGpsLines = new JCheckBox("Force lines if no line segments imported.");
    102126        /**
    103127         * The checkbox stating whether nodes should be merged together.
     
    155179                });
    156180               
     181                // drawRawGpsLines
     182                drawRawGpsLines.addActionListener(new ActionListener(){
     183                        public void actionPerformed(ActionEvent e) {
     184                                if (!drawRawGpsLines.isSelected())
     185                                        forceRawGpsLines.setSelected(false);
     186                                forceRawGpsLines.setEnabled(drawRawGpsLines.isSelected());
     187                        }
     188                });
     189
     190               
    157191                // tooltips
     192                osmDataServer.setToolTipText("The base URL to the OSM server (REST API)");
     193                osmDataUsername.setToolTipText("Login name (email) to the OSM account.");
     194                osmDataPassword.setToolTipText("Login password to the OSM account. Leave blank to not store any password.");
    158195                drawRawGpsLines.setToolTipText("If your gps device draw to few lines, select this to draw lines along your track.");
    159196                drawRawGpsLines.setSelected(Main.pref.isDrawRawGpsLines());
     197                forceRawGpsLines.setToolTipText("Force drawing of lines if the imported data contain no line information.");
     198                forceRawGpsLines.setSelected(Main.pref.isForceRawGpsLines());
    160199                mergeNodes.setToolTipText("When importing GPX data, all nodes with exact the same lat/lon are merged.");
    161200                mergeNodes.setSelected(Main.pref.mergeNodes);
    162                
     201
     202                osmDataServer.setText(Main.pref.osmDataServer);
     203                osmDataUsername.setText(Main.pref.osmDataUsername);
     204                osmDataPassword.setText(Main.pref.osmDataPassword);
     205
    163206                // Display tab
    164207                JPanel display = createPreferenceTab("display", "Display Settings", "Various settings that influence the visual representation of the whole program.");
     
    167210                display.add(lafCombo, GBC.eol().fill(GBC.HORIZONTAL));
    168211                display.add(drawRawGpsLines, GBC.eol().insets(20,0,0,0));
     212                display.add(forceRawGpsLines, GBC.eol().insets(40,0,0,0));
    169213                display.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
    170214
     215                // Connection tab
     216                JPanel con = createPreferenceTab("connection", "Connection Settings", "Connection Settings to the OSM server.");
     217                con.add(new JLabel("Base Server URL"), GBC.std());
     218                con.add(osmDataServer, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
     219                con.add(new JLabel("OSM username (email)"), GBC.std());
     220                con.add(osmDataUsername, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
     221                con.add(new JLabel("OSM password"), GBC.std());
     222                con.add(osmDataPassword, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,0));
     223                JLabel warning = new JLabel("<html>" +
     224                                "WARNING: The password is stored in plain text in the preferences file.<br>" +
     225                                "The password is transfered in plain text to the server, encoded in the url.<br>" +
     226                                "<b>Do not use a valuable Password.</b></html>");
     227                warning.setFont(warning.getFont().deriveFont(Font.ITALIC));
     228                con.add(warning, GBC.eop().fill(GBC.HORIZONTAL));
     229
     230               
    171231                // Map tab
    172232                JPanel map = createPreferenceTab("map", "Map Settings", "Settings for the map projection and data interpretation.");
     
    221281
    222282                tabPane.addTab(null, ImageProvider.get("preferences", icon), p);
     283                tabPane.setToolTipTextAt(tabPane.getTabCount()-1, desc);
    223284                return p;
    224285        }
  • src/org/openstreetmap/josm/gui/dialogs/LayerList.java

    r17 r18  
    8989                                        icon = ImageProvider.overlay(icon, invisible, ImageProvider.OverlayPosition.SOUTHEAST);
    9090                                label.setIcon(icon);
     91                               
     92                                DataSet ds = layer.getDataSet();
     93                                if (ds != null) {
     94                                        label.setToolTipText(ds.nodes.size()+" nodes, "+
     95                                                        ds.tracks().size()+" tracks");
     96                                }
    9197                                return label;
    9298                        }
  • src/org/openstreetmap/josm/gui/engine/RawGpsEngine.java

    r17 r18  
    22
    33import java.awt.Color;
     4import java.awt.Graphics;
    45import java.awt.Point;
    56import java.beans.PropertyChangeEvent;
     
    1011import org.openstreetmap.josm.data.osm.Track;
    1112import org.openstreetmap.josm.gui.Main;
     13import org.openstreetmap.josm.gui.MapView;
    1214
    1315/**
     
    1921
    2022        /**
     23         * Draw a line to this node if forceRawGpsLines is set.
     24         */
     25        private Node lastNode;
     26       
     27        /**
    2128         * Create a raw gps engine. The engine will register itself as listener on
    2229         * the main preference settings to capture the drawRawGpsLines changes.
     
    2431        public RawGpsEngine() {
    2532                Main.pref.addPropertyChangeListener(this);
     33        }
     34
     35       
     36        @Override
     37        public void init(Graphics g, MapView mv) {
     38                super.init(g, mv);
     39                lastNode = null;
    2640        }
    2741
     
    3448                g.setColor(n.isSelected() ? Color.WHITE : Color.GRAY);
    3549                g.drawRect(p.x, p.y, 0, 0);
     50                if (Main.pref.isForceRawGpsLines()) {
     51                        if (lastNode != null)
     52                                drawLine(lastNode, n, false, Color.GRAY);
     53                        lastNode = n;
     54                }
    3655        }
    3756
     
    4665                        return;
    4766                for (LineSegment ls : t.segments())
    48                         drawLineSegment(ls, t.isSelected() ? Color.WHITE : Color.GRAY);
     67                        drawLine(ls.getStart(), ls.getEnd(), ls.isSelected(), t.isSelected() ? Color.WHITE : Color.GRAY);
    4968        }
    5069
     
    5473        @Override
    5574        public void drawPendingLineSegment(LineSegment ls) {
    56                 drawLineSegment(ls, Color.GRAY);
     75                drawLine(ls.getStart(), ls.getEnd(), ls.isSelected(), Color.GRAY);
    5776        }
    5877
     
    6281         * @param color         The color, the line segment should be drawn in.
    6382         */
    64         private void drawLineSegment(LineSegment ls, Color color) {
    65                 g.setColor(ls.isSelected() ? Color.WHITE : color);
    66                 Point p1 = mv.getScreenPoint(ls.getStart().coor);
    67                 Point p2 = mv.getScreenPoint(ls.getEnd().coor);
     83        private void drawLine(Node start, Node end, boolean isSelected, Color color) {
     84                g.setColor(isSelected ? Color.WHITE : color);
     85                Point p1 = mv.getScreenPoint(start.coor);
     86                Point p2 = mv.getScreenPoint(end.coor);
    6887                g.drawLine(p1.x, p1.y, p2.x, p2.y);
    6988        }
     
    7493         */
    7594        public void propertyChange(PropertyChangeEvent e) {
    76                 if (e.getPropertyName().equals("drawRawGpsLines"))
     95                if (e.getPropertyName().equals("drawRawGpsLines") || e.getPropertyName().equals("forceRawGpsLines"))
    7796                        mv.repaint();
    7897        }
Note: See TracChangeset for help on using the changeset viewer.