]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/gui/ProfileChart.java
Version 7, February 2009
[GpsPrune.git] / tim / prune / gui / ProfileChart.java
index 22724b5f6a431d674396f626393e6c8d2ca1d464..a0adfdbe33b74424ce6432eb8be2e20c052f1cf3 100644 (file)
@@ -6,6 +6,7 @@ import java.awt.Graphics;
 import java.awt.event.MouseEvent;
 
 import tim.prune.I18nManager;
+import tim.prune.data.Altitude;
 import tim.prune.data.AltitudeRange;
 import tim.prune.data.Track;
 import tim.prune.data.TrackInfo;
@@ -86,28 +87,33 @@ public class ProfileChart extends GenericChart
                                }
                        }
 
-                       // loop through points
-                       int chartFormat = altitudeRange.getFormat();
-                       for (int p = 0; p < numPoints; p++)
+                       try
                        {
-                               int x = (int) (_xScaleFactor * p);
-                               if (p == selectedPoint)
+                               // loop through points
+                               Altitude.Format chartFormat = altitudeRange.getFormat();
+                               for (int p = 0; p < numPoints; p++)
                                {
-                                       g.setColor(COLOR_SELECTED_BG);
-                                       g.fillRect(BORDER_WIDTH + x, BORDER_WIDTH+1, barWidth, height-2*BORDER_WIDTH-2);
-                                       g.setColor(COLOR_SELECTED);
-                               }
-                               else
-                               {
-                                       g.setColor(COLOR_ALT_BARS);
-                               }
-                               if (_track.getPoint(p).getAltitude().isValid())
-                               {
-                                       altitude = _track.getPoint(p).getAltitude().getValue(chartFormat);
-                                       y = (int) (yScaleFactor * (altitude - minAltitude));
-                                       g.fillRect(BORDER_WIDTH+x, height-BORDER_WIDTH - y, barWidth, y);
+                                       int x = (int) (_xScaleFactor * p);
+                                       if (p == selectedPoint)
+                                       {
+                                               g.setColor(COLOR_SELECTED_BG);
+                                               g.fillRect(BORDER_WIDTH + x, BORDER_WIDTH+1, barWidth, height-2*BORDER_WIDTH-2);
+                                               g.setColor(COLOR_SELECTED);
+                                       }
+                                       else
+                                       {
+                                               g.setColor(COLOR_ALT_BARS);
+                                       }
+                                       if (_track.getPoint(p).getAltitude().isValid())
+                                       {
+                                               altitude = _track.getPoint(p).getAltitude().getValue(chartFormat);
+                                               y = (int) (yScaleFactor * (altitude - minAltitude));
+                                               g.fillRect(BORDER_WIDTH+x, height-BORDER_WIDTH - y, barWidth, y);
+                                       }
                                }
                        }
+                       catch (NullPointerException npe) { // ignore, probably due to data being changed
+                       }
                        // Draw numbers on top of the graph to mark scale
                        if (lineScale > 1)
                        {