]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/DetailsDisplay.java
13df7cd31609b0ea8ef1eb6b7fdb59d6639a722d
[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 _coordFormatDropdown = null;
86         private JComboBox _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(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();
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.getDistance()) + " " + distUnitsStr);
398                         if (selection.getNumSeconds() > 0)
399                         {
400                                 _durationLabel.setText(LABEL_RANGE_DURATION + DisplayUtils.buildDurationString(selection.getNumSeconds()));
401                                 _aveSpeedLabel.setText(I18nManager.getText("details.range.avespeed") + ": "
402                                         + DisplayUtils.roundedNumber(selection.getDistance()/selection.getNumSeconds()*3600.0) + " " + speedUnitsStr);
403                         }
404                         else {
405                                 _durationLabel.setText("");
406                                 _aveSpeedLabel.setText("");
407                         }
408                         AltitudeRange altRange = selection.getAltitudeRange();
409                         Unit altUnit = Config.getUnitSet().getAltitudeUnit();
410                         String altUnitsLabel = I18nManager.getText(altUnit.getShortnameKey());
411                         if (altRange.hasRange())
412                         {
413                                 _altRangeLabel.setText(LABEL_RANGE_ALTITUDE
414                                         + altRange.getMinimum(altUnit) + altUnitsLabel + " "
415                                         + I18nManager.getText("details.altitude.to") + " "
416                                         + altRange.getMaximum(altUnit) + altUnitsLabel);
417                                 _updownLabel.setText(LABEL_RANGE_CLIMB + altRange.getClimb(altUnit) + altUnitsLabel
418                                         + LABEL_RANGE_DESCENT + altRange.getDescent(altUnit) + altUnitsLabel);
419                         }
420                         else
421                         {
422                                 _altRangeLabel.setText("");
423                                 _updownLabel.setText("");
424                         }
425                 }
426                 // show photo details and thumbnail
427                 _photoDetailsPanel.setVisible(_trackInfo.getPhotoList().getNumPhotos() > 0);
428                 Photo currentPhoto = _trackInfo.getPhotoList().getPhoto(_trackInfo.getSelection().getCurrentPhotoIndex());
429                 if ((currentPoint == null || currentPoint.getPhoto() == null) && currentPhoto == null)
430                 {
431                         // no photo, hide details
432                         _photoLabel.setText(I18nManager.getText("details.nophoto"));
433                         _photoPathLabel.setText("");
434                         _photoPathLabel.setToolTipText("");
435                         _photoTimestampLabel.setText("");
436                         _photoConnectedLabel.setText("");
437                         _photoBearingLabel.setText("");
438                         _photoThumbnail.setVisible(false);
439                         _rotationButtons.setVisible(false);
440                 }
441                 else
442                 {
443                         if (currentPhoto == null) {currentPhoto = currentPoint.getPhoto();}
444                         _photoLabel.setText(I18nManager.getText("details.photofile") + ": " + currentPhoto.getName());
445                         String fullPath = currentPhoto.getFullPath();
446                         String shortPath = shortenPath(fullPath);
447                         _photoPathLabel.setText(fullPath == null ? "" : LABEL_FULL_PATH + shortPath);
448                         _photoPathLabel.setToolTipText(currentPhoto.getFullPath());
449                         _photoTimestampLabel.setText(currentPhoto.hasTimestamp()?(LABEL_POINT_TIMESTAMP + currentPhoto.getTimestamp().getText()):"");
450                         _photoConnectedLabel.setText(I18nManager.getText("details.media.connected") + ": "
451                                 + (currentPhoto.getCurrentStatus() == Photo.Status.NOT_CONNECTED ?
452                                         I18nManager.getText("dialog.about.no"):I18nManager.getText("dialog.about.yes")));
453                         if (currentPhoto.getBearing() >= 0.0 && currentPhoto.getBearing() <= 360.0)
454                         {
455                                 _photoBearingLabel.setText(I18nManager.getText("details.photo.bearing") + ": "
456                                         + (int) currentPhoto.getBearing() + " \u00B0");
457                         }
458                         else _photoBearingLabel.setText("");
459                         _photoThumbnail.setVisible(true);
460                         _photoThumbnail.setPhoto(currentPhoto);
461                         _rotationButtons.setVisible(true);
462                         if ((inUpdateType & DataSubscriber.PHOTOS_MODIFIED) > 0) {_photoThumbnail.refresh();}
463                 }
464                 _photoThumbnail.repaint();
465
466                 // audio details
467                 _audioDetailsPanel.setVisible(_trackInfo.getAudioList().getNumAudios() > 0);
468                 AudioClip currentAudio = _trackInfo.getAudioList().getAudio(_trackInfo.getSelection().getCurrentAudioIndex());
469                 if (currentAudio == null)
470                 {
471                         _audioLabel.setText(I18nManager.getText("details.noaudio"));
472                         _audioPathLabel.setText("");
473                         _audioPathLabel.setToolTipText("");
474                         _audioTimestampLabel.setText("");
475                         _audioLengthLabel.setText("");
476                         _audioConnectedLabel.setText("");
477                 }
478                 else
479                 {
480                         _audioLabel.setText(LABEL_AUDIO_FILE + currentAudio.getName());
481                         String fullPath = currentAudio.getFullPath();
482                         String shortPath = shortenPath(fullPath);
483                         _audioPathLabel.setText(fullPath == null ? "" : LABEL_FULL_PATH + shortPath);
484                         _audioPathLabel.setToolTipText(fullPath == null ? "" : fullPath);
485                         _audioTimestampLabel.setText(currentAudio.hasTimestamp()?(LABEL_POINT_TIMESTAMP + currentAudio.getTimestamp().getText()):"");
486                         int audioLength = currentAudio.getLengthInSeconds();
487                         _audioLengthLabel.setText(audioLength < 0?"":LABEL_RANGE_DURATION + DisplayUtils.buildDurationString(audioLength));
488                         _audioConnectedLabel.setText(I18nManager.getText("details.media.connected") + ": "
489                                 + (currentAudio.getCurrentStatus() == Photo.Status.NOT_CONNECTED ?
490                                         I18nManager.getText("dialog.about.no"):I18nManager.getText("dialog.about.yes")));
491                 }
492                 _playAudioPanel.setVisible(currentAudio != null);
493         }
494
495
496         /**
497          * Construct an appropriate coordinate label using the selected format
498          * @param inPrefix prefix of label
499          * @param inCoordinate coordinate
500          * @param inFormat index of format selection dropdown
501          * @return language-sensitive string
502          */
503         private static String makeCoordinateLabel(String inPrefix, Coordinate inCoordinate, int inFormat)
504         {
505                 String coord = null;
506                 switch (inFormat) {
507                         case 1: // degminsec
508                                 coord = inCoordinate.output(Coordinate.FORMAT_DEG_MIN_SEC); break;
509                         case 2: // degmin
510                                 coord = inCoordinate.output(Coordinate.FORMAT_DEG_MIN); break;
511                         case 3: // degrees
512                                 coord = inCoordinate.output(Coordinate.FORMAT_DEG); break;
513                         default: // just as it was
514                                 coord = inCoordinate.output(Coordinate.FORMAT_NONE);
515                 }
516                 // Fix broken degree signs (due to unicode mangling)
517                 final char brokenDeg = 65533;
518                 if (coord.indexOf(brokenDeg) >= 0) {
519                         coord = coord.replaceAll(String.valueOf(brokenDeg), "\u00B0");
520                 }
521                 return inPrefix + restrictDP(coord);
522         }
523
524
525         /**
526          * Restrict the given coordinate to a limited number of decimal places for display
527          * @param inCoord coordinate string
528          * @return chopped string
529          */
530         private static String restrictDP(String inCoord)
531         {
532                 final int DECIMAL_PLACES = 7;
533                 if (inCoord == null) return "";
534                 final int dotPos = Math.max(inCoord.lastIndexOf('.'), inCoord.lastIndexOf(','));
535                 if (dotPos >= 0) {
536                         final int chopPos = dotPos + DECIMAL_PLACES;
537                         if (chopPos < (inCoord.length()-1)) {
538                                 return inCoord.substring(0, chopPos);
539                         }
540                 }
541                 return inCoord;
542         }
543
544         /**
545          * Make a details subpanel
546          * @param inNameKey key to use for top label
547          * @param inFont font for top label
548          * @return panel with correct layout, label
549          */
550         private static JPanel makeDetailsPanel(String inNameKey, Font inFont)
551         {
552                 JPanel detailsPanel = new JPanel();
553                 detailsPanel.setLayout(new BoxLayout(detailsPanel, BoxLayout.Y_AXIS));
554                 detailsPanel.setBorder(BorderFactory.createCompoundBorder(
555                         BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(3, 3, 3, 3))
556                 );
557                 JLabel detailsLabel = new JLabel(I18nManager.getText(inNameKey));
558                 detailsLabel.setFont(inFont);
559                 detailsPanel.add(detailsLabel);
560                 return detailsPanel;
561         }
562
563         /**
564          * Create a little button for rotating the current photo
565          * @param inIcon icon to use (from IconManager)
566          * @param inFunction function to call (from FunctionLibrary)
567          * @return button object
568          */
569         private static JButton makeRotateButton(String inIcon, GenericFunction inFunction)
570         {
571                 JButton button = new JButton(IconManager.getImageIcon(inIcon));
572                 button.setToolTipText(I18nManager.getText(inFunction.getNameKey()));
573                 button.setMargin(new Insets(0, 2, 0, 2));
574                 button.addActionListener(new FunctionLauncher(inFunction));
575                 return button;
576         }
577
578         /**
579          * @param inFullPath full file path or URL to be shortened
580          * @return shortened string from beginning of path
581          */
582         private static String shortenPath(String inFullPath)
583         {
584                 String path = inFullPath;
585                 // Chop off the home path if possible
586                 final String homePath = System.getProperty("user.home").toLowerCase();
587                 if (inFullPath != null && inFullPath.toLowerCase().startsWith(homePath)) {
588                         path = inFullPath.substring(homePath.length()+1);
589                 }
590                 return shortenString(path);
591         }
592
593         /**
594          * @param inString string to shorten
595          * @return shortened string from the beginning
596          */
597         private static String shortenString(String inString)
598         {
599                 // Limit is hardcoded here, maybe it should depend on parent component width and font size etc?
600                 if (inString == null || inString.length() < 21) {
601                         return inString;
602                 }
603                 // string is too long
604                 return inString.substring(0, 20) + "...";
605         }
606 }