]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/DetailsDisplay.java
ec68e162633dc66472138c20d6c1ac3a602c7303
[GpsPrune.git] / tim / prune / gui / DetailsDisplay.java
1 package tim.prune.gui;
2
3 import java.awt.BorderLayout;
4 import java.awt.Component;
5 import java.awt.Dimension;
6 import java.awt.FlowLayout;
7 import java.awt.Font;
8 import java.awt.Insets;
9 import java.awt.event.ActionEvent;
10 import java.awt.event.ActionListener;
11 import java.text.NumberFormat;
12
13 import javax.swing.BorderFactory;
14 import javax.swing.Box;
15 import javax.swing.BoxLayout;
16 import javax.swing.JButton;
17 import javax.swing.JComboBox;
18 import javax.swing.JLabel;
19 import javax.swing.JPanel;
20 import javax.swing.JProgressBar;
21 import javax.swing.border.EtchedBorder;
22
23 import tim.prune.DataSubscriber;
24 import tim.prune.FunctionLibrary;
25 import tim.prune.GenericFunction;
26 import tim.prune.I18nManager;
27 import tim.prune.UpdateMessageBroker;
28 import tim.prune.config.Config;
29 import tim.prune.data.Altitude;
30 import tim.prune.data.AudioClip;
31 import tim.prune.data.Coordinate;
32 import tim.prune.data.DataPoint;
33 import tim.prune.data.Distance;
34 import tim.prune.data.Field;
35 import tim.prune.data.IntegerRange;
36 import tim.prune.data.Photo;
37 import tim.prune.data.Selection;
38 import tim.prune.data.TrackInfo;
39
40 /**
41  * Class to hold point details and selection details
42  * as a visual component
43  */
44 public class DetailsDisplay extends GenericDisplay
45 {
46         // Point details
47         private JLabel _indexLabel = null;
48         private JLabel _latLabel = null, _longLabel = null;
49         private JLabel _altLabel = null;
50         private JLabel _timeLabel = null, _speedLabel = null;
51         private JLabel _nameLabel = null, _typeLabel = null;
52
53         // Range details
54         private JLabel _rangeLabel = null;
55         private JLabel _distanceLabel = null;
56         private JLabel _durationLabel = null;
57         private JLabel _altRangeLabel = null, _updownLabel = null;
58         private JLabel _aveSpeedLabel = null;
59
60         // Photo details
61         private JPanel _photoDetailsPanel = null;
62         private JLabel _photoLabel = null;
63         private PhotoThumbnail _photoThumbnail = null;
64         private JLabel _photoTimestampLabel = null;
65         private JLabel _photoConnectedLabel = null;
66         private JLabel _photoBearingLabel = null;
67         private JPanel _rotationButtons = null;
68
69         // Audio details
70         private JPanel _audioDetailsPanel = null;
71         private JLabel _audioLabel = null;
72         private JLabel _audioConnectedLabel = null;
73         private JLabel _audioTimestampLabel = null;
74         private JLabel _audioLengthLabel = null;
75         private JProgressBar _audioProgress = null;
76         private JPanel _playAudioPanel = null;
77
78         // Units
79         private JComboBox _coordFormatDropdown = null;
80         private JComboBox _distUnitsDropdown = null;
81         // Formatter
82         private NumberFormat _distanceFormatter = NumberFormat.getInstance();
83
84         // Cached labels
85         private static final String LABEL_POINT_SELECTED = I18nManager.getText("details.index.selected") + ": ";
86         private static final String LABEL_POINT_LATITUDE = I18nManager.getText("fieldname.latitude") + ": ";
87         private static final String LABEL_POINT_LONGITUDE = I18nManager.getText("fieldname.longitude") + ": ";
88         private static final String LABEL_POINT_ALTITUDE = I18nManager.getText("fieldname.altitude") + ": ";
89         private static final String LABEL_POINT_TIMESTAMP = I18nManager.getText("fieldname.timestamp") + ": ";
90         private static final String LABEL_POINT_WAYPOINTNAME = I18nManager.getText("fieldname.waypointname") + ": ";
91         private static final String LABEL_POINT_WAYPOINTTYPE = I18nManager.getText("fieldname.waypointtype") + ": ";
92         private static final String LABEL_RANGE_SELECTED = I18nManager.getText("details.range.selected") + ": ";
93         private static final String LABEL_RANGE_DURATION = I18nManager.getText("fieldname.duration") + ": ";
94         private static final String LABEL_RANGE_DISTANCE = I18nManager.getText("fieldname.distance") + ": ";
95         private static final String LABEL_RANGE_ALTITUDE = I18nManager.getText("fieldname.altitude") + ": ";
96         private static final String LABEL_RANGE_CLIMB = I18nManager.getText("details.range.climb") + ": ";
97         private static final String LABEL_RANGE_DESCENT = ", " + I18nManager.getText("details.range.descent") + ": ";
98         private static final String LABEL_AUDIO_FILE = I18nManager.getText("details.audio.file") + ": ";
99         private static String LABEL_POINT_ALTITUDE_UNITS = null;
100         private static Altitude.Format LABEL_POINT_ALTITUDE_FORMAT = Altitude.Format.NO_FORMAT;
101
102
103         /**
104          * Constructor
105          * @param inTrackInfo Track info object
106          */
107         public DetailsDisplay(TrackInfo inTrackInfo)
108         {
109                 super(inTrackInfo);
110                 setLayout(new BorderLayout());
111
112                 JPanel mainPanel = new JPanel();
113                 mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
114                 mainPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
115                 Font biggerFont = new JLabel().getFont();
116                 biggerFont = biggerFont.deriveFont(Font.BOLD, biggerFont.getSize2D() + 2.0f);
117
118                 // Point details panel
119                 JPanel pointDetailsPanel = makeDetailsPanel("details.pointdetails", biggerFont);
120                 _indexLabel = new JLabel(I18nManager.getText("details.nopointselection"));
121                 pointDetailsPanel.add(_indexLabel);
122                 _latLabel = new JLabel("");
123                 pointDetailsPanel.add(_latLabel);
124                 _longLabel = new JLabel("");
125                 pointDetailsPanel.add(_longLabel);
126                 _altLabel = new JLabel("");
127                 pointDetailsPanel.add(_altLabel);
128                 _timeLabel = new JLabel("");
129                 _timeLabel.setMinimumSize(new Dimension(120, 10));
130                 pointDetailsPanel.add(_timeLabel);
131                 _speedLabel = new JLabel("");
132                 pointDetailsPanel.add(_speedLabel);
133                 _nameLabel = new JLabel("");
134                 pointDetailsPanel.add(_nameLabel);
135                 _typeLabel = new JLabel("");
136                 pointDetailsPanel.add(_typeLabel);
137                 pointDetailsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
138
139                 // range details panel
140                 JPanel rangeDetailsPanel = makeDetailsPanel("details.rangedetails", biggerFont);
141                 _rangeLabel = new JLabel(I18nManager.getText("details.norangeselection"));
142                 rangeDetailsPanel.add(_rangeLabel);
143                 _distanceLabel = new JLabel("");
144                 rangeDetailsPanel.add(_distanceLabel);
145                 _durationLabel = new JLabel("");
146                 rangeDetailsPanel.add(_durationLabel);
147                 _aveSpeedLabel = new JLabel("");
148                 rangeDetailsPanel.add(_aveSpeedLabel);
149                 _altRangeLabel = new JLabel("");
150                 rangeDetailsPanel.add(_altRangeLabel);
151                 _updownLabel = new JLabel("");
152                 rangeDetailsPanel.add(_updownLabel);
153                 rangeDetailsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
154
155                 // photo details panel
156                 _photoDetailsPanel = makeDetailsPanel("details.photodetails", biggerFont);
157                 _photoLabel = new JLabel(I18nManager.getText("details.nophoto"));
158                 _photoDetailsPanel.add(_photoLabel);
159                 _photoTimestampLabel = new JLabel("");
160                 _photoTimestampLabel.setMinimumSize(new Dimension(120, 10));
161                 _photoDetailsPanel.add(_photoTimestampLabel);
162                 _photoConnectedLabel = new JLabel("");
163                 _photoDetailsPanel.add(_photoConnectedLabel);
164                 _photoBearingLabel = new JLabel("");
165                 _photoDetailsPanel.add(_photoBearingLabel);
166                 _photoThumbnail = new PhotoThumbnail();
167                 _photoThumbnail.setVisible(false);
168                 _photoThumbnail.setPreferredSize(new Dimension(100, 100));
169                 _photoDetailsPanel.add(_photoThumbnail);
170                 // Rotate buttons
171                 JButton rotLeft = makeRotateButton(IconManager.ROTATE_LEFT, FunctionLibrary.FUNCTION_ROTATE_PHOTO_LEFT);
172                 JButton rotRight = makeRotateButton(IconManager.ROTATE_RIGHT, FunctionLibrary.FUNCTION_ROTATE_PHOTO_RIGHT);
173                 JButton popup = makeRotateButton(IconManager.SHOW_DETAILS, FunctionLibrary.FUNCTION_PHOTO_POPUP);
174                 _rotationButtons = new JPanel();
175                 _rotationButtons.add(rotLeft);
176                 _rotationButtons.add(rotRight);
177                 _rotationButtons.add(Box.createHorizontalStrut(10));
178                 _rotationButtons.add(popup);
179                 _rotationButtons.setAlignmentX(Component.LEFT_ALIGNMENT);
180                 _rotationButtons.setVisible(false);
181                 _photoDetailsPanel.add(_rotationButtons);
182                 _photoDetailsPanel.setVisible(false);
183
184                 // audio details panel
185                 _audioDetailsPanel = makeDetailsPanel("details.audiodetails", biggerFont);
186                 _audioLabel = new JLabel(I18nManager.getText("details.noaudio"));
187                 _audioDetailsPanel.add(_audioLabel);
188                 _audioTimestampLabel = new JLabel("");
189                 _audioTimestampLabel.setMinimumSize(new Dimension(120, 10));
190                 _audioDetailsPanel.add(_audioTimestampLabel);
191                 _audioLengthLabel = new JLabel("");
192                 _audioDetailsPanel.add(_audioLengthLabel);
193                 _audioConnectedLabel = new JLabel("");
194                 _audioDetailsPanel.add(_audioConnectedLabel);
195                 _audioProgress = new JProgressBar(0, 100);
196                 _audioProgress.setString(I18nManager.getText("details.audio.playing"));
197                 _audioProgress.setStringPainted(true);
198                 _audioProgress.setVisible(false);
199                 _audioDetailsPanel.add(_audioProgress);
200                 _playAudioPanel = new JPanel();
201                 _playAudioPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
202                 JButton playAudio = makeRotateButton(IconManager.PLAY_AUDIO, FunctionLibrary.FUNCTION_PLAY_AUDIO);
203                 playAudio.addActionListener(new AudioListener(_audioProgress));
204                 _playAudioPanel.add(playAudio);
205                 JButton stopAudio = makeRotateButton(IconManager.STOP_AUDIO, FunctionLibrary.FUNCTION_STOP_AUDIO);
206                 _playAudioPanel.add(stopAudio);
207                 _playAudioPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
208                 _playAudioPanel.setVisible(false);
209                 _audioDetailsPanel.add(_playAudioPanel);
210                 _audioDetailsPanel.setVisible(false);
211
212                 // add the details panels to the main panel
213                 mainPanel.add(pointDetailsPanel);
214                 mainPanel.add(Box.createVerticalStrut(5));
215                 mainPanel.add(rangeDetailsPanel);
216                 mainPanel.add(Box.createVerticalStrut(5));
217                 mainPanel.add(_photoDetailsPanel);
218                 mainPanel.add(Box.createVerticalStrut(5));
219                 mainPanel.add(_audioDetailsPanel);
220                 mainPanel.add(Box.createVerticalStrut(5));
221                 // add the main panel at the top
222                 add(mainPanel, BorderLayout.NORTH);
223
224                 // Add format, units selection
225                 JPanel lowerPanel = new JPanel();
226                 lowerPanel.setLayout(new BoxLayout(lowerPanel, BoxLayout.Y_AXIS));
227                 JLabel coordFormatLabel = new JLabel(I18nManager.getText("details.coordformat") + ": ");
228                 coordFormatLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
229                 lowerPanel.add(coordFormatLabel);
230                 String[] coordFormats = {I18nManager.getText("units.original"), I18nManager.getText("units.degminsec"),
231                         I18nManager.getText("units.degmin"), I18nManager.getText("units.deg")};
232                 _coordFormatDropdown = new JComboBox(coordFormats);
233                 _coordFormatDropdown.addActionListener(new ActionListener() {
234                         public void actionPerformed(ActionEvent e)
235                         {
236                                 dataUpdated(DataSubscriber.UNITS_CHANGED);
237                         }
238                 });
239                 lowerPanel.add(_coordFormatDropdown);
240                 _coordFormatDropdown.setAlignmentX(Component.LEFT_ALIGNMENT);
241                 JLabel unitsLabel = new JLabel(I18nManager.getText("details.distanceunits") + ": ");
242                 unitsLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
243                 lowerPanel.add(unitsLabel);
244                 String[] distUnits = {I18nManager.getText("units.kilometres"), I18nManager.getText("units.miles")};
245                 _distUnitsDropdown = new JComboBox(distUnits);
246                 if (!Config.getConfigBoolean(Config.KEY_METRIC_UNITS)) {_distUnitsDropdown.setSelectedIndex(1);}
247                 _distUnitsDropdown.addActionListener(new ActionListener() {
248                         public void actionPerformed(ActionEvent e)
249                         {
250                                 Config.setConfigBoolean(Config.KEY_METRIC_UNITS, _distUnitsDropdown.getSelectedIndex() == 0);
251                                 UpdateMessageBroker.informSubscribers(DataSubscriber.UNITS_CHANGED);
252                         }
253                 });
254                 lowerPanel.add(_distUnitsDropdown);
255                 _distUnitsDropdown.setAlignmentX(Component.LEFT_ALIGNMENT);
256                 add(lowerPanel, BorderLayout.SOUTH);
257         }
258
259
260         /**
261          * Notification that Track has been updated
262          * @param inUpdateType byte to specify what has been updated
263          */
264         public void dataUpdated(byte inUpdateType)
265         {
266                 // Update current point data, if any
267                 DataPoint currentPoint = _trackInfo.getCurrentPoint();
268                 Selection selection = _trackInfo.getSelection();
269                 if ((inUpdateType | DATA_ADDED_OR_REMOVED) > 0) selection.markInvalid();
270                 int currentPointIndex = selection.getCurrentPointIndex();
271                 _speedLabel.setText("");
272                 Distance.Units distUnits = _distUnitsDropdown.getSelectedIndex()==0?Distance.Units.KILOMETRES:Distance.Units.MILES;
273                 String distUnitsStr = I18nManager.getText(_distUnitsDropdown.getSelectedIndex()==0?"units.kilometres.short":"units.miles.short");
274                 String speedUnitsStr = I18nManager.getText(_distUnitsDropdown.getSelectedIndex()==0?"units.kmh":"units.mph");
275                 if (_track == null || currentPoint == null)
276                 {
277                         _indexLabel.setText(I18nManager.getText("details.nopointselection"));
278                         _latLabel.setText("");
279                         _longLabel.setText("");
280                         _altLabel.setText("");
281                         _timeLabel.setText("");
282                         _nameLabel.setText("");
283                         _typeLabel.setText("");
284                 }
285                 else
286                 {
287                         _indexLabel.setText(LABEL_POINT_SELECTED
288                                 + (currentPointIndex+1) + " " + I18nManager.getText("details.index.of")
289                                 + " " + _track.getNumPoints());
290                         _latLabel.setText(makeCoordinateLabel(LABEL_POINT_LATITUDE, currentPoint.getLatitude(), _coordFormatDropdown.getSelectedIndex()));
291                         _longLabel.setText(makeCoordinateLabel(LABEL_POINT_LONGITUDE, currentPoint.getLongitude(), _coordFormatDropdown.getSelectedIndex()));
292                         _altLabel.setText(currentPoint.hasAltitude()?
293                                 (LABEL_POINT_ALTITUDE + currentPoint.getAltitude().getValue() + getAltitudeUnitsLabel(currentPoint.getAltitude().getFormat()))
294                                 :"");
295                         if (currentPoint.getTimestamp().isValid())
296                         {
297                                 if (currentPointIndex > 0 && currentPointIndex < (_trackInfo.getTrack().getNumPoints()-1))
298                                 {
299                                         DataPoint prevPoint = _trackInfo.getTrack().getPoint(currentPointIndex - 1);
300                                         DataPoint nextPoint = _trackInfo.getTrack().getPoint(currentPointIndex + 1);
301                                         if (prevPoint.getTimestamp().isValid() && nextPoint.getTimestamp().isValid())
302                                         {
303                                                 // use total distance and total time between neighbouring points
304                                                 long diff = nextPoint.getTimestamp().getSecondsSince(prevPoint.getTimestamp());
305                                                 if (diff < 1000 && diff > 0)
306                                                 {
307                                                         double rads = DataPoint.calculateRadiansBetween(prevPoint, currentPoint) +
308                                                                 DataPoint.calculateRadiansBetween(currentPoint, nextPoint);
309                                                         double dist = Distance.convertRadiansToDistance(rads, distUnits);
310                                                         String speed = roundedNumber(3600 * dist / diff) + " " + speedUnitsStr;
311                                                         _speedLabel.setText(I18nManager.getText("fieldname.speed") + ": " + speed);
312                                                 }
313                                         }
314                                 }
315                                 _timeLabel.setText(LABEL_POINT_TIMESTAMP + currentPoint.getTimestamp().getText());
316                         }
317                         else {
318                                 _timeLabel.setText("");
319                         }
320                         // Waypoint name
321                         final String name = currentPoint.getWaypointName();
322                         if (name != null && !name.equals(""))
323                         {
324                                 _nameLabel.setText(LABEL_POINT_WAYPOINTNAME + name);
325                         }
326                         else _nameLabel.setText("");
327                         // Waypoint type
328                         final String type = currentPoint.getFieldValue(Field.WAYPT_TYPE);
329                         if (type != null && !type.equals("")) {
330                                 _typeLabel.setText(LABEL_POINT_WAYPOINTTYPE + type);
331                         }
332                         else _typeLabel.setText("");
333                 }
334
335                 // Update range details
336                 if (_track == null || !selection.hasRangeSelected())
337                 {
338                         _rangeLabel.setText(I18nManager.getText("details.norangeselection"));
339                         _distanceLabel.setText("");
340                         _durationLabel.setText("");
341                         _altRangeLabel.setText("");
342                         _updownLabel.setText("");
343                         _aveSpeedLabel.setText("");
344                 }
345                 else
346                 {
347                         _rangeLabel.setText(LABEL_RANGE_SELECTED
348                                 + (selection.getStart()+1) + " " + I18nManager.getText("details.range.to")
349                                 + " " + (selection.getEnd()+1));
350                         _distanceLabel.setText(LABEL_RANGE_DISTANCE + roundedNumber(selection.getDistance(distUnits)) + " " + distUnitsStr);
351                         if (selection.getNumSeconds() > 0)
352                         {
353                                 _durationLabel.setText(LABEL_RANGE_DURATION + DisplayUtils.buildDurationString(selection.getNumSeconds()));
354                                 _aveSpeedLabel.setText(I18nManager.getText("details.range.avespeed") + ": "
355                                         + roundedNumber(selection.getDistance(distUnits)/selection.getNumSeconds()*3600.0) + " " + speedUnitsStr);
356                         }
357                         else {
358                                 _durationLabel.setText("");
359                                 _aveSpeedLabel.setText("");
360                         }
361                         String altUnitsLabel = getAltitudeUnitsLabel(selection.getAltitudeFormat());
362                         IntegerRange altRange = selection.getAltitudeRange();
363                         if (altRange.getMinimum() >= 0 && altRange.getMaximum() >= 0)
364                         {
365                                 _altRangeLabel.setText(LABEL_RANGE_ALTITUDE
366                                         + altRange.getMinimum() + altUnitsLabel + " "
367                                         + I18nManager.getText("details.altitude.to") + " "
368                                         + altRange.getMaximum() + altUnitsLabel);
369                                 _updownLabel.setText(LABEL_RANGE_CLIMB + selection.getClimb() + altUnitsLabel
370                                         + LABEL_RANGE_DESCENT + selection.getDescent() + altUnitsLabel);
371                         }
372                         else
373                         {
374                                 _altRangeLabel.setText("");
375                                 _updownLabel.setText("");
376                         }
377                 }
378                 // show photo details and thumbnail
379                 _photoDetailsPanel.setVisible(_trackInfo.getPhotoList().getNumPhotos() > 0);
380                 Photo currentPhoto = _trackInfo.getPhotoList().getPhoto(_trackInfo.getSelection().getCurrentPhotoIndex());
381                 if ((currentPoint == null || currentPoint.getPhoto() == null) && currentPhoto == null)
382                 {
383                         // no photo, hide details
384                         _photoLabel.setText(I18nManager.getText("details.nophoto"));
385                         _photoTimestampLabel.setText("");
386                         _photoConnectedLabel.setText("");
387                         _photoBearingLabel.setText("");
388                         _photoThumbnail.setVisible(false);
389                         _rotationButtons.setVisible(false);
390                 }
391                 else
392                 {
393                         if (currentPhoto == null) {currentPhoto = currentPoint.getPhoto();}
394                         _photoLabel.setText(I18nManager.getText("details.photofile") + ": " + currentPhoto.getName());
395                         _photoTimestampLabel.setText(currentPhoto.hasTimestamp()?(LABEL_POINT_TIMESTAMP + currentPhoto.getTimestamp().getText()):"");
396                         _photoConnectedLabel.setText(I18nManager.getText("details.media.connected") + ": "
397                                 + (currentPhoto.getCurrentStatus() == Photo.Status.NOT_CONNECTED ?
398                                         I18nManager.getText("dialog.about.no"):I18nManager.getText("dialog.about.yes")));
399                         if (currentPhoto.getBearing() >= 0.0 && currentPhoto.getBearing() <= 360.0)
400                         {
401                                 _photoBearingLabel.setText(I18nManager.getText("details.photo.bearing") + ": "
402                                         + (int) currentPhoto.getBearing() + " \u00B0");
403                         }
404                         else _photoBearingLabel.setText("");
405                         _photoThumbnail.setVisible(true);
406                         _photoThumbnail.setPhoto(currentPhoto);
407                         _rotationButtons.setVisible(true);
408                         if ((inUpdateType & DataSubscriber.PHOTOS_MODIFIED) > 0) {_photoThumbnail.refresh();}
409                 }
410                 _photoThumbnail.repaint();
411
412                 // audio details
413                 _audioDetailsPanel.setVisible(_trackInfo.getAudioList().getNumAudios() > 0);
414                 AudioClip currentAudio = _trackInfo.getAudioList().getAudio(_trackInfo.getSelection().getCurrentAudioIndex());
415                 if (currentAudio == null) {
416                         _audioLabel.setText(I18nManager.getText("details.noaudio"));
417                         _audioTimestampLabel.setText("");
418                         _audioLengthLabel.setText("");
419                         _audioConnectedLabel.setText("");
420                 }
421                 else
422                 {
423                         _audioLabel.setText(LABEL_AUDIO_FILE + currentAudio.getName());
424                         _audioTimestampLabel.setText(currentAudio.hasTimestamp()?(LABEL_POINT_TIMESTAMP + currentAudio.getTimestamp().getText()):"");
425                         int audioLength = currentAudio.getLengthInSeconds();
426                         _audioLengthLabel.setText(audioLength < 0?"":LABEL_RANGE_DURATION + DisplayUtils.buildDurationString(audioLength));
427                         _audioConnectedLabel.setText(I18nManager.getText("details.media.connected") + ": "
428                                 + (currentAudio.getCurrentStatus() == Photo.Status.NOT_CONNECTED ?
429                                         I18nManager.getText("dialog.about.no"):I18nManager.getText("dialog.about.yes")));
430                 }
431                 _playAudioPanel.setVisible(currentAudio != null);
432         }
433
434
435         /**
436          * Choose the appropriate altitude units label for the specified format
437          * @param inFormat altitude format
438          * @return language-sensitive string
439          */
440         private static String getAltitudeUnitsLabel(Altitude.Format inFormat)
441         {
442                 if (inFormat == LABEL_POINT_ALTITUDE_FORMAT && LABEL_POINT_ALTITUDE_UNITS != null)
443                         return LABEL_POINT_ALTITUDE_UNITS;
444                 LABEL_POINT_ALTITUDE_FORMAT = inFormat;
445                 if (inFormat == Altitude.Format.METRES)
446                         return " " + I18nManager.getText("units.metres.short");
447                 return " " + I18nManager.getText("units.feet.short");
448         }
449
450
451         /**
452          * Construct an appropriate coordinate label using the selected format
453          * @param inPrefix prefix of label
454          * @param inCoordinate coordinate
455          * @param inFormat index of format selection dropdown
456          * @return language-sensitive string
457          */
458         private static String makeCoordinateLabel(String inPrefix, Coordinate inCoordinate, int inFormat)
459         {
460                 String coord = null;
461                 switch (inFormat) {
462                         case 1: // degminsec
463                                 coord = inCoordinate.output(Coordinate.FORMAT_DEG_MIN_SEC); break;
464                         case 2: // degmin
465                                 coord = inCoordinate.output(Coordinate.FORMAT_DEG_MIN); break;
466                         case 3: // degrees
467                                 coord = inCoordinate.output(Coordinate.FORMAT_DEG); break;
468                         default: // just as it was
469                                 coord = inCoordinate.output(Coordinate.FORMAT_NONE);
470                 }
471                 // Fix broken degree signs (due to unicode mangling)
472                 final char brokenDeg = 65533;
473                 if (coord.indexOf(brokenDeg) >= 0) {
474                         coord = coord.replaceAll(String.valueOf(brokenDeg), "\u00B0");
475                 }
476                 return inPrefix + restrictDP(coord);
477         }
478
479
480         /**
481          * Format a number to a sensible precision
482          * @param inDist distance
483          * @return formatted String
484          */
485         private String roundedNumber(double inDist)
486         {
487                 // Set precision of formatter
488                 int numDigits = 0;
489                 if (inDist < 1.0)
490                         numDigits = 3;
491                 else if (inDist < 10.0)
492                         numDigits = 2;
493                 else if (inDist < 100.0)
494                         numDigits = 1;
495                 // set formatter
496                 _distanceFormatter.setMaximumFractionDigits(numDigits);
497                 _distanceFormatter.setMinimumFractionDigits(numDigits);
498                 return _distanceFormatter.format(inDist);
499         }
500
501         /**
502          * Restrict the given coordinate to a limited number of decimal places for display
503          * @param inCoord coordinate string
504          * @return chopped string
505          */
506         private static String restrictDP(String inCoord)
507         {
508                 final int DECIMAL_PLACES = 7;
509                 if (inCoord == null) return "";
510                 final int dotPos = Math.max(inCoord.lastIndexOf('.'), inCoord.lastIndexOf(','));
511                 if (dotPos >= 0) {
512                         final int chopPos = dotPos + DECIMAL_PLACES;
513                         if (chopPos < (inCoord.length()-1)) {
514                                 return inCoord.substring(0, chopPos);
515                         }
516                 }
517                 return inCoord;
518         }
519
520         /**
521          * Make a details subpanel
522          * @param inNameKey key to use for top label
523          * @param inFont font for top label
524          * @return panel with correct layout, label
525          */
526         private static JPanel makeDetailsPanel(String inNameKey, Font inFont)
527         {
528                 JPanel detailsPanel = new JPanel();
529                 detailsPanel.setLayout(new BoxLayout(detailsPanel, BoxLayout.Y_AXIS));
530                 detailsPanel.setBorder(BorderFactory.createCompoundBorder(
531                         BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(3, 3, 3, 3))
532                 );
533                 JLabel detailsLabel = new JLabel(I18nManager.getText(inNameKey));
534                 detailsLabel.setFont(inFont);
535                 detailsPanel.add(detailsLabel);
536                 return detailsPanel;
537         }
538
539         /**
540          * Create a little button for rotating the current photo
541          * @param inIcon icon to use (from IconManager)
542          * @param inFunction function to call (from FunctionLibrary)
543          * @return button object
544          */
545         private static JButton makeRotateButton(String inIcon, GenericFunction inFunction)
546         {
547                 JButton button = new JButton(IconManager.getImageIcon(inIcon));
548                 button.setToolTipText(I18nManager.getText(inFunction.getNameKey()));
549                 button.setMargin(new Insets(0, 2, 0, 2));
550                 button.addActionListener(new FunctionLauncher(inFunction));
551                 return button;
552         }
553 }