]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/gui/DetailsDisplay.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / gui / DetailsDisplay.java
index 765b88b30c37f5206e6abb30ac676c5d850ce885..7b3a4ff6843f9b34c4c7df048081a54f92ec17e6 100644 (file)
@@ -2,13 +2,12 @@ package tim.prune.gui;
 
 import java.awt.BorderLayout;
 import java.awt.Component;
+import java.awt.Dimension;
 import java.awt.FlowLayout;
 import java.awt.Font;
-import java.awt.GridLayout;
+import java.awt.Insets;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.awt.event.AdjustmentEvent;
-import java.awt.event.AdjustmentListener;
 import java.text.NumberFormat;
 
 import javax.swing.BorderFactory;
@@ -17,25 +16,29 @@ import javax.swing.BoxLayout;
 import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JLabel;
-import javax.swing.JList;
 import javax.swing.JPanel;
-import javax.swing.JScrollBar;
-import javax.swing.JScrollPane;
-import javax.swing.JTabbedPane;
+import javax.swing.JProgressBar;
 import javax.swing.border.EtchedBorder;
-import javax.swing.event.ListSelectionEvent;
-import javax.swing.event.ListSelectionListener;
 
-import tim.prune.App;
 import tim.prune.DataSubscriber;
+import tim.prune.FunctionLibrary;
+import tim.prune.GenericFunction;
 import tim.prune.I18nManager;
-import tim.prune.data.Altitude;
+import tim.prune.UpdateMessageBroker;
+import tim.prune.config.Config;
+import tim.prune.data.AltitudeRange;
+import tim.prune.data.AudioClip;
 import tim.prune.data.Coordinate;
 import tim.prune.data.DataPoint;
-import tim.prune.data.Distance;
-import tim.prune.data.IntegerRange;
+import tim.prune.data.Field;
+import tim.prune.data.Photo;
 import tim.prune.data.Selection;
+import tim.prune.data.SpeedCalculator;
+import tim.prune.data.SpeedValue;
 import tim.prune.data.TrackInfo;
+import tim.prune.data.Unit;
+import tim.prune.data.UnitSet;
+import tim.prune.data.UnitSetLibrary;
 
 /**
  * Class to hold point details and selection details
@@ -43,97 +46,84 @@ import tim.prune.data.TrackInfo;
  */
 public class DetailsDisplay extends GenericDisplay
 {
-       // App object to be notified of editing commands
-       private App _app = null;
-
-       // Track details
-       private JLabel _trackpointsLabel = null;
-       private JLabel _filenameLabel = null;
        // Point details
        private JLabel _indexLabel = null;
        private JLabel _latLabel = null, _longLabel = null;
-       private JLabel _altLabel = null, _nameLabel = null;
-       private JLabel _timeLabel = null, _photoFileLabel = null;
-       // Scroll bar
-       private JScrollBar _scroller = null;
-       private boolean _ignoreScrollEvents = false;
-       // Button panel
-       private JButton _startRangeButton = null, _endRangeButton = null;
-       private JButton _deletePointButton = null, _deleteRangeButton = null;
+       private JLabel _altLabel = null;
+       private JLabel _timeLabel = null;
+       private JLabel _speedLabel = null, _vSpeedLabel = 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;
-       // Photos
-       private JList _photoList = null;
-       private PhotoListModel _photoListModel = null;
-       // Waypoints
-       private JList _waypointList = null;
-       private WaypointListModel _waypointListModel = null;
+       private JLabel _aveSpeedLabel = null;
+
+       // Photo details
+       private JPanel _photoDetailsPanel = null;
+       private JLabel _photoLabel = null;
+       private JLabel _photoPathLabel = null;
+       private PhotoThumbnail _photoThumbnail = null;
+       private JLabel _photoTimestampLabel = null;
+       private JLabel _photoConnectedLabel = null;
+       private JLabel _photoBearingLabel = null;
+       private JPanel _rotationButtons = null;
+
+       // Audio details
+       private JPanel _audioDetailsPanel = null;
+       private JLabel _audioLabel = null;
+       private JLabel _audioPathLabel = null;
+       private JLabel _audioConnectedLabel = null;
+       private JLabel _audioTimestampLabel = null;
+       private JLabel _audioLengthLabel = null;
+       private JProgressBar _audioProgress = null;
+       private JPanel _playAudioPanel = 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_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") + ": ";
        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;
-       // scrollbar interval
-       private static final int SCROLLBAR_INTERVAL = 50;
+       private static final String LABEL_AUDIO_FILE = I18nManager.getText("details.audio.file") + ": ";
+       private static final String LABEL_FULL_PATH = I18nManager.getText("details.media.fullpath") + ": ";
 
 
        /**
         * Constructor
-        * @param inApp App object for callbacks
         * @param inTrackInfo Track info object
         */
-       public DetailsDisplay(App inApp, TrackInfo inTrackInfo)
+       public DetailsDisplay(TrackInfo inTrackInfo)
        {
                super(inTrackInfo);
-               _app = inApp;
                setLayout(new BorderLayout());
 
                JPanel mainPanel = new JPanel();
                mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
                mainPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
-               // Track details panel
-               JPanel trackDetailsPanel = new JPanel();
-               trackDetailsPanel.setLayout(new BoxLayout(trackDetailsPanel, BoxLayout.Y_AXIS));
-               trackDetailsPanel.setBorder(BorderFactory.createCompoundBorder(
-                       BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(3, 3, 3, 3))
-               );
-               JLabel trackDetailsLabel = new JLabel(I18nManager.getText("details.trackdetails"));
-               Font biggerFont = trackDetailsLabel.getFont();
+               Font biggerFont = new JLabel().getFont();
                biggerFont = biggerFont.deriveFont(Font.BOLD, biggerFont.getSize2D() + 2.0f);
-               trackDetailsLabel.setFont(biggerFont);
-               trackDetailsPanel.add(trackDetailsLabel);
-               _trackpointsLabel = new JLabel(I18nManager.getText("details.notrack"));
-               trackDetailsPanel.add(_trackpointsLabel);
-               _filenameLabel = new JLabel("");
-               trackDetailsPanel.add(_filenameLabel);
 
                // Point details panel
-               JPanel pointDetailsPanel = new JPanel();
-               pointDetailsPanel.setLayout(new BoxLayout(pointDetailsPanel, BoxLayout.Y_AXIS));
-               pointDetailsPanel.setBorder(BorderFactory.createCompoundBorder(
-                       BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(3, 3, 3, 3))
-               );
-               JLabel pointDetailsLabel = new JLabel(I18nManager.getText("details.pointdetails"));
-               pointDetailsLabel.setFont(biggerFont);
-               pointDetailsPanel.add(pointDetailsLabel);
+               JPanel pointDetailsPanel = makeDetailsPanel("details.pointdetails", biggerFont);
                _indexLabel = new JLabel(I18nManager.getText("details.nopointselection"));
                pointDetailsPanel.add(_indexLabel);
                _latLabel = new JLabel("");
@@ -143,231 +133,162 @@ public class DetailsDisplay extends GenericDisplay
                _altLabel = new JLabel("");
                pointDetailsPanel.add(_altLabel);
                _timeLabel = new JLabel("");
+               _timeLabel.setMinimumSize(new Dimension(120, 10));
                pointDetailsPanel.add(_timeLabel);
-               _photoFileLabel = new JLabel("");
-               pointDetailsPanel.add(_photoFileLabel);
+               _speedLabel = new JLabel("");
+               pointDetailsPanel.add(_speedLabel);
+               _vSpeedLabel = new JLabel("");
+               pointDetailsPanel.add(_vSpeedLabel);
                _nameLabel = new JLabel("");
                pointDetailsPanel.add(_nameLabel);
+               _typeLabel = new JLabel("");
+               pointDetailsPanel.add(_typeLabel);
                pointDetailsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
 
-               // Scroll bar
-               _scroller = new JScrollBar(JScrollBar.HORIZONTAL, 0, SCROLLBAR_INTERVAL, 0, 100);
-               _scroller.addAdjustmentListener(new AdjustmentListener() {
-                       public void adjustmentValueChanged(AdjustmentEvent e)
-                       {
-                               selectPoint(e.getValue());
-                       }
-               });
-               _scroller.setEnabled(false);
-
-               // Button panel
-               JPanel buttonPanel = new JPanel();
-               buttonPanel.setLayout(new GridLayout(2, 2, 3, 3));
-               _startRangeButton = new JButton(I18nManager.getText("button.startrange"));
-               _startRangeButton.addActionListener(new ActionListener()
-                       {
-                               public void actionPerformed(ActionEvent e)
-                               {
-                                       _trackInfo.getSelection().selectRangeStart();
-                               }
-                       });
-               _startRangeButton.setEnabled(false);
-               buttonPanel.add(_startRangeButton);
-               _endRangeButton = new JButton(I18nManager.getText("button.endrange"));
-               _endRangeButton.addActionListener(new ActionListener()
-                       {
-                               public void actionPerformed(ActionEvent e)
-                               {
-                                       _trackInfo.getSelection().selectRangeEnd();
-                               }
-                       });
-               _endRangeButton.setEnabled(false);
-               buttonPanel.add(_endRangeButton);
-               _deletePointButton = new JButton(I18nManager.getText("button.deletepoint"));
-               _deletePointButton.addActionListener(new ActionListener()
-                       {
-                               public void actionPerformed(ActionEvent e)
-                               {
-                                       _app.deleteCurrentPoint();
-                               }
-                       });
-               _deletePointButton.setEnabled(false);
-               buttonPanel.add(_deletePointButton);
-               _deleteRangeButton = new JButton(I18nManager.getText("button.deleterange"));
-               _deleteRangeButton.addActionListener(new ActionListener()
-                       {
-                               public void actionPerformed(ActionEvent e)
-                               {
-                                       _app.deleteSelectedRange();
-                               }
-                       });
-               _deleteRangeButton.setEnabled(false);
-               buttonPanel.add(_deleteRangeButton);
-               buttonPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
-
                // range details panel
-               JPanel otherDetailsPanel = new JPanel();
-               otherDetailsPanel.setLayout(new BoxLayout(otherDetailsPanel, BoxLayout.Y_AXIS));
-               otherDetailsPanel.setBorder(BorderFactory.createCompoundBorder(
-                       BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(3, 3, 3, 3))
-               );
-
-               JLabel otherDetailsLabel = new JLabel(I18nManager.getText("details.rangedetails"));
-               otherDetailsLabel.setFont(biggerFont);
-               otherDetailsPanel.add(otherDetailsLabel);
+               JPanel rangeDetailsPanel = makeDetailsPanel("details.rangedetails", biggerFont);
                _rangeLabel = new JLabel(I18nManager.getText("details.norangeselection"));
-               otherDetailsPanel.add(_rangeLabel);
+               rangeDetailsPanel.add(_rangeLabel);
                _distanceLabel = new JLabel("");
-               otherDetailsPanel.add(_distanceLabel);
+               rangeDetailsPanel.add(_distanceLabel);
                _durationLabel = new JLabel("");
-               otherDetailsPanel.add(_durationLabel);
+               rangeDetailsPanel.add(_durationLabel);
+               _aveSpeedLabel = new JLabel("");
+               rangeDetailsPanel.add(_aveSpeedLabel);
                _altRangeLabel = new JLabel("");
-               otherDetailsPanel.add(_altRangeLabel);
+               rangeDetailsPanel.add(_altRangeLabel);
                _updownLabel = new JLabel("");
-               otherDetailsPanel.add(_updownLabel);
-               otherDetailsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
-
-               // Add tab panel for waypoints / photos
-               JPanel waypointsPanel = new JPanel();
-               waypointsPanel.setLayout(new BoxLayout(waypointsPanel, BoxLayout.Y_AXIS));
-               waypointsPanel.setBorder(BorderFactory.createCompoundBorder(
-                       BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(3, 3, 3, 3))
-               );
-               JTabbedPane tabPane = new JTabbedPane();
-               _waypointListModel = new WaypointListModel(_trackInfo.getTrack());
-               _waypointList = new JList(_waypointListModel);
-               _waypointList.setVisibleRowCount(5);
-               _waypointList.addListSelectionListener(new ListSelectionListener() {
-                       public void valueChanged(ListSelectionEvent e)
-                       {
-                               if (!e.getValueIsAdjusting()) selectWaypoint(_waypointList.getSelectedIndex());
-                       }});
-               tabPane.addTab(I18nManager.getText("details.waypointsphotos.waypoints"), new JScrollPane(_waypointList));
-               _photoListModel = new PhotoListModel(_trackInfo.getPhotoList());
-               _photoList = new JList(_photoListModel);
-               _photoList.setVisibleRowCount(5);
-               _photoList.addListSelectionListener(new ListSelectionListener() {
-                       public void valueChanged(ListSelectionEvent e)
-                       {
-                               if (!e.getValueIsAdjusting()) selectPhoto(_photoList.getSelectedIndex());
-                       }});
-               // TODO: Re-add photos list after v2
-               // tabPane.addTab(I18nManager.getText("details.waypointsphotos.photos"), new JScrollPane(_photoList));
-               tabPane.setAlignmentX(Component.LEFT_ALIGNMENT);
-               waypointsPanel.add(tabPane);
-               waypointsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
-
-               // add the slider, point details, and the other details to the main panel
-               mainPanel.add(buttonPanel);
-               mainPanel.add(Box.createVerticalStrut(5));
-               mainPanel.add(_scroller);
+               rangeDetailsPanel.add(_updownLabel);
+               rangeDetailsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
+
+               // photo details panel
+               _photoDetailsPanel = makeDetailsPanel("details.photodetails", biggerFont);
+               _photoLabel = new JLabel(I18nManager.getText("details.nophoto"));
+               _photoDetailsPanel.add(_photoLabel);
+               _photoPathLabel = new JLabel("");
+               _photoDetailsPanel.add(_photoPathLabel);
+               _photoTimestampLabel = new JLabel("");
+               _photoTimestampLabel.setMinimumSize(new Dimension(120, 10));
+               _photoDetailsPanel.add(_photoTimestampLabel);
+               _photoConnectedLabel = new JLabel("");
+               _photoDetailsPanel.add(_photoConnectedLabel);
+               _photoBearingLabel = new JLabel("");
+               _photoDetailsPanel.add(_photoBearingLabel);
+               _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);
+               JButton popup = makeRotateButton(IconManager.SHOW_DETAILS, FunctionLibrary.FUNCTION_PHOTO_POPUP);
+               _rotationButtons = new JPanel();
+               _rotationButtons.add(rotLeft);
+               _rotationButtons.add(rotRight);
+               _rotationButtons.add(Box.createHorizontalStrut(10));
+               _rotationButtons.add(popup);
+               _rotationButtons.setAlignmentX(Component.LEFT_ALIGNMENT);
+               _rotationButtons.setVisible(false);
+               _photoDetailsPanel.add(_rotationButtons);
+               _photoDetailsPanel.setVisible(false);
+
+               // audio details panel
+               _audioDetailsPanel = makeDetailsPanel("details.audiodetails", biggerFont);
+               _audioLabel = new JLabel(I18nManager.getText("details.noaudio"));
+               _audioDetailsPanel.add(_audioLabel);
+               _audioPathLabel = new JLabel("");
+               _audioDetailsPanel.add(_audioPathLabel);
+               _audioTimestampLabel = new JLabel("");
+               _audioTimestampLabel.setMinimumSize(new Dimension(120, 10));
+               _audioDetailsPanel.add(_audioTimestampLabel);
+               _audioLengthLabel = new JLabel("");
+               _audioDetailsPanel.add(_audioLengthLabel);
+               _audioConnectedLabel = new JLabel("");
+               _audioDetailsPanel.add(_audioConnectedLabel);
+               _audioProgress = new JProgressBar(0, 100);
+               _audioProgress.setString(I18nManager.getText("details.audio.playing"));
+               _audioProgress.setStringPainted(true);
+               _audioProgress.setVisible(false);
+               _audioDetailsPanel.add(_audioProgress);
+               _playAudioPanel = new JPanel();
+               _playAudioPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
+               JButton playAudio = makeRotateButton(IconManager.PLAY_AUDIO, FunctionLibrary.FUNCTION_PLAY_AUDIO);
+               playAudio.addActionListener(new AudioListener(_audioProgress));
+               _playAudioPanel.add(playAudio);
+               JButton stopAudio = makeRotateButton(IconManager.STOP_AUDIO, FunctionLibrary.FUNCTION_STOP_AUDIO);
+               _playAudioPanel.add(stopAudio);
+               _playAudioPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
+               _playAudioPanel.setVisible(false);
+               _audioDetailsPanel.add(_playAudioPanel);
+               _audioDetailsPanel.setVisible(false);
+
+               // add the details panels to the main panel
+               mainPanel.add(pointDetailsPanel);
                mainPanel.add(Box.createVerticalStrut(5));
-               mainPanel.add(trackDetailsPanel);
+               mainPanel.add(rangeDetailsPanel);
                mainPanel.add(Box.createVerticalStrut(5));
-               mainPanel.add(pointDetailsPanel);
+               mainPanel.add(_photoDetailsPanel);
                mainPanel.add(Box.createVerticalStrut(5));
-               mainPanel.add(otherDetailsPanel);
+               mainPanel.add(_audioDetailsPanel);
                mainPanel.add(Box.createVerticalStrut(5));
-               mainPanel.add(waypointsPanel);
                // 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 FlowLayout(FlowLayout.LEFT));
-               lowerPanel.add(new JLabel(I18nManager.getText("details.distanceunits") + ": "));
-               String[] distUnits = {I18nManager.getText("units.kilometres"), I18nManager.getText("units.miles")};
-               _unitsDropdown = new JComboBox(distUnits);
-               _unitsDropdown.addActionListener(new ActionListener() {
+               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(_unitsDropdown);
-               add(lowerPanel, BorderLayout.SOUTH);
-       }
-
-
-       /**
-        * Select the specified point
-        * @param inValue value to select
-        */
-       private void selectPoint(int inValue)
-       {
-               if (_track != null && !_ignoreScrollEvents)
-               {
-                       _trackInfo.getSelection().selectPoint(inValue);
+               lowerPanel.add(_coordFormatDropdown);
+               _coordFormatDropdown.setAlignmentX(Component.LEFT_ALIGNMENT);
+               JLabel unitsLabel = new JLabel(I18nManager.getText("details.distanceunits") + ": ");
+               unitsLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
+               lowerPanel.add(unitsLabel);
+               // Make dropdown for distance units
+               _distUnitsDropdown = new JComboBox();
+               final UnitSet currUnits = Config.getUnitSet();
+               for (int i=0; i<UnitSetLibrary.getNumUnitSets(); i++) {
+                       _distUnitsDropdown.addItem(I18nManager.getText(UnitSetLibrary.getUnitSet(i).getDistanceUnit().getNameKey()));
+                       if (UnitSetLibrary.getUnitSet(i) == currUnits) {_distUnitsDropdown.setSelectedIndex(i);}
                }
-       }
-
-
-       /**
-        * Select the specified photo
-        * @param inPhotoIndex index of selected photo
-        */
-       private void selectPhoto(int inPhotoIndex)
-       {
-               if (_photoListModel.getPhoto(inPhotoIndex) != null)
-               {
-                       // TODO: Deselect the photo when another point is selected
-                       // TODO: show photo thumbnail
-                       // select associated point, if any
-                       DataPoint point = _photoListModel.getPhoto(inPhotoIndex).getDataPoint();
-                       if (point != null)
+               _distUnitsDropdown.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent e)
                        {
-                               _trackInfo.selectPoint(point);
+                               Config.selectUnitSet(_distUnitsDropdown.getSelectedIndex());
+                               UpdateMessageBroker.informSubscribers(DataSubscriber.UNITS_CHANGED);
                        }
-               }
-       }
-
-
-       /**
-        * Select the specified waypoint
-        * @param inWaypointIndex index of selected waypoint
-        */
-       private void selectWaypoint(int inWaypointIndex)
-       {
-               if (inWaypointIndex >= 0)
-               {
-                       _trackInfo.selectPoint(_waypointListModel.getWaypoint(inWaypointIndex));
-               }
+               });
+               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)
        {
-               // Update track data
-               if (_track == null || _track.getNumPoints() <= 0)
-               {
-                       _trackpointsLabel.setText(I18nManager.getText("details.notrack"));
-                       _filenameLabel.setText("");
-               }
-               else
-               {
-                       _trackpointsLabel.setText(I18nManager.getText("details.track.points") + ": "
-                               + _track.getNumPoints());
-                       int numFiles = _trackInfo.getFileInfo().getNumFiles();
-                       if (numFiles == 1)
-                       {
-                               _filenameLabel.setText(I18nManager.getText("details.track.file") + ": "
-                                       + _trackInfo.getFileInfo().getFilename());
-                       }
-                       else if (numFiles > 1)
-                       {
-                               _filenameLabel.setText(I18nManager.getText("details.track.numfiles") + ": "
-                                       + numFiles);
-                       }
-                       else _filenameLabel.setText("");
-               }
-
                // Update current point data, if any
                DataPoint currentPoint = _trackInfo.getCurrentPoint();
                Selection selection = _trackInfo.getSelection();
+               if ((inUpdateType | DATA_ADDED_OR_REMOVED) > 0) selection.markInvalid();
                int currentPointIndex = selection.getCurrentPointIndex();
+               _speedLabel.setText("");
+               UnitSet unitSet = UnitSetLibrary.getUnitSet(_distUnitsDropdown.getSelectedIndex());
+               String distUnitsStr = I18nManager.getText(unitSet.getDistanceUnit().getShortnameKey());
+               String speedUnitsStr = I18nManager.getText(unitSet.getSpeedUnit().getShortnameKey());
                if (_track == null || currentPoint == null)
                {
                        _indexLabel.setText(I18nManager.getText("details.nopointselection"));
@@ -375,63 +296,69 @@ public class DetailsDisplay extends GenericDisplay
                        _longLabel.setText("");
                        _altLabel.setText("");
                        _timeLabel.setText("");
-                       _photoFileLabel.setText("");
                        _nameLabel.setText("");
+                       _typeLabel.setText("");
+                       _speedLabel.setText("");
+                       _vSpeedLabel.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())):
-                               ""));
-                       if (currentPoint.getTimestamp().isValid())
+                       _latLabel.setText(makeCoordinateLabel(LABEL_POINT_LATITUDE, currentPoint.getLatitude(), _coordFormatDropdown.getSelectedIndex()));
+                       _longLabel.setText(makeCoordinateLabel(LABEL_POINT_LONGITUDE, currentPoint.getLongitude(), _coordFormatDropdown.getSelectedIndex()));
+                       Unit altUnit = Config.getUnitSet().getAltitudeUnit();
+                       _altLabel.setText(currentPoint.hasAltitude()?
+                               (LABEL_POINT_ALTITUDE + currentPoint.getAltitude().getValue(altUnit) + " " +
+                               I18nManager.getText(altUnit.getShortnameKey()))
+                               : "");
+                       if (currentPoint.hasTimestamp()) {
                                _timeLabel.setText(LABEL_POINT_TIMESTAMP + currentPoint.getTimestamp().getText());
-                       else
+                       }
+                       else {
                                _timeLabel.setText("");
-                       if (currentPoint.getPhoto() != null && currentPoint.getPhoto().getFile() != null)
+                       }
+
+                       // Speed can come from either timestamps and distances, or speed values in data
+                       SpeedValue speedValue = new SpeedValue();
+                       SpeedCalculator.calculateSpeed(_track, currentPointIndex, speedValue);
+                       if (speedValue.isValid())
                        {
-                               _photoFileLabel.setText(I18nManager.getText("details.photofile") + ": "
-                                       + currentPoint.getPhoto().getFile().getName());
+                               String speed = roundedNumber(speedValue.getValue()) + " " + speedUnitsStr;
+                               _speedLabel.setText(LABEL_POINT_SPEED + speed);
                        }
-                       else
-                               _photoFileLabel.setText("");
-                       String name = currentPoint.getWaypointName();
+                       else {
+                               _speedLabel.setText("");
+                       }
+
+                       // Now do the vertical speed in the same way
+                       SpeedCalculator.calculateVerticalSpeed(_track, currentPointIndex, speedValue);
+                       if (speedValue.isValid())
+                       {
+                               String vSpeedUnitsStr = I18nManager.getText(unitSet.getVerticalSpeedUnit().getShortnameKey());
+                               String speed = roundedNumber(speedValue.getValue()) + " " + vSpeedUnitsStr;
+                               _vSpeedLabel.setText(LABEL_POINT_VERTSPEED + speed);
+                       }
+                       else {
+                               _vSpeedLabel.setText("");
+                       }
+
+                       // 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 scroller settings
-               _ignoreScrollEvents = true;
-               if (_track == null || _track.getNumPoints() < 2)
-               {
-                       // careful to avoid event loops here
-                       // _scroller.setValue(0);
-                       _scroller.setEnabled(false);
-               }
-               else
-               {
-                       _scroller.setMaximum(_track.getNumPoints() + SCROLLBAR_INTERVAL);
-                       if (currentPointIndex >= 0)
-                               _scroller.setValue(currentPointIndex);
-                       _scroller.setEnabled(true);
-               }
-               _ignoreScrollEvents = false;
-
-               // Update button panel
-               boolean hasPoint = (_track != null && currentPointIndex >= 0);
-               _startRangeButton.setEnabled(hasPoint);
-               _endRangeButton.setEnabled(hasPoint);
-               _deletePointButton.setEnabled(hasPoint);
-               _deleteRangeButton.setEnabled(selection.hasRangeSelected());
-
                // Update range details
                if (_track == null || !selection.hasRangeSelected())
                {
@@ -440,34 +367,35 @@ 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()) + " " + 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()/selection.getNumSeconds()*3600.0) + " " + speedUnitsStr);
+                       }
+                       else {
                                _durationLabel.setText("");
-                       String altUnitsLabel = getAltitudeUnitsLabel(selection.getAltitudeFormat());
-                       IntegerRange altRange = selection.getAltitudeRange();
-                       if (altRange.getMinimum() >= 0 && altRange.getMaximum() >= 0)
+                               _aveSpeedLabel.setText("");
+                       }
+                       AltitudeRange altRange = selection.getAltitudeRange();
+                       Unit altUnit = Config.getUnitSet().getAltitudeUnit();
+                       String altUnitsLabel = I18nManager.getText(altUnit.getShortnameKey());
+                       if (altRange.hasRange())
                        {
                                _altRangeLabel.setText(LABEL_RANGE_ALTITUDE
-                                       + altRange.getMinimum() + altUnitsLabel + " "
+                                       + altRange.getMinimum(altUnit) + altUnitsLabel + " "
                                        + I18nManager.getText("details.altitude.to") + " "
-                                       + altRange.getMaximum() + altUnitsLabel);
-                               _updownLabel.setText(LABEL_RANGE_CLIMB + selection.getClimb() + altUnitsLabel
-                                       + LABEL_RANGE_DESCENT + selection.getDescent() + altUnitsLabel);
+                                       + altRange.getMaximum(altUnit) + altUnitsLabel);
+                               _updownLabel.setText(LABEL_RANGE_CLIMB + altRange.getClimb(altUnit) + altUnitsLabel
+                                       + LABEL_RANGE_DESCENT + altRange.getDescent(altUnit) + altUnitsLabel);
                        }
                        else
                        {
@@ -475,80 +403,111 @@ public class DetailsDisplay extends GenericDisplay
                                _updownLabel.setText("");
                        }
                }
-               // update waypoints and photos if necessary
-               if ((inUpdateType |
-                       (DataSubscriber.DATA_ADDED_OR_REMOVED | DataSubscriber.DATA_EDITED | DataSubscriber.WAYPOINTS_MODIFIED)) > 0)
-               {
-                       _waypointListModel.fireChanged();
-               }
-               if ((inUpdateType |
-                       (DataSubscriber.DATA_ADDED_OR_REMOVED | DataSubscriber.DATA_EDITED | DataSubscriber.PHOTOS_MODIFIED)) > 0)
+               // show photo details and thumbnail
+               _photoDetailsPanel.setVisible(_trackInfo.getPhotoList().getNumPhotos() > 0);
+               Photo currentPhoto = _trackInfo.getPhotoList().getPhoto(_trackInfo.getSelection().getCurrentPhotoIndex());
+               if ((currentPoint == null || currentPoint.getPhoto() == null) && currentPhoto == null)
                {
-                       _photoListModel.fireChanged();
+                       // no photo, hide details
+                       _photoLabel.setText(I18nManager.getText("details.nophoto"));
+                       _photoPathLabel.setText("");
+                       _photoPathLabel.setToolTipText("");
+                       _photoTimestampLabel.setText("");
+                       _photoConnectedLabel.setText("");
+                       _photoBearingLabel.setText("");
+                       _photoThumbnail.setVisible(false);
+                       _rotationButtons.setVisible(false);
                }
-               // Deselect selected waypoint if selected point has since changed
-               if (_waypointList.getSelectedIndex() >= 0)
+               else
                {
-                       if (_trackInfo.getCurrentPoint() == null
-                        || !_waypointListModel.getWaypoint(_waypointList.getSelectedIndex()).equals(_trackInfo.getCurrentPoint()))
+                       if (currentPhoto == null) {currentPhoto = currentPoint.getPhoto();}
+                       _photoLabel.setText(I18nManager.getText("details.photofile") + ": " + currentPhoto.getName());
+                       String fullPath = currentPhoto.getFullPath();
+                       String shortPath = shortenPath(fullPath);
+                       _photoPathLabel.setText(fullPath == null ? "" : LABEL_FULL_PATH + shortPath);
+                       _photoPathLabel.setToolTipText(currentPhoto.getFullPath());
+                       _photoTimestampLabel.setText(currentPhoto.hasTimestamp()?(LABEL_POINT_TIMESTAMP + currentPhoto.getTimestamp().getText()):"");
+                       _photoConnectedLabel.setText(I18nManager.getText("details.media.connected") + ": "
+                               + (currentPhoto.getCurrentStatus() == Photo.Status.NOT_CONNECTED ?
+                                       I18nManager.getText("dialog.about.no"):I18nManager.getText("dialog.about.yes")));
+                       if (currentPhoto.getBearing() >= 0.0 && currentPhoto.getBearing() <= 360.0)
                        {
-                               // point is selected in list but different from current point - deselect
-                               _waypointList.clearSelection();
+                               _photoBearingLabel.setText(I18nManager.getText("details.photo.bearing") + ": "
+                                       + (int) currentPhoto.getBearing() + " \u00B0");
                        }
+                       else _photoBearingLabel.setText("");
+                       _photoThumbnail.setVisible(true);
+                       _photoThumbnail.setPhoto(currentPhoto);
+                       _rotationButtons.setVisible(true);
+                       if ((inUpdateType & DataSubscriber.PHOTOS_MODIFIED) > 0) {_photoThumbnail.refresh();}
                }
-               // Do the same for the photos
-               if (_photoList.getSelectedIndex() >= 0)
+               _photoThumbnail.repaint();
+
+               // audio details
+               _audioDetailsPanel.setVisible(_trackInfo.getAudioList().getNumAudios() > 0);
+               AudioClip currentAudio = _trackInfo.getAudioList().getAudio(_trackInfo.getSelection().getCurrentAudioIndex());
+               if (currentAudio == null)
                {
-                       if (_trackInfo.getCurrentPoint() == null
-                               || !_photoListModel.getPhoto(_photoList.getSelectedIndex()).getDataPoint().equals(_trackInfo.getCurrentPoint()))
-                       {
-                               // photo is selected in list but different from current point - deselect
-                               _photoList.clearSelection();
-                       }
+                       _audioLabel.setText(I18nManager.getText("details.noaudio"));
+                       _audioPathLabel.setText("");
+                       _audioPathLabel.setToolTipText("");
+                       _audioTimestampLabel.setText("");
+                       _audioLengthLabel.setText("");
+                       _audioConnectedLabel.setText("");
+               }
+               else
+               {
+                       _audioLabel.setText(LABEL_AUDIO_FILE + currentAudio.getName());
+                       String fullPath = currentAudio.getFullPath();
+                       String shortPath = shortenPath(fullPath);
+                       _audioPathLabel.setText(fullPath == null ? "" : LABEL_FULL_PATH + shortPath);
+                       _audioPathLabel.setToolTipText(fullPath == null ? "" : fullPath);
+                       _audioTimestampLabel.setText(currentAudio.hasTimestamp()?(LABEL_POINT_TIMESTAMP + currentAudio.getTimestamp().getText()):"");
+                       int audioLength = currentAudio.getLengthInSeconds();
+                       _audioLengthLabel.setText(audioLength < 0?"":LABEL_RANGE_DURATION + DisplayUtils.buildDurationString(audioLength));
+                       _audioConnectedLabel.setText(I18nManager.getText("details.media.connected") + ": "
+                               + (currentAudio.getCurrentStatus() == Photo.Status.NOT_CONNECTED ?
+                                       I18nManager.getText("dialog.about.no"):I18nManager.getText("dialog.about.yes")));
                }
+               _playAudioPanel.setVisible(currentAudio != null);
        }
 
 
        /**
-        * Choose the appropriate altitude units label for the specified format
-        * @param inFormat altitude format
+        * 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 getAltitudeUnitsLabel(int inFormat)
+       private static String makeCoordinateLabel(String inPrefix, Coordinate inCoordinate, int 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)
-                       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
-        */
-       private static String buildDurationString(long inNumSecs)
-       {
-               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);
+               }
+               // Fix broken degree signs (due to unicode mangling)
+               final char brokenDeg = 65533;
+               if (coord.indexOf(brokenDeg) >= 0) {
+                       coord = coord.replaceAll(String.valueOf(brokenDeg), "\u00B0");
+               }
+               return inPrefix + restrictDP(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;
@@ -563,4 +522,75 @@ public class DetailsDisplay extends GenericDisplay
                _distanceFormatter.setMinimumFractionDigits(numDigits);
                return _distanceFormatter.format(inDist);
        }
+
+       /**
+        * Restrict the given coordinate to a limited number of decimal places for display
+        * @param inCoord coordinate string
+        * @return chopped string
+        */
+       private static String restrictDP(String inCoord)
+       {
+               final int DECIMAL_PLACES = 7;
+               if (inCoord == null) return "";
+               final int dotPos = Math.max(inCoord.lastIndexOf('.'), inCoord.lastIndexOf(','));
+               if (dotPos >= 0) {
+                       final int chopPos = dotPos + DECIMAL_PLACES;
+                       if (chopPos < (inCoord.length()-1)) {
+                               return inCoord.substring(0, chopPos);
+                       }
+               }
+               return inCoord;
+       }
+
+       /**
+        * Make a details subpanel
+        * @param inNameKey key to use for top label
+        * @param inFont font for top label
+        * @return panel with correct layout, label
+        */
+       private static JPanel makeDetailsPanel(String inNameKey, Font inFont)
+       {
+               JPanel detailsPanel = new JPanel();
+               detailsPanel.setLayout(new BoxLayout(detailsPanel, BoxLayout.Y_AXIS));
+               detailsPanel.setBorder(BorderFactory.createCompoundBorder(
+                       BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(3, 3, 3, 3))
+               );
+               JLabel detailsLabel = new JLabel(I18nManager.getText(inNameKey));
+               detailsLabel.setFont(inFont);
+               detailsPanel.add(detailsLabel);
+               return detailsPanel;
+       }
+
+       /**
+        * 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;
+       }
+
+       /**
+        * @param inFullPath full file path or URL to be shortened
+        * @return shortened string from beginning of path
+        */
+       private static String shortenPath(String 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);
+               }
+               if (inFullPath == null || inFullPath.length() < 21) {
+                       return inFullPath;
+               }
+               // path is too long
+               return inFullPath.substring(0, 20) + "...";
+       }
 }