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.SpeedCalculator;
36 import tim.prune.data.SpeedValue;
37 import tim.prune.data.TrackInfo;
38 import tim.prune.data.Unit;
39 import tim.prune.data.UnitSet;
40 import tim.prune.data.UnitSetLibrary;
43 * Class to hold point details and selection details
44 * as a visual component
46 public class DetailsDisplay extends GenericDisplay
49 private JLabel _indexLabel = null;
50 private JLabel _latLabel = null, _longLabel = null;
51 private JLabel _altLabel = null;
52 private JLabel _timeLabel = null;
53 private JLabel _descLabel = null;
54 private JLabel _speedLabel = null, _vSpeedLabel = null;
55 private JLabel _nameLabel = null, _typeLabel = null;
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;
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;
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;
85 private JComboBox _coordFormatDropdown = null;
86 private JComboBox _distUnitsDropdown = null;
89 private static final String LABEL_POINT_SELECTED = I18nManager.getText("details.index.selected") + ": ";
90 private static final String LABEL_POINT_LATITUDE = I18nManager.getText("fieldname.latitude") + ": ";
91 private static final String LABEL_POINT_LONGITUDE = I18nManager.getText("fieldname.longitude") + ": ";
92 private static final String LABEL_POINT_ALTITUDE = I18nManager.getText("fieldname.altitude") + ": ";
93 private static final String LABEL_POINT_TIMESTAMP = I18nManager.getText("fieldname.timestamp") + ": ";
94 private static final String LABEL_POINT_WAYPOINTNAME = I18nManager.getText("fieldname.waypointname") + ": ";
95 private static final String LABEL_POINT_WAYPOINTTYPE = I18nManager.getText("fieldname.waypointtype") + ": ";
96 private static final String LABEL_POINT_DESCRIPTION = I18nManager.getText("fieldname.description") + ": ";
97 private static final String LABEL_POINT_SPEED = I18nManager.getText("fieldname.speed") + ": ";
98 private static final String LABEL_POINT_VERTSPEED = I18nManager.getText("fieldname.verticalspeed") + ": ";
99 private static final String LABEL_RANGE_SELECTED = I18nManager.getText("details.range.selected") + ": ";
100 private static final String LABEL_RANGE_DURATION = I18nManager.getText("fieldname.duration") + ": ";
101 private static final String LABEL_RANGE_DISTANCE = I18nManager.getText("fieldname.distance") + ": ";
102 private static final String LABEL_RANGE_ALTITUDE = I18nManager.getText("fieldname.altitude") + ": ";
103 private static final String LABEL_RANGE_CLIMB = I18nManager.getText("details.range.climb") + ": ";
104 private static final String LABEL_RANGE_DESCENT = ", " + I18nManager.getText("details.range.descent") + ": ";
105 private static final String LABEL_AUDIO_FILE = I18nManager.getText("details.audio.file") + ": ";
106 private static final String LABEL_FULL_PATH = I18nManager.getText("details.media.fullpath") + ": ";
111 * @param inTrackInfo Track info object
113 public DetailsDisplay(TrackInfo inTrackInfo)
116 setLayout(new BorderLayout());
118 JPanel mainPanel = new JPanel();
119 mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
120 mainPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
121 Font biggerFont = new JLabel().getFont();
122 biggerFont = biggerFont.deriveFont(Font.BOLD, biggerFont.getSize2D() + 2.0f);
124 // Point details panel
125 JPanel pointDetailsPanel = makeDetailsPanel("details.pointdetails", biggerFont);
126 _indexLabel = new JLabel(I18nManager.getText("details.nopointselection"));
127 pointDetailsPanel.add(_indexLabel);
128 _latLabel = new JLabel("");
129 pointDetailsPanel.add(_latLabel);
130 _longLabel = new JLabel("");
131 pointDetailsPanel.add(_longLabel);
132 _altLabel = new JLabel("");
133 pointDetailsPanel.add(_altLabel);
134 _timeLabel = new JLabel("");
135 _timeLabel.setMinimumSize(new Dimension(120, 10));
136 pointDetailsPanel.add(_timeLabel);
137 _descLabel = new JLabel("");
138 pointDetailsPanel.add(_descLabel);
139 _speedLabel = new JLabel("");
140 pointDetailsPanel.add(_speedLabel);
141 _vSpeedLabel = new JLabel("");
142 pointDetailsPanel.add(_vSpeedLabel);
143 _nameLabel = new JLabel("");
144 pointDetailsPanel.add(_nameLabel);
145 _typeLabel = new JLabel("");
146 pointDetailsPanel.add(_typeLabel);
147 pointDetailsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
149 // range details panel
150 JPanel rangeDetailsPanel = makeDetailsPanel("details.rangedetails", biggerFont);
151 _rangeLabel = new JLabel(I18nManager.getText("details.norangeselection"));
152 rangeDetailsPanel.add(_rangeLabel);
153 _distanceLabel = new JLabel("");
154 rangeDetailsPanel.add(_distanceLabel);
155 _durationLabel = new JLabel("");
156 rangeDetailsPanel.add(_durationLabel);
157 _aveSpeedLabel = new JLabel("");
158 rangeDetailsPanel.add(_aveSpeedLabel);
159 _altRangeLabel = new JLabel("");
160 rangeDetailsPanel.add(_altRangeLabel);
161 _updownLabel = new JLabel("");
162 rangeDetailsPanel.add(_updownLabel);
163 rangeDetailsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
165 // photo details panel
166 _photoDetailsPanel = makeDetailsPanel("details.photodetails", biggerFont);
167 _photoLabel = new JLabel(I18nManager.getText("details.nophoto"));
168 _photoDetailsPanel.add(_photoLabel);
169 _photoPathLabel = new JLabel("");
170 _photoDetailsPanel.add(_photoPathLabel);
171 _photoTimestampLabel = new JLabel("");
172 _photoTimestampLabel.setMinimumSize(new Dimension(120, 10));
173 _photoDetailsPanel.add(_photoTimestampLabel);
174 _photoConnectedLabel = new JLabel("");
175 _photoDetailsPanel.add(_photoConnectedLabel);
176 _photoBearingLabel = new JLabel("");
177 _photoDetailsPanel.add(_photoBearingLabel);
178 _photoThumbnail = new PhotoThumbnail();
179 _photoThumbnail.setVisible(false);
180 _photoThumbnail.setPreferredSize(new Dimension(100, 100));
181 _photoDetailsPanel.add(_photoThumbnail);
183 JButton rotLeft = makeRotateButton(IconManager.ROTATE_LEFT, FunctionLibrary.FUNCTION_ROTATE_PHOTO_LEFT);
184 JButton rotRight = makeRotateButton(IconManager.ROTATE_RIGHT, FunctionLibrary.FUNCTION_ROTATE_PHOTO_RIGHT);
185 JButton popup = makeRotateButton(IconManager.SHOW_DETAILS, FunctionLibrary.FUNCTION_PHOTO_POPUP);
186 _rotationButtons = new JPanel();
187 _rotationButtons.add(rotLeft);
188 _rotationButtons.add(rotRight);
189 _rotationButtons.add(Box.createHorizontalStrut(10));
190 _rotationButtons.add(popup);
191 _rotationButtons.setAlignmentX(Component.LEFT_ALIGNMENT);
192 _rotationButtons.setVisible(false);
193 _photoDetailsPanel.add(_rotationButtons);
194 _photoDetailsPanel.setVisible(false);
196 // audio details panel
197 _audioDetailsPanel = makeDetailsPanel("details.audiodetails", biggerFont);
198 _audioLabel = new JLabel(I18nManager.getText("details.noaudio"));
199 _audioDetailsPanel.add(_audioLabel);
200 _audioPathLabel = new JLabel("");
201 _audioDetailsPanel.add(_audioPathLabel);
202 _audioTimestampLabel = new JLabel("");
203 _audioTimestampLabel.setMinimumSize(new Dimension(120, 10));
204 _audioDetailsPanel.add(_audioTimestampLabel);
205 _audioLengthLabel = new JLabel("");
206 _audioDetailsPanel.add(_audioLengthLabel);
207 _audioConnectedLabel = new JLabel("");
208 _audioDetailsPanel.add(_audioConnectedLabel);
209 _audioProgress = new JProgressBar(0, 100);
210 _audioProgress.setString(I18nManager.getText("details.audio.playing"));
211 _audioProgress.setStringPainted(true);
212 _audioProgress.setVisible(false);
213 _audioDetailsPanel.add(_audioProgress);
214 _playAudioPanel = new JPanel();
215 _playAudioPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
216 JButton playAudio = makeRotateButton(IconManager.PLAY_AUDIO, FunctionLibrary.FUNCTION_PLAY_AUDIO);
217 playAudio.addActionListener(new AudioListener(_audioProgress));
218 _playAudioPanel.add(playAudio);
219 JButton stopAudio = makeRotateButton(IconManager.STOP_AUDIO, FunctionLibrary.FUNCTION_STOP_AUDIO);
220 _playAudioPanel.add(stopAudio);
221 _playAudioPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
222 _playAudioPanel.setVisible(false);
223 _audioDetailsPanel.add(_playAudioPanel);
224 _audioDetailsPanel.setVisible(false);
226 // add the details panels to the main panel
227 mainPanel.add(pointDetailsPanel);
228 mainPanel.add(Box.createVerticalStrut(5));
229 mainPanel.add(rangeDetailsPanel);
230 mainPanel.add(Box.createVerticalStrut(5));
231 mainPanel.add(_photoDetailsPanel);
232 mainPanel.add(Box.createVerticalStrut(5));
233 mainPanel.add(_audioDetailsPanel);
234 mainPanel.add(Box.createVerticalStrut(5));
235 // add the main panel at the top
236 add(mainPanel, BorderLayout.NORTH);
238 // Add format, units selection
239 JPanel lowerPanel = new JPanel();
240 lowerPanel.setLayout(new BoxLayout(lowerPanel, BoxLayout.Y_AXIS));
241 JLabel coordFormatLabel = new JLabel(I18nManager.getText("details.coordformat") + ": ");
242 coordFormatLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
243 lowerPanel.add(coordFormatLabel);
244 String[] coordFormats = {I18nManager.getText("units.original"), I18nManager.getText("units.degminsec"),
245 I18nManager.getText("units.degmin"), I18nManager.getText("units.deg")};
246 _coordFormatDropdown = new JComboBox(coordFormats);
247 _coordFormatDropdown.addActionListener(new ActionListener() {
248 public void actionPerformed(ActionEvent e)
250 dataUpdated(DataSubscriber.UNITS_CHANGED);
253 lowerPanel.add(_coordFormatDropdown);
254 _coordFormatDropdown.setAlignmentX(Component.LEFT_ALIGNMENT);
255 JLabel unitsLabel = new JLabel(I18nManager.getText("details.distanceunits") + ": ");
256 unitsLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
257 lowerPanel.add(unitsLabel);
258 // Make dropdown for distance units
259 _distUnitsDropdown = new JComboBox();
260 final UnitSet currUnits = Config.getUnitSet();
261 for (int i=0; i<UnitSetLibrary.getNumUnitSets(); i++) {
262 _distUnitsDropdown.addItem(I18nManager.getText(UnitSetLibrary.getUnitSet(i).getDistanceUnit().getNameKey()));
263 if (UnitSetLibrary.getUnitSet(i) == currUnits) {_distUnitsDropdown.setSelectedIndex(i);}
265 _distUnitsDropdown.addActionListener(new ActionListener() {
266 public void actionPerformed(ActionEvent e)
268 Config.selectUnitSet(_distUnitsDropdown.getSelectedIndex());
269 UpdateMessageBroker.informSubscribers(DataSubscriber.UNITS_CHANGED);
272 lowerPanel.add(_distUnitsDropdown);
273 _distUnitsDropdown.setAlignmentX(Component.LEFT_ALIGNMENT);
274 add(lowerPanel, BorderLayout.SOUTH);
279 * Notification that Track has been updated
280 * @param inUpdateType byte to specify what has been updated
282 public void dataUpdated(byte inUpdateType)
284 // Update current point data, if any
285 DataPoint currentPoint = _trackInfo.getCurrentPoint();
286 Selection selection = _trackInfo.getSelection();
287 if ((inUpdateType | DATA_ADDED_OR_REMOVED) > 0) selection.markInvalid();
288 int currentPointIndex = selection.getCurrentPointIndex();
289 _speedLabel.setText("");
290 UnitSet unitSet = UnitSetLibrary.getUnitSet(_distUnitsDropdown.getSelectedIndex());
291 String distUnitsStr = I18nManager.getText(unitSet.getDistanceUnit().getShortnameKey());
292 String speedUnitsStr = I18nManager.getText(unitSet.getSpeedUnit().getShortnameKey());
293 if (_track == null || currentPoint == null)
295 _indexLabel.setText(I18nManager.getText("details.nopointselection"));
296 _latLabel.setText("");
297 _longLabel.setText("");
298 _altLabel.setText("");
299 _timeLabel.setText("");
300 _descLabel.setText("");
301 _nameLabel.setText("");
302 _typeLabel.setText("");
303 _speedLabel.setText("");
304 _vSpeedLabel.setText("");
308 _indexLabel.setText(LABEL_POINT_SELECTED
309 + (currentPointIndex+1) + " " + I18nManager.getText("details.index.of")
310 + " " + _track.getNumPoints());
311 _latLabel.setText(makeCoordinateLabel(LABEL_POINT_LATITUDE, currentPoint.getLatitude(), _coordFormatDropdown.getSelectedIndex()));
312 _longLabel.setText(makeCoordinateLabel(LABEL_POINT_LONGITUDE, currentPoint.getLongitude(), _coordFormatDropdown.getSelectedIndex()));
313 Unit altUnit = Config.getUnitSet().getAltitudeUnit();
314 _altLabel.setText(currentPoint.hasAltitude()?
315 (LABEL_POINT_ALTITUDE + currentPoint.getAltitude().getValue(altUnit) + " " +
316 I18nManager.getText(altUnit.getShortnameKey()))
318 if (currentPoint.hasTimestamp()) {
319 _timeLabel.setText(LABEL_POINT_TIMESTAMP + currentPoint.getTimestamp().getText());
320 _timeLabel.setToolTipText(currentPoint.getTimestamp().getText());
323 _timeLabel.setText("");
324 _timeLabel.setToolTipText("");
326 // Maybe the point has a description?
327 String pointDesc = currentPoint.getFieldValue(Field.DESCRIPTION);
328 if (pointDesc == null || pointDesc.equals("") || currentPoint.hasMedia()) {
329 _descLabel.setText("");
330 _descLabel.setToolTipText("");
334 if (pointDesc.length() < 5) {
335 _descLabel.setText(LABEL_POINT_DESCRIPTION + pointDesc);
338 _descLabel.setText(shortenString(pointDesc));
340 _descLabel.setToolTipText(pointDesc);
343 // Speed can come from either timestamps and distances, or speed values in data
344 SpeedValue speedValue = new SpeedValue();
345 SpeedCalculator.calculateSpeed(_track, currentPointIndex, speedValue);
346 if (speedValue.isValid())
348 String speed = DisplayUtils.roundedNumber(speedValue.getValue()) + " " + speedUnitsStr;
349 _speedLabel.setText(LABEL_POINT_SPEED + speed);
352 _speedLabel.setText("");
355 // Now do the vertical speed in the same way
356 SpeedCalculator.calculateVerticalSpeed(_track, currentPointIndex, speedValue);
357 if (speedValue.isValid())
359 String vSpeedUnitsStr = I18nManager.getText(unitSet.getVerticalSpeedUnit().getShortnameKey());
360 String speed = DisplayUtils.roundedNumber(speedValue.getValue()) + " " + vSpeedUnitsStr;
361 _vSpeedLabel.setText(LABEL_POINT_VERTSPEED + speed);
364 _vSpeedLabel.setText("");
368 final String name = currentPoint.getWaypointName();
369 if (name != null && !name.equals(""))
371 _nameLabel.setText(LABEL_POINT_WAYPOINTNAME + name);
373 else _nameLabel.setText("");
375 final String type = currentPoint.getFieldValue(Field.WAYPT_TYPE);
376 if (type != null && !type.equals("")) {
377 _typeLabel.setText(LABEL_POINT_WAYPOINTTYPE + type);
379 else _typeLabel.setText("");
382 // Update range details
383 if (_track == null || !selection.hasRangeSelected())
385 _rangeLabel.setText(I18nManager.getText("details.norangeselection"));
386 _distanceLabel.setText("");
387 _durationLabel.setText("");
388 _altRangeLabel.setText("");
389 _updownLabel.setText("");
390 _aveSpeedLabel.setText("");
394 _rangeLabel.setText(LABEL_RANGE_SELECTED
395 + (selection.getStart()+1) + " " + I18nManager.getText("details.range.to")
396 + " " + (selection.getEnd()+1));
397 _distanceLabel.setText(LABEL_RANGE_DISTANCE + DisplayUtils.roundedNumber(selection.getDistance()) + " " + distUnitsStr);
398 if (selection.getNumSeconds() > 0)
400 _durationLabel.setText(LABEL_RANGE_DURATION + DisplayUtils.buildDurationString(selection.getNumSeconds()));
401 _aveSpeedLabel.setText(I18nManager.getText("details.range.avespeed") + ": "
402 + DisplayUtils.roundedNumber(selection.getDistance()/selection.getNumSeconds()*3600.0) + " " + speedUnitsStr);
405 _durationLabel.setText("");
406 _aveSpeedLabel.setText("");
408 AltitudeRange altRange = selection.getAltitudeRange();
409 Unit altUnit = Config.getUnitSet().getAltitudeUnit();
410 String altUnitsLabel = I18nManager.getText(altUnit.getShortnameKey());
411 if (altRange.hasRange())
413 _altRangeLabel.setText(LABEL_RANGE_ALTITUDE
414 + altRange.getMinimum(altUnit) + altUnitsLabel + " "
415 + I18nManager.getText("details.altitude.to") + " "
416 + altRange.getMaximum(altUnit) + altUnitsLabel);
417 _updownLabel.setText(LABEL_RANGE_CLIMB + altRange.getClimb(altUnit) + altUnitsLabel
418 + LABEL_RANGE_DESCENT + altRange.getDescent(altUnit) + altUnitsLabel);
422 _altRangeLabel.setText("");
423 _updownLabel.setText("");
426 // show photo details and thumbnail
427 _photoDetailsPanel.setVisible(_trackInfo.getPhotoList().getNumPhotos() > 0);
428 Photo currentPhoto = _trackInfo.getPhotoList().getPhoto(_trackInfo.getSelection().getCurrentPhotoIndex());
429 if ((currentPoint == null || currentPoint.getPhoto() == null) && currentPhoto == null)
431 // no photo, hide details
432 _photoLabel.setText(I18nManager.getText("details.nophoto"));
433 _photoPathLabel.setText("");
434 _photoPathLabel.setToolTipText("");
435 _photoTimestampLabel.setText("");
436 _photoConnectedLabel.setText("");
437 _photoBearingLabel.setText("");
438 _photoThumbnail.setVisible(false);
439 _rotationButtons.setVisible(false);
443 if (currentPhoto == null) {currentPhoto = currentPoint.getPhoto();}
444 _photoLabel.setText(I18nManager.getText("details.photofile") + ": " + currentPhoto.getName());
445 String fullPath = currentPhoto.getFullPath();
446 String shortPath = shortenPath(fullPath);
447 _photoPathLabel.setText(fullPath == null ? "" : LABEL_FULL_PATH + shortPath);
448 _photoPathLabel.setToolTipText(currentPhoto.getFullPath());
449 _photoTimestampLabel.setText(currentPhoto.hasTimestamp()?(LABEL_POINT_TIMESTAMP + currentPhoto.getTimestamp().getText()):"");
450 _photoConnectedLabel.setText(I18nManager.getText("details.media.connected") + ": "
451 + (currentPhoto.getCurrentStatus() == Photo.Status.NOT_CONNECTED ?
452 I18nManager.getText("dialog.about.no"):I18nManager.getText("dialog.about.yes")));
453 if (currentPhoto.getBearing() >= 0.0 && currentPhoto.getBearing() <= 360.0)
455 _photoBearingLabel.setText(I18nManager.getText("details.photo.bearing") + ": "
456 + (int) currentPhoto.getBearing() + " \u00B0");
458 else _photoBearingLabel.setText("");
459 _photoThumbnail.setVisible(true);
460 _photoThumbnail.setPhoto(currentPhoto);
461 _rotationButtons.setVisible(true);
462 if ((inUpdateType & DataSubscriber.PHOTOS_MODIFIED) > 0) {_photoThumbnail.refresh();}
464 _photoThumbnail.repaint();
467 _audioDetailsPanel.setVisible(_trackInfo.getAudioList().getNumAudios() > 0);
468 AudioClip currentAudio = _trackInfo.getAudioList().getAudio(_trackInfo.getSelection().getCurrentAudioIndex());
469 if (currentAudio == null)
471 _audioLabel.setText(I18nManager.getText("details.noaudio"));
472 _audioPathLabel.setText("");
473 _audioPathLabel.setToolTipText("");
474 _audioTimestampLabel.setText("");
475 _audioLengthLabel.setText("");
476 _audioConnectedLabel.setText("");
480 _audioLabel.setText(LABEL_AUDIO_FILE + currentAudio.getName());
481 String fullPath = currentAudio.getFullPath();
482 String shortPath = shortenPath(fullPath);
483 _audioPathLabel.setText(fullPath == null ? "" : LABEL_FULL_PATH + shortPath);
484 _audioPathLabel.setToolTipText(fullPath == null ? "" : fullPath);
485 _audioTimestampLabel.setText(currentAudio.hasTimestamp()?(LABEL_POINT_TIMESTAMP + currentAudio.getTimestamp().getText()):"");
486 int audioLength = currentAudio.getLengthInSeconds();
487 _audioLengthLabel.setText(audioLength < 0?"":LABEL_RANGE_DURATION + DisplayUtils.buildDurationString(audioLength));
488 _audioConnectedLabel.setText(I18nManager.getText("details.media.connected") + ": "
489 + (currentAudio.getCurrentStatus() == Photo.Status.NOT_CONNECTED ?
490 I18nManager.getText("dialog.about.no"):I18nManager.getText("dialog.about.yes")));
492 _playAudioPanel.setVisible(currentAudio != null);
497 * Construct an appropriate coordinate label using the selected format
498 * @param inPrefix prefix of label
499 * @param inCoordinate coordinate
500 * @param inFormat index of format selection dropdown
501 * @return language-sensitive string
503 private static String makeCoordinateLabel(String inPrefix, Coordinate inCoordinate, int inFormat)
508 coord = inCoordinate.output(Coordinate.FORMAT_DEG_MIN_SEC); break;
510 coord = inCoordinate.output(Coordinate.FORMAT_DEG_MIN); break;
512 coord = inCoordinate.output(Coordinate.FORMAT_DEG); break;
513 default: // just as it was
514 coord = inCoordinate.output(Coordinate.FORMAT_NONE);
516 // Fix broken degree signs (due to unicode mangling)
517 final char brokenDeg = 65533;
518 if (coord.indexOf(brokenDeg) >= 0) {
519 coord = coord.replaceAll(String.valueOf(brokenDeg), "\u00B0");
521 return inPrefix + restrictDP(coord);
526 * Restrict the given coordinate to a limited number of decimal places for display
527 * @param inCoord coordinate string
528 * @return chopped string
530 private static String restrictDP(String inCoord)
532 final int DECIMAL_PLACES = 7;
533 if (inCoord == null) return "";
534 final int dotPos = Math.max(inCoord.lastIndexOf('.'), inCoord.lastIndexOf(','));
536 final int chopPos = dotPos + DECIMAL_PLACES;
537 if (chopPos < (inCoord.length()-1)) {
538 return inCoord.substring(0, chopPos);
545 * Make a details subpanel
546 * @param inNameKey key to use for top label
547 * @param inFont font for top label
548 * @return panel with correct layout, label
550 private static JPanel makeDetailsPanel(String inNameKey, Font inFont)
552 JPanel detailsPanel = new JPanel();
553 detailsPanel.setLayout(new BoxLayout(detailsPanel, BoxLayout.Y_AXIS));
554 detailsPanel.setBorder(BorderFactory.createCompoundBorder(
555 BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(3, 3, 3, 3))
557 JLabel detailsLabel = new JLabel(I18nManager.getText(inNameKey));
558 detailsLabel.setFont(inFont);
559 detailsPanel.add(detailsLabel);
564 * Create a little button for rotating the current photo
565 * @param inIcon icon to use (from IconManager)
566 * @param inFunction function to call (from FunctionLibrary)
567 * @return button object
569 private static JButton makeRotateButton(String inIcon, GenericFunction inFunction)
571 JButton button = new JButton(IconManager.getImageIcon(inIcon));
572 button.setToolTipText(I18nManager.getText(inFunction.getNameKey()));
573 button.setMargin(new Insets(0, 2, 0, 2));
574 button.addActionListener(new FunctionLauncher(inFunction));
579 * @param inFullPath full file path or URL to be shortened
580 * @return shortened string from beginning of path
582 private static String shortenPath(String inFullPath)
584 String path = inFullPath;
585 // Chop off the home path if possible
586 final String homePath = System.getProperty("user.home").toLowerCase();
587 if (inFullPath != null && inFullPath.toLowerCase().startsWith(homePath)) {
588 path = inFullPath.substring(homePath.length()+1);
590 return shortenString(path);
594 * @param inString string to shorten
595 * @return shortened string from the beginning
597 private static String shortenString(String inString)
599 // Limit is hardcoded here, maybe it should depend on parent component width and font size etc?
600 if (inString == null || inString.length() < 21) {
603 // string is too long
604 return inString.substring(0, 20) + "...";