X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fgui%2FProfileChart.java;h=f7ae105cfae85665f848287d37fc85ec0f59c7d1;hb=112bb0c9b46894adca9a33ed8c99ea712b253185;hp=431da0d396f0a1217e65e8098423cc2febc858fb;hpb=312fec956e43f5d0a38617da5d0add9c62563e2c;p=GpsPrune.git diff --git a/tim/prune/gui/ProfileChart.java b/tim/prune/gui/ProfileChart.java index 431da0d..f7ae105 100644 --- a/tim/prune/gui/ProfileChart.java +++ b/tim/prune/gui/ProfileChart.java @@ -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; @@ -19,6 +20,7 @@ public class ProfileChart extends GenericChart private static final int[] ALTITUDE_SCALES = {10000, 5000, 2000, 1000, 500, 200, 100, 50}; private static final Color COLOR_LINES = Color.GRAY; private static final Color COLOR_ALT_BARS = Color.BLUE; + private static final Color COLOR_CURR_RANGE = Color.GREEN; private static final Color COLOR_SELECTED = Color.RED; private static final Color COLOR_SELECTED_BG = Color.ORANGE; private static final Color COLOR_ALT_SCALE = Color.RED; @@ -38,6 +40,7 @@ public class ProfileChart extends GenericChart /** * Override paint method to draw map + * @param g Graphics object */ public void paint(Graphics g) { @@ -46,12 +49,9 @@ public class ProfileChart extends GenericChart { int width = getWidth(); int height = getHeight(); - AltitudeRange altitudeRange = _track.getAltitudeRange(); - int minAltitude = altitudeRange.getMinimum(); - int maxAltitude = altitudeRange.getMaximum(); // message if no altitudes in track - if (minAltitude < 0 || maxAltitude < 0) + if (!_track.hasAltitudeData()) { g.setColor(COLOR_LINES); g.drawString(I18nManager.getText("display.noaltitudes"), 50, height/2); @@ -59,12 +59,20 @@ public class ProfileChart extends GenericChart } // altitude profile + AltitudeRange altitudeRange = _track.getAltitudeRange(); + int minAltitude = altitudeRange.getMinimum(); + int maxAltitude = altitudeRange.getMaximum(); int numPoints = _track.getNumPoints(); _xScaleFactor = 1.0 * (width - 2 * BORDER_WIDTH) / numPoints; - double yScaleFactor = 1.0 * (height - 2 * BORDER_WIDTH) / - (altitudeRange.getMaximum() - minAltitude); + double yScaleFactor = 1.0 * (height - 2 * BORDER_WIDTH) / (maxAltitude - minAltitude); int barWidth = (int) (_xScaleFactor + 1.0); int selectedPoint = _trackInfo.getSelection().getCurrentPointIndex(); + // selection start, end + int selectionStart = -1, selectionEnd = -1; + if (_trackInfo.getSelection().hasRangeSelected()) { + selectionStart = _trackInfo.getSelection().getStart(); + selectionEnd = _trackInfo.getSelection().getEnd(); + } // horizontal lines for scale - set to round numbers eg 500m int lineScale = getLineScale(minAltitude, maxAltitude); @@ -84,28 +92,36 @@ 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 (p >= selectionStart && p <= selectionEnd) { + g.setColor(COLOR_CURR_RANGE); + } + } + 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) { @@ -176,6 +192,7 @@ public class ProfileChart extends GenericChart /** * Method to inform map that data has changed + * @param inTrack track object */ public void dataUpdated(Track inTrack) { @@ -200,7 +217,7 @@ public class ProfileChart extends GenericChart { // work out which data point is nearest and select it int pointNum = (int) ((e.getX() - BORDER_WIDTH) / _xScaleFactor); - _trackInfo.getSelection().selectPoint(pointNum); + _trackInfo.selectPoint(pointNum); } } }