Ignore:
Timestamp:
2009-03-24T09:19:10+01:00 (15 years ago)
Author:
stoecker
Message:

fixed indent, updated

Location:
applications/editors/josm/plugins/editgpx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/editgpx/build.xml

    r14221 r14245  
    2525                <attribute name="Plugin-Date" value="${version.entry.commit.date}"/>
    2626                <attribute name="Plugin-Description" value="Provides an editable GPX track layer. Only deletion of points is supported. This plugin can be used to prepare tracks for upload to OSM eg. deleting uninteresting parts of track." />
    27                 <attribute name="Plugin-Mainversion" value="1000" />
     27                <attribute name="Plugin-Mainversion" value="1500" />
    2828                <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
    2929            </manifest>
  • applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxLayer.java

    r14221 r14245  
    1111import java.awt.event.ActionEvent;
    1212import java.util.ArrayList;
     13import java.util.Date;
    1314import java.util.HashSet;
    1415
     
    4041public class EditGpxLayer extends Layer {
    4142
    42         private static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(EditGpxPlugin.class.getResource("/images/editgpx_layer.png")));
    43         private DataSet dataSet;
    44         private GPXLayerImportAction layerImport;
    45        
    46         public EditGpxLayer(String str, DataSet ds) {
    47                 super(str);
    48                 dataSet = ds;
    49                 layerImport = new GPXLayerImportAction(dataSet);
    50         }
    51        
    52         /**
    53          * check if dataSet is empty
    54          * if so show import dialog to user
    55          */
    56         public void initializeImport() {
    57                 try {
    58                         if(dataSet.nodes.isEmpty() ) {
    59                                 layerImport.activateImport();
    60                         }
    61                 } catch (Exception e) {
    62                         System.out.println(e.getMessage());
    63                         e.printStackTrace();
    64                 }
    65         }
    66        
    67 
    68         @Override
    69         public Icon getIcon() {
    70                 return icon;
    71         }
    72 
    73 
    74         @Override
    75         public Object getInfoComponent() {
    76                 return getToolTipText();
    77         }
    78 
    79 
    80         @Override
    81         public Component[] getMenuEntries() {
    82                 return new Component[] {
    83                         new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
    84                         new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
    85                         new JSeparator(),
    86                         new JMenuItem(layerImport),
    87                         new JMenuItem(new ConvertToGpxLayerAction()),
    88                         new JMenuItem(new ConvertToAnonTimeGpxLayerAction()),
    89                         new JSeparator(),
    90                         new JMenuItem(new LayerListPopup.InfoAction(this))};
    91         }
    92 
    93 
    94         @Override
    95         public String getToolTipText() {
    96                 return tr("Layer for editing GPX tracks");
    97         }
    98 
    99 
    100         @Override
    101         public boolean isMergable(Layer other) {
    102                 // TODO
    103                 return false;
    104         }
    105 
    106 
    107         @Override
    108         public void mergeFrom(Layer from) {
    109                 // TODO
    110         }
    111 
    112 
    113         @Override
    114         public void paint(Graphics g, MapView mv) {
    115                 g.setColor(Color.yellow);
    116 
    117                 //don't iterate through dataSet whiling making changes
    118                 synchronized(layerImport.importing) {
    119                         for(Node n: dataSet.nodes) {
    120                                 if (!n.deleted) {
    121                             LatLon c = n.coor;
    122                             Point pnt = Main.map.mapView.getPoint(Main.proj.latlon2eastNorth(c));
    123                             g.drawOval(pnt.x - 2, pnt.y - 2, 4, 4);
    124                         }
    125                 }
    126                 }
    127         }
    128        
     43    private static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(EditGpxPlugin.class.getResource("/images/editgpx_layer.png")));
     44    private DataSet dataSet;
     45    private GPXLayerImportAction layerImport;
     46
     47    public EditGpxLayer(String str, DataSet ds) {
     48        super(str);
     49        dataSet = ds;
     50        layerImport = new GPXLayerImportAction(dataSet);
     51    }
     52
     53    /**
     54     * check if dataSet is empty
     55     * if so show import dialog to user
     56     */
     57    public void initializeImport() {
     58        try {
     59            if(dataSet.nodes.isEmpty() ) {
     60                layerImport.activateImport();
     61            }
     62        } catch (Exception e) {
     63            System.out.println(e.getMessage());
     64            e.printStackTrace();
     65        }
     66    }
     67
     68    @Override
     69    public Icon getIcon() {
     70        return icon;
     71    }
     72
     73    @Override
     74    public Object getInfoComponent() {
     75        return getToolTipText();
     76    }
     77
     78    @Override
     79    public Component[] getMenuEntries() {
     80        return new Component[] {
     81            new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)),
     82            new JMenuItem(new LayerListDialog.DeleteLayerAction(this)),
     83            new JSeparator(),
     84            new JMenuItem(layerImport),
     85            new JMenuItem(new ConvertToGpxLayerAction()),
     86            new JMenuItem(new ConvertToAnonTimeGpxLayerAction()),
     87            new JSeparator(),
     88            new JMenuItem(new LayerListPopup.InfoAction(this))};
     89    }
     90
     91    @Override
     92    public String getToolTipText() {
     93        return tr("Layer for editing GPX tracks");
     94    }
     95
     96    @Override
     97    public boolean isMergable(Layer other) {
     98        // TODO
     99        return false;
     100    }
     101
     102    @Override
     103    public void mergeFrom(Layer from) {
     104        // TODO
     105    }
     106
     107    @Override
     108    public void paint(Graphics g, MapView mv) {
     109        g.setColor(Color.yellow);
     110
     111        //don't iterate through dataSet whiling making changes
     112        synchronized(layerImport.importing) {
     113            for(Node n: dataSet.nodes) {
     114                if (!n.deleted) {
     115                    LatLon c = n.coor;
     116                    Point pnt = Main.map.mapView.getPoint(Main.proj.latlon2eastNorth(c));
     117                    g.drawOval(pnt.x - 2, pnt.y - 2, 4, 4);
     118                }
     119            }
     120        }
     121    }
     122
    129123
    130124    public void reset(){
    131125        //TODO implement a reset
    132126    }
    133        
    134 
    135         @Override
    136         public void visitBoundingBox(BoundingXYVisitor v) {
    137                 // TODO Auto-generated method stub
    138         }
    139        
    140        
    141         /**
    142         * convert a DataSet to GPX
    143          *
    144         * @param boolean anonTime If true set all time and date in GPX to 01/01/1970 00:00 ?
    145         * @return GPXData
    146         */
    147         private GpxData toGpxData(boolean anonTime) {
     127
     128
     129    @Override
     130    public void visitBoundingBox(BoundingXYVisitor v) {
     131        // TODO Auto-generated method stub
     132    }
     133
     134
     135    /**
     136    * convert a DataSet to GPX
     137     *
     138    * @param boolean anonTime If true set all time and date in GPX to 01/01/1970 00:00 ?
     139    * @return GPXData
     140    */
     141    private GpxData toGpxData(boolean anonTime) {
    148142        GpxData gpxData = new GpxData();
    149143        HashSet<Node> doneNodes = new HashSet<Node>();
     
    163157                    continue;
    164158                }
     159
     160                Date tstamp = n.getTimestamp();
     161
    165162                if (trkseg == null) {
    166163                    trkseg = new ArrayList<WayPoint>();
    167164                    trk.trackSegs.add(trkseg);
    168165                }
    169                 if (!n.isTagged()) {
    170                     doneNodes.add(n);
    171                 }
     166                doneNodes.add(n);
     167
    172168                WayPoint wpt = new WayPoint(n.coor);
    173                 if (!n.isTimestampEmpty())
    174                 {
    175                     if (anonTime) {
    176                         wpt.attr.put("time", "1970-01-01T00:00:00");
    177                     } else {
    178                         wpt.attr.put("time", n.getTimestamp());
    179                         System.out.println("timestamp: "+n.getTimestamp());
    180                     }
    181                     wpt.setTime();
    182                 }
     169                if (anonTime) {
     170                    wpt.attr.put("time", "1970-01-01T00:00:00");
     171                } else {
     172                    wpt.attr.put("time", tstamp);
     173                    System.out.println("timestamp: "+tstamp);
     174                }
     175                wpt.setTime();
     176
    183177                trkseg.add(wpt);
    184178            }
     
    188182        for (Node n : dataSet.nodes) {
    189183            if (n.incomplete || n.deleted || doneNodes.contains(n)) continue;
     184
     185            Date tstamp = n.getTimestamp();
     186
    190187            WayPoint wpt = new WayPoint(n.coor);
    191             if (!n.isTimestampEmpty()) {
    192                 if (anonTime) {
    193                         wpt.attr.put("time", "1970-01-01T00:00:00");
    194                 } else {
    195                         wpt.attr.put("time", n.getTimestamp());
    196                 }
    197                 wpt.setTime();
    198             }
     188            if (anonTime) {
     189                wpt.attr.put("time", "1970-01-01T00:00:00");
     190            } else {
     191                wpt.attr.put("time", tstamp);
     192            }
     193            wpt.setTime();
     194
    199195            if (n.keys != null && n.keys.containsKey("name")) {
    200196                wpt.attr.put("name", n.keys.get("name"));
     
    204200        return gpxData;
    205201    }
    206        
    207         //context item "Convert to GPX layer"
    208         public class ConvertToGpxLayerAction extends AbstractAction {
     202
     203    //context item "Convert to GPX layer"
     204    public class ConvertToGpxLayerAction extends AbstractAction {
    209205        public ConvertToGpxLayerAction() {
    210206            super(tr("Convert to GPX layer"), ImageProvider.get("converttogpx"));
     
    216212    }
    217213
    218         //context item "Convert to GPX layer with anonymised time"
    219         public class ConvertToAnonTimeGpxLayerAction extends AbstractAction {
     214    //context item "Convert to GPX layer with anonymised time"
     215    public class ConvertToAnonTimeGpxLayerAction extends AbstractAction {
    220216        public ConvertToAnonTimeGpxLayerAction() {
    221217            super(tr("Convert to GPX layer with anonymised time"), ImageProvider.get("converttogpx"));
  • applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxMode.java

    r14221 r14245  
    2121public class EditGpxMode extends MapMode {
    2222
    23         private static final long serialVersionUID = 7940589057093872411L;
    24         Point pointPressed;
    25         DataSet dataSet;
    26         MapFrame mapFrame;
    27         Rectangle oldRect;
    28         MapFrame frame;
    29        
    30         public EditGpxMode(MapFrame mapFrame, String name, String desc, DataSet ds) {
    31                 super(name, "editgpx_mode.png", desc, mapFrame, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    32                 dataSet = ds;
    33         }
    34        
    35         @Override public void enterMode() {
     23    private static final long serialVersionUID = 7940589057093872411L;
     24    Point pointPressed;
     25    DataSet dataSet;
     26    MapFrame mapFrame;
     27    Rectangle oldRect;
     28    MapFrame frame;
     29
     30    public EditGpxMode(MapFrame mapFrame, String name, String desc, DataSet ds) {
     31        super(name, "editgpx_mode.png", desc, mapFrame, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
     32        dataSet = ds;
     33    }
     34
     35    @Override public void enterMode() {
    3636        super.enterMode();
    3737        Main.map.mapView.addMouseListener(this);
     
    4444        Main.map.mapView.removeMouseMotionListener(this);
    4545    }
    46    
    47    
     46
     47
    4848    @Override public void mousePressed(MouseEvent e) {
    49         pointPressed = new Point(e.getPoint());
     49        pointPressed = new Point(e.getPoint());
    5050    }
    51    
    52    
     51
     52
    5353    @Override public void mouseDragged(MouseEvent e) {
    54         if ( (e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) ==  MouseEvent.BUTTON1_DOWN_MASK) {
    55                 //if button1 is hold, draw the rectangle.
    56                 paintRect(pointPressed, e.getPoint());
    57         }
     54        if ( (e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) ==  MouseEvent.BUTTON1_DOWN_MASK) {
     55            //if button1 is hold, draw the rectangle.
     56            paintRect(pointPressed, e.getPoint());
     57        }
    5858    }
    59    
    60    
     59
    6160    @Override public void mouseReleased(MouseEvent e) {
    6261        if (e.getButton() != MouseEvent.BUTTON1) {
    63                 return;
     62            return;
    6463        } else {
    65                 Point pointReleased = e.getPoint();
    66                
    67                 //prepare vars
     64            Point pointReleased = e.getPoint();
     65
     66            //prepare vars
    6867            EastNorth en;
    69                 double scale = Main.map.mapView.getScale();
    70             EastNorth center = Main.map.mapView.getCenter(); //Center n/e coordinate of the desired screen center.
    71             int width = Main.map.mapView.getWidth();
    72             int height = Main.map.mapView.getHeight();
    73             Rectangle r = createRect(pointReleased, pointPressed);
    74            
    75                         //go through nodes and mark the ones in the selection rect as deleted
    76             for (Node n: dataSet.nodes) {
    77                         en = n.eastNorth;
     68            double scale = Main.map.mapView.getScale();
     69            EastNorth center = Main.map.mapView.getCenter(); //Center n/e coordinate of the desired screen center.
     70            int width = Main.map.mapView.getWidth();
     71            int height = Main.map.mapView.getHeight();
     72            Rectangle r = createRect(pointReleased, pointPressed);
     73
     74            //go through nodes and mark the ones in the selection rect as deleted
     75            for (Node n: dataSet.nodes) {
     76                en = n.eastNorth;
    7877                //calculate point on screen from node n
    79                         double x = (en.east()-center.east())/scale + width/2;
     78                double x = (en.east()-center.east())/scale + width/2;
    8079                double y = (center.north()-en.north())/scale + height/2;
    8180                Point p = new Point((int)x,(int)y);
    8281                if (r.contains(p)) {
    83                         n.deleted = true; //only set as deleted. this makes reset to beginning possible
     82                    n.deleted = true; //only set as deleted. this makes reset to beginning possible
    8483                }
    8584            }
    86                 oldRect = null;
    87                 Main.map.mapView.repaint();
    88            
     85            oldRect = null;
     86            Main.map.mapView.repaint();
    8987        }
    90        
    9188    }
    9289
     
    9592     */
    9693    public Rectangle createRect(Point p1, Point p2) {
    97         int x,y,w,h;
    98         if (p1.x == p2.x && p1.y == p2.y) {
    99                 //if p1 and p2 same points draw a small rectangle around them
    100                 x = p1.x -1;
    101                 y = p1.y -1;
    102                 w = 3;
    103                 h = 3;
    104         } else {
    105                 if (p1.x < p2.x){
    106                         x = p1.x;
    107                         w = p2.x-p1.x;
    108                 } else {
    109                         x = p2.x;
    110                         w = p1.x-p2.x;
    111                 }
    112                 if (p1.y < p2.y) {
    113                         y = p1.y;
    114                         h = p2.y-p1.y;
    115                 } else {
    116                         y = p2.y;
    117                         h = p1.y-p2.y;
    118                 }
    119         }
    120         return new Rectangle(x,y,w,h);
     94        int x,y,w,h;
     95        if (p1.x == p2.x && p1.y == p2.y) {
     96            //if p1 and p2 same points draw a small rectangle around them
     97            x = p1.x -1;
     98            y = p1.y -1;
     99            w = 3;
     100            h = 3;
     101        } else {
     102            if (p1.x < p2.x){
     103                x = p1.x;
     104                w = p2.x-p1.x;
     105            } else {
     106                x = p2.x;
     107                w = p1.x-p2.x;
     108            }
     109            if (p1.y < p2.y) {
     110                y = p1.y;
     111                h = p2.y-p1.y;
     112            } else {
     113                y = p2.y;
     114                h = p1.y-p2.y;
     115            }
     116        }
     117        return new Rectangle(x,y,w,h);
    121118    }
    122  
    123    
     119
    124120    /**
    125121     * Draw a selection rectangle on screen.
    126122     */
    127123    private void paintRect(Point p1, Point p2) {
    128         Graphics g = frame.getGraphics();//Main.map.mapView.getGraphics();
    129        
    130         Rectangle r = oldRect;
    131         if (r != null) {
    132                 //overwrite old rct
    133                 g.setXORMode(Color.BLACK);
    134                 g.setColor(Color.WHITE);
    135                 g.drawRect(r.x,r.y,r.width,r.height);
    136             }
    137                
     124        Graphics g = frame.getGraphics();//Main.map.mapView.getGraphics();
     125
     126        Rectangle r = oldRect;
     127        if (r != null) {
     128            //overwrite old rct
     129            g.setXORMode(Color.BLACK);
     130            g.setColor(Color.WHITE);
     131            g.drawRect(r.x,r.y,r.width,r.height);
     132        }
     133
    138134        g.setXORMode(Color.BLACK);
    139         g.setColor(Color.WHITE);       
     135        g.setColor(Color.WHITE);
    140136        r = createRect(p1,p2);
    141137        g.drawRect(r.x,r.y,r.width,r.height);
    142138        oldRect = r;
    143      
    144139    }
    145    
     140
    146141
    147142    public void setFrame(MapFrame mapFrame) {
    148         frame = mapFrame;
     143        frame = mapFrame;
    149144    }
    150    
    151 
    152145}
  • applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxPlugin.java

    r14221 r14245  
    2121
    2222/**
    23  * Provides an editable GPX layer. Editable layer here means the deletion of points is supported. 
     23 * Provides an editable GPX layer. Editable layer here means the deletion of points is supported.
    2424 * This plugin can be used to prepare tracks for upload to OSM eg. delete uninteresting parts
    25  * of the track. 
    26  * Additionally while converting the track back to a normal GPX layer the time can be made 
    27  * anonymous. This feature sets all time stamps to 1970-01-01 00:00. 
    28  * 
     25 * of the track.
     26 * Additionally while converting the track back to a normal GPX layer the time can be made
     27 * anonymous. This feature sets all time stamps to 1970-01-01 00:00.
     28 *
    2929 * TODO:
    30  * - TODO s durchschauen
    31  * - write docu
    32  * - upload beta of plugin
    3330 * - BUG: when importing eGpxLayer is shown as RawGpxLayer??
    3431 * - BUG: after deletion of layer not all data is deleted (eg dataset)
    3532 * - implement reset if user made mistake while marking
    36  * 
    37  * 
     33 *
     34 *
    3835 */
    3936public class EditGpxPlugin extends Plugin {
    4037
    41         private IconToggleButton btn;
    42         private EditGpxMode mode;
    43         protected static EditGpxLayer eGpxLayer;
    44         protected static DataSet dataSet;
    45         public static boolean active = false;
    46        
    47         public EditGpxPlugin() {
    48                 dataSet = new DataSet();
    49                 mode = new EditGpxMode(Main.map, "editgpx", tr("edit gpx tracks"), dataSet);
    50                
     38    private IconToggleButton btn;
     39    private EditGpxMode mode;
     40    protected static EditGpxLayer eGpxLayer;
     41    protected static DataSet dataSet;
     42    public static boolean active = false;
     43
     44    public EditGpxPlugin() {
     45        dataSet = new DataSet();
     46        mode = new EditGpxMode(Main.map, "editgpx", tr("edit gpx tracks"), dataSet);
     47
    5148        btn = new IconToggleButton(mode);
    5249        btn.setVisible(true);
    53         }
    54        
    55        
    56         /**
    57          * initialize button. if button is pressed create new layer.
    58          */
    59         @Override
     50    }
     51
     52    /**
     53     * initialize button. if button is pressed create new layer.
     54     */
     55    @Override
    6056    public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
    61                 if(oldFrame == null && newFrame != null) {
     57        if(oldFrame == null && newFrame != null) {
    6258            mode.setFrame(newFrame);
    63                
    64                 if(Main.map != null)
    65                     Main.map.addMapMode(btn);
    66                        
    67                 active = btn.isSelected();
    68                
    69                 btn.addActionListener(new ActionListener() {
    70                         public void actionPerformed(ActionEvent e) {
    71                                 active = btn.isSelected();
    72                                 if (active) {
    73                                         Main.worker.execute(new Runnable() {
    74                                                 public void run() {
    75                                                         updateLayer();
    76                                                 }
    77                                         });
    78                                 }
    79                         }
    80                 });
    81         }
    82     }
    83        
    84         /**
    85          * create new layer, add listeners and try importing gpx data.
    86          */
    87         private void updateLayer() {
    88         if(eGpxLayer == null) {
    89                 eGpxLayer = new EditGpxLayer(tr("EditGpx"), dataSet);
    90             Main.main.addLayer(eGpxLayer);
    91             Layer.listeners.add(new LayerChangeListener(){
    92                
    93                 public void activeLayerChange(final Layer oldLayer, final Layer newLayer) {
    94                     if(newLayer instanceof EditGpxLayer)
    95                         EditGpxPlugin.eGpxLayer = (EditGpxLayer)newLayer;
    96                 }
    97                
    98                 public void layerAdded(final Layer newLayer) {
    99                 }
    100                
    101                 public void layerRemoved(final Layer oldLayer) {
    102                         if(oldLayer == eGpxLayer) {
    103                         eGpxLayer = null;
    104                         //dataSet = new DataSet();
    105                        
     59
     60            if(Main.map != null)
     61                Main.map.addMapMode(btn);
     62
     63            active = btn.isSelected();
     64
     65            btn.addActionListener(new ActionListener() {
     66                public void actionPerformed(ActionEvent e) {
     67                    active = btn.isSelected();
     68                    if (active) {
     69                        Main.worker.execute(new Runnable() {
     70                            public void run() {
     71                                updateLayer();
     72                            }
     73                        });
    10674                    }
    10775                }
    10876            });
    109            
     77        }
     78    }
     79
     80    /**
     81     * create new layer, add listeners and try importing gpx data.
     82     */
     83    private void updateLayer() {
     84        if(eGpxLayer == null) {
     85            eGpxLayer = new EditGpxLayer(tr("EditGpx"), dataSet);
     86            Main.main.addLayer(eGpxLayer);
     87            Layer.listeners.add(new LayerChangeListener(){
     88
     89                public void activeLayerChange(final Layer oldLayer, final Layer newLayer) {
     90                    if(newLayer instanceof EditGpxLayer)
     91                        EditGpxPlugin.eGpxLayer = (EditGpxLayer)newLayer;
     92                }
     93
     94                public void layerAdded(final Layer newLayer) {
     95                }
     96
     97                public void layerRemoved(final Layer oldLayer) {
     98                    if(oldLayer == eGpxLayer) {
     99                        eGpxLayer = null;
     100                        //dataSet = new DataSet();
     101
     102                    }
     103                }
     104            });
     105
    110106            eGpxLayer.initializeImport();
    111         } 
     107        }
    112108        Main.map.mapView.repaint();
    113109    }
    114    
    115    
     110
    116111    public static ImageIcon loadIcon(String name) {
    117112        URL url = EditGpxPlugin.class.getResource("/images/editgpx.png");
    118113        return new ImageIcon(url);
    119114    }
    120 
    121115}
  • applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/GPXLayerImportAction.java

    r14221 r14245  
    33 *
    44 * other source from mesurement plugin written by Raphael Mack
    5  * 
     5 *
    66 */
    77package org.openstreetmap.josm.plugins.editgpx;
     
    3737/**
    3838 * Import GPX data from available layers
    39  * 
     39 *
    4040 *
    4141 */
    4242class GPXLayerImportAction extends AbstractAction {
    43        
    44        
    45         private static final long serialVersionUID = 5794897888911798168L;
    46         private DataSet dataSet;
    47         public Object importing = new Object(); //used for synchronization
    48        
    49         public GPXLayerImportAction(DataSet ds) {
    50                 //TODO what is icon at the end?
    51                 super(tr("Import path from GPX layer"), ImageProvider.get("dialogs", "edit"));
     43
     44
     45    private static final long serialVersionUID = 5794897888911798168L;
     46    private DataSet dataSet;
     47    public Object importing = new Object(); //used for synchronization
     48
     49    public GPXLayerImportAction(DataSet ds) {
     50        //TODO what is icon at the end?
     51        super(tr("Import path from GPX layer"), ImageProvider.get("dialogs", "edit"));
    5252        this.dataSet = ds;
    53         }
    54        
    55         /**
    56          * shows a list of GPX layers. if user selects one the data from this layer is
    57          * imported.
    58          */
    59         public void activateImport() {
    60                 Box panel = Box.createVerticalBox();
    61                 DefaultListModel dModel= new DefaultListModel();
     53    }
    6254
    63                 final JList layerList = new JList(dModel);
     55    /**
     56     * shows a list of GPX layers. if user selects one the data from this layer is
     57     * imported.
     58     */
     59    public void activateImport() {
     60        Box panel = Box.createVerticalBox();
     61        DefaultListModel dModel= new DefaultListModel();
     62
     63        final JList layerList = new JList(dModel);
    6464        Collection<Layer> data = Main.map.mapView.getAllLayers();
    6565        Layer lastLayer = null;
     
    111111
    112112            synchronized(importing) {
    113                     for (GpxTrack trk : gpx.data.tracks) {
    114                         for (Collection<WayPoint> segment : trk.trackSegs) {
    115                             Way w = new Way();
    116                             for (WayPoint p : segment) {
    117                                 Node n = new Node(p.latlon);
    118                                 String timestr = p.getString("time");
    119                                 if(timestr != null)
    120                                 {
    121                                     timestr = timestr.replace("Z","+00:00");
    122                                     n.setTimestamp(DateUtils.fromString(timestr));
    123                                 }
    124                                 dataSet.nodes.add(n);
    125                                 w.nodes.add(n); //TODO what to do with these while deletion
    126                             }
    127                             dataSet.ways.add(w);
    128                         }
    129                     }
     113                for (GpxTrack trk : gpx.data.tracks) {
     114                    for (Collection<WayPoint> segment : trk.trackSegs) {
     115                        Way w = new Way();
     116                        for (WayPoint p : segment) {
     117                            Node n = new Node(p.latlon);
     118                            String timestr = p.getString("time");
     119                            if(timestr != null)
     120                            {
     121                                timestr = timestr.replace("Z","+00:00");
     122                                n.setTimestamp(DateUtils.fromString(timestr));
     123                            }
     124                            dataSet.nodes.add(n);
     125                            w.nodes.add(n); //TODO what to do with these while deletion
     126                        }
     127                        dataSet.ways.add(w);
     128                    }
     129                }
    130130            }
    131131            Main.map.mapView.repaint();
    132132
    133         } else { 
     133        } else {
    134134            // no gps layer
    135135            JOptionPane.showMessageDialog(Main.parent,tr("No GPX data layer found."));
    136136        }
    137        
    138         }
     137    }
    139138
    140         /**
    141          * called when pressing "Import.." from context menu of EditGpx layer
    142          *
    143          */
    144         public void actionPerformed(ActionEvent arg0) {
    145                 activateImport();
    146         }
    147                
    148 
     139    /**
     140     * called when pressing "Import.." from context menu of EditGpx layer
     141     *
     142     */
     143    public void actionPerformed(ActionEvent arg0) {
     144        activateImport();
     145    }
    149146}
Note: See TracChangeset for help on using the changeset viewer.