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