X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fgui%2FDetailsDisplay.java;h=f66d99b3c469f7690400919faf909afba1ccbf67;hb=326f489e36aa7f235bc19409a57bf4955cd50f24;hp=7b3a4ff6843f9b34c4c7df048081a54f92ec17e6;hpb=4d5796d02a15808311c09448d79e6e7d1de9d636;p=GpsPrune.git diff --git a/tim/prune/gui/DetailsDisplay.java b/tim/prune/gui/DetailsDisplay.java index 7b3a4ff..f66d99b 100644 --- a/tim/prune/gui/DetailsDisplay.java +++ b/tim/prune/gui/DetailsDisplay.java @@ -8,7 +8,6 @@ import java.awt.Font; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.text.NumberFormat; import javax.swing.BorderFactory; import javax.swing.Box; @@ -51,6 +50,7 @@ public class DetailsDisplay extends GenericDisplay private JLabel _latLabel = null, _longLabel = null; private JLabel _altLabel = null; private JLabel _timeLabel = null; + private JLabel _descLabel = null; private JLabel _speedLabel = null, _vSpeedLabel = null; private JLabel _nameLabel = null, _typeLabel = null; @@ -82,10 +82,8 @@ public class DetailsDisplay extends GenericDisplay private JPanel _playAudioPanel = null; // Units - private JComboBox _coordFormatDropdown = null; - private JComboBox _distUnitsDropdown = null; - // Formatter - private NumberFormat _distanceFormatter = NumberFormat.getInstance(); + private JComboBox _coordFormatDropdown = null; + private JComboBox _distUnitsDropdown = null; // Cached labels private static final String LABEL_POINT_SELECTED = I18nManager.getText("details.index.selected") + ": "; @@ -95,6 +93,7 @@ public class DetailsDisplay extends GenericDisplay 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_POINT_WAYPOINTTYPE = I18nManager.getText("fieldname.waypointtype") + ": "; + private static final String LABEL_POINT_DESCRIPTION = I18nManager.getText("fieldname.description") + ": "; private static final String LABEL_POINT_SPEED = I18nManager.getText("fieldname.speed") + ": "; private static final String LABEL_POINT_VERTSPEED = I18nManager.getText("fieldname.verticalspeed") + ": "; private static final String LABEL_RANGE_SELECTED = I18nManager.getText("details.range.selected") + ": "; @@ -135,6 +134,8 @@ public class DetailsDisplay extends GenericDisplay _timeLabel = new JLabel(""); _timeLabel.setMinimumSize(new Dimension(120, 10)); pointDetailsPanel.add(_timeLabel); + _descLabel = new JLabel(""); + pointDetailsPanel.add(_descLabel); _speedLabel = new JLabel(""); pointDetailsPanel.add(_speedLabel); _vSpeedLabel = new JLabel(""); @@ -242,7 +243,7 @@ public class DetailsDisplay extends GenericDisplay 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 = new JComboBox(coordFormats); _coordFormatDropdown.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -255,7 +256,7 @@ public class DetailsDisplay extends GenericDisplay unitsLabel.setAlignmentX(Component.LEFT_ALIGNMENT); lowerPanel.add(unitsLabel); // Make dropdown for distance units - _distUnitsDropdown = new JComboBox(); + _distUnitsDropdown = new JComboBox(); final UnitSet currUnits = Config.getUnitSet(); for (int i=0; i 0) + _distanceLabel.setText(LABEL_RANGE_DISTANCE + DisplayUtils.roundedNumber(selection.getMovingDistance()) + " " + distUnitsStr); + final long numMovingSeconds = selection.getMovingSeconds(); + if (numMovingSeconds > 0L) { - _durationLabel.setText(LABEL_RANGE_DURATION + DisplayUtils.buildDurationString(selection.getNumSeconds())); + _durationLabel.setText(LABEL_RANGE_DURATION + DisplayUtils.buildDurationString(numMovingSeconds)); _aveSpeedLabel.setText(I18nManager.getText("details.range.avespeed") + ": " - + roundedNumber(selection.getDistance()/selection.getNumSeconds()*3600.0) + " " + speedUnitsStr); + + DisplayUtils.roundedNumber(selection.getMovingDistance()/numMovingSeconds*3600.0) + " " + speedUnitsStr); } else { _durationLabel.setText(""); @@ -502,27 +523,6 @@ public class DetailsDisplay extends GenericDisplay } - /** - * Format a number to a sensible precision - * @param inDist distance - * @return formatted String - */ - private String roundedNumber(double inDist) - { - // Set precision of formatter - int numDigits = 0; - if (inDist < 1.0) - numDigits = 3; - else if (inDist < 10.0) - numDigits = 2; - else if (inDist < 100.0) - numDigits = 1; - // set formatter - _distanceFormatter.setMaximumFractionDigits(numDigits); - _distanceFormatter.setMinimumFractionDigits(numDigits); - return _distanceFormatter.format(inDist); - } - /** * Restrict the given coordinate to a limited number of decimal places for display * @param inCoord coordinate string @@ -582,15 +582,26 @@ public class DetailsDisplay extends GenericDisplay */ private static String shortenPath(String inFullPath) { + String path = inFullPath; // Chop off the home path if possible final String homePath = System.getProperty("user.home").toLowerCase(); if (inFullPath != null && inFullPath.toLowerCase().startsWith(homePath)) { - inFullPath = inFullPath.substring(homePath.length()+1); + path = inFullPath.substring(homePath.length()+1); } - if (inFullPath == null || inFullPath.length() < 21) { - return inFullPath; + return shortenString(path); + } + + /** + * @param inString string to shorten + * @return shortened string from the beginning + */ + private static String shortenString(String inString) + { + // Limit is hardcoded here, maybe it should depend on parent component width and font size etc? + if (inString == null || inString.length() < 21) { + return inString; } - // path is too long - return inFullPath.substring(0, 20) + "..."; + // string is too long + return inString.substring(0, 20) + "..."; } }