]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/DetailsDisplay.java
Version 14, October 2012
[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 import java.text.NumberFormat;
12
13 import javax.swing.BorderFactory;
14 import javax.swing.Box;
15 import javax.swing.BoxLayout;
16 import javax.swing.JButton;
17 import javax.swing.JComboBox;
18 import javax.swing.JLabel;
19 import javax.swing.JPanel;
20 import javax.swing.JProgressBar;
21 import javax.swing.border.EtchedBorder;
22
23 import tim.prune.DataSubscriber;
24 import tim.prune.FunctionLibrary;
25 import tim.prune.GenericFunction;
26 import tim.prune.I18nManager;
27 import tim.prune.UpdateMessageBroker;
28 import tim.prune.config.Config;
29 import tim.prune.data.AltitudeRange;
30 import tim.prune.data.AudioClip;
31 import tim.prune.data.Coordinate;
32 import tim.prune.data.DataPoint;
33 import tim.prune.data.Field;
34 import tim.prune.data.Photo;
35 import tim.prune.data.Selection;
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 _timeLabel = 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         // Formatter
88         private NumberFormat _distanceFormatter = NumberFormat.getInstance();
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_TIMESTAMP = I18nManager.getText("fieldname.timestamp") + ": ";
96         private static final String LABEL_POINT_WAYPOINTNAME = I18nManager.getText("fieldname.waypointname") + ": ";
97         private static final String LABEL_POINT_WAYPOINTTYPE = I18nManager.getText("fieldname.waypointtype") + ": ";
98         private static final String LABEL_POINT_SPEED        = I18nManager.getText("fieldname.speed") + ": ";
99         private static final String LABEL_POINT_VERTSPEED    = I18nManager.getText("fieldname.verticalspeed") + ": ";
100         private static final String LABEL_RANGE_SELECTED = I18nManager.getText("details.range.selected") + ": ";
101         private static final String LABEL_RANGE_DURATION = I18nManager.getText("fieldname.duration") + ": ";
102         private static final String LABEL_RANGE_DISTANCE = I18nManager.getText("fieldname.distance") + ": ";
103         private static final String LABEL_RANGE_ALTITUDE = I18nManager.getText("fieldname.altitude") + ": ";
104         private static final String LABEL_RANGE_CLIMB = I18nManager.getText("details.range.climb") + ": ";
105         private static final String LABEL_RANGE_DESCENT = ", " + I18nManager.getText("details.range.descent") + ": ";
106         private static final String LABEL_AUDIO_FILE = I18nManager.getText("details.audio.file") + ": ";
107         private static final String LABEL_FULL_PATH = I18nManager.getText("details.media.fullpath") + ": ";
108
109
110         /**
111          * Constructor
112          * @param inTrackInfo Track info object
113          */
114         public DetailsDisplay(TrackInfo inTrackInfo)
115         {
116                 super(inTrackInfo);
117                 setLayout(new BorderLayout());
118
119                 JPanel mainPanel = new JPanel();
120                 mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
121                 mainPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
122                 Font biggerFont = new JLabel().getFont();
123                 biggerFont = biggerFont.deriveFont(Font.BOLD, biggerFont.getSize2D() + 2.0f);
124
125                 // Point details panel
126                 JPanel pointDetailsPanel = makeDetailsPanel("details.pointdetails", biggerFont);
127                 _indexLabel = new JLabel(I18nManager.getText("details.nopointselection"));
128                 pointDetailsPanel.add(_indexLabel);
129                 _latLabel = new JLabel("");
130                 pointDetailsPanel.add(_latLabel);
131                 _longLabel = new JLabel("");
132                 pointDetailsPanel.add(_longLabel);
133                 _altLabel = new JLabel("");
134                 pointDetailsPanel.add(_altLabel);
135                 _timeLabel = new JLabel("");
136                 _timeLabel.setMinimumSize(new Dimension(120, 10));
137                 pointDetailsPanel.add(_timeLabel);
138                 _speedLabel = new JLabel("");
139                 pointDetailsPanel.add(_speedLabel);
140                 _vSpeedLabel = new JLabel("");
141                 pointDetailsPanel.add(_vSpeedLabel);
142                 _nameLabel = new JLabel("");
143                 pointDetailsPanel.add(_nameLabel);
144                 _typeLabel = new JLabel("");
145                 pointDetailsPanel.add(_typeLabel);
146                 pointDetailsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
147
148                 // range details panel
149                 JPanel rangeDetailsPanel = makeDetailsPanel("details.rangedetails", biggerFont);
150                 _rangeLabel = new JLabel(I18nManager.getText("details.norangeselection"));
151                 rangeDetailsPanel.add(_rangeLabel);
152                 _distanceLabel = new JLabel("");
153                 rangeDetailsPanel.add(_distanceLabel);
154                 _durationLabel = new JLabel("");
155                 rangeDetailsPanel.add(_durationLabel);
156                 _aveSpeedLabel = new JLabel("");
157                 rangeDetailsPanel.add(_aveSpeedLabel);
158                 _altRangeLabel = new JLabel("");
159                 rangeDetailsPanel.add(_altRangeLabel);
160                 _updownLabel = new JLabel("");
161                 rangeDetailsPanel.add(_updownLabel);
162                 rangeDetailsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
163
164                 // photo details panel
165                 _photoDetailsPanel = makeDetailsPanel("details.photodetails", biggerFont);
166                 _photoLabel = new JLabel(I18nManager.getText("details.nophoto"));
167                 _photoDetailsPanel.add(_photoLabel);
168                 _photoPathLabel = new JLabel("");
169                 _photoDetailsPanel.add(_photoPathLabel);
170                 _photoTimestampLabel = new JLabel("");
171                 _photoTimestampLabel.setMinimumSize(new Dimension(120, 10));
172                 _photoDetailsPanel.add(_photoTimestampLabel);
173                 _photoConnectedLabel = new JLabel("");
174                 _photoDetailsPanel.add(_photoConnectedLabel);
175                 _photoBearingLabel = new JLabel("");
176                 _photoDetailsPanel.add(_photoBearingLabel);
177                 _photoThumbnail = new PhotoThumbnail();
178                 _photoThumbnail.setVisible(false);
179                 _photoThumbnail.setPreferredSize(new Dimension(100, 100));
180                 _photoDetailsPanel.add(_photoThumbnail);
181                 // Rotate buttons
182                 JButton rotLeft = makeRotateButton(IconManager.ROTATE_LEFT, FunctionLibrary.FUNCTION_ROTATE_PHOTO_LEFT);
183                 JButton rotRight = makeRotateButton(IconManager.ROTATE_RIGHT, FunctionLibrary.FUNCTION_ROTATE_PHOTO_RIGHT);
184                 JButton popup = makeRotateButton(IconManager.SHOW_DETAILS, FunctionLibrary.FUNCTION_PHOTO_POPUP);
185                 _rotationButtons = new JPanel();
186                 _rotationButtons.add(rotLeft);
187                 _rotationButtons.add(rotRight);
188                 _rotationButtons.add(Box.createHorizontalStrut(10));
189                 _rotationButtons.add(popup);
190                 _rotationButtons.setAlignmentX(Component.LEFT_ALIGNMENT);
191                 _rotationButtons.setVisible(false);
192                 _photoDetailsPanel.add(_rotationButtons);
193                 _photoDetailsPanel.setVisible(false);
194
195                 // audio details panel
196                 _audioDetailsPanel = makeDetailsPanel("details.audiodetails", biggerFont);
197                 _audioLabel = new JLabel(I18nManager.getText("details.noaudio"));
198                 _audioDetailsPanel.add(_audioLabel);
199                 _audioPathLabel = new JLabel("");
200                 _audioDetailsPanel.add(_audioPathLabel);
201                 _audioTimestampLabel = new JLabel("");
202                 _audioTimestampLabel.setMinimumSize(new Dimension(120, 10));
203                 _audioDetailsPanel.add(_audioTimestampLabel);
204                 _audioLengthLabel = new JLabel("");
205                 _audioDetailsPanel.add(_audioLengthLabel);
206                 _audioConnectedLabel = new JLabel("");
207                 _audioDetailsPanel.add(_audioConnectedLabel);
208                 _audioProgress = new JProgressBar(0, 100);
209                 _audioProgress.setString(I18nManager.getText("details.audio.playing"));
210                 _audioProgress.setStringPainted(true);
211                 _audioProgress.setVisible(false);
212                 _audioDetailsPanel.add(_audioProgress);
213                 _playAudioPanel = new JPanel();
214                 _playAudioPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
215                 JButton playAudio = makeRotateButton(IconManager.PLAY_AUDIO, FunctionLibrary.FUNCTION_PLAY_AUDIO);
216                 playAudio.addActionListener(new AudioListener(_audioProgress));
217                 _playAudioPanel.add(playAudio);
218                 JButton stopAudio = makeRotateButton(IconManager.STOP_AUDIO, FunctionLibrary.FUNCTION_STOP_AUDIO);
219                 _playAudioPanel.add(stopAudio);
220                 _playAudioPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
221                 _playAudioPanel.setVisible(false);
222                 _audioDetailsPanel.add(_playAudioPanel);
223                 _audioDetailsPanel.setVisible(false);
224
225                 // add the details panels to the main panel
226                 mainPanel.add(pointDetailsPanel);
227                 mainPanel.add(Box.createVerticalStrut(5));
228                 mainPanel.add(rangeDetailsPanel);
229                 mainPanel.add(Box.createVerticalStrut(5));
230                 mainPanel.add(_photoDetailsPanel);
231                 mainPanel.add(Box.createVerticalStrut(5));
232                 mainPanel.add(_audioDetailsPanel);
233                 mainPanel.add(Box.createVerticalStrut(5));
234                 // add the main panel at the top
235                 add(mainPanel, BorderLayout.NORTH);
236
237                 // Add format, units selection
238                 JPanel lowerPanel = new JPanel();
239                 lowerPanel.setLayout(new BoxLayout(lowerPanel, BoxLayout.Y_AXIS));
240                 JLabel coordFormatLabel = new JLabel(I18nManager.getText("details.coordformat") + ": ");
241                 coordFormatLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
242                 lowerPanel.add(coordFormatLabel);
243                 String[] coordFormats = {I18nManager.getText("units.original"), I18nManager.getText("units.degminsec"),
244                         I18nManager.getText("units.degmin"), I18nManager.getText("units.deg")};
245                 _coordFormatDropdown = new JComboBox(coordFormats);
246                 _coordFormatDropdown.addActionListener(new ActionListener() {
247                         public void actionPerformed(ActionEvent e)
248                         {
249                                 dataUpdated(DataSubscriber.UNITS_CHANGED);
250                         }
251                 });
252                 lowerPanel.add(_coordFormatDropdown);
253                 _coordFormatDropdown.setAlignmentX(Component.LEFT_ALIGNMENT);
254                 JLabel unitsLabel = new JLabel(I18nManager.getText("details.distanceunits") + ": ");
255                 unitsLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
256                 lowerPanel.add(unitsLabel);
257                 // Make dropdown for distance units
258                 _distUnitsDropdown = new JComboBox();
259                 final UnitSet currUnits = Config.getUnitSet();
260                 for (int i=0; i<UnitSetLibrary.getNumUnitSets(); i++) {
261                         _distUnitsDropdown.addItem(I18nManager.getText(UnitSetLibrary.getUnitSet(i).getDistanceUnit().getNameKey()));
262                         if (UnitSetLibrary.getUnitSet(i) == currUnits) {_distUnitsDropdown.setSelectedIndex(i);}
263                 }
264                 _distUnitsDropdown.addActionListener(new ActionListener() {
265                         public void actionPerformed(ActionEvent e)
266                         {
267                                 Config.selectUnitSet(_distUnitsDropdown.getSelectedIndex());
268                                 UpdateMessageBroker.informSubscribers(DataSubscriber.UNITS_CHANGED);
269                         }
270                 });
271                 lowerPanel.add(_distUnitsDropdown);
272                 _distUnitsDropdown.setAlignmentX(Component.LEFT_ALIGNMENT);
273                 add(lowerPanel, BorderLayout.SOUTH);
274         }
275
276
277         /**
278          * Notification that Track has been updated
279          * @param inUpdateType byte to specify what has been updated
280          */
281         public void dataUpdated(byte inUpdateType)
282         {
283                 // Update current point data, if any
284                 DataPoint currentPoint = _trackInfo.getCurrentPoint();
285                 Selection selection = _trackInfo.getSelection();
286                 if ((inUpdateType | DATA_ADDED_OR_REMOVED) > 0) selection.markInvalid();
287                 int currentPointIndex = selection.getCurrentPointIndex();
288                 _speedLabel.setText("");
289                 UnitSet unitSet = UnitSetLibrary.getUnitSet(_distUnitsDropdown.getSelectedIndex());
290                 String distUnitsStr = I18nManager.getText(unitSet.getDistanceUnit().getShortnameKey());
291                 String speedUnitsStr = I18nManager.getText(unitSet.getSpeedUnit().getShortnameKey());
292                 if (_track == null || currentPoint == null)
293                 {
294                         _indexLabel.setText(I18nManager.getText("details.nopointselection"));
295                         _latLabel.setText("");
296                         _longLabel.setText("");
297                         _altLabel.setText("");
298                         _timeLabel.setText("");
299                         _nameLabel.setText("");
300                         _typeLabel.setText("");
301                         _speedLabel.setText("");
302                         _vSpeedLabel.setText("");
303                 }
304                 else
305                 {
306                         _indexLabel.setText(LABEL_POINT_SELECTED
307                                 + (currentPointIndex+1) + " " + I18nManager.getText("details.index.of")
308                                 + " " + _track.getNumPoints());
309                         _latLabel.setText(makeCoordinateLabel(LABEL_POINT_LATITUDE, currentPoint.getLatitude(), _coordFormatDropdown.getSelectedIndex()));
310                         _longLabel.setText(makeCoordinateLabel(LABEL_POINT_LONGITUDE, currentPoint.getLongitude(), _coordFormatDropdown.getSelectedIndex()));
311                         Unit altUnit = Config.getUnitSet().getAltitudeUnit();
312                         _altLabel.setText(currentPoint.hasAltitude()?
313                                 (LABEL_POINT_ALTITUDE + currentPoint.getAltitude().getValue(altUnit) + " " +
314                                 I18nManager.getText(altUnit.getShortnameKey()))
315                                 : "");
316                         if (currentPoint.hasTimestamp()) {
317                                 _timeLabel.setText(LABEL_POINT_TIMESTAMP + currentPoint.getTimestamp().getText());
318                         }
319                         else {
320                                 _timeLabel.setText("");
321                         }
322
323                         // Speed can come from either timestamps and distances, or speed values in data
324                         SpeedValue speedValue = new SpeedValue();
325                         SpeedCalculator.calculateSpeed(_track, currentPointIndex, speedValue);
326                         if (speedValue.isValid())
327                         {
328                                 String speed = roundedNumber(speedValue.getValue()) + " " + speedUnitsStr;
329                                 _speedLabel.setText(LABEL_POINT_SPEED + speed);
330                         }
331                         else {
332                                 _speedLabel.setText("");
333                         }
334
335                         // Now do the vertical speed in the same way
336                         SpeedCalculator.calculateVerticalSpeed(_track, currentPointIndex, speedValue);
337                         if (speedValue.isValid())
338                         {
339                                 String vSpeedUnitsStr = I18nManager.getText(unitSet.getVerticalSpeedUnit().getShortnameKey());
340                                 String speed = roundedNumber(speedValue.getValue()) + " " + vSpeedUnitsStr;
341                                 _vSpeedLabel.setText(LABEL_POINT_VERTSPEED + speed);
342                         }
343                         else {
344                                 _vSpeedLabel.setText("");
345                         }
346
347                         // Waypoint name
348                         final String name = currentPoint.getWaypointName();
349                         if (name != null && !name.equals(""))
350                         {
351                                 _nameLabel.setText(LABEL_POINT_WAYPOINTNAME + name);
352                         }
353                         else _nameLabel.setText("");
354                         // Waypoint type
355                         final String type = currentPoint.getFieldValue(Field.WAYPT_TYPE);
356                         if (type != null && !type.equals("")) {
357                                 _typeLabel.setText(LABEL_POINT_WAYPOINTTYPE + type);
358                         }
359                         else _typeLabel.setText("");
360                 }
361
362                 // Update range details
363                 if (_track == null || !selection.hasRangeSelected())
364                 {
365                         _rangeLabel.setText(I18nManager.getText("details.norangeselection"));
366                         _distanceLabel.setText("");
367                         _durationLabel.setText("");
368                         _altRangeLabel.setText("");
369                         _updownLabel.setText("");
370                         _aveSpeedLabel.setText("");
371                 }
372                 else
373                 {
374                         _rangeLabel.setText(LABEL_RANGE_SELECTED
375                                 + (selection.getStart()+1) + " " + I18nManager.getText("details.range.to")
376                                 + " " + (selection.getEnd()+1));
377                         _distanceLabel.setText(LABEL_RANGE_DISTANCE + roundedNumber(selection.getDistance()) + " " + distUnitsStr);
378                         if (selection.getNumSeconds() > 0)
379                         {
380                                 _durationLabel.setText(LABEL_RANGE_DURATION + DisplayUtils.buildDurationString(selection.getNumSeconds()));
381                                 _aveSpeedLabel.setText(I18nManager.getText("details.range.avespeed") + ": "
382                                         + roundedNumber(selection.getDistance()/selection.getNumSeconds()*3600.0) + " " + speedUnitsStr);
383                         }
384                         else {
385                                 _durationLabel.setText("");
386                                 _aveSpeedLabel.setText("");
387                         }
388                         AltitudeRange altRange = selection.getAltitudeRange();
389                         Unit altUnit = Config.getUnitSet().getAltitudeUnit();
390                         String altUnitsLabel = I18nManager.getText(altUnit.getShortnameKey());
391                         if (altRange.hasRange())
392                         {
393                                 _altRangeLabel.setText(LABEL_RANGE_ALTITUDE
394                                         + altRange.getMinimum(altUnit) + altUnitsLabel + " "
395                                         + I18nManager.getText("details.altitude.to") + " "
396                                         + altRange.getMaximum(altUnit) + altUnitsLabel);
397                                 _updownLabel.setText(LABEL_RANGE_CLIMB + altRange.getClimb(altUnit) + altUnitsLabel
398                                         + LABEL_RANGE_DESCENT + altRange.getDescent(altUnit) + altUnitsLabel);
399                         }
400                         else
401                         {
402                                 _altRangeLabel.setText("");
403                                 _updownLabel.setText("");
404                         }
405                 }
406                 // show photo details and thumbnail
407                 _photoDetailsPanel.setVisible(_trackInfo.getPhotoList().getNumPhotos() > 0);
408                 Photo currentPhoto = _trackInfo.getPhotoList().getPhoto(_trackInfo.getSelection().getCurrentPhotoIndex());
409                 if ((currentPoint == null || currentPoint.getPhoto() == null) && currentPhoto == null)
410                 {
411                         // no photo, hide details
412                         _photoLabel.setText(I18nManager.getText("details.nophoto"));
413                         _photoPathLabel.setText("");
414                         _photoPathLabel.setToolTipText("");
415                         _photoTimestampLabel.setText("");
416                         _photoConnectedLabel.setText("");
417                         _photoBearingLabel.setText("");
418                         _photoThumbnail.setVisible(false);
419                         _rotationButtons.setVisible(false);
420                 }
421                 else
422                 {
423                         if (currentPhoto == null) {currentPhoto = currentPoint.getPhoto();}
424                         _photoLabel.setText(I18nManager.getText("details.photofile") + ": " + currentPhoto.getName());
425                         String fullPath = currentPhoto.getFullPath();
426                         String shortPath = shortenPath(fullPath);
427                         _photoPathLabel.setText(fullPath == null ? "" : LABEL_FULL_PATH + shortPath);
428                         _photoPathLabel.setToolTipText(currentPhoto.getFullPath());
429                         _photoTimestampLabel.setText(currentPhoto.hasTimestamp()?(LABEL_POINT_TIMESTAMP + currentPhoto.getTimestamp().getText()):"");
430                         _photoConnectedLabel.setText(I18nManager.getText("details.media.connected") + ": "
431                                 + (currentPhoto.getCurrentStatus() == Photo.Status.NOT_CONNECTED ?
432                                         I18nManager.getText("dialog.about.no"):I18nManager.getText("dialog.about.yes")));
433                         if (currentPhoto.getBearing() >= 0.0 && currentPhoto.getBearing() <= 360.0)
434                         {
435                                 _photoBearingLabel.setText(I18nManager.getText("details.photo.bearing") + ": "
436                                         + (int) currentPhoto.getBearing() + " \u00B0");
437                         }
438                         else _photoBearingLabel.setText("");
439                         _photoThumbnail.setVisible(true);
440                         _photoThumbnail.setPhoto(currentPhoto);
441                         _rotationButtons.setVisible(true);
442                         if ((inUpdateType & DataSubscriber.PHOTOS_MODIFIED) > 0) {_photoThumbnail.refresh();}
443                 }
444                 _photoThumbnail.repaint();
445
446                 // audio details
447                 _audioDetailsPanel.setVisible(_trackInfo.getAudioList().getNumAudios() > 0);
448                 AudioClip currentAudio = _trackInfo.getAudioList().getAudio(_trackInfo.getSelection().getCurrentAudioIndex());
449                 if (currentAudio == null)
450                 {
451                         _audioLabel.setText(I18nManager.getText("details.noaudio"));
452                         _audioPathLabel.setText("");
453                         _audioPathLabel.setToolTipText("");
454                         _audioTimestampLabel.setText("");
455                         _audioLengthLabel.setText("");
456                         _audioConnectedLabel.setText("");
457                 }
458                 else
459                 {
460                         _audioLabel.setText(LABEL_AUDIO_FILE + currentAudio.getName());
461                         String fullPath = currentAudio.getFullPath();
462                         String shortPath = shortenPath(fullPath);
463                         _audioPathLabel.setText(fullPath == null ? "" : LABEL_FULL_PATH + shortPath);
464                         _audioPathLabel.setToolTipText(fullPath == null ? "" : fullPath);
465                         _audioTimestampLabel.setText(currentAudio.hasTimestamp()?(LABEL_POINT_TIMESTAMP + currentAudio.getTimestamp().getText()):"");
466                         int audioLength = currentAudio.getLengthInSeconds();
467                         _audioLengthLabel.setText(audioLength < 0?"":LABEL_RANGE_DURATION + DisplayUtils.buildDurationString(audioLength));
468                         _audioConnectedLabel.setText(I18nManager.getText("details.media.connected") + ": "
469                                 + (currentAudio.getCurrentStatus() == Photo.Status.NOT_CONNECTED ?
470                                         I18nManager.getText("dialog.about.no"):I18nManager.getText("dialog.about.yes")));
471                 }
472                 _playAudioPanel.setVisible(currentAudio != null);
473         }
474
475
476         /**
477          * Construct an appropriate coordinate label using the selected format
478          * @param inPrefix prefix of label
479          * @param inCoordinate coordinate
480          * @param inFormat index of format selection dropdown
481          * @return language-sensitive string
482          */
483         private static String makeCoordinateLabel(String inPrefix, Coordinate inCoordinate, int inFormat)
484         {
485                 String coord = null;
486                 switch (inFormat) {
487                         case 1: // degminsec
488                                 coord = inCoordinate.output(Coordinate.FORMAT_DEG_MIN_SEC); break;
489                         case 2: // degmin
490                                 coord = inCoordinate.output(Coordinate.FORMAT_DEG_MIN); break;
491                         case 3: // degrees
492                                 coord = inCoordinate.output(Coordinate.FORMAT_DEG); break;
493                         default: // just as it was
494                                 coord = inCoordinate.output(Coordinate.FORMAT_NONE);
495                 }
496                 // Fix broken degree signs (due to unicode mangling)
497                 final char brokenDeg = 65533;
498                 if (coord.indexOf(brokenDeg) >= 0) {
499                         coord = coord.replaceAll(String.valueOf(brokenDeg), "\u00B0");
500                 }
501                 return inPrefix + restrictDP(coord);
502         }
503
504
505         /**
506          * Format a number to a sensible precision
507          * @param inDist distance
508          * @return formatted String
509          */
510         private String roundedNumber(double inDist)
511         {
512                 // Set precision of formatter
513                 int numDigits = 0;
514                 if (inDist < 1.0)
515                         numDigits = 3;
516                 else if (inDist < 10.0)
517                         numDigits = 2;
518                 else if (inDist < 100.0)
519                         numDigits = 1;
520                 // set formatter
521                 _distanceFormatter.setMaximumFractionDigits(numDigits);
522                 _distanceFormatter.setMinimumFractionDigits(numDigits);
523                 return _distanceFormatter.format(inDist);
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                 // 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                         inFullPath = inFullPath.substring(homePath.length()+1);
589                 }
590                 if (inFullPath == null || inFullPath.length() < 21) {
591                         return inFullPath;
592                 }
593                 // path is too long
594                 return inFullPath.substring(0, 20) + "...";
595         }
596 }