Changeset 43 in josm


Ignore:
Timestamp:
2006-01-22T16:10:57+01:00 (18 years ago)
Author:
imi
Message:
  • removed UTM (too complex)
  • added please wait dialog for down-/uploading
  • added created_by=JOSM to every new element
Location:
src/org/openstreetmap/josm
Files:
1 deleted
11 edited

Legend:

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

    r42 r43  
    1414import javax.swing.JButton;
    1515import javax.swing.JCheckBox;
     16import javax.swing.JDialog;
    1617import javax.swing.JLabel;
    1718import javax.swing.JOptionPane;
     
    7475                dlg.add(latlon[2], GBC.std());
    7576                dlg.add(new JLabel("max lon"), GBC.std().insets(10,0,5,0));
    76                 dlg.add(latlon[3], GBC.eop());
     77                dlg.add(latlon[3], GBC.eol());
    7778
    7879                if (Main.main.getMapFrame() != null) {
     
    159160                        return;
    160161                }
    161                 OsmServerReader osmReader = new OsmServerReader(b.latlon[0], b.latlon[1], b.latlon[2], b.latlon[3]);
    162                 try {
    163                         String name = latlon[0].getText()+" "+latlon[1].getText()+" x "+
    164                                         latlon[2].getText()+" "+latlon[3].getText();
    165                        
    166                         Layer layer;
    167                         if (rawGps.isSelected()) {
    168                                 layer = new RawGpsDataLayer(osmReader.parseRawGps(), name);
    169                         } else {
    170                                 DataSet dataSet = osmReader.parseOsm();
    171                                 if (dataSet == null)
    172                                         return; // user cancelled download
    173                                 if (dataSet.nodes.isEmpty())
    174                                         JOptionPane.showMessageDialog(Main.main, "No data imported.");
    175                                
    176                                 layer = new OsmDataLayer(dataSet, name);
    177                         }
    178 
    179                         if (Main.main.getMapFrame() == null)
    180                                 Main.main.setMapFrame(name, new MapFrame(layer));
    181                         else
    182                                 Main.main.getMapFrame().mapView.addLayer(layer);
    183                 } catch (JDOMException x) {
    184                         x.printStackTrace();
    185                         JOptionPane.showMessageDialog(Main.main, x.getMessage());
    186                 } catch (FileNotFoundException x) {
    187                         x.printStackTrace();
    188                         JOptionPane.showMessageDialog(Main.main, "URL nicht gefunden: "+x.getMessage());
    189                 } catch (IOException x) {
    190                         x.printStackTrace();
    191                         JOptionPane.showMessageDialog(Main.main, x.getMessage());
    192                 }
     162               
     163                final OsmServerReader osmReader = new OsmServerReader(b.latlon[0], b.latlon[1], b.latlon[2], b.latlon[3]);
     164               
     165                final JDialog pleaseWaitDlg = createPleaseWaitDialog("Downloading data");
     166               
     167                new Thread(){
     168                        @Override
     169                        public void run() {
     170                                try {
     171                                        String name = latlon[0].getText() + " "
     172                                                        + latlon[1].getText() + " x " + latlon[2].getText()
     173                                                        + " " + latlon[3].getText();
     174
     175                                        Layer layer = null;
     176                                        if (rawGps.isSelected()) {
     177                                                layer = new RawGpsDataLayer(osmReader.parseRawGps(),
     178                                                                name);
     179                                        } else {
     180                                                DataSet dataSet = osmReader.parseOsm();
     181                                                if (dataSet == null)
     182                                                        return; // user cancelled download
     183                                                if (dataSet.nodes.isEmpty())
     184                                                        JOptionPane.showMessageDialog(Main.main,
     185                                                                        "No data imported.");
     186
     187                                                layer = new OsmDataLayer(dataSet, name);
     188                                        }
     189
     190                                        if (Main.main.getMapFrame() == null)
     191                                                Main.main.setMapFrame(name, new MapFrame(layer));
     192                                        else
     193                                                Main.main.getMapFrame().mapView.addLayer(layer);
     194                                        pleaseWaitDlg.setVisible(false);
     195                                } catch (JDOMException x) {
     196                                        pleaseWaitDlg.setVisible(false);
     197                                        x.printStackTrace();
     198                                        JOptionPane.showMessageDialog(Main.main, x.getMessage());
     199                                } catch (FileNotFoundException x) {
     200                                        pleaseWaitDlg.setVisible(false);
     201                                        x.printStackTrace();
     202                                        JOptionPane.showMessageDialog(Main.main,
     203                                                        "URL nicht gefunden: " + x.getMessage());
     204                                } catch (IOException x) {
     205                                        pleaseWaitDlg.setVisible(false);
     206                                        x.printStackTrace();
     207                                        JOptionPane.showMessageDialog(Main.main, x.getMessage());
     208                                } finally {
     209                                        pleaseWaitDlg.setVisible(false);
     210                                }
     211                        }
     212                }.start();
     213               
     214                pleaseWaitDlg.setVisible(true);
    193215        }
    194216       
  • src/org/openstreetmap/josm/actions/JosmAction.java

    r30 r43  
    44
    55import javax.swing.AbstractAction;
     6import javax.swing.BorderFactory;
     7import javax.swing.JDialog;
     8import javax.swing.JLabel;
    69
     10import org.openstreetmap.josm.Main;
    711import org.openstreetmap.josm.gui.ImageProvider;
    812
     
    3034                        putValue(ACCELERATOR_KEY, shortCut);
    3135        }
     36
     37        /**
     38         * @return A dialog labeled "... Please Wait." where ... is the message parameter.
     39         */
     40        protected JDialog createPleaseWaitDialog(String msg) {
     41                final JDialog pleaseWaitDlg = new JDialog(Main.main, true);
     42                pleaseWaitDlg.setUndecorated(true);
     43                JLabel l = new JLabel(msg+". Please Wait.");
     44                l.setBorder(BorderFactory.createCompoundBorder(
     45                                BorderFactory.createEtchedBorder(),
     46                                BorderFactory.createEmptyBorder(20,20,20,20)));
     47                pleaseWaitDlg.getContentPane().add(l);
     48                pleaseWaitDlg.pack();
     49                pleaseWaitDlg.setLocation(Main.main.getWidth()/2-pleaseWaitDlg.getWidth()/2,
     50                                Main.main.getHeight()/2-pleaseWaitDlg.getHeight()/2);
     51                pleaseWaitDlg.setResizable(false);
     52                pleaseWaitDlg.setAlwaysOnTop(true);
     53                return pleaseWaitDlg;
     54        }
    3255}
  • src/org/openstreetmap/josm/actions/UploadAction.java

    r35 r43  
    88import java.util.LinkedList;
    99
     10import javax.swing.JDialog;
    1011import javax.swing.JLabel;
    1112import javax.swing.JList;
     
    4243                Collection<OsmPrimitive> update = new LinkedList<OsmPrimitive>();
    4344                Collection<OsmPrimitive> delete = new LinkedList<OsmPrimitive>();
     45                boolean acceptedTracks = false;
    4446                for (OsmPrimitive osm : Main.main.ds.allPrimitives()) {
    45                         if (osm instanceof Track) {
     47                        boolean doSomething = true;
     48                        if (osm.id == 0 && !osm.isDeleted())
     49                                add.add(osm);
     50                        else if ((osm.modified || osm.modifiedProperties) && !osm.isDeleted())
     51                                update.add(osm);
     52                        else if (osm.isDeleted() && osm.id != 0)
     53                                delete.add(osm);
     54                        else
     55                                doSomething = false;
     56
     57                        if (osm instanceof Track && doSomething && !acceptedTracks) {
    4658                                int answer = JOptionPane.showConfirmDialog(Main.main,
    4759                                                "The server currently does not understand the concept of Tracks.\n" +
     
    5062                                if (answer != JOptionPane.YES_OPTION)
    5163                                        return;
     64                                acceptedTracks = true;
    5265                        }
    53                         if (osm.id == 0 && !osm.isDeleted())
    54                                 add.add(osm);
    55                         else if ((osm.modified || osm.modifiedProperties) && !osm.isDeleted())
    56                                 update.add(osm);
    57                         else if (osm.isDeleted() && osm.id != 0)
    58                                 delete.add(osm);
    5966                }
    6067
     
    6269                        return;
    6370
    64                 OsmServerWriter server = new OsmServerWriter();
    65                 try {
    66                         Collection<OsmPrimitive> all = new LinkedList<OsmPrimitive>();
    67                         all.addAll(add);
    68                         all.addAll(update);
    69                         all.addAll(delete);
    70                         server.uploadOsm(all);
    71                         // finished without errors -> clean dataset
    72                         Main.main.getMapFrame().mapView.editLayer().cleanData();
    73                 } catch (JDOMException x) {
    74                         x.printStackTrace();
    75                         JOptionPane.showMessageDialog(Main.main, x.getMessage());
    76                 }
     71                final OsmServerWriter server = new OsmServerWriter();
     72                final Collection<OsmPrimitive> all = new LinkedList<OsmPrimitive>();
     73                all.addAll(add);
     74                all.addAll(update);
     75                all.addAll(delete);
     76               
     77                final JDialog dlg = createPleaseWaitDialog("Uploading data");
     78                new Thread(){
     79                        @Override
     80                        public void run() {
     81                                try {
     82                                        server.uploadOsm(all);
     83                                } catch (JDOMException x) {
     84                                        dlg.setVisible(false);
     85                                        x.printStackTrace();
     86                                        JOptionPane.showMessageDialog(Main.main, x.getMessage());
     87                                } finally {
     88                                        dlg.setVisible(false);
     89                                }
     90                        }
     91                }.start();
     92               
     93                dlg.setVisible(true);
     94               
     95                // finished without errors -> clean dataset
     96                Main.main.getMapFrame().mapView.editLayer().cleanData();
    7797        }
    7898       
  • src/org/openstreetmap/josm/data/Preferences.java

    r42 r43  
    2121import org.openstreetmap.josm.data.projection.Mercator;
    2222import org.openstreetmap.josm.data.projection.Projection;
    23 import org.openstreetmap.josm.data.projection.UTM;
    2423
    2524
     
    3938         * The convertor used to translate lat/lon points to screen points.
    4039         */
    41         private Projection projection = new UTM();
     40        private Projection projection = new Epsg4263();
    4241
    4342
     
    7877         */
    7978        public static final Projection[] allProjections = new Projection[]{
    80                 new Mercator(),
    81                 new UTM(),
    82                 new Epsg4263()
     79                new Epsg4263(),
     80                new Mercator()
    8381        };
    8482
     
    124122                        // projection
    125123                        Class<?> projectionClass = Class.forName(root.getChildText("projection"));
    126                         projection = allProjections[0]; // defaults to UTM
     124                        projection = allProjections[0];
    127125                        for (Projection p : allProjections) {
    128126                                if (p.getClass() == projectionClass) {
  • src/org/openstreetmap/josm/data/projection/Epsg4263.java

    r42 r43  
    11package org.openstreetmap.josm.data.projection;
    2 
    3 import javax.swing.JComponent;
    42
    53import org.openstreetmap.josm.data.GeoPoint;
     
    108 * @author imi
    119 */
    12 public class Epsg4263 extends Projection {
     10public class Epsg4263 implements Projection {
    1311
    14         @Override
    1512        public void latlon2xy(GeoPoint p) {
    1613                p.x = p.lon;
     
    1815        }
    1916
    20         @Override
    2117        public void xy2latlon(GeoPoint p) {
    2218                p.lat = p.y;
     
    2824                return "EPSG:4263";
    2925        }
    30 
    31         @Override
    32         public JComponent getConfigurationPanel() {
    33                 return null;
    34         }
    35 
    36         @Override
    37         public void commitConfigurationPanel() {
    38         }
    3926}
  • src/org/openstreetmap/josm/data/projection/Mercator.java

    r39 r43  
    11package org.openstreetmap.josm.data.projection;
    2 
    3 import javax.swing.JComponent;
    42
    53import org.openstreetmap.josm.data.GeoPoint;
     
    1412 * @author imi
    1513 */
    16 public class Mercator extends Projection {
     14public class Mercator implements Projection {
    1715
    18         @Override
    1916        public void latlon2xy(GeoPoint p) {
    2017                p.x = p.lon*Math.PI/180;
     
    2219        }
    2320
    24         @Override
    2521        public void xy2latlon(GeoPoint p) {
    2622                p.lon = p.x*180/Math.PI;
     
    3228                return "Mercator";
    3329        }
    34 
    35         @Override
    36         public JComponent getConfigurationPanel() {
    37                 return null;
    38         }
    39 
    40         @Override
    41         public void commitConfigurationPanel() {
    42         }
    4330}
  • src/org/openstreetmap/josm/data/projection/Projection.java

    r41 r43  
    11package org.openstreetmap.josm.data.projection;
    22
    3 import java.util.LinkedList;
    4 import java.util.List;
    5 
    6 import javax.swing.JComponent;
    7 import javax.swing.event.ChangeEvent;
    8 import javax.swing.event.ChangeListener;
    9 
    10 import org.openstreetmap.josm.data.Bounds;
    113import org.openstreetmap.josm.data.GeoPoint;
    124
     
    179 * @author imi
    1810 */
    19 abstract public class Projection implements Cloneable {
     11public interface Projection {
    2012
    2113        public static double MAX_LAT = 85;
    2214        public static double MAX_LON = 180;
    23 
    24         /**
    25          * The event list with all state chaned listener
    26          */
    27         List<ChangeListener> listener = new LinkedList<ChangeListener>();
    2815       
    2916        /**
     
    3219         * @param p             The geo point to convert. x/y members of the point are filled.
    3320         */
    34         abstract public void latlon2xy(GeoPoint p);
     21        void latlon2xy(GeoPoint p);
    3522       
    3623        /**
     
    3926         * @param p             The geo point to convert. lat/lon members of the point are filled.
    4027         */
    41         abstract public void xy2latlon(GeoPoint p);
     28        void xy2latlon(GeoPoint p);
    4229
    4330       
     
    4734         * Describe the projection converter in one or two words.
    4835         */
    49         @Override
    50         abstract public String toString();
    51        
    52         // miscellous functions
    53        
    54         /**
    55          * If the projection supports any configuration, this function return
    56          * the configuration panel. If no configuration needed,
    57          * return <code>null</code>.
    58          *
    59          * The items on the configuration panel should not update the configuration
    60          * directly, but remember changed settings so a call to commitConfigurationPanel
    61          * can set them.
    62          *
    63          * This function also rolls back all changes to the configuration panel interna
    64          * components.
    65          */
    66         abstract public JComponent getConfigurationPanel();
    67         /**
    68          * Commits any changes from components created by addToConfigurationPanel.
    69          * The projection should now obtain the new settings. If any setting has
    70          * changed, the implementation have to call to fireStateChanged to inform
    71          * the listeners.
    72          */
    73         abstract public void commitConfigurationPanel();
    74 
    75         /**
    76          * Initialize itself with the given bounding rectangle (regarding lat/lon).
    77          *
    78          * This function should initialize own parameters needed to do the
    79          * projection at best effort.
    80          *
    81          * Init must not fire an state changed event, since it is usually called
    82          * during the initialization of the mapFrame.
    83          *
    84          * This implementation does nothing. It is provided only for subclasses
    85          * to initialize their data members.
    86          */
    87         public void init(Bounds b) {}
    88        
    89         /**
    90          * Add an event listener to the state changed event queue. If passed
    91          * <code>null</code>, nothing happens.
    92          */
    93         public final void addChangeListener(ChangeListener l) {
    94                 if (l != null)
    95                         listener.add(l);
    96         }
    97         /**
    98          * Remove an event listener from the event queue. If passed
    99          * <code>null</code>, nothing happens.
    100          */
    101         public final void removeChangeListener(ChangeListener l) {
    102                 listener.remove(l);
    103         }
    104         /**
    105          * Fire an ChangeEvent to every listener on the queue.
    106          */
    107         public final void fireStateChanged() {
    108                 ChangeEvent e = null;
    109                 for(ChangeListener l : listener) {
    110                         if (e == null)
    111                                 e = new ChangeEvent(this);
    112                         l.stateChanged(e);
    113                 }
    114         }
     36        String toString();
    11537}
  • src/org/openstreetmap/josm/gui/MapView.java

    r42 r43  
    2020import org.openstreetmap.josm.data.GeoPoint;
    2121import org.openstreetmap.josm.data.osm.DataSet;
    22 import org.openstreetmap.josm.data.osm.Node;
    2322import org.openstreetmap.josm.data.projection.Projection;
    2423import org.openstreetmap.josm.gui.layer.Layer;
     
    9796         */
    9897        public void addLayer(Layer layer) {
    99                 // initialize the projection if it is the first layer
    100                 if (layers.isEmpty())
    101                         getProjection().init(layer.getBoundsLatLon());
    102 
    10398                // reinitialize layer's data
    10499                layer.init(getProjection());
     
    339334                // reset all datasets.
    340335                Projection p = getProjection();
    341                 for (Node n : Main.main.ds.nodes)
    342                         p.latlon2xy(n.coor);
     336                for (Layer l : layers)
     337                        l.init(p);
    343338                recalculateCenterScale();
    344339        }
     
    351346         */
    352347        public void propertyChange(PropertyChangeEvent evt) {
    353                 if (!evt.getPropertyName().equals("projection"))
    354                         return;
    355                 if (evt.getOldValue() != null)
    356                         ((Projection)evt.getOldValue()).removeChangeListener(this);
    357                 if (evt.getNewValue() != null) {
    358                         Projection p = (Projection)evt.getNewValue();
    359                         p.addChangeListener(this);
    360        
     348                if (evt.getPropertyName().equals("projection"))
    361349                        stateChanged(new ChangeEvent(this));
    362                 }
    363350        }
    364351}
  • src/org/openstreetmap/josm/gui/PreferenceDialog.java

    r38 r43  
    1515import javax.swing.JCheckBox;
    1616import javax.swing.JComboBox;
    17 import javax.swing.JComponent;
    1817import javax.swing.JDialog;
    1918import javax.swing.JLabel;
     
    5150                public void actionPerformed(ActionEvent e) {
    5251                        Main.pref.laf = (LookAndFeelInfo)lafCombo.getSelectedItem();
    53                         Projection projection = (Projection)projectionCombo.getSelectedItem();
    54                         projection.commitConfigurationPanel();
    55                         Main.pref.setProjection(projection);
     52                        Main.pref.setProjection((Projection)projectionCombo.getSelectedItem());
    5653                        Main.pref.osmDataServer = osmDataServer.getText();
    5754                        Main.pref.osmDataUsername = osmDataUsername.getText();
     
    9996         * Combobox with all projections available
    10097         */
    101         JComboBox projectionCombo = new JComboBox(Preferences.allProjections.clone());
     98        JComboBox projectionCombo = new JComboBox(Preferences.allProjections);
    10299        /**
    103100         * The main tab panel.
     
    160157                        }
    161158                }
    162                 JButton projectionDetail = new JButton("Configure");
    163                 projectionDetail.addActionListener(new ActionListener(){
    164                         public void actionPerformed(ActionEvent e) {
    165                                 Projection p = (Projection)projectionCombo.getSelectedItem();
    166                                 JComponent configurationPanel = p.getConfigurationPanel();
    167                                 if (configurationPanel == null) {
    168                                         JOptionPane.showMessageDialog(PreferenceDialog.this,
    169                                                         "This projection does not need any configuration.");
    170                                         return;
    171                                 }
    172                                 JPanel detail = new JPanel(new GridBagLayout());
    173                                 detail.setLayout(new GridBagLayout());
    174                                 detail.add(configurationPanel, GBC.eop().fill());
    175                                 int result = JOptionPane.showConfirmDialog(
    176                                                 PreferenceDialog.this, detail, "Configuration of "+p,
    177                                                 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    178                                 if (result != JOptionPane.OK_OPTION)
    179                                         p.getConfigurationPanel(); // rollback
    180                         }
    181                 });
    182159               
    183160                // drawRawGpsLines
     
    242219                map.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
    243220                map.add(projectionCombo, GBC.eol().fill(GBC.HORIZONTAL).insets(0,0,0,5));
    244                 map.add(new JLabel("Projection details:"), GBC.std());
    245                 map.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
    246                 map.add(projectionDetail, GBC.eop());
    247221                map.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
    248222
  • src/org/openstreetmap/josm/gui/WorldChooser.java

    r42 r43  
    1313
    1414import javax.swing.ImageIcon;
    15 import javax.swing.JComponent;
    1615import javax.swing.JTextField;
    1716import javax.swing.SwingUtilities;
     
    6362                new MapMover(this);
    6463                projection = new Projection(){
    65                         @Override
    6664                        public void latlon2xy(GeoPoint p) {
    6765                                p.x = (p.lon+180) / 360 * world.getIconWidth();
    6866                                p.y = (p.lat+90) / 180 * world.getIconHeight();
    6967                        }
    70                         @Override
    7168                        public void xy2latlon(GeoPoint p) {
    7269                                p.lon = p.x*360/world.getIconWidth() - 180;
     
    7673                        public String toString() {
    7774                                return "WorldChooser";
    78                         }
    79                         @Override
    80                         public JComponent getConfigurationPanel() {
    81                                 return null;
    82                         }
    83                         @Override
    84                         public void commitConfigurationPanel() {
    8575                        }
    8676                };
  • src/org/openstreetmap/josm/io/OsmServerWriter.java

    r41 r43  
    88import java.net.HttpURLConnection;
    99import java.net.URL;
     10import java.net.UnknownHostException;
    1011import java.util.Collection;
     12import java.util.HashMap;
    1113
    1214import org.jdom.Document;
     
    5658         * Upload a single node.
    5759         */
    58         @SuppressWarnings("unchecked")
    5960        public void visit(Node n) {
    6061                if (n.id == 0 && !n.isDeleted()) {
     62                        setCredits(n);
    6163                        sendRequest("PUT", "newnode", n, true);
    6264                } else if (n.isDeleted()) {
     
    6769        }
    6870
     71        /**
     72         * Upload a line segment (without the nodes).
     73         */
    6974        public void visit(LineSegment ls) {
    7075                if (ls.id == 0 && !ls.isDeleted()) {
     76                        setCredits(ls);
    7177                        sendRequest("PUT", "newsegment", ls, true);
    7278                } else if (ls.isDeleted()) {
     
    7581                        sendRequest("PUT", "segment/" + ls.id, ls, true);
    7682                }
     83        }
     84
     85        /**
     86         * Add the created_by - property to indicate that JOSM was the
     87         * creating application.
     88         * @param osm The primitive to add the credits to
     89         */
     90        private void setCredits(OsmPrimitive osm) {
     91                if (osm.keys == null)
     92                        osm.keys = new HashMap<Key, String>();
     93                osm.keys.put(Key.get("created_by"), "JOSM");
    7794        }
    7895
     
    130147                                osm.id = readId(con.getInputStream());
    131148                        con.disconnect();
     149                } catch (UnknownHostException e) {
     150                        throw new RuntimeException("Unknown host: "+e.getMessage(), e);
    132151                } catch (Exception e) {
    133152                        throw new RuntimeException(e.getMessage(), e);
Note: See TracChangeset for help on using the changeset viewer.