3 import java.awt.BorderLayout;
4 import java.awt.Component;
5 import java.awt.Dimension;
6 import java.awt.FlowLayout;
8 import java.awt.Insets;
9 import java.awt.event.ActionEvent;
10 import java.awt.event.ActionListener;
11 import java.util.TimeZone;
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;
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;
46 * Class to hold point details and selection details
47 * as a visual component
49 public class DetailsDisplay extends GenericDisplay
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;
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;
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;
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;
89 private JComboBox<String> _coordFormatDropdown = null;
90 private JComboBox<String> _distUnitsDropdown = null;
92 private TimeZone _timezone = null;
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") + ": ";
119 * @param inTrackInfo Track info object
121 public DetailsDisplay(TrackInfo inTrackInfo)
124 setLayout(new BorderLayout());
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);
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);
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);
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);
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);
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);
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);
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)
263 dataUpdated(DataSubscriber.UNITS_CHANGED);
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);}
278 _distUnitsDropdown.addActionListener(new ActionListener() {
279 public void actionPerformed(ActionEvent e)
281 Config.selectUnitSet(_distUnitsDropdown.getSelectedIndex());
282 UpdateMessageBroker.informSubscribers(DataSubscriber.UNITS_CHANGED);
285 lowerPanel.add(_distUnitsDropdown);
286 _distUnitsDropdown.setAlignmentX(Component.LEFT_ALIGNMENT);
287 add(lowerPanel, BorderLayout.SOUTH);
292 * Notification that Track has been updated
293 * @param inUpdateType byte to specify what has been updated
295 public void dataUpdated(byte inUpdateType)
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();
310 if (_track == null || currentPoint == null)
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("");
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()))
337 if (currentPoint.hasTimestamp())
339 _ptDateLabel.setText(LABEL_POINT_DATE + currentPoint.getTimestamp().getDateText(_timezone));
340 _ptTimeLabel.setText(LABEL_POINT_TIME + currentPoint.getTimestamp().getTimeText(_timezone));
344 _ptDateLabel.setText("");
345 _ptTimeLabel.setText("");
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("");
355 if (pointDesc.length() < 5) {
356 _descLabel.setText(LABEL_POINT_DESCRIPTION + pointDesc);
359 _descLabel.setText(shortenString(pointDesc));
361 _descLabel.setToolTipText(pointDesc);
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())
369 String speed = DisplayUtils.roundedNumber(speedValue.getValue()) + " " + speedUnitsStr;
370 _speedLabel.setText(LABEL_POINT_SPEED + speed);
373 _speedLabel.setText("");
376 // Now do the vertical speed in the same way
377 SpeedCalculator.calculateVerticalSpeed(_track, currentPointIndex, speedValue);
378 if (speedValue.isValid())
380 String vSpeedUnitsStr = I18nManager.getText(unitSet.getVerticalSpeedUnit().getShortnameKey());
381 String speed = DisplayUtils.roundedNumber(speedValue.getValue()) + " " + vSpeedUnitsStr;
382 _vSpeedLabel.setText(LABEL_POINT_VERTSPEED + speed);
385 _vSpeedLabel.setText("");
389 final String name = currentPoint.getWaypointName();
390 if (name != null && !name.equals(""))
392 _nameLabel.setText(LABEL_POINT_WAYPOINTNAME + name);
394 else _nameLabel.setText("");
396 final String type = currentPoint.getFieldValue(Field.WAYPT_TYPE);
397 if (type != null && !type.equals("")) {
398 _typeLabel.setText(LABEL_POINT_WAYPOINTTYPE + type);
400 else _typeLabel.setText("");
402 // File to which point belongs
403 final int numFiles = _trackInfo.getFileInfo().getNumFiles();
404 String filename = null;
407 final SourceInfo info = _trackInfo.getFileInfo().getSourceForPoint(currentPoint);
409 filename = info.getName();
412 if (filename != null) {
413 _filenameLabel.setText(LABEL_POINT_FILENAME + filename);
414 _filenameLabel.setToolTipText(filename);
417 _filenameLabel.setText("");
418 _filenameLabel.setToolTipText("");
422 // Update range details
423 if (_track == null || !selection.hasRangeSelected())
425 _rangeLabel.setText(I18nManager.getText("details.norangeselection"));
426 _distanceLabel.setText("");
427 _durationLabel.setText("");
428 _altRangeLabel.setText("");
429 _updownLabel.setText("");
430 _aveSpeedLabel.setText("");
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)
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);
446 _durationLabel.setText("");
447 _aveSpeedLabel.setText("");
449 AltitudeRange altRange = selection.getAltitudeRange();
450 Unit altUnit = Config.getUnitSet().getAltitudeUnit();
451 String altUnitsLabel = I18nManager.getText(altUnit.getShortnameKey());
452 if (altRange.hasRange())
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);
463 _altRangeLabel.setText("");
464 _updownLabel.setText("");
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)
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);
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))
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)
498 _photoBearingLabel.setText(I18nManager.getText("details.photo.bearing") + ": "
499 + (int) currentPhoto.getBearing() + " \u00B0");
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();}
507 _photoThumbnail.repaint();
510 _audioDetailsPanel.setVisible(_trackInfo.getAudioList().getNumAudios() > 0);
511 AudioClip currentAudio = _trackInfo.getAudioList().getAudio(_trackInfo.getSelection().getCurrentAudioIndex());
512 if (currentAudio == null)
514 _audioLabel.setText(I18nManager.getText("details.noaudio"));
515 _audioPathLabel.setText("");
516 _audioPathLabel.setToolTipText("");
517 _audioTimestampLabel.setText("");
518 _audioLengthLabel.setText("");
519 _audioConnectedLabel.setText("");
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))
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")));
537 _playAudioPanel.setVisible(currentAudio != null);
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
548 private static String makeCoordinateLabel(String inPrefix, Coordinate inCoordinate, int inFormat)
553 coord = inCoordinate.output(Coordinate.FORMAT_DEG_MIN_SEC); break;
555 coord = inCoordinate.output(Coordinate.FORMAT_DEG_MIN); break;
557 coord = inCoordinate.output(Coordinate.FORMAT_DEG); break;
558 default: // just as it was
559 coord = inCoordinate.output(Coordinate.FORMAT_NONE);
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");
566 return inPrefix + restrictDP(coord);
571 * Restrict the given coordinate to a limited number of decimal places for display
572 * @param inCoord coordinate string
573 * @return chopped string
575 private static String restrictDP(String inCoord)
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(','));
583 final int chopPos = dotPos + DECIMAL_PLACES;
584 if (chopPos < (inCoord.length()-1))
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))
591 result += inCoord.substring(expPos);
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
604 private static JPanel makeDetailsPanel(String inNameKey, Font inFont)
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))
611 JLabel detailsLabel = new JLabel(I18nManager.getText(inNameKey));
612 detailsLabel.setFont(inFont);
613 detailsPanel.add(detailsLabel);
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
623 private static JButton makeRotateButton(String inIcon, GenericFunction inFunction)
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));
633 * @param inFullPath full file path or URL to be shortened
634 * @return shortened string from beginning of path
636 private static String shortenPath(String inFullPath)
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);
644 return shortenString(path);
648 * @param inString string to shorten
649 * @return shortened string from the beginning
651 private static String shortenString(String inString)
653 // Limit is hardcoded here, maybe it should depend on parent component width and font size etc?
654 if (inString == null || inString.length() < 21) {
657 // string is too long
658 return inString.substring(0, 20) + "...";