Index: org/openstreetmap/josm/gui/layer/CustomizeColor.java
===================================================================
--- org/openstreetmap/josm/gui/layer/CustomizeColor.java	(revision 4261)
+++ org/openstreetmap/josm/gui/layer/CustomizeColor.java	(working copy)
@@ -62,7 +62,8 @@
 
     @Override
     public void actionPerformed(ActionEvent e) {
-        JColorChooser c = new JColorChooser(layers.get(0).getColor(false));
+        Color cl=layers.get(0).getColor(false); if (cl==null) cl=Color.gray;
+        JColorChooser c = new JColorChooser(cl);
         Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")};
         int answer = JOptionPane.showOptionDialog(
                 Main.parent,
Index: org/openstreetmap/josm/gui/layer/GpxLayer.java
===================================================================
--- org/openstreetmap/josm/gui/layer/GpxLayer.java	(revision 4261)
+++ org/openstreetmap/josm/gui/layer/GpxLayer.java	(working copy)
@@ -25,14 +25,18 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.Future;
 
 import javax.swing.AbstractAction;
 import javax.swing.Action;
 import javax.swing.Box;
 import javax.swing.ButtonGroup;
+import javax.swing.ButtonModel;
 import javax.swing.Icon;
 import javax.swing.JFileChooser;
 import javax.swing.JLabel;
@@ -229,7 +233,12 @@
 
     public colorModes getColorMode() {
         try {
-            return colorModes.values()[Main.pref.getInteger("draw.rawgps.colors", "layer "+getName(), 0)];
+            int i;
+            if (isLocalFile) 
+                i=Main.pref.getInteger("draw.rawgps.colors.local", "layer "+getName(), 0);
+            else
+                i=Main.pref.getInteger("draw.rawgps.colors", "layer "+getName(), 0);
+            return colorModes.values()[i];
         } catch (Exception e) {
         }
         return colorModes.none;
@@ -249,6 +258,7 @@
                 SeparatorLayerAction.INSTANCE,
                 new CustomizeColor(this),
                 new CustomizeLineDrawing(this),
+                new CustomizeColorMode(this),
                 new ConvertToDataLayerAction(),
                 SeparatorLayerAction.INSTANCE,
                 new RenameLayerAction(getAssociatedFile(), this),
@@ -262,6 +272,7 @@
                 new LayerSaveAsAction(this),
                 new CustomizeColor(this),
                 new CustomizeLineDrawing(this),
+                new CustomizeColorMode(this),
                 new ImportImages(),
                 new ImportAudio(),
                 new MarkersFromNamedPoins(),
@@ -375,7 +386,7 @@
 
     // the different color modes
     enum colorModes {
-        none, velocity, dilution, direction
+        none, velocity, dilution, direction, time
     }
 
     @Override
@@ -447,8 +458,8 @@
          ********** STEP 2b - RE-COMPUTE CACHE DATA *********************
          ****************************************************************/
         if (!computeCacheInSync) { // don't compute if the cache is good
-            Float minval = null;
-            Float maxval = null;
+            double minval = +1e10;
+            double maxval = -1e10;
             WayPoint oldWp = null;
             if (colorModeDynamic) {
                 if (colored == colorModes.velocity) {
@@ -461,9 +472,10 @@
                                     continue;
                                 }
                                 if (oldWp != null && trkPnt.time > oldWp.time) {
-                                    Float vel = new Float(c.greatCircleDistance(oldWp.getCoor()) / (trkPnt.time - oldWp.time));
-                                    if(maxval == null || vel > maxval) maxval = vel;
-                                    if(minval == null || vel < minval) minval = vel;
+                                    double vel = c.greatCircleDistance(oldWp.getCoor())
+                                            / (trkPnt.time - oldWp.time);
+                                    if(vel > maxval) maxval = vel;
+                                    if(vel < minval) minval = vel;
                                 }
                                 oldWp = trkPnt;
                             }
@@ -475,9 +487,9 @@
                             for (WayPoint trkPnt : segment.getWayPoints()) {
                                 Object val = trkPnt.attr.get("hdop");
                                 if (val != null) {
-                                    Float hdop = (Float) val;
-                                    if(maxval == null || hdop > maxval) maxval = hdop;
-                                    if(minval == null || hdop < minval) minval = hdop;
+                                    double hdop = ((Float) val).doubleValue();
+                                    if(hdop > maxval) maxval = hdop;
+                                    if(hdop < minval) minval = hdop;
                                 }
                             }
                         }
@@ -485,6 +497,19 @@
                 }
                 oldWp = null;
             }
+            if (colored == colorModes.time) {
+                    for (GpxTrack trk : data.tracks) {
+                        for (GpxTrackSegment segment : trk.getSegments()) {
+                            for (WayPoint trkPnt : segment.getWayPoints()) {
+                               double t=trkPnt.time;
+                               if (t==0) continue; // skip non-dated trackpoints
+                               if(t > maxval) maxval = t;
+                               if(t < minval) minval = t;
+                            }
+                        }
+                    }
+                }
+            
             for (GpxTrack trk : data.tracks) {
                 for (GpxTrackSegment segment : trk.getSegments()) {
                     if (!forceLines) { // don't draw lines between segments, unless forced to
@@ -498,7 +523,7 @@
                         trkPnt.customColoring = neutralColor;
                         if(colored == colorModes.dilution && trkPnt.attr.get("hdop") != null) {
                             float hdop = ((Float) trkPnt.attr.get("hdop")).floatValue();
-                            int hdoplvl = Math.round(colorModeDynamic ? ((hdop-minval)*255/(maxval-minval))
+                            int hdoplvl =(int) Math.round(colorModeDynamic ? ((hdop-minval)*255/(maxval-minval))
                             : (hdop <= 0 ? 0 : hdop * hdopfactor));
                             // High hdop is bad, but high values in colors are green.
                             // Therefore inverse the logic
@@ -507,13 +532,13 @@
                         }
                         if (oldWp != null) {
                             double dist = c.greatCircleDistance(oldWp.getCoor());
-
+                            boolean noDraw=false;
                             switch (colored) {
                             case velocity:
                                 double dtime = trkPnt.time - oldWp.time;
                                 if(dtime > 0) {
                                     float vel = (float) (dist / dtime);
-                                    int velColor = Math.round(colorModeDynamic ? ((vel-minval)*255/(maxval-minval))
+                                    int velColor =(int) Math.round(colorModeDynamic ? ((vel-minval)*255/(maxval-minval))
                                     : (vel <= 0 ? 0 : vel / colorTracksTune * 255));
                                     trkPnt.customColoring = colors[velColor > 255 ? 255 : velColor];
                                 } else {
@@ -529,9 +554,17 @@
                                     trkPnt.customColoring = colors_cyclic[(int) (dirColor)];
                                 }
                                 break;
+                            case time:
+                                if (trkPnt.time>0){
+                                    int tColor = (int) Math.round((trkPnt.time-minval)*255/(maxval-minval));
+                                    trkPnt.customColoring = colors[tColor];
+                                } else {
+                                    trkPnt.customColoring = neutralColor;
+                                }
+                                break;
                             }
-
-                            if (maxLineLength == -1 || dist <= maxLineLength) {
+                            
+                            if (!noDraw && (maxLineLength == -1 || dist <= maxLineLength)) {
                                 trkPnt.drawLine = true;
                                 trkPnt.dir = (int) oldWp.getCoor().heading(trkPnt.getCoor());
                             } else {
@@ -1417,6 +1450,92 @@
         }
     }
 
+        private class CustomizeColorMode extends AbstractAction implements LayerAction, MultiLayerAction {
+        List<Layer> layers;
+
+        public CustomizeColorMode(List<Layer> l) {
+            this();
+            layers = l;
+        }
+
+        public CustomizeColorMode(Layer l) {
+            this();
+            layers = new LinkedList<Layer>();
+            layers.add(l); 
+        }
+
+        private CustomizeColorMode() {
+            super(tr("Customize color mode"), ImageProvider.get("mapmode/addsegment"));
+        }
+
+        @Override
+        public boolean supportLayers(List<Layer> layers) {
+            for(Layer layer: layers) {
+                if(!(layer instanceof GpxLayer))
+                    return false;
+            }
+            return true;
+        }
+
+        @Override
+        public Component createMenuComponent() {
+            return new JMenuItem(this);
+        }
+
+        @Override
+        public Action getMultiLayerAction(List<Layer> layers) {
+            return new CustomizeLineDrawing(layers);
+        }
+
+        @Override
+        public void actionPerformed(ActionEvent e) {
+
+            JRadioButton[] r = new JRadioButton[6];
+            Map<ButtonModel,Integer> propVals = new HashMap<ButtonModel,Integer> ();;
+            
+            r[0] = new JRadioButton(tr("Use global settings."));
+            r[1] = new JRadioButton(tr("Single Color (can be customized for named layers)"));
+            r[2] = new JRadioButton(tr("Velocity (red = slow, green = fast)"));
+            r[3] = new JRadioButton(tr("Direction (red = west, yellow = north, green = east, blue = south)"));
+            r[4] = new JRadioButton(tr("Dilution of Position (red = high, green = low, if available)"));
+            r[5] = new JRadioButton(tr("Track date"));
+            propVals.put(r[1].getModel(), 0);
+            propVals.put(r[2].getModel(), 1);
+            propVals.put(r[4].getModel(), 2);
+            propVals.put(r[3].getModel(), 3);
+            propVals.put(r[5].getModel(), 4);
+            ButtonGroup group = new ButtonGroup();
+            Box panel = Box.createVerticalBox();
+            for (JRadioButton b : r) {
+                group.add(b);
+                panel.add(b);
+            }
+            String propbase = isLocalFile ? "draw.rawgps.colors.local" : "draw.rawgps.colors";
+            String propName = propbase + ".layer " + layers.get(0).getName();
+            if (Main.pref.hasKey(propName)) {
+                int v = Main.pref.getInteger(propName,-1);
+                for (int i=1;i<6;i++) {
+                    if (propVals.get(r[i].getModel()).intValue()==v)
+                            group.setSelected(r[i].getModel(), true);
+                }
+            } else {
+                group.setSelected(r[0].getModel(), true);
+            }
+            int answer = JOptionPane.showConfirmDialog(Main.parent, panel,
+                    tr("Select color mode"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
+            if (answer == JOptionPane.CANCEL_OPTION || answer == JOptionPane.CLOSED_OPTION) return;
+            for(Layer layer : layers) {
+                propName = propbase + ".layer " + layer.getName();
+                if (group.getSelection() == r[0].getModel()) {
+                    Main.pref.put(propName, null);
+                } else {
+                    Main.pref.putInteger(propName, propVals.get(group.getSelection()));
+                }
+            }
+            Main.map.repaint();
+        }
+    }
+
     private class MarkersFromNamedPoins extends AbstractAction {
 
         public MarkersFromNamedPoins() {
Index: org/openstreetmap/josm/gui/preferences/DrawingPreference.java
===================================================================
--- org/openstreetmap/josm/gui/preferences/DrawingPreference.java	(revision 4261)
+++ org/openstreetmap/josm/gui/preferences/DrawingPreference.java	(working copy)
@@ -46,6 +46,7 @@
     private JRadioButton colorTypeVelocity = new JRadioButton(tr("Velocity (red = slow, green = fast)"));
     private JRadioButton colorTypeDirection = new JRadioButton(tr("Direction (red = west, yellow = north, green = east, blue = south)"));
     private JRadioButton colorTypeDilution = new JRadioButton(tr("Dilution of Position (red = high, green = low, if available)"));
+    private JRadioButton colorTypeTime = new JRadioButton(tr("Track date"));
     private JRadioButton colorTypeNone = new JRadioButton(tr("Single Color (can be customized for named layers)"));
     private JComboBox colorTypeVelocityTune = new JComboBox(new String[] {tr("Car"), tr("Bicycle"), tr("Foot")});
     private JCheckBox directionHint = new JCheckBox(tr("Draw Direction Arrows"));
@@ -173,6 +174,7 @@
         colorGroup.add(colorTypeVelocity);
         colorGroup.add(colorTypeDirection);
         colorGroup.add(colorTypeDilution);
+        colorGroup.add(colorTypeTime);
 
         colorTypeVelocity.addChangeListener(new ChangeListener(){
             public void stateChanged(ChangeEvent e) {
@@ -199,12 +201,16 @@
         case 3:
             colorTypeDirection.setSelected(true);
             break;
+        case 4:
+            colorTypeTime.setSelected(true);
+            break;
         }
 
         colorTypeNone.setToolTipText(tr("All points and track segments will have the same color. Can be customized in Layer Manager."));
         colorTypeVelocity.setToolTipText(tr("Colors points and track segments by velocity."));
         colorTypeDirection.setToolTipText(tr("Colors points and track segments by direction."));
         colorTypeDilution.setToolTipText(tr("Colors points and track segments by dilution of position (HDOP). Your capture device needs to log that information."));
+        colorTypeTime.setToolTipText(tr("Colors points and track segments by its timestamp."));
 
         // color Tracks by Velocity Tune
         int ccts = Main.pref.getInteger("draw.rawgps.colorTracksTune", 45);
@@ -220,6 +226,8 @@
         panel.add(colorTypeVelocityTune, GBC.eop().insets(5,0,0,5));
         panel.add(colorTypeDirection, GBC.eol().insets(40,0,0,0));
         panel.add(colorTypeDilution, GBC.eol().insets(40,0,0,0));
+        panel.add(colorTypeTime, GBC.eol().insets(40,0,0,0));
+        
         colorDynamic.setToolTipText(tr("Draw direction arrows for lines, connecting GPS points."));
         colorDynamic.setSelected(Main.pref.getBoolean("draw.rawgps.colors.dynamic", false));
         colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected());
@@ -319,6 +327,8 @@
             Main.pref.putInteger("draw.rawgps.colors", 2);
         } else if(colorTypeDirection.isSelected()) {
             Main.pref.putInteger("draw.rawgps.colors", 3);
+        } else if(colorTypeTime.isSelected()) {
+            Main.pref.putInteger("draw.rawgps.colors", 4);
         } else {
             Main.pref.putInteger("draw.rawgps.colors", 0);
         }
