Ignore:
Timestamp:
2005-10-09T04:14:40+02:00 (19 years ago)
Author:
imi
Message:
  • added Layer support
  • added support for raw GPS data
  • fixed tooltips
  • added options for loading gpx files
File:
1 edited

Legend:

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

    r16 r17  
    11package org.openstreetmap.josm.actions;
    22
     3import java.awt.GridBagLayout;
    34import java.awt.event.ActionEvent;
    45import java.awt.event.KeyEvent;
     
    89
    910import javax.swing.AbstractAction;
    10 import javax.swing.ImageIcon;
     11import javax.swing.Box;
     12import javax.swing.JCheckBox;
    1113import javax.swing.JFileChooser;
     14import javax.swing.JLabel;
    1215import javax.swing.JOptionPane;
     16import javax.swing.JPanel;
    1317import javax.swing.filechooser.FileFilter;
    1418
    1519import org.openstreetmap.josm.data.osm.DataSet;
     20import org.openstreetmap.josm.gui.GBC;
     21import org.openstreetmap.josm.gui.ImageProvider;
    1622import org.openstreetmap.josm.gui.Main;
    1723import org.openstreetmap.josm.gui.MapFrame;
     24import org.openstreetmap.josm.gui.layer.Layer;
     25import org.openstreetmap.josm.gui.layer.LayerFactory;
    1826import org.openstreetmap.josm.io.GpxReader;
    1927import org.openstreetmap.josm.io.DataReader.ConnectionException;
     
    3240         */
    3341        public OpenGpxAction() {
    34                 super("Open GPX", new ImageIcon(Main.class.getResource("/images/opengpx.png")));
     42                super("Open GPX", ImageProvider.get("opengpx"));
    3543                putValue(MNEMONIC_KEY, KeyEvent.VK_O);
     44                putValue(SHORT_DESCRIPTION, "Open a file in GPX format.");
    3645        }
    3746
     
    4857                                return "GPX or XML Files";
    4958                        }});
    50                 fc.showOpenDialog(Main.main);
     59               
     60                // additional options
     61                JCheckBox rawGps = new JCheckBox("Raw GPS data", true);
     62                rawGps.setToolTipText("Check this, if the data are obtained from a gps device.");
     63                JCheckBox newLayer = new JCheckBox("As Layer", true);
     64                newLayer.setToolTipText("Open as a new layer or replace all current layers.");
     65                if (Main.main.getMapFrame() == null) {
     66                        newLayer.setEnabled(false);
     67                        newLayer.setSelected(false);
     68                }
     69               
     70                JPanel p = new JPanel(new GridBagLayout());
     71                p.add(new JLabel("Options"), GBC.eop());
     72                p.add(rawGps, GBC.eol());
     73                p.add(newLayer, GBC.eol());
     74                p.add(Box.createVerticalGlue(), GBC.eol().fill());
     75                fc.setAccessory(p);
     76
     77                if (fc.showOpenDialog(Main.main) != JFileChooser.APPROVE_OPTION)
     78                        return;
     79               
    5180                File gpxFile = fc.getSelectedFile();
    5281                if (gpxFile == null)
     
    5483               
    5584                try {
    56                         DataSet dataSet = new GpxReader(new FileReader(gpxFile)).parse();
    57                         MapFrame map = new MapFrame(dataSet);
    58                         Main.main.setMapFrame(gpxFile.getName(), map);
     85                        DataSet dataSet = new GpxReader(new FileReader(gpxFile), rawGps.isSelected()).parse();
     86
     87                        Layer layer = LayerFactory.create(dataSet, gpxFile.getName(), rawGps.isSelected());
     88                       
     89                        if (Main.main.getMapFrame() == null || !newLayer.isSelected())
     90                                Main.main.setMapFrame(gpxFile.getName(), new MapFrame(layer));
     91                        else
     92                                Main.main.getMapFrame().mapView.addLayer(layer);
     93                       
    5994                } catch (ParseException x) {
    6095                        x.printStackTrace();
Note: See TracChangeset for help on using the changeset viewer.