X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fgui%2FDetailsDisplay.java;h=5e31a4e97aee5086ba60d184bc69e6e6d276d0be;hb=1ee49ae3c8ef3aa2e63eadd458531e5f8bd4f92c;hp=1c686262dff5b979a01ab4d1a590efe8546fc54d;hpb=5625a1abadb5f2ca5f017fe7dbda1d5141cb637b;p=GpsPrune.git diff --git a/tim/prune/gui/DetailsDisplay.java b/tim/prune/gui/DetailsDisplay.java index 1c68626..5e31a4e 100644 --- a/tim/prune/gui/DetailsDisplay.java +++ b/tim/prune/gui/DetailsDisplay.java @@ -4,6 +4,7 @@ import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; +import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.NumberFormat; @@ -11,16 +12,22 @@ import java.text.NumberFormat; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.border.EtchedBorder; + import tim.prune.DataSubscriber; +import tim.prune.FunctionLibrary; +import tim.prune.GenericFunction; import tim.prune.I18nManager; +import tim.prune.config.Config; import tim.prune.data.Altitude; import tim.prune.data.Coordinate; import tim.prune.data.DataPoint; import tim.prune.data.Distance; +import tim.prune.data.Field; import tim.prune.data.IntegerRange; import tim.prune.data.Photo; import tim.prune.data.Selection; @@ -35,38 +42,46 @@ public class DetailsDisplay extends GenericDisplay // Point details private JLabel _indexLabel = null; private JLabel _latLabel = null, _longLabel = null; - private JLabel _altLabel = null, _nameLabel = null; - private JLabel _timeLabel = null; + private JLabel _altLabel = null; + private JLabel _timeLabel = null, _speedLabel = null; + private JLabel _nameLabel = null, _typeLabel = null; // Range details private JLabel _rangeLabel = null; - private JLabel _distanceLabel = null, _durationLabel = null; + private JLabel _distanceLabel = null; + private JLabel _durationLabel = null; private JLabel _altRangeLabel = null, _updownLabel = null; + private JLabel _aveSpeedLabel = null; // Photo details private JLabel _photoLabel = null; private PhotoThumbnail _photoThumbnail = null; + private JLabel _photoTimestampLabel = null; + private JLabel _photoConnectedLabel = null; + private JPanel _rotationButtons = null; // Units - private JComboBox _unitsDropdown = null; + private JComboBox _coordFormatDropdown = null; + private JComboBox _distUnitsDropdown = null; // Formatter private NumberFormat _distanceFormatter = NumberFormat.getInstance(); // Cached labels - private static final String LABEL_POINT_SELECTED1 = I18nManager.getText("details.index.selected") + ": "; + private static final String LABEL_POINT_SELECTED = I18nManager.getText("details.index.selected") + ": "; private static final String LABEL_POINT_LATITUDE = I18nManager.getText("fieldname.latitude") + ": "; private static final String LABEL_POINT_LONGITUDE = I18nManager.getText("fieldname.longitude") + ": "; private static final String LABEL_POINT_ALTITUDE = I18nManager.getText("fieldname.altitude") + ": "; private static final String LABEL_POINT_TIMESTAMP = I18nManager.getText("fieldname.timestamp") + ": "; private static final String LABEL_POINT_WAYPOINTNAME = I18nManager.getText("fieldname.waypointname") + ": "; - private static final String LABEL_RANGE_SELECTED1 = I18nManager.getText("details.range.selected") + ": "; + private static final String LABEL_POINT_WAYPOINTTYPE = I18nManager.getText("fieldname.waypointtype") + ": "; + private static final String LABEL_RANGE_SELECTED = I18nManager.getText("details.range.selected") + ": "; private static final String LABEL_RANGE_DURATION = I18nManager.getText("fieldname.duration") + ": "; private static final String LABEL_RANGE_DISTANCE = I18nManager.getText("fieldname.distance") + ": "; private static final String LABEL_RANGE_ALTITUDE = I18nManager.getText("fieldname.altitude") + ": "; 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; /** @@ -103,8 +118,12 @@ public class DetailsDisplay extends GenericDisplay pointDetailsPanel.add(_altLabel); _timeLabel = new JLabel(""); pointDetailsPanel.add(_timeLabel); + _speedLabel = new JLabel(""); + pointDetailsPanel.add(_speedLabel); _nameLabel = new JLabel(""); pointDetailsPanel.add(_nameLabel); + _typeLabel = new JLabel(""); + pointDetailsPanel.add(_typeLabel); pointDetailsPanel.setAlignmentX(Component.LEFT_ALIGNMENT); // range details panel @@ -122,13 +141,15 @@ public class DetailsDisplay extends GenericDisplay rangeDetailsPanel.add(_distanceLabel); _durationLabel = new JLabel(""); rangeDetailsPanel.add(_durationLabel); + _aveSpeedLabel = new JLabel(""); + rangeDetailsPanel.add(_aveSpeedLabel); _altRangeLabel = new JLabel(""); rangeDetailsPanel.add(_altRangeLabel); _updownLabel = new JLabel(""); rangeDetailsPanel.add(_updownLabel); rangeDetailsPanel.setAlignmentX(Component.LEFT_ALIGNMENT); - // range details panel + // photo details panel JPanel photoDetailsPanel = new JPanel(); photoDetailsPanel.setLayout(new BoxLayout(photoDetailsPanel, BoxLayout.Y_AXIS)); photoDetailsPanel.setBorder(BorderFactory.createCompoundBorder( @@ -139,10 +160,23 @@ public class DetailsDisplay extends GenericDisplay photoDetailsPanel.add(photoDetailsLabel); _photoLabel = new JLabel(I18nManager.getText("details.nophoto")); photoDetailsPanel.add(_photoLabel); + _photoTimestampLabel = new JLabel(""); + photoDetailsPanel.add(_photoTimestampLabel); + _photoConnectedLabel = new JLabel(""); + photoDetailsPanel.add(_photoConnectedLabel); _photoThumbnail = new PhotoThumbnail(); _photoThumbnail.setVisible(false); _photoThumbnail.setPreferredSize(new Dimension(100, 100)); photoDetailsPanel.add(_photoThumbnail); + // Rotate buttons + JButton rotLeft = makeRotateButton(IconManager.ROTATE_LEFT, FunctionLibrary.FUNCTION_ROTATE_PHOTO_LEFT); + JButton rotRight = makeRotateButton(IconManager.ROTATE_RIGHT, FunctionLibrary.FUNCTION_ROTATE_PHOTO_RIGHT); + _rotationButtons = new JPanel(); + _rotationButtons.add(rotLeft); + _rotationButtons.add(rotRight); + _rotationButtons.setAlignmentX(Component.LEFT_ALIGNMENT); + _rotationButtons.setVisible(false); + photoDetailsPanel.add(_rotationButtons); // add the details panels to the main panel mainPanel.add(pointDetailsPanel); @@ -154,28 +188,45 @@ public class DetailsDisplay extends GenericDisplay // add the main panel at the top add(mainPanel, BorderLayout.NORTH); - // Add units selection + // Add format, units selection JPanel lowerPanel = new JPanel(); lowerPanel.setLayout(new BoxLayout(lowerPanel, BoxLayout.Y_AXIS)); + JLabel coordFormatLabel = new JLabel(I18nManager.getText("details.coordformat") + ": "); + coordFormatLabel.setAlignmentX(Component.LEFT_ALIGNMENT); + lowerPanel.add(coordFormatLabel); + String[] coordFormats = {I18nManager.getText("units.original"), I18nManager.getText("units.degminsec"), + I18nManager.getText("units.degmin"), I18nManager.getText("units.deg")}; + _coordFormatDropdown = new JComboBox(coordFormats); + _coordFormatDropdown.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) + { + dataUpdated(DataSubscriber.UNITS_CHANGED); + } + }); + lowerPanel.add(_coordFormatDropdown); + _coordFormatDropdown.setAlignmentX(Component.LEFT_ALIGNMENT); JLabel unitsLabel = new JLabel(I18nManager.getText("details.distanceunits") + ": "); unitsLabel.setAlignmentX(Component.LEFT_ALIGNMENT); lowerPanel.add(unitsLabel); String[] distUnits = {I18nManager.getText("units.kilometres"), I18nManager.getText("units.miles")}; - _unitsDropdown = new JComboBox(distUnits); - _unitsDropdown.addActionListener(new ActionListener() { + _distUnitsDropdown = new JComboBox(distUnits); + 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(_unitsDropdown); - _unitsDropdown.setAlignmentX(Component.LEFT_ALIGNMENT); + lowerPanel.add(_distUnitsDropdown); + _distUnitsDropdown.setAlignmentX(Component.LEFT_ALIGNMENT); add(lowerPanel, BorderLayout.SOUTH); } /** * Notification that Track has been updated + * @param inUpdateType byte to specify what has been updated */ public void dataUpdated(byte inUpdateType) { @@ -183,6 +234,10 @@ public class DetailsDisplay extends GenericDisplay DataPoint currentPoint = _trackInfo.getCurrentPoint(); Selection selection = _trackInfo.getSelection(); int currentPointIndex = selection.getCurrentPointIndex(); + _speedLabel.setText(""); + 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) { _indexLabel.setText(I18nManager.getText("details.nopointselection")); @@ -191,28 +246,56 @@ public class DetailsDisplay extends GenericDisplay _altLabel.setText(""); _timeLabel.setText(""); _nameLabel.setText(""); + _typeLabel.setText(""); } else { - _indexLabel.setText(LABEL_POINT_SELECTED1 + _indexLabel.setText(LABEL_POINT_SELECTED + (currentPointIndex+1) + " " + I18nManager.getText("details.index.of") + " " + _track.getNumPoints()); - _latLabel.setText(LABEL_POINT_LATITUDE + currentPoint.getLatitude().output(Coordinate.FORMAT_NONE)); - _longLabel.setText(LABEL_POINT_LONGITUDE + currentPoint.getLongitude().output(Coordinate.FORMAT_NONE)); - _altLabel.setText(LABEL_POINT_ALTITUDE - + (currentPoint.hasAltitude()? - (currentPoint.getAltitude().getValue() + getAltitudeUnitsLabel(currentPoint.getAltitude().getFormat())): - "")); + _latLabel.setText(makeCoordinateLabel(LABEL_POINT_LATITUDE, currentPoint.getLatitude(), _coordFormatDropdown.getSelectedIndex())); + _longLabel.setText(makeCoordinateLabel(LABEL_POINT_LONGITUDE, currentPoint.getLongitude(), _coordFormatDropdown.getSelectedIndex())); + _altLabel.setText(currentPoint.hasAltitude()? + (LABEL_POINT_ALTITUDE + currentPoint.getAltitude().getValue() + getAltitudeUnitsLabel(currentPoint.getAltitude().getFormat())) + :""); if (currentPoint.getTimestamp().isValid()) + { + 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 && 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("fieldname.speed") + ": " + speed); + } + } + } _timeLabel.setText(LABEL_POINT_TIMESTAMP + currentPoint.getTimestamp().getText()); - else + } + else { _timeLabel.setText(""); - String name = currentPoint.getWaypointName(); + } + // Waypoint name + final String name = currentPoint.getWaypointName(); if (name != null && !name.equals("")) { _nameLabel.setText(LABEL_POINT_WAYPOINTNAME + name); } else _nameLabel.setText(""); + // Waypoint type + final String type = currentPoint.getFieldValue(Field.WAYPT_TYPE); + if (type != null && !type.equals("")) { + _typeLabel.setText(LABEL_POINT_WAYPOINTTYPE + type); + } + else _typeLabel.setText(""); } // Update range details @@ -223,24 +306,24 @@ public class DetailsDisplay extends GenericDisplay _durationLabel.setText(""); _altRangeLabel.setText(""); _updownLabel.setText(""); + _aveSpeedLabel.setText(""); } else { - _rangeLabel.setText(LABEL_RANGE_SELECTED1 + _rangeLabel.setText(LABEL_RANGE_SELECTED + (selection.getStart()+1) + " " + I18nManager.getText("details.range.to") + " " + (selection.getEnd()+1)); - if (_unitsDropdown.getSelectedIndex() == 0) - _distanceLabel.setText(LABEL_RANGE_DISTANCE + buildDistanceString( - selection.getDistance(Distance.UNITS_KILOMETRES)) - + " " + I18nManager.getText("units.kilometres.short")); - else - _distanceLabel.setText(LABEL_RANGE_DISTANCE + buildDistanceString( - selection.getDistance(Distance.UNITS_MILES)) - + " " + I18nManager.getText("units.miles.short")); + _distanceLabel.setText(LABEL_RANGE_DISTANCE + roundedNumber(selection.getDistance(distUnits)) + " " + distUnitsStr); if (selection.getNumSeconds() > 0) - _durationLabel.setText(LABEL_RANGE_DURATION + buildDurationString(selection.getNumSeconds())); - else + { + _durationLabel.setText(LABEL_RANGE_DURATION + DisplayUtils.buildDurationString(selection.getNumSeconds())); + _aveSpeedLabel.setText(I18nManager.getText("details.range.avespeed") + ": " + + roundedNumber(selection.getDistance(distUnits)/selection.getNumSeconds()*3600.0) + " " + speedUnitsStr); + } + else { _durationLabel.setText(""); + _aveSpeedLabel.setText(""); + } String altUnitsLabel = getAltitudeUnitsLabel(selection.getAltitudeFormat()); IntegerRange altRange = selection.getAltitudeRange(); if (altRange.getMinimum() >= 0 && altRange.getMaximum() >= 0) @@ -260,18 +343,27 @@ 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")); + _photoTimestampLabel.setText(""); + _photoConnectedLabel.setText(""); _photoThumbnail.setVisible(false); + _rotationButtons.setVisible(false); } else { if (currentPhoto == null) {currentPhoto = currentPoint.getPhoto();} _photoLabel.setText(I18nManager.getText("details.photofile") + ": " + currentPhoto.getFile().getName()); + _photoTimestampLabel.setText(LABEL_POINT_TIMESTAMP + currentPhoto.getTimestamp().getText()); + _photoConnectedLabel.setText(I18nManager.getText("details.photo.connected") + ": " + + (currentPhoto.getCurrentStatus() == Photo.Status.NOT_CONNECTED ? + I18nManager.getText("dialog.about.no"):I18nManager.getText("dialog.about.yes"))); _photoThumbnail.setVisible(true); _photoThumbnail.setPhoto(currentPhoto); + _rotationButtons.setVisible(true); + if ((inUpdateType & DataSubscriber.PHOTOS_MODIFIED) > 0) {_photoThumbnail.refresh();} } _photoThumbnail.repaint(); } @@ -282,41 +374,47 @@ 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"); } /** - * Build a String to describe a time duration - * @param inNumSecs number of seconds - * @return time as a string, days, hours, mins, secs as appropriate + * Construct an appropriate coordinate label using the selected format + * @param inPrefix prefix of label + * @param inCoordinate coordinate + * @param inFormat index of format selection dropdown + * @return language-sensitive string */ - private static String buildDurationString(long inNumSecs) + private static String makeCoordinateLabel(String inPrefix, Coordinate inCoordinate, int inFormat) { - if (inNumSecs <= 0L) return ""; - if (inNumSecs < 60L) return "" + inNumSecs + I18nManager.getText("display.range.time.secs"); - if (inNumSecs < 3600L) return "" + (inNumSecs / 60) + I18nManager.getText("display.range.time.mins") - + " " + (inNumSecs % 60) + I18nManager.getText("display.range.time.secs"); - if (inNumSecs < 86400L) return "" + (inNumSecs / 60 / 60) + I18nManager.getText("display.range.time.hours") - + " " + ((inNumSecs / 60) % 60) + I18nManager.getText("display.range.time.mins"); - if (inNumSecs < 8640000L) return "" + (inNumSecs / 86400L) + I18nManager.getText("display.range.time.days"); - return "big"; + String coord = null; + switch (inFormat) { + case 1: // degminsec + coord = inCoordinate.output(Coordinate.FORMAT_DEG_MIN_SEC); break; + case 2: // degmin + coord = inCoordinate.output(Coordinate.FORMAT_DEG_MIN); break; + case 3: // degrees + coord = inCoordinate.output(Coordinate.FORMAT_DEG); break; + default: // just as it was + coord = inCoordinate.output(Coordinate.FORMAT_NONE); + } + return inPrefix + coord; } /** - * Build a String to describe a distance + * Format a number to a sensible precision * @param inDist distance * @return formatted String */ - private String buildDistanceString(double inDist) + private String roundedNumber(double inDist) { // Set precision of formatter int numDigits = 0; @@ -331,4 +429,19 @@ public class DetailsDisplay extends GenericDisplay _distanceFormatter.setMinimumFractionDigits(numDigits); return _distanceFormatter.format(inDist); } + + /** + * Create a little button for rotating the current photo + * @param inIcon icon to use (from IconManager) + * @param inFunction function to call (from FunctionLibrary) + * @return button object + */ + private static JButton makeRotateButton(String inIcon, GenericFunction inFunction) + { + JButton button = new JButton(IconManager.getImageIcon(inIcon)); + button.setToolTipText(I18nManager.getText(inFunction.getNameKey())); + button.setMargin(new Insets(0, 2, 0, 2)); + button.addActionListener(new FunctionLauncher(inFunction)); + return button; + } }