]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/gui/DetailsDisplay.java
Version 20.4, May 2021
[GpsPrune.git] / src / tim / prune / gui / DetailsDisplay.java
1 package tim.prune.gui;
2
3 import java.awt.BorderLayout;
4 import java.awt.Component;
5 import java.awt.Dimension;
6 import java.awt.FlowLayout;
7 import java.awt.Font;
8 import java.awt.Insets;
9 import java.awt.event.ActionEvent;
10 import java.awt.event.ActionListener;
11 import java.util.TimeZone;
12
13 import javax.swing.BorderFactory;
14 import javax.swing.Box;
15 import javax.swing.BoxLayout;
16 import javax.swing.JButton;
17 import javax.swing.JComboBox;
18 import javax.swing.JLabel;
19 import javax.swing.JPanel;
20 import javax.swing.JProgressBar;
21 import javax.swing.border.EtchedBorder;
22
23 import tim.prune.DataSubscriber;
24 import tim.prune.FunctionLibrary;
25 import tim.prune.GenericFunction;
26 import tim.prune.I18nManager;
27 import tim.prune.UpdateMessageBroker;
28 import tim.prune.config.Config;
29 import tim.prune.config.TimezoneHelper;
30 import tim.prune.data.AltitudeRange;
31 import tim.prune.data.AudioClip;
32 import tim.prune.data.Coordinate;
33 import tim.prune.data.DataPoint;
34 import tim.prune.data.Field;
35 import tim.prune.data.Photo;
36 import tim.prune.data.Selection;
37 import tim.prune.data.SourceInfo;
38 import tim.prune.data.SpeedCalculator;
39 import tim.prune.data.SpeedValue;
40 import tim.prune.data.TrackInfo;
41 import tim.prune.data.Unit;
42 import tim.prune.data.UnitSet;
43 import tim.prune.data.UnitSetLibrary;
44
45 /**
46  * Class to hold point details and selection details
47  * as a visual component
48  */
49 public class DetailsDisplay extends GenericDisplay
50 {
51         // Point details
52         private JLabel _indexLabel = null;
53         private JLabel _latLabel = null, _longLabel = null;
54         private JLabel _altLabel = null;
55         private JLabel _ptDateLabel = null, _ptTimeLabel = null;
56         private JLabel _descLabel = null;
57         private JLabel _speedLabel = null, _vSpeedLabel = null;
58         private JLabel _nameLabel = null, _typeLabel = null;
59         private JLabel _filenameLabel = null;
60
61         // Range details
62         private JLabel _rangeLabel = null;
63         private JLabel _distanceLabel = null;
64         private JLabel _durationLabel = null;
65         private JLabel _altRangeLabel = null, _updownLabel = null;
66         private JLabel _aveSpeedLabel = null;
67
68         // Photo details
69         private JPanel _photoDetailsPanel = null;
70         private JLabel _photoLabel = null;
71         private JLabel _photoPathLabel = null;
72         private PhotoThumbnail _photoThumbnail = null;
73         private JLabel _photoTimestampLabel = null;
74         private JLabel _photoConnectedLabel = null;
75         private JLabel _photoBearingLabel = null;
76         private JPanel _rotationButtons = null;
77
78         // Audio details
79         private JPanel _audioDetailsPanel = null;
80         private JLabel _audioLabel = null;
81         private JLabel _audioPathLabel = null;
82         private JLabel _audioConnectedLabel = null;
83         private JLabel _audioTimestampLabel = null;
84         private JLabel _audioLengthLabel = null;
85         private JProgressBar _audioProgress = null;
86         private JPanel _playAudioPanel = null;
87
88         // Units
89         private JComboBox<String> _coordFormatDropdown = null;
90         private JComboBox<String> _distUnitsDropdown = null;
91         // Timezone
92         private TimeZone _timezone = null;
93
94         // Cached labels
95         private static final String LABEL_POINT_SELECTED = I18nManager.getText("details.index.selected") + ": ";
96         private static final String LABEL_POINT_LATITUDE = I18nManager.getText("fieldname.latitude") + ": ";
97         private static final String LABEL_POINT_LONGITUDE = I18nManager.getText("fieldname.longitude") + ": ";
98         private static final String LABEL_POINT_ALTITUDE = I18nManager.getText("fieldname.altitude") + ": ";
99         private static final String LABEL_POINT_DATE     = I18nManager.getText("fieldname.date") + ": ";
100         private static final String LABEL_POINT_TIME     = I18nManager.getText("fieldname.timestamp") + ": ";
101         private static final String LABEL_POINT_WAYPOINTNAME = I18nManager.getText("fieldname.waypointname") + ": ";
102         private static final String LABEL_POINT_WAYPOINTTYPE = I18nManager.getText("fieldname.waypointtype") + ": ";
103         private static final String LABEL_POINT_DESCRIPTION  = I18nManager.getText("fieldname.description") + ": ";
104         private static final String LABEL_POINT_SPEED        = I18nManager.getText("fieldname.speed") + ": ";
105         private static final String LABEL_POINT_VERTSPEED    = I18nManager.getText("fieldname.verticalspeed") + ": ";
106         private static final String LABEL_POINT_FILENAME     = I18nManager.getText("details.track.file") + ": ";
107         private static final String LABEL_RANGE_SELECTED = I18nManager.getText("details.range.selected") + ": ";
108         private static final String LABEL_RANGE_DURATION = I18nManager.getText("fieldname.duration") + ": ";
109         private static final String LABEL_RANGE_DISTANCE = I18nManager.getText("fieldname.distance") + ": ";
110         private static final String LABEL_RANGE_ALTITUDE = I18nManager.getText("fieldname.altitude") + ": ";
111         private static final String LABEL_RANGE_CLIMB = I18nManager.getText("details.range.climb") + ": ";
112         private static final String LABEL_RANGE_DESCENT = ", " + I18nManager.getText("details.range.descent") + ": ";
113         private static final String LABEL_AUDIO_FILE = I18nManager.getText("details.audio.file") + ": ";
114         private static final String LABEL_FULL_PATH = I18nManager.getText("details.media.fullpath") + ": ";
115
116
117         /**
118          * Constructor
119          * @param inTrackInfo Track info object
120          */
121         public DetailsDisplay(TrackInfo inTrackInfo)
122         {
123                 super(inTrackInfo);
124                 setLayout(new BorderLayout());
125
126                 JPanel mainPanel = new JPanel();
127                 mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
128                 mainPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
129                 Font biggerFont = new JLabel().getFont();
130                 biggerFont = biggerFont.deriveFont(Font.BOLD, biggerFont.getSize2D() + 2.0f);
131
132                 // Point details panel
133                 JPanel pointDetailsPanel = makeDetailsPanel("details.pointdetails", biggerFont);
134                 _indexLabel = new JLabel(I18nManager.getText("details.nopointselection"));
135                 pointDetailsPanel.add(_indexLabel);
136                 _latLabel = new JLabel("");
137                 pointDetailsPanel.add(_latLabel);
138                 _longLabel = new JLabel("");
139                 pointDetailsPanel.add(_longLabel);
140                 _altLabel = new JLabel("");
141                 pointDetailsPanel.add(_altLabel);
142                 _ptDateLabel = new JLabel("");
143                 _ptDateLabel.setMinimumSize(new Dimension(120, 10));
144                 pointDetailsPanel.add(_ptDateLabel);
145                 _ptTimeLabel = new JLabel("");
146                 _ptTimeLabel.setMinimumSize(new Dimension(120, 10));
147                 pointDetailsPanel.add(_ptTimeLabel);
148                 _descLabel = new JLabel("");
149                 pointDetailsPanel.add(_descLabel);
150                 _speedLabel = new JLabel("");
151                 pointDetailsPanel.add(_speedLabel);
152                 _vSpeedLabel = new JLabel("");
153                 pointDetailsPanel.add(_vSpeedLabel);
154                 _nameLabel = new JLabel("");
155                 pointDetailsPanel.add(_nameLabel);
156                 _typeLabel = new JLabel("");
157                 pointDetailsPanel.add(_typeLabel);
158                 _filenameLabel = new JLabel("");
159                 pointDetailsPanel.add(_filenameLabel);
160                 pointDetailsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
161
162                 // range details panel
163                 JPanel rangeDetailsPanel = makeDetailsPanel("details.rangedetails", biggerFont);
164                 _rangeLabel = new JLabel(I18nManager.getText("details.norangeselection"));
165                 rangeDetailsPanel.add(_rangeLabel);
166                 _distanceLabel = new JLabel("");
167                 rangeDetailsPanel.add(_distanceLabel);
168                 _durationLabel = new JLabel("");
169                 rangeDetailsPanel.add(_durationLabel);
170                 _aveSpeedLabel = new JLabel("");
171                 rangeDetailsPanel.add(_aveSpeedLabel);
172                 _altRangeLabel = new JLabel("");
173                 rangeDetailsPanel.add(_altRangeLabel);
174                 _updownLabel = new JLabel("");
175                 rangeDetailsPanel.add(_updownLabel);
176                 rangeDetailsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
177
178                 // photo details panel
179                 _photoDetailsPanel = makeDetailsPanel("details.photodetails", biggerFont);
180                 _photoLabel = new JLabel(I18nManager.getText("details.nophoto"));
181                 _photoDetailsPanel.add(_photoLabel);
182                 _photoPathLabel = new JLabel("");
183                 _photoDetailsPanel.add(_photoPathLabel);
184                 _photoTimestampLabel = new JLabel("");
185                 _photoTimestampLabel.setMinimumSize(new Dimension(120, 10));
186                 _photoDetailsPanel.add(_photoTimestampLabel);
187                 _photoConnectedLabel = new JLabel("");
188                 _photoDetailsPanel.add(_photoConnectedLabel);
189                 _photoBearingLabel = new JLabel("");
190                 _photoDetailsPanel.add(_photoBearingLabel);
191                 _photoThumbnail = new PhotoThumbnail();
192                 _photoThumbnail.setVisible(false);
193                 _photoThumbnail.setPreferredSize(new Dimension(100, 100));
194                 _photoDetailsPanel.add(_photoThumbnail);
195                 // Rotate buttons
196                 JButton rotLeft = makeRotateButton(IconManager.ROTATE_LEFT, FunctionLibrary.FUNCTION_ROTATE_PHOTO_LEFT);
197                 JButton rotRight = makeRotateButton(IconManager.ROTATE_RIGHT, FunctionLibrary.FUNCTION_ROTATE_PHOTO_RIGHT);
198                 JButton popup = makeRotateButton(IconManager.SHOW_DETAILS, FunctionLibrary.FUNCTION_PHOTO_POPUP);
199                 _rotationButtons = new JPanel();
200                 _rotationButtons.add(rotLeft);
201                 _rotationButtons.add(rotRight);
202                 _rotationButtons.add(Box.createHorizontalStrut(10));
203                 _rotationButtons.add(popup);
204                 _rotationButtons.setAlignmentX(Component.LEFT_ALIGNMENT);
205                 _rotationButtons.setVisible(false);
206                 _photoDetailsPanel.add(_rotationButtons);
207                 _photoDetailsPanel.setVisible(false);
208
209                 // audio details panel
210                 _audioDetailsPanel = makeDetailsPanel("details.audiodetails", biggerFont);
211                 _audioLabel = new JLabel(I18nManager.getText("details.noaudio"));
212                 _audioDetailsPanel.add(_audioLabel);
213                 _audioPathLabel = new JLabel("");
214                 _audioDetailsPanel.add(_audioPathLabel);
215                 _audioTimestampLabel = new JLabel("");
216                 _audioTimestampLabel.setMinimumSize(new Dimension(120, 10));
217                 _audioDetailsPanel.add(_audioTimestampLabel);
218                 _audioLengthLabel = new JLabel("");
219                 _audioDetailsPanel.add(_audioLengthLabel);
220                 _audioConnectedLabel = new JLabel("");
221                 _audioDetailsPanel.add(_audioConnectedLabel);
222                 _audioProgress = new JProgressBar(0, 100);
223                 _audioProgress.setString(I18nManager.getText("details.audio.playing"));
224                 _audioProgress.setStringPainted(true);
225                 _audioProgress.setVisible(false);
226                 _audioDetailsPanel.add(_audioProgress);
227                 _playAudioPanel = new JPanel();
228                 _playAudioPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
229                 JButton playAudio = makeRotateButton(IconManager.PLAY_AUDIO, FunctionLibrary.FUNCTION_PLAY_AUDIO);
230                 playAudio.addActionListener(new AudioListener(_audioProgress));
231                 _playAudioPanel.add(playAudio);
232                 JButton stopAudio = makeRotateButton(IconManager.STOP_AUDIO, FunctionLibrary.FUNCTION_STOP_AUDIO);
233                 _playAudioPanel.add(stopAudio);
234                 _playAudioPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
235                 _playAudioPanel.setVisible(false);
236                 _audioDetailsPanel.add(_playAudioPanel);
237                 _audioDetailsPanel.setVisible(false);
238
239                 // add the details panels to the main panel
240                 mainPanel.add(pointDetailsPanel);
241                 mainPanel.add(Box.createVerticalStrut(5));
242                 mainPanel.add(rangeDetailsPanel);
243                 mainPanel.add(Box.createVerticalStrut(5));
244                 mainPanel.add(_photoDetailsPanel);
245                 mainPanel.add(Box.createVerticalStrut(5));
246                 mainPanel.add(_audioDetailsPanel);
247                 mainPanel.add(Box.createVerticalStrut(5));
248                 // add the main panel at the top
249                 add(mainPanel, BorderLayout.NORTH);
250
251                 // Add format, units selection
252                 JPanel lowerPanel = new JPanel();
253                 lowerPanel.setLayout(new BoxLayout(lowerPanel, BoxLayout.Y_AXIS));
254                 JLabel coordFormatLabel = new JLabel(I18nManager.getText("details.coordformat") + ": ");
255                 coordFormatLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
256                 lowerPanel.add(coordFormatLabel);
257                 String[] coordFormats = {I18nManager.getText("units.original"), I18nManager.getText("units.degminsec"),
258                         I18nManager.getText("units.degmin"), I18nManager.getText("units.deg")};
259                 _coordFormatDropdown = new JComboBox<String>(coordFormats);
260                 _coordFormatDropdown.addActionListener(new ActionListener() {
261                         public void actionPerformed(ActionEvent e)
262                         {
263                                 dataUpdated(DataSubscriber.UNITS_CHANGED);
264                         }
265                 });
266                 lowerPanel.add(_coordFormatDropdown);
267                 _coordFormatDropdown.setAlignmentX(Component.LEFT_ALIGNMENT);
268                 JLabel unitsLabel = new JLabel(I18nManager.getText("details.distanceunits") + ": ");
269                 unitsLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
270                 lowerPanel.add(unitsLabel);
271                 // Make dropdown for distance units
272                 _distUnitsDropdown = new JComboBox<String>();
273                 final UnitSet currUnits = Config.getUnitSet();
274                 for (int i=0; i<UnitSetLibrary.getNumUnitSets(); i++) {
275                         _distUnitsDropdown.addItem(I18nManager.getText(UnitSetLibrary.getUnitSet(i).getDistanceUnit().getNameKey()));
276                         if (UnitSetLibrary.getUnitSet(i) == currUnits) {_distUnitsDropdown.setSelectedIndex(i);}
277                 }
278                 _distUnitsDropdown.addActionListener(new ActionListener() {
279                         public void actionPerformed(ActionEvent e)
280                         {
281                                 Config.selectUnitSet(_distUnitsDropdown.getSelectedIndex());
282                                 UpdateMessageBroker.informSubscribers(DataSubscriber.UNITS_CHANGED);
283                         }
284                 });
285                 lowerPanel.add(_distUnitsDropdown);
286                 _distUnitsDropdown.setAlignmentX(Component.LEFT_ALIGNMENT);
287                 add(lowerPanel, BorderLayout.SOUTH);
288         }
289
290
291         /**
292          * Notification that Track has been updated
293          * @param inUpdateType byte to specify what has been updated
294          */
295         public void dataUpdated(byte inUpdateType)
296         {
297                 // Update current point data, if any
298                 DataPoint currentPoint = _trackInfo.getCurrentPoint();
299                 Selection selection = _trackInfo.getSelection();
300                 if ((inUpdateType | DATA_ADDED_OR_REMOVED) > 0) selection.markInvalid();
301                 int currentPointIndex = selection.getCurrentPointIndex();
302                 _speedLabel.setText("");
303                 UnitSet unitSet = UnitSetLibrary.getUnitSet(_distUnitsDropdown.getSelectedIndex());
304                 String distUnitsStr = I18nManager.getText(unitSet.getDistanceUnit().getShortnameKey());
305                 String speedUnitsStr = I18nManager.getText(unitSet.getSpeedUnit().getShortnameKey());
306                 if (_timezone == null || (inUpdateType | UNITS_CHANGED) > 0) {
307                         _timezone = TimezoneHelper.getSelectedTimezone();
308                 }
309                 if ((inUpdateType | UNITS_CHANGED) > 0) {
310                         Config.setConfigString(Config.KEY_COORD_DISPLAY_FORMAT, "" + getSelectedCoordFormat());
311                 }
312
313                 if (_track == null || currentPoint == null)
314                 {
315                         _indexLabel.setText(I18nManager.getText("details.nopointselection"));
316                         _latLabel.setText("");
317                         _longLabel.setText("");
318                         _altLabel.setText("");
319                         _ptDateLabel.setText("");
320                         _ptTimeLabel.setText("");
321                         _descLabel.setText("");
322                         _nameLabel.setText("");
323                         _typeLabel.setText("");
324                         _speedLabel.setText("");
325                         _vSpeedLabel.setText("");
326                         _filenameLabel.setText("");
327                 }
328                 else
329                 {
330                         _indexLabel.setText(LABEL_POINT_SELECTED
331                                 + (currentPointIndex+1) + " " + I18nManager.getText("details.index.of")
332                                 + " " + _track.getNumPoints());
333                         _latLabel.setText(LABEL_POINT_LATITUDE
334                                 + CoordDisplay.makeCoordinateLabel(currentPoint.getLatitude(), getSelectedCoordFormat()));
335                         _longLabel.setText(LABEL_POINT_LONGITUDE
336                                 + CoordDisplay.makeCoordinateLabel(currentPoint.getLongitude(), getSelectedCoordFormat()));
337                         Unit altUnit = Config.getUnitSet().getAltitudeUnit();
338                         _altLabel.setText(currentPoint.hasAltitude()?
339                                 (LABEL_POINT_ALTITUDE + currentPoint.getAltitude().getValue(altUnit) + " " +
340                                 I18nManager.getText(altUnit.getShortnameKey()))
341                                 : "");
342                         if (currentPoint.hasTimestamp())
343                         {
344                                 _ptDateLabel.setText(LABEL_POINT_DATE + currentPoint.getTimestamp().getDateText(_timezone));
345                                 _ptTimeLabel.setText(LABEL_POINT_TIME + currentPoint.getTimestamp().getTimeText(_timezone));
346                         }
347                         else
348                         {
349                                 _ptDateLabel.setText("");
350                                 _ptTimeLabel.setText("");
351                         }
352                         // Maybe the point has a description?
353                         String pointDesc = currentPoint.getFieldValue(Field.DESCRIPTION);
354                         if (pointDesc == null || pointDesc.equals("") || currentPoint.hasMedia())
355                         {
356                                 _descLabel.setText("");
357                                 _descLabel.setToolTipText("");
358                         }
359                         else
360                         {
361                                 if (pointDesc.length() < 5) {
362                                         _descLabel.setText(LABEL_POINT_DESCRIPTION + pointDesc);
363                                 }
364                                 else {
365                                         _descLabel.setText(shortenString(pointDesc));
366                                 }
367                                 _descLabel.setToolTipText(pointDesc);
368                         }
369
370                         // Speed can come from either timestamps and distances, or speed values in data
371                         SpeedValue speedValue = new SpeedValue();
372                         SpeedCalculator.calculateSpeed(_track, currentPointIndex, speedValue);
373                         if (speedValue.isValid())
374                         {
375                                 String speed = DisplayUtils.roundedNumber(speedValue.getValue()) + " " + speedUnitsStr;
376                                 _speedLabel.setText(LABEL_POINT_SPEED + speed);
377                         }
378                         else {
379                                 _speedLabel.setText("");
380                         }
381
382                         // Now do the vertical speed in the same way
383                         SpeedCalculator.calculateVerticalSpeed(_track, currentPointIndex, speedValue);
384                         if (speedValue.isValid())
385                         {
386                                 String vSpeedUnitsStr = I18nManager.getText(unitSet.getVerticalSpeedUnit().getShortnameKey());
387                                 String speed = DisplayUtils.roundedNumber(speedValue.getValue()) + " " + vSpeedUnitsStr;
388                                 _vSpeedLabel.setText(LABEL_POINT_VERTSPEED + speed);
389                         }
390                         else {
391                                 _vSpeedLabel.setText("");
392                         }
393
394                         // Waypoint name
395                         final String name = currentPoint.getWaypointName();
396                         if (name != null && !name.equals(""))
397                         {
398                                 _nameLabel.setText(LABEL_POINT_WAYPOINTNAME + name);
399                         }
400                         else _nameLabel.setText("");
401                         // Waypoint type
402                         final String type = currentPoint.getFieldValue(Field.WAYPT_TYPE);
403                         if (type != null && !type.equals("")) {
404                                 _typeLabel.setText(LABEL_POINT_WAYPOINTTYPE + type);
405                         }
406                         else _typeLabel.setText("");
407
408                         // File to which point belongs
409                         final int numFiles = _trackInfo.getFileInfo().getNumFiles();
410                         String filename = null;
411                         if (numFiles > 1)
412                         {
413                                 final SourceInfo info = _trackInfo.getFileInfo().getSourceForPoint(currentPoint);
414                                 if (info != null) {
415                                         filename = info.getName();
416                                 }
417                         }
418                         if (filename != null)
419                         {
420                                 _filenameLabel.setText(LABEL_POINT_FILENAME + filename);
421                                 _filenameLabel.setToolTipText(filename);
422                         }
423                         else
424                         {
425                                 _filenameLabel.setText("");
426                                 _filenameLabel.setToolTipText("");
427                         }
428                 }
429
430                 // Update range details
431                 if (_track == null || !selection.hasRangeSelected())
432                 {
433                         _rangeLabel.setText(I18nManager.getText("details.norangeselection"));
434                         _distanceLabel.setText("");
435                         _durationLabel.setText("");
436                         _altRangeLabel.setText("");
437                         _updownLabel.setText("");
438                         _aveSpeedLabel.setText("");
439                 }
440                 else
441                 {
442                         _rangeLabel.setText(LABEL_RANGE_SELECTED
443                                 + (selection.getStart()+1) + " " + I18nManager.getText("details.range.to")
444                                 + " " + (selection.getEnd()+1));
445                         _distanceLabel.setText(LABEL_RANGE_DISTANCE + DisplayUtils.roundedNumber(selection.getMovingDistance()) + " " + distUnitsStr);
446                         final long numMovingSeconds = selection.getMovingSeconds();
447                         if (numMovingSeconds > 0L)
448                         {
449                                 _durationLabel.setText(LABEL_RANGE_DURATION + DisplayUtils.buildDurationString(numMovingSeconds));
450                                 _aveSpeedLabel.setText(I18nManager.getText("details.range.avespeed") + ": "
451                                         + DisplayUtils.roundedNumber(selection.getMovingDistance()/numMovingSeconds*3600.0) + " " + speedUnitsStr);
452                         }
453                         else
454                         {
455                                 _durationLabel.setText("");
456                                 _aveSpeedLabel.setText("");
457                         }
458                         AltitudeRange altRange = selection.getAltitudeRange();
459                         Unit altUnit = Config.getUnitSet().getAltitudeUnit();
460                         String altUnitsLabel = I18nManager.getText(altUnit.getShortnameKey());
461                         if (altRange.hasRange())
462                         {
463                                 _altRangeLabel.setText(LABEL_RANGE_ALTITUDE
464                                         + altRange.getMinimum(altUnit) + altUnitsLabel + " "
465                                         + I18nManager.getText("details.altitude.to") + " "
466                                         + altRange.getMaximum(altUnit) + altUnitsLabel);
467                                 _updownLabel.setText(LABEL_RANGE_CLIMB + altRange.getClimb(altUnit) + altUnitsLabel
468                                         + LABEL_RANGE_DESCENT + altRange.getDescent(altUnit) + altUnitsLabel);
469                         }
470                         else
471                         {
472                                 _altRangeLabel.setText("");
473                                 _updownLabel.setText("");
474                         }
475                 }
476                 // show photo details and thumbnail
477                 _photoDetailsPanel.setVisible(_trackInfo.getPhotoList().getNumPhotos() > 0);
478                 Photo currentPhoto = _trackInfo.getPhotoList().getPhoto(_trackInfo.getSelection().getCurrentPhotoIndex());
479                 if ((currentPoint == null || currentPoint.getPhoto() == null) && currentPhoto == null)
480                 {
481                         // no photo, hide details
482                         _photoLabel.setText(I18nManager.getText("details.nophoto"));
483                         _photoPathLabel.setText("");
484                         _photoPathLabel.setToolTipText("");
485                         _photoTimestampLabel.setText("");
486                         _photoConnectedLabel.setText("");
487                         _photoBearingLabel.setText("");
488                         _photoThumbnail.setVisible(false);
489                         _rotationButtons.setVisible(false);
490                 }
491                 else
492                 {
493                         if (currentPhoto == null) {currentPhoto = currentPoint.getPhoto();}
494                         _photoLabel.setText(I18nManager.getText("details.photofile") + ": " + currentPhoto.getName());
495                         String fullPath = currentPhoto.getFullPath();
496                         String shortPath = shortenPath(fullPath);
497                         _photoPathLabel.setText(fullPath == null ? "" : LABEL_FULL_PATH + shortPath);
498                         _photoPathLabel.setToolTipText(currentPhoto.getFullPath());
499                         _photoTimestampLabel.setText(currentPhoto.hasTimestamp() ?
500                                 (LABEL_POINT_TIME + currentPhoto.getTimestamp().getText(_timezone))
501                                 : "");
502                         _photoConnectedLabel.setText(I18nManager.getText("details.media.connected") + ": "
503                                 + (currentPhoto.getCurrentStatus() == Photo.Status.NOT_CONNECTED ?
504                                         I18nManager.getText("dialog.about.no"):I18nManager.getText("dialog.about.yes")));
505                         if (currentPhoto.getBearing() >= 0.0 && currentPhoto.getBearing() <= 360.0)
506                         {
507                                 _photoBearingLabel.setText(I18nManager.getText("details.photo.bearing") + ": "
508                                         + (int) currentPhoto.getBearing() + " \u00B0");
509                         }
510                         else _photoBearingLabel.setText("");
511                         _photoThumbnail.setVisible(true);
512                         _photoThumbnail.setPhoto(currentPhoto);
513                         _rotationButtons.setVisible(true);
514                         if ((inUpdateType & DataSubscriber.PHOTOS_MODIFIED) > 0) {
515                                 _photoThumbnail.refresh();
516                         }
517                 }
518                 _photoThumbnail.repaint();
519
520                 // audio details
521                 _audioDetailsPanel.setVisible(_trackInfo.getAudioList().getNumAudios() > 0);
522                 AudioClip currentAudio = _trackInfo.getAudioList().getAudio(_trackInfo.getSelection().getCurrentAudioIndex());
523                 if (currentAudio == null)
524                 {
525                         _audioLabel.setText(I18nManager.getText("details.noaudio"));
526                         _audioPathLabel.setText("");
527                         _audioPathLabel.setToolTipText("");
528                         _audioTimestampLabel.setText("");
529                         _audioLengthLabel.setText("");
530                         _audioConnectedLabel.setText("");
531                 }
532                 else
533                 {
534                         _audioLabel.setText(LABEL_AUDIO_FILE + currentAudio.getName());
535                         String fullPath = currentAudio.getFullPath();
536                         String shortPath = shortenPath(fullPath);
537                         _audioPathLabel.setText(fullPath == null ? "" : LABEL_FULL_PATH + shortPath);
538                         _audioPathLabel.setToolTipText(fullPath == null ? "" : fullPath);
539                         _audioTimestampLabel.setText(currentAudio.hasTimestamp() ?
540                                 (LABEL_POINT_TIME + currentAudio.getTimestamp().getText(_timezone))
541                                 : "");
542                         int audioLength = currentAudio.getLengthInSeconds();
543                         _audioLengthLabel.setText(audioLength < 0?"":LABEL_RANGE_DURATION + DisplayUtils.buildDurationString(audioLength));
544                         _audioConnectedLabel.setText(I18nManager.getText("details.media.connected") + ": "
545                                 + (currentAudio.getCurrentStatus() == Photo.Status.NOT_CONNECTED ?
546                                         I18nManager.getText("dialog.about.no"):I18nManager.getText("dialog.about.yes")));
547                 }
548                 _playAudioPanel.setVisible(currentAudio != null);
549         }
550
551
552         /**
553          * Make a details subpanel
554          * @param inNameKey key to use for top label
555          * @param inFont font for top label
556          * @return panel with correct layout, label
557          */
558         private static JPanel makeDetailsPanel(String inNameKey, Font inFont)
559         {
560                 JPanel detailsPanel = new JPanel();
561                 detailsPanel.setLayout(new BoxLayout(detailsPanel, BoxLayout.Y_AXIS));
562                 detailsPanel.setBorder(BorderFactory.createCompoundBorder(
563                         BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(3, 3, 3, 3))
564                 );
565                 JLabel detailsLabel = new JLabel(I18nManager.getText(inNameKey));
566                 detailsLabel.setFont(inFont);
567                 detailsPanel.add(detailsLabel);
568                 return detailsPanel;
569         }
570
571         /**
572          * Create a little button for rotating the current photo
573          * @param inIcon icon to use (from IconManager)
574          * @param inFunction function to call (from FunctionLibrary)
575          * @return button object
576          */
577         private static JButton makeRotateButton(String inIcon, GenericFunction inFunction)
578         {
579                 JButton button = new JButton(IconManager.getImageIcon(inIcon));
580                 button.setToolTipText(I18nManager.getText(inFunction.getNameKey()));
581                 button.setMargin(new Insets(0, 2, 0, 2));
582                 button.addActionListener(new FunctionLauncher(inFunction));
583                 return button;
584         }
585
586         /**
587          * @param inFullPath full file path or URL to be shortened
588          * @return shortened string from beginning of path
589          */
590         private static String shortenPath(String inFullPath)
591         {
592                 String path = inFullPath;
593                 // Chop off the home path if possible
594                 final String homePath = System.getProperty("user.home").toLowerCase();
595                 if (inFullPath != null && inFullPath.toLowerCase().startsWith(homePath)) {
596                         path = inFullPath.substring(homePath.length()+1);
597                 }
598                 return shortenString(path);
599         }
600
601         /**
602          * @param inString string to shorten
603          * @return shortened string from the beginning
604          */
605         private static String shortenString(String inString)
606         {
607                 // Limit is hardcoded here, maybe it should depend on parent component width and font size etc?
608                 if (inString == null || inString.length() < 21) {
609                         return inString;
610                 }
611                 // string is too long
612                 return inString.substring(0, 20) + "...";
613         }
614
615         /**
616          * @return the currently selected coordinate display format
617          */
618         private int getSelectedCoordFormat()
619         {
620                 switch (_coordFormatDropdown.getSelectedIndex())
621                 {
622                         case 1: // degminsec
623                                 return Coordinate.FORMAT_DEG_MIN_SEC;
624                         case 2: // degmin
625                                 return Coordinate.FORMAT_DEG_MIN;
626                         case 3: // degrees
627                                 return Coordinate.FORMAT_DEG;
628                         default: // just as it was
629                                 return Coordinate.FORMAT_NONE;
630                 }
631         }
632 }