X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;ds=sidebyside;f=tim%2Fprune%2Fgui%2FDetailsDisplay.java;h=c40f8c2b4891360144bfe60d55dfd4817fd9a456;hb=112bb0c9b46894adca9a33ed8c99ea712b253185;hp=e153a6cead5feb9dca2a776559e9f163130b3d16;hpb=52bf9e8686c916be37a26a0b75340393d4478b05;p=GpsPrune.git diff --git a/tim/prune/gui/DetailsDisplay.java b/tim/prune/gui/DetailsDisplay.java index e153a6c..c40f8c2 100644 --- a/tim/prune/gui/DetailsDisplay.java +++ b/tim/prune/gui/DetailsDisplay.java @@ -25,7 +25,6 @@ import tim.prune.data.DataPoint; import tim.prune.data.Distance; import tim.prune.data.IntegerRange; import tim.prune.data.Photo; -import tim.prune.data.PhotoStatus; import tim.prune.data.Selection; import tim.prune.data.TrackInfo; @@ -47,6 +46,7 @@ public class DetailsDisplay extends GenericDisplay private JLabel _durationLabel = null; private JLabel _altRangeLabel = null, _updownLabel = null; private JLabel _aveSpeedLabel = null, _aveMovingSpeedLabel = null; + private JLabel _paceLabel = null; // Photo details private JLabel _photoLabel = null; @@ -75,7 +75,7 @@ public class DetailsDisplay extends GenericDisplay private static final String LABEL_RANGE_CLIMB = I18nManager.getText("details.range.climb") + ": "; private static final String LABEL_RANGE_DESCENT = ", " + I18nManager.getText("details.range.descent") + ": "; private static String LABEL_POINT_ALTITUDE_UNITS = null; - private static int LABEL_POINT_ALTITUDE_FORMAT = Altitude.FORMAT_NONE; + private static Altitude.Format LABEL_POINT_ALTITUDE_FORMAT = Altitude.Format.NO_FORMAT; /** @@ -139,6 +139,8 @@ public class DetailsDisplay extends GenericDisplay rangeDetailsPanel.add(_aveSpeedLabel); _aveMovingSpeedLabel = new JLabel(""); rangeDetailsPanel.add(_aveMovingSpeedLabel); + _paceLabel = new JLabel(""); + rangeDetailsPanel.add(_paceLabel); _altRangeLabel = new JLabel(""); rangeDetailsPanel.add(_altRangeLabel); _updownLabel = new JLabel(""); @@ -197,11 +199,12 @@ public class DetailsDisplay extends GenericDisplay lowerPanel.add(unitsLabel); String[] distUnits = {I18nManager.getText("units.kilometres"), I18nManager.getText("units.miles")}; _distUnitsDropdown = new JComboBox(distUnits); - if (!Config.getUseMetricUnits()) {_distUnitsDropdown.setSelectedIndex(1);} + if (!Config.getConfigBoolean(Config.KEY_METRIC_UNITS)) {_distUnitsDropdown.setSelectedIndex(1);} _distUnitsDropdown.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dataUpdated(DataSubscriber.UNITS_CHANGED); + Config.setConfigBoolean(Config.KEY_METRIC_UNITS, _distUnitsDropdown.getSelectedIndex() == 0); } }); lowerPanel.add(_distUnitsDropdown); @@ -221,7 +224,7 @@ public class DetailsDisplay extends GenericDisplay Selection selection = _trackInfo.getSelection(); int currentPointIndex = selection.getCurrentPointIndex(); _speedLabel.setText(""); - int distUnits = _distUnitsDropdown.getSelectedIndex()==0?Distance.UNITS_KILOMETRES:Distance.UNITS_MILES; + Distance.Units distUnits = _distUnitsDropdown.getSelectedIndex()==0?Distance.Units.KILOMETRES:Distance.Units.MILES; String distUnitsStr = I18nManager.getText(_distUnitsDropdown.getSelectedIndex()==0?"units.kilometres.short":"units.miles.short"); String speedUnitsStr = I18nManager.getText(_distUnitsDropdown.getSelectedIndex()==0?"units.kmh":"units.mph"); if (_track == null || currentPoint == null) @@ -245,19 +248,21 @@ public class DetailsDisplay extends GenericDisplay :""); if (currentPoint.getTimestamp().isValid()) { - if (currentPointIndex > 0 && currentPointIndex < (_trackInfo.getTrack().getNumPoints()-1)) { + if (currentPointIndex > 0 && currentPointIndex < (_trackInfo.getTrack().getNumPoints()-1)) + { DataPoint prevPoint = _trackInfo.getTrack().getPoint(currentPointIndex - 1); DataPoint nextPoint = _trackInfo.getTrack().getPoint(currentPointIndex + 1); if (prevPoint.getTimestamp().isValid() && nextPoint.getTimestamp().isValid()) { // use total distance and total time between neighbouring points long diff = nextPoint.getTimestamp().getSecondsSince(prevPoint.getTimestamp()); - if (diff < 1000) { + if (diff < 1000 && diff > 0) + { double rads = DataPoint.calculateRadiansBetween(prevPoint, currentPoint) + DataPoint.calculateRadiansBetween(currentPoint, nextPoint); double dist = Distance.convertRadiansToDistance(rads, distUnits); String speed = roundedNumber(3600 * dist / diff) + " " + speedUnitsStr; - _speedLabel.setText(I18nManager.getText("details.speed") + ": " + speed); + _speedLabel.setText(I18nManager.getText("fieldname.speed") + ": " + speed); } } } @@ -285,6 +290,7 @@ public class DetailsDisplay extends GenericDisplay _updownLabel.setText(""); _aveSpeedLabel.setText(""); _aveMovingSpeedLabel.setText(""); + _paceLabel.setText(""); } else { @@ -292,19 +298,38 @@ public class DetailsDisplay extends GenericDisplay + (selection.getStart()+1) + " " + I18nManager.getText("details.range.to") + " " + (selection.getEnd()+1)); _distanceLabel.setText(LABEL_RANGE_DISTANCE + roundedNumber(selection.getDistance(distUnits)) + " " + distUnitsStr); - _movingDistanceLabel.setText(LABEL_RANGE_MOVINGDISTANCE + roundedNumber(selection.getMovingDistance(distUnits)) + " " + distUnitsStr); + if (selection.getHasMultipleSegments()) { + _movingDistanceLabel.setText(LABEL_RANGE_MOVINGDISTANCE + roundedNumber(selection.getMovingDistance(distUnits)) + " " + distUnitsStr); + } + else { + _movingDistanceLabel.setText(null); + } if (selection.getNumSeconds() > 0) { _durationLabel.setText(LABEL_RANGE_DURATION + buildDurationString(selection.getNumSeconds())); _aveSpeedLabel.setText(I18nManager.getText("details.range.avespeed") + ": " + roundedNumber(selection.getDistance(distUnits)/selection.getNumSeconds()*3600.0) + " " + speedUnitsStr); - _aveMovingSpeedLabel.setText(I18nManager.getText("details.range.avemovingspeed") + ": " - + roundedNumber(selection.getMovingDistance(distUnits)/selection.getMovingSeconds()*3600.0) + " " + speedUnitsStr); + if (selection.getHasMultipleSegments()) { + _aveMovingSpeedLabel.setText(I18nManager.getText("details.range.avemovingspeed") + ": " + + roundedNumber(selection.getMovingDistance(distUnits)/selection.getMovingSeconds()*3600.0) + " " + speedUnitsStr); + } + else { + _aveMovingSpeedLabel.setText(null); + } + if (Config.getConfigBoolean(Config.KEY_SHOW_PACE)) { + _paceLabel.setText(I18nManager.getText("details.range.pace") + ": " + + buildDurationString((long) (selection.getNumSeconds()/selection.getDistance(distUnits))) + + " / " + distUnitsStr); + } + else { + _paceLabel.setText(""); + } } else { _durationLabel.setText(""); _aveSpeedLabel.setText(""); _aveMovingSpeedLabel.setText(""); + _paceLabel.setText(""); } String altUnitsLabel = getAltitudeUnitsLabel(selection.getAltitudeFormat()); IntegerRange altRange = selection.getAltitudeRange(); @@ -325,7 +350,7 @@ public class DetailsDisplay extends GenericDisplay } // show photo details and thumbnail Photo currentPhoto = _trackInfo.getPhotoList().getPhoto(_trackInfo.getSelection().getCurrentPhotoIndex()); - if (_track == null || ( (currentPoint == null || currentPoint.getPhoto() == null) && currentPhoto == null)) + if ((currentPoint == null || currentPoint.getPhoto() == null) && currentPhoto == null) { // no photo, hide details _photoLabel.setText(I18nManager.getText("details.nophoto")); @@ -337,9 +362,9 @@ public class DetailsDisplay extends GenericDisplay { if (currentPhoto == null) {currentPhoto = currentPoint.getPhoto();} _photoLabel.setText(I18nManager.getText("details.photofile") + ": " + currentPhoto.getFile().getName()); - _photoLabel.setText(LABEL_POINT_TIMESTAMP + currentPhoto.getTimestamp().getText()); + _photoTimestampLabel.setText(LABEL_POINT_TIMESTAMP + currentPhoto.getTimestamp().getText()); _photoConnectedLabel.setText(I18nManager.getText("details.photo.connected") + ": " - + (currentPhoto.getCurrentStatus() == PhotoStatus.NOT_CONNECTED ? + + (currentPhoto.getCurrentStatus() == Photo.Status.NOT_CONNECTED ? I18nManager.getText("dialog.about.no"):I18nManager.getText("dialog.about.yes"))); _photoThumbnail.setVisible(true); _photoThumbnail.setPhoto(currentPhoto); @@ -353,12 +378,12 @@ public class DetailsDisplay extends GenericDisplay * @param inFormat altitude format * @return language-sensitive string */ - private static String getAltitudeUnitsLabel(int inFormat) + private static String getAltitudeUnitsLabel(Altitude.Format inFormat) { if (inFormat == LABEL_POINT_ALTITUDE_FORMAT && LABEL_POINT_ALTITUDE_UNITS != null) return LABEL_POINT_ALTITUDE_UNITS; LABEL_POINT_ALTITUDE_FORMAT = inFormat; - if (inFormat == Altitude.FORMAT_METRES) + if (inFormat == Altitude.Format.METRES) return " " + I18nManager.getText("units.metres.short"); return " " + I18nManager.getText("units.feet.short"); } @@ -402,7 +427,7 @@ public class DetailsDisplay extends GenericDisplay if (inNumSecs < 86400L) return "" + (inNumSecs / 60 / 60) + I18nManager.getText("display.range.time.hours") + " " + ((inNumSecs / 60) % 60) + I18nManager.getText("display.range.time.mins"); if (inNumSecs < 432000L) return "" + (inNumSecs / 86400L) + I18nManager.getText("display.range.time.days") - + " " + (inNumSecs / 60 / 60) + I18nManager.getText("display.range.time.hours"); + + " " + (inNumSecs / 60 / 60) % 24 + I18nManager.getText("display.range.time.hours"); if (inNumSecs < 8640000L) return "" + (inNumSecs / 86400L) + I18nManager.getText("display.range.time.days"); return "big"; }