Changeset 1519 in josm


Ignore:
Timestamp:
2009-03-30T16:42:12+02:00 (13 years ago)
Author:
stoecker
Message:

fixed #2370 - Allow line drawing for local GPX files only - patch by jonobennett

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

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

    r1275 r1519  
    117117            r = new GpxReader(is,file.getAbsoluteFile().getParentFile());
    118118            r.data.storageFile = file;
    119             GpxLayer gpxLayer = new GpxLayer(r.data, fn);
     119            GpxLayer gpxLayer = new GpxLayer(r.data, fn, true);
    120120            Main.main.addLayer(gpxLayer);
    121121            if (Main.pref.getBoolean("marker.makeautomarkers", true)) {
     
    155155            if(r.getNumberOfCoordinates()>0) {
    156156                r.data.storageFile = file;
    157                 GpxLayer gpxLayer = new GpxLayer(r.data, fn);
     157                GpxLayer gpxLayer = new GpxLayer(r.data, fn, true);
    158158                Main.main.addLayer(gpxLayer);
    159159                if (Main.pref.getBoolean("marker.makeautomarkers", true)) {
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r1508 r1519  
    8484    private colorModes computeCacheColored;
    8585    private int computeCacheColorTracksTune;
     86    private boolean isLocalFile;
    8687
    8788    public GpxLayer(GpxData d) {
     
    9596        this(d);
    9697        this.name = name;
     98    }
     99
     100    public GpxLayer(GpxData d, String name, boolean isLocal) {
     101        this(d);
     102        this.name = name;
     103        this.isLocalFile = isLocal;
    97104    }
    98105
     
    204211                    File sel[] = fc.getSelectedFiles();
    205212                    if(sel != null) {
    206                         // sort files in increasing order of timestamp (this is the end time, but so long as they don't overlap, that's fine)
    207                         if (sel.length > 1) {
    208                                 Arrays.sort(sel, new Comparator<File>() {
    209                                         public int compare(File a, File b) {
    210                                                 return a.lastModified() <= b.lastModified() ? -1 : 1;
    211                                         }
    212                                 });
    213                         }
     213                        // sort files in increasing order of timestamp (this is the end time, but so long as they don't overlap, that's fine)
     214                        if (sel.length > 1) {
     215                            Arrays.sort(sel, new Comparator<File>() {
     216                                public int compare(File a, File b) {
     217                                    return a.lastModified() <= b.lastModified() ? -1 : 1;
     218                                }
     219                            });
     220                        }
    214221                        double firstStartTime = sel[0].lastModified()/1000.0 /* ms -> seconds */ - AudioUtil.getCalibratedDuration(sel[0]);
    215222                        for (int i = 0; i < sel.length; i++) {
     
    391398        int maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length", -1);
    392399        // draw line between points, global setting
    393         boolean lines = Main.pref.getBoolean("draw.rawgps.lines");
     400        boolean lines = (Main.pref.getBoolean("draw.rawgps.lines") || (Main.pref.getBoolean("draw.rawgps.lines.localfiles") && this.isLocalFile));
    394401        String linesKey = "draw.rawgps.lines.layer "+name;
    395402        // draw lines, per-layer setting
     
    923930            double startTime = lastModified - duration;
    924931            startTime = firstStartTime + (startTime - firstStartTime) / 
    925                 Main.pref.getDouble("audio.calibration", "1.0" /* default, ratio */);
     932                Main.pref.getDouble("audio.calibration", "1.0" /* default, ratio */);
    926933            WayPoint w1 = null;
    927934            WayPoint w2 = null;
    928935
    929                 for (GpxTrack track : data.tracks) {
    930                         if (track.trackSegs == null) continue;
    931                         for (Collection<WayPoint> seg : track.trackSegs) {
    932                                 for (WayPoint w : seg) {
     936            for (GpxTrack track : data.tracks) {
     937                if (track.trackSegs == null) continue;
     938                for (Collection<WayPoint> seg : track.trackSegs) {
     939                    for (WayPoint w : seg) {
    933940                        if (startTime < w.time) {
    934941                            w2 = w;
     
    939946                    if (w2 != null) break;
    940947                }
    941             }   
     948            }   
    942949
    943950            if (w1 == null || w2 == null) {
    944                 timedMarkersOmitted = true;
     951                timedMarkersOmitted = true;
    945952            } else {
    946                 EastNorth eastNorth = w1.eastNorth.interpolate(
    947                                         w2.eastNorth,
    948                                         (startTime - w1.time)/(w2.time - w1.time));
     953                EastNorth eastNorth = w1.eastNorth.interpolate(
     954                            w2.eastNorth,
     955                            (startTime - w1.time)/(w2.time - w1.time));
    949956                wayPointFromTimeStamp = new WayPoint(Main.proj.eastNorth2latlon(eastNorth));
    950957                wayPointFromTimeStamp.time = startTime;
     
    954961                wayPointFromTimeStamp.attr.put("name", name);
    955962                waypoints.add(wayPointFromTimeStamp);
    956             }           
     963            }           
    957964        }
    958965       
     
    10041011            /* timeFromAudio intended for future use to shift markers of this type on synchronization */
    10051012            if (w == wayPointFromTimeStamp) {
    1006                 am.timeFromAudio = true;
     1013                am.timeFromAudio = true;
    10071014            }
    10081015            ml.data.add(am);
  • trunk/src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java

    r1425 r1519  
    2727public class DrawingPreference implements PreferenceSetting {
    2828
    29     private JCheckBox drawRawGpsLines = new JCheckBox(tr("Draw lines between raw gps points."));
     29    private ButtonGroup gpsLinesGroup;
     30    private JRadioButton drawRawGpsLinesAll = new JRadioButton(tr("All"));
     31    private JRadioButton drawRawGpsLinesLocal = new JRadioButton(tr("Local files"));
     32    private JRadioButton drawRawGpsLinesNone = new JRadioButton(tr("None"));
     33    private ActionListener drawRawGpsLinesActionListener;
    3034    private JTextField drawRawGpsMaxLineLength = new JTextField(8);
    3135    private JCheckBox forceRawGpsLines = new JCheckBox(tr("Force lines if no segments imported."));
     
    5458
    5559        // drawRawGpsLines
    56         drawRawGpsLines.addActionListener(new ActionListener(){
     60        gpsLinesGroup = new ButtonGroup();
     61        gpsLinesGroup.add(drawRawGpsLinesNone);
     62        gpsLinesGroup.add(drawRawGpsLinesLocal);
     63        gpsLinesGroup.add(drawRawGpsLinesAll);
     64
     65        if(Main.pref.getBoolean("draw.rawgps.lines")) {
     66            drawRawGpsLinesAll.setSelected(true);
     67        } else if (Main.pref.getBoolean("draw.rawgps.lines.localfiles")) {
     68            drawRawGpsLinesLocal.setSelected(true);
     69        } else {
     70            drawRawGpsLinesNone.setSelected(true);
     71        }
     72
     73        panel.add(new JLabel(tr("Draw lines between raw GPS points")), GBC.eol().insets(20,0,0,0));
     74        panel.add(drawRawGpsLinesNone, GBC.eol().insets(40,0,0,0));
     75        panel.add(drawRawGpsLinesLocal, GBC.eol().insets(40,0,0,0));
     76        panel.add(drawRawGpsLinesAll, GBC.eol().insets(40,0,0,0));
     77
     78        drawRawGpsLinesActionListener = new ActionListener(){
    5779            public void actionPerformed(ActionEvent e) {
    58                 forceRawGpsLines.setEnabled(drawRawGpsLines.isSelected());
    59                 drawRawGpsMaxLineLength.setEnabled(drawRawGpsLines.isSelected());
    60                 drawGpsArrows.setEnabled(drawRawGpsLines.isSelected());
     80                forceRawGpsLines.setEnabled(!drawRawGpsLinesNone.isSelected());
     81                drawRawGpsMaxLineLength.setEnabled(!drawRawGpsLinesNone.isSelected());
     82                drawGpsArrows.setEnabled(!drawRawGpsLinesNone.isSelected() );
    6183                drawGpsArrowsFast.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
    6284                drawGpsArrowsMinDist.setEnabled(drawGpsArrows.isSelected() && drawGpsArrows.isEnabled());
    6385            }
    64         });
    65         drawRawGpsLines.setSelected(Main.pref.getBoolean("draw.rawgps.lines"));
    66         drawRawGpsLines.setToolTipText(tr("If your gps device draws too few lines, select this to draw lines along your way."));
    67         panel.add(drawRawGpsLines, GBC.eol().insets(20,0,0,0));
     86        };
     87
     88        drawRawGpsLinesNone.addActionListener(drawRawGpsLinesActionListener);
     89        drawRawGpsLinesLocal.addActionListener(drawRawGpsLinesActionListener);
     90        drawRawGpsLinesAll.addActionListener(drawRawGpsLinesActionListener);
    6891
    6992        // drawRawGpsMaxLineLength
    7093        drawRawGpsMaxLineLength.setText(Integer.toString(Main.pref.getInteger("draw.rawgps.max-line-length", -1)));
    7194        drawRawGpsMaxLineLength.setToolTipText(tr("Maximum length (in meters) to draw lines. Set to '-1' to draw all lines."));
    72         drawRawGpsMaxLineLength.setEnabled(drawRawGpsLines.isSelected());
     95        drawRawGpsMaxLineLength.setEnabled(!drawRawGpsLinesNone.isSelected());
    7396        panel.add(new JLabel(tr("Maximum length (meters)")), GBC.std().insets(40,0,0,0));
    7497        panel.add(drawRawGpsMaxLineLength, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5));
     
    77100        forceRawGpsLines.setToolTipText(tr("Force drawing of lines if the imported data contain no line information."));
    78101        forceRawGpsLines.setSelected(Main.pref.getBoolean("draw.rawgps.lines.force"));
    79         forceRawGpsLines.setEnabled(drawRawGpsLines.isSelected());
     102        forceRawGpsLines.setEnabled(!drawRawGpsLinesNone.isSelected());
    80103        panel.add(forceRawGpsLines, GBC.eop().insets(40,0,0,0));
    81104
     
    89112        drawGpsArrows.setToolTipText(tr("Draw direction arrows for lines, connecting GPS points."));
    90113        drawGpsArrows.setSelected(Main.pref.getBoolean("draw.rawgps.direction"));
    91         drawGpsArrows.setEnabled(drawRawGpsLines.isSelected());
     114        drawGpsArrows.setEnabled(!drawRawGpsLinesNone.isSelected());
    92115        panel.add(drawGpsArrows, GBC.eop().insets(40,0,0,0));
    93116
     
    221244
    222245    public boolean ok() {
    223         Main.pref.put("draw.rawgps.lines", drawRawGpsLines.isSelected());
     246        Main.pref.put("draw.rawgps.lines", drawRawGpsLinesAll.isSelected());
     247        Main.pref.put("draw.rawgps.lines.localfiles", drawRawGpsLinesLocal.isSelected());
    224248        Main.pref.put("draw.rawgps.max-line-length", drawRawGpsMaxLineLength.getText());
    225249        Main.pref.put("draw.rawgps.lines.force", forceRawGpsLines.isSelected());
Note: See TracChangeset for help on using the changeset viewer.