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