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