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