Changeset 38 in josm


Ignore:
Timestamp:
2006-01-02T21:57:25+01:00 (18 years ago)
Author:
imi
Message:

Added support for CSV import (well, CSV without "" specification)

Location:
src/org/openstreetmap/josm
Files:
1 added
4 edited

Legend:

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

    r32 r38  
    88import java.io.FileReader;
    99import java.io.IOException;
     10import java.io.Reader;
    1011import java.util.Collection;
     12import java.util.LinkedList;
    1113
    1214import javax.swing.Box;
     
    2931import org.openstreetmap.josm.io.GpxReader;
    3032import org.openstreetmap.josm.io.OsmReader;
     33import org.openstreetmap.josm.io.RawCsvReader;
    3134import org.openstreetmap.josm.io.RawGpsReader;
    3235
     
    5558                JCheckBox rawGps = new JCheckBox("Raw GPS data", true);
    5659                rawGps.setToolTipText("Check this, if the data were obtained from a gps device.");
    57                 JCheckBox newLayer = new JCheckBox("As Layer", true);
    58                 newLayer.setToolTipText("Open as a new layer or replace all current layers.");
    59                 if (Main.main.getMapFrame() == null) {
    60                         newLayer.setEnabled(false);
    61                         newLayer.setSelected(false);
    62                 }
    6360               
    6461                JPanel p = new JPanel(new GridBagLayout());
    6562                p.add(new JLabel("Options"), GBC.eop());
    6663                p.add(rawGps, GBC.eol());
    67                 p.add(newLayer, GBC.eol());
    6864                p.add(Box.createVerticalGlue(), GBC.eol().fill());
    6965                fc.setAccessory(p);
     
    7167                if (fc.showOpenDialog(Main.main) != JFileChooser.APPROVE_OPTION)
    7268                        return;
    73                
     69
    7470                File filename = fc.getSelectedFile();
    7571                if (filename == null)
     
    7874                try {
    7975                        Layer layer;
     76                        Reader in = new FileReader(filename);
     77                        String extension = filename.getName().toLowerCase().substring(filename.getName().lastIndexOf('.')+1);
    8078                        if (rawGps.isSelected()) {
    81                                 Collection<Collection<GeoPoint>> data = new RawGpsReader(new FileReader(filename)).parse();
     79                                Collection<Collection<GeoPoint>> data;
     80                                if (extension.equals("gpx"))
     81                                        data = new RawGpsReader(in).parse();
     82                                else if (extension.equals("xml") || extension.equals("osm")) {
     83                                        JOptionPane.showMessageDialog(Main.main, "Osm server data import for GPS data is not supported.");
     84                                        return;
     85                                } else if (extension.equals("csv") || extension.equals("txt")) {
     86                                        data = new LinkedList<Collection<GeoPoint>>();
     87                                        data.add(new RawCsvReader(in).parse());
     88                                } else {
     89                                        JOptionPane.showMessageDialog(Main.main, "Unknown file extension: "+extension);
     90                                        return;
     91                                }
    8292                                layer = new RawGpsDataLayer(data, filename.getName());
    8393                        } else {
    84                                 DataSet dataSet = filename.getName().toLowerCase().endsWith(".gpx") ?
    85                                                 new GpxReader(new FileReader(filename)).parse() :
    86                                                 new OsmReader(new FileReader(filename)).parse();
     94                                DataSet dataSet;
     95                                if (extension.equals("gpx"))
     96                                        dataSet = new GpxReader(in).parse();
     97                                else if (extension.equals("xml") || extension.equals("osm"))
     98                                        dataSet = new OsmReader(in).parse();
     99                                else if (extension.equals("csv") || extension.equals("txt")) {
     100                                        JOptionPane.showMessageDialog(Main.main, "CSV Data import for non-GPS data is not implemented yet.");
     101                                        return;
     102                                } else {
     103                                        JOptionPane.showMessageDialog(Main.main, "Unknown file extension: "+extension);
     104                                        return;
     105                                }
    87106                                layer = new OsmDataLayer(dataSet, filename.getName());
    88107                        }
    89108                       
    90                         if (Main.main.getMapFrame() == null || !newLayer.isSelected())
     109                        if (Main.main.getMapFrame() == null)
    91110                                Main.main.setMapFrame(filename.getName(), new MapFrame(layer));
    92111                        else
  • src/org/openstreetmap/josm/data/Preferences.java

    r36 r38  
    6565         */
    6666        public String osmDataPassword = null;
     67        /**
     68         * The csv input style string or <code>null</code> for auto. The style is a
     69         * comma seperated list of identifiers as specified in the tooltip help text
     70         * of csvImportString in PreferenceDialog.
     71         *
     72         * @see org.openstreetmap.josm.gui.PreferenceDialog#csvImportString
     73         */
     74        public String csvImportString = null;
    6775
    6876        /**
     
    129137                                osmDataUsername = osmServer.getChildText("username");
    130138                                osmDataPassword = osmServer.getChildText("password");
     139                                csvImportString = osmServer.getChildText("csvImportString");
    131140                        }
    132141                        drawRawGpsLines = root.getChild("drawRawGpsLines") != null;
     
    158167                osmServer.getChildren().add(new Element("username").setText(osmDataUsername));
    159168                osmServer.getChildren().add(new Element("password").setText(osmDataPassword));
     169                osmServer.getChildren().add(new Element("csvImportString").setText(csvImportString));
    160170                children.add(osmServer);
    161171
  • src/org/openstreetmap/josm/gui/PreferenceDialog.java

    r33 r38  
    5959                        if (Main.pref.osmDataPassword == "")
    6060                                Main.pref.osmDataPassword = null;
     61                        Main.pref.csvImportString = csvImportString.getText();
    6162                        Main.pref.setDrawRawGpsLines(drawRawGpsLines.isSelected());
    6263                        Main.pref.setForceRawGpsLines(forceRawGpsLines.isSelected());
     
    116117         */
    117118        JPasswordField osmDataPassword = new JPasswordField(20);
     119        /**
     120         * Comma seperated import string specifier or <code>null</code> if the first
     121         * data line should be interpreted as one.
     122         */
     123        JTextField csvImportString = new JTextField(20);
    118124        /**
    119125         * The checkbox stating whether nodes should be merged together.
     
    188194                osmDataUsername.setToolTipText("Login name (email) to the OSM account.");
    189195                osmDataPassword.setToolTipText("Login password to the OSM account. Leave blank to not store any password.");
     196                csvImportString.setToolTipText("<html>Import string specification. Currently, only lat/lon pairs are imported.<br>" +
     197                                "<b>lat</b>: The latitude coordinate<br>" +
     198                                "<b>lon</b>: The longitude coordinate<br>" +
     199                                "<b>ignore</b>: Skip this field<br>" +
     200                                "An example: \"ignore ignore lat lon\" will use ' ' as delimiter, skip the first two values and read then lat/lon.<br>" +
     201                                "Other example: \"lat,lon\" will just read lat/lon values comma seperated.</html>");
    190202                drawRawGpsLines.setToolTipText("If your gps device draw to few lines, select this to draw lines along your track.");
    191203                drawRawGpsLines.setSelected(Main.pref.isDrawRawGpsLines());
     
    197209                osmDataUsername.setText(Main.pref.osmDataUsername);
    198210                osmDataPassword.setText(Main.pref.osmDataPassword);
     211                csvImportString.setText(Main.pref.csvImportString);
    199212
    200213                // Display tab
     
    221234                warning.setFont(warning.getFont().deriveFont(Font.ITALIC));
    222235                con.add(warning, GBC.eop().fill(GBC.HORIZONTAL));
    223 
     236                con.add(new JLabel("CSV import specification (empty: read from first line in data)"), GBC.eol());
     237                con.add(csvImportString, GBC.eop().fill(GBC.HORIZONTAL));
    224238               
    225239                // Map tab
  • src/org/openstreetmap/josm/gui/layer/RawGpsDataLayer.java

    r23 r38  
    4242                                }
    4343                                if (evt.getPropertyName().equals("drawRawGpsLines") ||
    44                                                 evt.getPropertyName().equals("drawRawGpsLines"))
     44                                                evt.getPropertyName().equals("forceRawGpsLines"))
    4545                                        Main.main.getMapFrame().repaint();
    4646                        }
     
    6767                        for (GeoPoint p : c) {
    6868                                Point screen = mv.getScreenPoint(p);
    69                                 if (Main.pref.isDrawRawGpsLines() && old != null) {
     69                                if (Main.pref.isDrawRawGpsLines() && old != null)
    7070                                        g.drawLine(old.x, old.y, screen.x, screen.y);
    71                                 } else {
     71                                else
    7272                                        g.drawRect(screen.x, screen.y, 0, 0);
    73                                         old = screen;
    74                                 }
     73                                old = screen;
    7574                        }
    7675                }
Note: See TracChangeset for help on using the changeset viewer.