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