]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/gui/MenuManager.java
Add a settings entry to configure Earthdata account
[GpsPrune.git] / src / tim / prune / gui / MenuManager.java
1 package tim.prune.gui;
2
3 import java.awt.Toolkit;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import java.awt.event.KeyEvent;
7
8 import javax.swing.JButton;
9 import javax.swing.JCheckBoxMenuItem;
10 import javax.swing.JMenu;
11 import javax.swing.JMenuBar;
12 import javax.swing.JMenuItem;
13 import javax.swing.JToolBar;
14 import javax.swing.KeyStroke;
15
16 import tim.prune.App;
17 import tim.prune.DataSubscriber;
18 import tim.prune.FunctionLibrary;
19 import tim.prune.GenericFunction;
20 import tim.prune.I18nManager;
21 import tim.prune.UpdateMessageBroker;
22 import tim.prune.config.Config;
23 import tim.prune.data.AudioClip;
24 import tim.prune.data.DataPoint;
25 import tim.prune.data.Field;
26 import tim.prune.data.Photo;
27 import tim.prune.data.RecentFile;
28 import tim.prune.data.RecentFileList;
29 import tim.prune.data.Selection;
30 import tim.prune.data.Track;
31 import tim.prune.data.TrackInfo;
32 import tim.prune.function.ChooseSingleParameter;
33 import tim.prune.function.PasteCoordinateList;
34 import tim.prune.function.PasteCoordinates;
35 import tim.prune.function.PlusCodeFunction;
36 import tim.prune.function.SearchOpenCachingDeFunction;
37 import tim.prune.function.browser.UrlGenerator;
38 import tim.prune.function.browser.WebMapFunction;
39 import tim.prune.function.search.SearchMapillaryFunction;
40 import tim.prune.function.settings.SaveConfig;
41 import tim.prune.function.srtm.DownloadSrtmFunction;
42 import tim.prune.function.srtm.SrtmGl1Source;
43 import tim.prune.function.srtm.Srtm3Source;
44
45 /**
46  * Class to manage the menu bar and tool bar,
47  * including enabling and disabling the items
48  */
49 public class MenuManager implements DataSubscriber
50 {
51         private App _app = null;
52         private Track _track = null;
53         private Selection _selection = null;
54
55         // Menu items which need enabling/disabling
56         private JMenuItem _sendGpsItem = null;
57         private JMenuItem _saveItem = null;
58         private JMenuItem _exportKmlItem = null;
59         private JMenuItem _exportGpxItem = null;
60         private JMenuItem _exportPovItem = null;
61         private JMenuItem _exportImageItem = null;
62         private JMenu     _recentFileMenu = null;
63         private JMenuItem _undoItem = null;
64         private JMenuItem _clearUndoItem = null;
65         private JMenuItem _editPointItem = null;
66         private JMenuItem _editWaypointNameItem = null;
67         private JMenuItem _deletePointItem = null;
68         private JMenuItem _deleteRangeItem = null;
69         private JMenuItem _cropTrackItem = null;
70         private JMenuItem _compressItem = null;
71         private JMenuItem _markRectangleItem = null;
72         private JMenuItem _markUphillLiftsItem = null;
73         private JMenuItem _deleteMarkedPointsItem = null;
74         private JMenuItem _deleteByDateItem = null;
75         private JMenuItem _interpolateItem = null;
76         private JMenuItem _averageItem = null;
77         private JMenuItem _selectAllItem = null;
78         private JMenuItem _selectNoneItem = null;
79         private JMenuItem _selectSegmentItem = null;
80         private JMenuItem _selectStartItem = null;
81         private JMenuItem _selectEndItem = null;
82         private JMenuItem _findWaypointItem = null;
83         private JMenuItem _duplicatePointItem = null;
84         private JMenuItem _projectPointItem = null;
85         private JMenuItem _reverseItem = null;
86         private JMenuItem _addTimeOffsetItem = null;
87         private JMenuItem _addAltitudeOffsetItem = null;
88         private JMenuItem _mergeSegmentsItem = null;
89         private JMenuItem _rearrangeWaypointsItem = null;
90         private JMenuItem _splitSegmentsItem = null;
91         private JMenuItem _sewSegmentsItem = null;
92         private JMenuItem _createMarkerWaypointsItem = null;
93         private JMenuItem _cutAndMoveItem = null;
94         private JMenuItem _convertNamesToTimesItem = null;
95         private JMenuItem _deleteFieldValuesItem = null;
96         private JCheckBoxMenuItem _mapCheckbox = null;
97         private JMenuItem _show3dItem = null;
98         private JMenu     _browserMapMenu = null;
99         private JMenuItem _routingGraphHopperItem = null;
100         private JMenuItem _chartItem = null;
101         private JMenuItem _lookupSrtmItem = null;
102         private JMenu     _downloadSrtmMenu = null;
103         private JMenuItem _nearbyWikipediaItem = null;
104         private JMenuItem _nearbyOsmPoiItem = null;
105         private JMenuItem _showPeakfinderItem = null;
106         private JMenuItem _showGeohackItem = null;
107         private JMenuItem _searchOpencachingDeItem = null;
108         private JMenuItem _searchMapillaryItem = null;
109         private JMenuItem _downloadOsmItem = null;
110         private JMenuItem _getWeatherItem = null;
111         private JMenuItem _distanceItem = null;
112         private JMenuItem _viewFullDetailsItem = null;
113         private JMenuItem _estimateTimeItem = null;
114         private JMenuItem _learnEstimationParams = null;
115         private JMenuItem _autoplayTrack = null;
116         private JMenuItem _saveExifItem = null;
117         private JMenuItem _photoPopupItem = null;
118         private JMenuItem _selectNoPhotoItem = null;
119         private JMenuItem _connectPhotoItem = null;
120         private JMenuItem _removePhotoItem = null;
121         private JMenuItem _disconnectPhotoItem = null;
122         private JMenuItem _correlatePhotosItem = null;
123         private JMenuItem _rearrangePhotosItem = null;
124         private JMenuItem _rotatePhotoLeft = null;
125         private JMenuItem _rotatePhotoRight = null;
126         private JMenuItem _ignoreExifThumb = null;
127         private JMenuItem _connectAudioItem = null;
128         private JMenuItem _disconnectAudioItem = null;
129         private JMenuItem _removeAudioItem = null;
130         private JMenuItem _correlateAudiosItem = null;
131         private JMenuItem _selectNoAudioItem = null;
132         private JCheckBoxMenuItem _onlineCheckbox = null;
133         private JCheckBoxMenuItem _autosaveSettingsCheckbox = null;
134
135         // ActionListeners for reuse by menu and toolbar
136         private ActionListener _openFileAction = null;
137         private ActionListener _addPhotoAction = null;
138         private ActionListener _saveAction = null;
139         private ActionListener _undoAction = null;
140         private ActionListener _editPointAction = null;
141         private ActionListener _deletePointAction = null;
142         private ActionListener _selectStartAction = null;
143         private ActionListener _selectEndAction = null;
144
145         // Toolbar buttons which need enabling/disabling
146         private JButton _saveButton = null;
147         private JButton _undoButton = null;
148         private JButton _editPointButton = null;
149         private JButton _deletePointButton = null;
150         private JButton _deleteRangeButton = null;
151         private JButton _cutAndMoveButton = null;
152         private JButton _selectStartButton = null;
153         private JButton _selectEndButton = null;
154         private JButton _connectButton = null;
155
156         /** Array of key events */
157         private static final int[] KEY_EVENTS = {
158                 KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_C, KeyEvent.VK_D, KeyEvent.VK_E,
159                 KeyEvent.VK_F, KeyEvent.VK_G, KeyEvent.VK_H, KeyEvent.VK_I, KeyEvent.VK_J,
160                 KeyEvent.VK_K, KeyEvent.VK_L, KeyEvent.VK_M, KeyEvent.VK_N, KeyEvent.VK_O,
161                 KeyEvent.VK_P, KeyEvent.VK_Q, KeyEvent.VK_R, KeyEvent.VK_S, KeyEvent.VK_T,
162                 KeyEvent.VK_U, KeyEvent.VK_V, KeyEvent.VK_W, KeyEvent.VK_X, KeyEvent.VK_Y, KeyEvent.VK_Z};
163
164
165         /**
166          * Constructor
167          * @param inApp application to call on menu actions
168          * @param inTrackInfo track info object
169          */
170         public MenuManager(App inApp, TrackInfo inTrackInfo)
171         {
172                 _app = inApp;
173                 _track = inTrackInfo.getTrack();
174                 _selection = inTrackInfo.getSelection();
175         }
176
177
178         /**
179          * Create a JMenuBar containing all menu items
180          * @return JMenuBar
181          */
182         public JMenuBar createMenuBar()
183         {
184                 JMenuBar menubar = new JMenuBar();
185                 JMenu fileMenu = new JMenu(I18nManager.getText("menu.file"));
186                 setAltKey(fileMenu, "altkey.menu.file");
187                 // Open file
188                 JMenuItem openMenuItem = new JMenuItem(I18nManager.getText("function.open"));
189                 setShortcut(openMenuItem, "shortcut.menu.file.open");
190                 _openFileAction = new ActionListener() {
191                         public void actionPerformed(ActionEvent e) {
192                                 _app.openFile();
193                         }
194                 };
195                 openMenuItem.addActionListener(_openFileAction);
196                 fileMenu.add(openMenuItem);
197                 // import through gpsbabel
198                 JMenuItem importBabelItem = makeMenuItem(FunctionLibrary.FUNCTION_IMPORTBABEL);
199                 fileMenu.add(importBabelItem);
200                 // Add photos
201                 JMenuItem addPhotosMenuItem = new JMenuItem(I18nManager.getText("menu.file.addphotos"));
202                 _addPhotoAction = new ActionListener() {
203                         public void actionPerformed(ActionEvent e) {
204                                 _app.addPhotos();
205                         }
206                 };
207                 addPhotosMenuItem.addActionListener(_addPhotoAction);
208                 fileMenu.add(addPhotosMenuItem);
209                 // Add audio clips
210                 JMenuItem addAudioMenuItem = makeMenuItem(FunctionLibrary.FUNCTION_LOAD_AUDIO);
211                 fileMenu.add(addAudioMenuItem);
212                 // recent files
213                 _recentFileMenu = new JMenu(I18nManager.getText("menu.file.recentfiles"));
214                 _recentFileMenu.setEnabled(false);
215                 fileMenu.add(_recentFileMenu);
216                 fileMenu.addSeparator();
217                 // Load from GPS
218                 JMenuItem loadFromGpsMenuItem = makeMenuItem(FunctionLibrary.FUNCTION_GPSLOAD);
219                 setShortcut(loadFromGpsMenuItem, "shortcut.menu.file.load");
220                 fileMenu.add(loadFromGpsMenuItem);
221                 // Send to GPS
222                 _sendGpsItem = makeMenuItem(FunctionLibrary.FUNCTION_GPSSAVE, false);
223                 fileMenu.add(_sendGpsItem);
224                 fileMenu.addSeparator();
225                 // Save
226                 _saveItem = new JMenuItem(I18nManager.getText("menu.file.save"), KeyEvent.VK_S);
227                 setShortcut(_saveItem, "shortcut.menu.file.save");
228                 _saveAction = new ActionListener() {
229                         public void actionPerformed(ActionEvent e) {
230                                 _app.saveFile();
231                         }
232                 };
233                 _saveItem.addActionListener(_saveAction);
234                 _saveItem.setEnabled(false);
235                 fileMenu.add(_saveItem);
236                 // Export - Kml
237                 _exportKmlItem = makeMenuItem(FunctionLibrary.FUNCTION_KMLEXPORT, false);
238                 fileMenu.add(_exportKmlItem);
239                 // Gpx
240                 _exportGpxItem = makeMenuItem(FunctionLibrary.FUNCTION_GPXEXPORT, false);
241                 fileMenu.add(_exportGpxItem);
242                 // Pov
243                 _exportPovItem = makeMenuItem(FunctionLibrary.FUNCTION_POVEXPORT, false);
244                 fileMenu.add(_exportPovItem);
245                 // Image
246                 _exportImageItem = makeMenuItem(FunctionLibrary.FUNCTION_IMAGEEXPORT, false);
247                 fileMenu.add(_exportImageItem);
248                 fileMenu.addSeparator();
249                 // Exit
250                 JMenuItem exitMenuItem = new JMenuItem(I18nManager.getText("menu.file.exit"));
251                 exitMenuItem.addActionListener(new ActionListener() {
252                         public void actionPerformed(ActionEvent e) {
253                                 _app.exit();
254                         }
255                 });
256                 fileMenu.add(exitMenuItem);
257                 menubar.add(fileMenu);
258
259                 ////////////////////////////////////////////////////
260                 // Online menu
261                 JMenu onlineMenu = new JMenu(I18nManager.getText("menu.online"));
262                 setAltKey(onlineMenu, "altkey.menu.online");
263                 // SRTM
264                 _lookupSrtmItem = makeMenuItem(FunctionLibrary.FUNCTION_LOOKUP_SRTM, false);
265                 onlineMenu.add(_lookupSrtmItem);
266                 // Download SRTM sub-menu
267                 _downloadSrtmMenu = new JMenu(I18nManager.getText("function.downloadsrtm"));
268                 _downloadSrtmMenu.setEnabled(false);
269                 JMenuItem downloadStrmGl1Item = makeMenuItem(new DownloadSrtmFunction(_app, new SrtmGl1Source()));
270                 _downloadSrtmMenu.add(downloadStrmGl1Item);
271                 JMenuItem downloadStrm3Item = makeMenuItem(new DownloadSrtmFunction(_app, new Srtm3Source()));
272                 _downloadSrtmMenu.add(downloadStrm3Item);
273                 onlineMenu.add(_downloadSrtmMenu);
274
275                 onlineMenu.addSeparator();
276                 // browser submenu
277                 _browserMapMenu = new JMenu(I18nManager.getText("menu.view.browser"));
278                 _browserMapMenu.setEnabled(false);
279                 JMenuItem googleMapsItem = makeMenuItem(new WebMapFunction(_app, UrlGenerator.WebService.MAP_SOURCE_GOOGLE, "menu.view.browser.google"));
280                 _browserMapMenu.add(googleMapsItem);
281                 JMenuItem openMapsItem = makeMenuItem(new WebMapFunction(_app, UrlGenerator.WebService.MAP_SOURCE_OSM, "menu.view.browser.openstreetmap"));
282                 _browserMapMenu.add(openMapsItem);
283                 JMenuItem mapquestMapsItem = makeMenuItem(new WebMapFunction(_app, UrlGenerator.WebService.MAP_SOURCE_MAPQUEST, "menu.view.browser.mapquest"));
284                 _browserMapMenu.add(mapquestMapsItem);
285                 JMenuItem yahooMapsItem = makeMenuItem(new WebMapFunction(_app, UrlGenerator.WebService.MAP_SOURCE_YAHOO, "menu.view.browser.yahoo"));
286                 _browserMapMenu.add(yahooMapsItem);
287                 JMenuItem bingMapsItem = makeMenuItem(new WebMapFunction(_app, UrlGenerator.WebService.MAP_SOURCE_BING, "menu.view.browser.bing"));
288                 _browserMapMenu.add(bingMapsItem);
289                 JMenuItem inlineMapItem = makeMenuItem(new WebMapFunction(_app, UrlGenerator.WebService.MAP_SOURCE_INLINESKATE, "menu.view.browser.inlinemap"));
290                 _browserMapMenu.add(inlineMapItem);
291                 _routingGraphHopperItem = makeMenuItem(new WebMapFunction(_app, UrlGenerator.WebService.MAP_SOURCE_GRAPHHOPPER, "menu.view.browser.graphhopper"));
292                 _browserMapMenu.add(_routingGraphHopperItem);
293                 onlineMenu.add(_browserMapMenu);
294                 // wikipedia
295                 _nearbyWikipediaItem = makeMenuItem(FunctionLibrary.FUNCTION_NEARBY_WIKIPEDIA, false);
296                 onlineMenu.add(_nearbyWikipediaItem);
297                 JMenuItem searchWikipediaNamesItem = makeMenuItem(FunctionLibrary.FUNCTION_SEARCH_WIKIPEDIA);
298                 onlineMenu.add(searchWikipediaNamesItem);
299                 _nearbyOsmPoiItem = makeMenuItem(FunctionLibrary.FUNCTION_SEARCH_OSMPOIS);
300                 onlineMenu.add(_nearbyOsmPoiItem);
301                 _showPeakfinderItem = makeMenuItem(new WebMapFunction(_app, UrlGenerator.WebService.MAP_SOURCE_PEAKFINDER, "webservice.peakfinder"), false);
302                 onlineMenu.add(_showPeakfinderItem);
303                 _showGeohackItem = makeMenuItem(new WebMapFunction(_app, UrlGenerator.WebService.MAP_SOURCE_GEOHACK, "webservice.geohack"), false);
304                 onlineMenu.add(_showGeohackItem);
305
306                 onlineMenu.addSeparator();
307                 _searchOpencachingDeItem = makeMenuItem(new SearchOpenCachingDeFunction(_app), false);
308                 onlineMenu.add(_searchOpencachingDeItem);
309                 _searchMapillaryItem = makeMenuItem(new SearchMapillaryFunction(_app), false);
310                 onlineMenu.add(_searchMapillaryItem);
311                 _downloadOsmItem = makeMenuItem(FunctionLibrary.FUNCTION_DOWNLOAD_OSM, false);
312                 onlineMenu.add(_downloadOsmItem);
313                 _getWeatherItem = makeMenuItem(FunctionLibrary.FUNCTION_GET_WEATHER_FORECAST, false);
314                 onlineMenu.add(_getWeatherItem);
315                 menubar.add(onlineMenu);
316
317                 ////////////////////////////////////////////////////
318                 // Track menu
319                 JMenu trackMenu = new JMenu(I18nManager.getText("menu.track"));
320                 setAltKey(trackMenu, "altkey.menu.track");
321                 _undoItem = new JMenuItem(I18nManager.getText("menu.track.undo"));
322                 setShortcut(_undoItem, "shortcut.menu.track.undo");
323                 _undoAction = new ActionListener() {
324                         public void actionPerformed(ActionEvent e) {
325                                 _app.beginUndo();
326                         }
327                 };
328                 _undoItem.addActionListener(_undoAction);
329                 _undoItem.setEnabled(false);
330                 trackMenu.add(_undoItem);
331                 _clearUndoItem = new JMenuItem(I18nManager.getText("menu.track.clearundo"));
332                 _clearUndoItem.addActionListener(new ActionListener() {
333                         public void actionPerformed(ActionEvent e) {
334                                 _app.clearUndo();
335                         }
336                 });
337                 _clearUndoItem.setEnabled(false);
338                 trackMenu.add(_clearUndoItem);
339                 trackMenu.addSeparator();
340                 _compressItem = makeMenuItem(FunctionLibrary.FUNCTION_COMPRESS, false);
341                 setShortcut(_compressItem, "shortcut.menu.track.compress");
342                 trackMenu.add(_compressItem);
343                 _markRectangleItem = new JMenuItem(I18nManager.getText("menu.track.markrectangle"));
344                 _markRectangleItem.addActionListener(new ActionListener() {
345                         public void actionPerformed(ActionEvent e) {
346                                 _app.setCurrentMode(App.AppMode.DRAWRECT);
347                                 UpdateMessageBroker.informSubscribers();
348                         }
349                 });
350                 _markRectangleItem.setEnabled(false);
351                 trackMenu.add(_markRectangleItem);
352                 _markUphillLiftsItem = makeMenuItem(FunctionLibrary.FUNCTION_MARK_LIFTS, false);
353                 trackMenu.add(_markUphillLiftsItem);
354                 _deleteMarkedPointsItem = makeMenuItem(FunctionLibrary.FUNCTION_DELETE_MARKED_POINTS, false);
355                 trackMenu.add(_deleteMarkedPointsItem);
356                 _deleteByDateItem = makeMenuItem(FunctionLibrary.FUNCTION_DELETE_BY_DATE, false);
357                 trackMenu.add(_deleteByDateItem);
358                 trackMenu.addSeparator();
359                 // Rearrange waypoints
360                 _rearrangeWaypointsItem = makeMenuItem(FunctionLibrary.FUNCTION_REARRANGE_WAYPOINTS, false);
361                 trackMenu.add(_rearrangeWaypointsItem);
362                 // Split track segments
363                 _splitSegmentsItem = makeMenuItem(FunctionLibrary.FUNCTION_SPLIT_SEGMENTS, false);
364                 trackMenu.add(_splitSegmentsItem);
365                 // Sew track segments
366                 _sewSegmentsItem = makeMenuItem(FunctionLibrary.FUNCTION_SEW_SEGMENTS, false);
367                 trackMenu.add(_sewSegmentsItem);
368                 // Create marker waypoints
369                 _createMarkerWaypointsItem = makeMenuItem(FunctionLibrary.FUNCTION_CREATE_MARKER_WAYPOINTS, false);
370                 trackMenu.add(_createMarkerWaypointsItem);
371                 trackMenu.addSeparator();
372                 _learnEstimationParams = makeMenuItem(FunctionLibrary.FUNCTION_LEARN_ESTIMATION_PARAMS, false);
373                 trackMenu.add(_learnEstimationParams);
374                 menubar.add(trackMenu);
375
376                 // Range menu
377                 JMenu rangeMenu = new JMenu(I18nManager.getText("menu.range"));
378                 setAltKey(rangeMenu, "altkey.menu.range");
379                 _selectAllItem = new JMenuItem(I18nManager.getText("menu.range.all"));
380                 setShortcut(_selectAllItem, "shortcut.menu.range.all");
381                 _selectAllItem.setEnabled(false);
382                 _selectAllItem.addActionListener(new ActionListener() {
383                         public void actionPerformed(ActionEvent e) {
384                                 _selection.selectRange(0, _track.getNumPoints()-1);
385                         }
386                 });
387                 rangeMenu.add(_selectAllItem);
388                 _selectNoneItem = new JMenuItem(I18nManager.getText("menu.range.none"));
389                 _selectNoneItem.setEnabled(false);
390                 _selectNoneItem.addActionListener(new ActionListener() {
391                         public void actionPerformed(ActionEvent e) {
392                                 _app.selectNone();
393                         }
394                 });
395                 rangeMenu.add(_selectNoneItem);
396                 _selectSegmentItem = makeMenuItem(FunctionLibrary.FUNCTION_SELECT_SEGMENT);
397                 rangeMenu.add(_selectSegmentItem);
398                 rangeMenu.addSeparator();
399                 _selectStartItem = new JMenuItem(I18nManager.getText("menu.range.start"));
400                 _selectStartItem.setEnabled(false);
401                 _selectStartAction = new ActionListener() {
402                         public void actionPerformed(ActionEvent e) {
403                                 _selection.selectRangeStart();
404                         }
405                 };
406                 _selectStartItem.addActionListener(_selectStartAction);
407                 rangeMenu.add(_selectStartItem);
408                 _selectEndItem = new JMenuItem(I18nManager.getText("menu.range.end"));
409                 _selectEndItem.setEnabled(false);
410                 _selectEndAction = new ActionListener() {
411                         public void actionPerformed(ActionEvent e) {
412                                 _selection.selectRangeEnd();
413                         }
414                 };
415                 _selectEndItem.addActionListener(_selectEndAction);
416                 rangeMenu.add(_selectEndItem);
417                 rangeMenu.addSeparator();
418                 _deleteRangeItem = makeMenuItem(FunctionLibrary.FUNCTION_DELETE_RANGE, false);
419                 rangeMenu.add(_deleteRangeItem);
420                 _cropTrackItem = makeMenuItem(FunctionLibrary.FUNCTION_CROP_TRACK, false);
421                 rangeMenu.add(_cropTrackItem);
422                 _reverseItem = new JMenuItem(I18nManager.getText("menu.range.reverse"));
423                 _reverseItem.addActionListener(new ActionListener() {
424                         public void actionPerformed(ActionEvent e) {
425                                 _app.reverseRange();
426                         }
427                 });
428                 _reverseItem.setEnabled(false);
429                 rangeMenu.add(_reverseItem);
430                 _addTimeOffsetItem = makeMenuItem(FunctionLibrary.FUNCTION_ADD_TIME_OFFSET, false);
431                 rangeMenu.add(_addTimeOffsetItem);
432                 _addAltitudeOffsetItem = makeMenuItem(FunctionLibrary.FUNCTION_ADD_ALTITUDE_OFFSET, false);
433                 rangeMenu.add(_addAltitudeOffsetItem);
434                 _mergeSegmentsItem = new JMenuItem(I18nManager.getText("menu.range.mergetracksegments"));
435                 _mergeSegmentsItem.addActionListener(new ActionListener() {
436                         public void actionPerformed(ActionEvent e) {
437                                 _app.mergeTrackSegments();
438                         }
439                 });
440                 _mergeSegmentsItem.setEnabled(false);
441                 rangeMenu.add(_mergeSegmentsItem);
442                 _deleteFieldValuesItem = makeMenuItem(FunctionLibrary.FUNCTION_DELETE_FIELD_VALUES, false);
443                 rangeMenu.add(_deleteFieldValuesItem);
444                 rangeMenu.addSeparator();
445                 _interpolateItem = makeMenuItem(new ChooseSingleParameter(_app, FunctionLibrary.FUNCTION_INTERPOLATE), false);
446                 rangeMenu.add(_interpolateItem);
447                 _averageItem = new JMenuItem(I18nManager.getText("menu.range.average"));
448                 _averageItem.addActionListener(new ActionListener() {
449                         public void actionPerformed(ActionEvent e) {
450                                 _app.averageSelection();
451                         }
452                 });
453                 _averageItem.setEnabled(false);
454                 rangeMenu.add(_averageItem);
455                 _cutAndMoveItem = new JMenuItem(I18nManager.getText("menu.range.cutandmove"));
456                 _cutAndMoveItem.addActionListener(new ActionListener() {
457                         public void actionPerformed(ActionEvent e)
458                         {
459                                 _app.cutAndMoveSelection();
460                         }
461                 });
462                 _cutAndMoveItem.setEnabled(false);
463                 rangeMenu.add(_cutAndMoveItem);
464                 _convertNamesToTimesItem = makeMenuItem(FunctionLibrary.FUNCTION_CONVERT_NAMES_TO_TIMES, false);
465                 rangeMenu.add(_convertNamesToTimesItem);
466                 menubar.add(rangeMenu);
467
468                 // Point menu
469                 JMenu pointMenu = new JMenu(I18nManager.getText("menu.point"));
470                 setAltKey(pointMenu, "altkey.menu.point");
471                 _editPointItem = new JMenuItem(I18nManager.getText("menu.point.editpoint"));
472                 _editPointAction = new ActionListener() {
473                         public void actionPerformed(ActionEvent e) {
474                                 _app.editCurrentPoint();
475                         }
476                 };
477                 _editPointItem.addActionListener(_editPointAction);
478                 _editPointItem.setEnabled(false);
479                 setShortcut(_editPointItem, "shortcut.menu.point.edit");
480                 pointMenu.add(_editPointItem);
481                 _editWaypointNameItem = makeMenuItem(FunctionLibrary.FUNCTION_EDIT_WAYPOINT_NAME, false);
482                 pointMenu.add(_editWaypointNameItem);
483                 _deletePointItem = new JMenuItem(I18nManager.getText("menu.point.deletepoint"));
484                 _deletePointAction = new ActionListener() {
485                         public void actionPerformed(ActionEvent e) {
486                                 _app.deleteCurrentPoint();
487                         }
488                 };
489                 _deletePointItem.addActionListener(_deletePointAction);
490                 _deletePointItem.setEnabled(false);
491                 _deletePointItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
492                 pointMenu.add(_deletePointItem);
493                 pointMenu.addSeparator();
494                 // find a waypoint
495                 _findWaypointItem = makeMenuItem(FunctionLibrary.FUNCTION_FIND_WAYPOINT, false);
496                 pointMenu.add(_findWaypointItem);
497                 // duplicate current point
498                 _duplicatePointItem = makeMenuItem(FunctionLibrary.FUNCTION_DUPLICATE_POINT, false);
499                 pointMenu.add(_duplicatePointItem);
500                 // project current point
501                 _projectPointItem = makeMenuItem(FunctionLibrary.FUNCTION_PROJECT_POINT, false);
502                 pointMenu.add(_projectPointItem);
503                 // paste coordinates function
504                 JMenuItem pasteCoordsItem = makeMenuItem(new PasteCoordinates(_app));
505                 pointMenu.add(pasteCoordsItem);
506                 JMenuItem pasteCoordsListItem = makeMenuItem(new PasteCoordinateList(_app));
507                 pointMenu.add(pasteCoordsListItem);
508                 // pluscodes function
509                 JMenuItem plusCodeItem = makeMenuItem(new PlusCodeFunction(_app));
510                 pointMenu.add(plusCodeItem);
511                 menubar.add(pointMenu);
512
513                 // Add view menu
514                 JMenu viewMenu = new JMenu(I18nManager.getText("menu.view"));
515                 setAltKey(viewMenu, "altkey.menu.view");
516                 // Turn map display on/off
517                 _mapCheckbox = new JCheckBoxMenuItem(
518                         I18nManager.getText("menu.map.showmap"), false);
519                 _mapCheckbox.addActionListener(new ActionListener() {
520                         public void actionPerformed(ActionEvent e) {
521                                 Config.setConfigBoolean(Config.KEY_SHOW_MAP, _mapCheckbox.isSelected());
522                                 UpdateMessageBroker.informSubscribers(MAPSERVER_CHANGED);
523                         }
524                 });
525                 viewMenu.add(_mapCheckbox);
526                 // Turn off the sidebars
527                 JCheckBoxMenuItem sidebarsCheckbox = new JCheckBoxMenuItem(I18nManager.getText("menu.view.showsidebars"));
528                 sidebarsCheckbox.setSelected(true);
529                 sidebarsCheckbox.addActionListener(new ActionListener() {
530                         public void actionPerformed(ActionEvent e) {
531                                 _app.toggleSidebars();
532                         }
533                 });
534                 sidebarsCheckbox.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0)); // shortcut F11
535                 viewMenu.add(sidebarsCheckbox);
536                 // 3d
537                 _show3dItem = makeMenuItem(FunctionLibrary.FUNCTION_3D, false);
538                 viewMenu.add(_show3dItem);
539                 // Charts
540                 _chartItem = makeMenuItem(FunctionLibrary.FUNCTION_CHARTS, false);
541                 viewMenu.add(_chartItem);
542                 viewMenu.addSeparator();
543                 // Distances
544                 _distanceItem = makeMenuItem(FunctionLibrary.FUNCTION_DISTANCES, false);
545                 viewMenu.add(_distanceItem);
546                 // full range details
547                 _viewFullDetailsItem = makeMenuItem(FunctionLibrary.FUNCTION_FULL_DETAILS, false);
548                 viewMenu.add(_viewFullDetailsItem);
549                 // estimate time
550                 _estimateTimeItem = makeMenuItem(FunctionLibrary.FUNCTION_ESTIMATE_TIME, false);
551                 viewMenu.add(_estimateTimeItem);
552                 viewMenu.addSeparator();
553                 // autoplay
554                 _autoplayTrack = makeMenuItem(FunctionLibrary.FUNCTION_AUTOPLAY_TRACK, false);
555                 viewMenu.add(_autoplayTrack);
556                 menubar.add(viewMenu);
557
558                 // Add photo menu
559                 JMenu photoMenu = new JMenu(I18nManager.getText("menu.photo"));
560                 setAltKey(photoMenu, "altkey.menu.photo");
561                 addPhotosMenuItem = new JMenuItem(I18nManager.getText("menu.file.addphotos"));
562                 addPhotosMenuItem.addActionListener(_addPhotoAction);
563                 photoMenu.add(addPhotosMenuItem);
564                 _saveExifItem = new JMenuItem(I18nManager.getText("menu.photo.saveexif"));
565                 _saveExifItem.addActionListener(new ActionListener() {
566                         public void actionPerformed(ActionEvent e) {
567                                 _app.saveExif();
568                         }
569                 });
570                 _saveExifItem.setEnabled(false);
571                 photoMenu.add(_saveExifItem);
572                 // Deselect current photo
573                 _selectNoPhotoItem = new JMenuItem(I18nManager.getText("menu.range.none"));
574                 _selectNoPhotoItem.setEnabled(false);
575                 _selectNoPhotoItem.addActionListener(new ActionListener() {
576                         public void actionPerformed(ActionEvent e) {
577                                 _app.getTrackInfo().selectPhoto(-1);
578                         }
579                 });
580                 photoMenu.add(_selectNoPhotoItem);
581                 photoMenu.addSeparator();
582                 _connectPhotoItem = makeMenuItem(FunctionLibrary.FUNCTION_CONNECT_TO_POINT, false);
583                 photoMenu.add(_connectPhotoItem);
584                 // disconnect photo
585                 _disconnectPhotoItem = makeMenuItem(FunctionLibrary.FUNCTION_DISCONNECT_PHOTO, false);
586                 photoMenu.add(_disconnectPhotoItem);
587                 _removePhotoItem = makeMenuItem(FunctionLibrary.FUNCTION_REMOVE_PHOTO, false);
588                 photoMenu.add(_removePhotoItem);
589                 // Rotate current photo
590                 _rotatePhotoLeft = makeMenuItem(FunctionLibrary.FUNCTION_ROTATE_PHOTO_LEFT, false);
591                 photoMenu.add(_rotatePhotoLeft);
592                 _rotatePhotoRight = makeMenuItem(FunctionLibrary.FUNCTION_ROTATE_PHOTO_RIGHT, false);
593                 photoMenu.add(_rotatePhotoRight);
594                 // Show photo popup
595                 _photoPopupItem = makeMenuItem(FunctionLibrary.FUNCTION_PHOTO_POPUP, false);
596                 photoMenu.add(_photoPopupItem);
597                 _ignoreExifThumb = makeMenuItem(FunctionLibrary.FUNCTION_IGNORE_EXIF_THUMB, false);
598                 photoMenu.add(_ignoreExifThumb);
599                 photoMenu.addSeparator();
600                 // correlate all photos
601                 _correlatePhotosItem = makeMenuItem(FunctionLibrary.FUNCTION_CORRELATE_PHOTOS, false);
602                 photoMenu.add(_correlatePhotosItem);
603                 // rearrange photo points
604                 _rearrangePhotosItem = makeMenuItem(FunctionLibrary.FUNCTION_REARRANGE_PHOTOS, false);
605                 photoMenu.add(_rearrangePhotosItem);
606                 menubar.add(photoMenu);
607
608                 // Audio menu
609                 JMenu audioMenu = new JMenu(I18nManager.getText("menu.audio"));
610                 setAltKey(audioMenu, "altkey.menu.audio");
611                 addAudioMenuItem = makeMenuItem(FunctionLibrary.FUNCTION_LOAD_AUDIO);
612                 audioMenu.add(addAudioMenuItem);
613                 _selectNoAudioItem = new JMenuItem(I18nManager.getText("menu.range.none"));
614                 _selectNoAudioItem.setEnabled(false);
615                 _selectNoAudioItem.addActionListener(new ActionListener() {
616                         public void actionPerformed(ActionEvent e) {
617                                 _app.getTrackInfo().selectAudio(-1);
618                         }
619                 });
620                 audioMenu.add(_selectNoAudioItem);
621                 audioMenu.addSeparator();
622                 // connect audio
623                 _connectAudioItem = makeMenuItem(FunctionLibrary.FUNCTION_CONNECT_TO_POINT, false);
624                 audioMenu.add(_connectAudioItem);
625                 // Disconnect current audio clip
626                 _disconnectAudioItem = makeMenuItem(FunctionLibrary.FUNCTION_DISCONNECT_AUDIO, false);
627                 audioMenu.add(_disconnectAudioItem);
628                 // Remove current audio clip
629                 _removeAudioItem = makeMenuItem(FunctionLibrary.FUNCTION_REMOVE_AUDIO, false);
630                 audioMenu.add(_removeAudioItem);
631                 audioMenu.addSeparator();
632                 // Correlate audio clips
633                 _correlateAudiosItem = makeMenuItem(FunctionLibrary.FUNCTION_CORRELATE_AUDIOS, false);
634                 audioMenu.add(_correlateAudiosItem);
635                 menubar.add(audioMenu);
636
637                 // Settings menu
638                 JMenu settingsMenu = new JMenu(I18nManager.getText("menu.settings"));
639                 setAltKey(settingsMenu, "altkey.menu.settings");
640                 // Set the map background
641                 JMenuItem mapBgItem = makeMenuItem(FunctionLibrary.FUNCTION_SET_MAP_BG);
642                 settingsMenu.add(mapBgItem);
643                 _onlineCheckbox = new JCheckBoxMenuItem(I18nManager.getText("menu.settings.onlinemode"));
644                 _onlineCheckbox.setSelected(Config.getConfigBoolean(Config.KEY_ONLINE_MODE));
645                 _onlineCheckbox.addActionListener(new ActionListener() {
646                         public void actionPerformed(ActionEvent e) {
647                                 boolean isOnline = _onlineCheckbox.isSelected();
648                                 Config.setConfigBoolean(Config.KEY_ONLINE_MODE, isOnline);
649                                 if (isOnline) {UpdateMessageBroker.informSubscribers();}
650                         }
651                 });
652                 settingsMenu.add(_onlineCheckbox);
653                 settingsMenu.add(makeMenuItem(FunctionLibrary.FUNCTION_SET_DISK_CACHE));
654                 settingsMenu.addSeparator();
655                 // Set program paths
656                 settingsMenu.add(makeMenuItem(FunctionLibrary.FUNCTION_SET_PATHS));
657                 // Set colours
658                 settingsMenu.add(makeMenuItem(FunctionLibrary.FUNCTION_SET_COLOURS));
659                 // display settings
660                 JMenuItem setDisplaySettingsItem = makeMenuItem(FunctionLibrary.FUNCTION_SET_DISPLAY_SETTINGS);
661                 settingsMenu.add(setDisplaySettingsItem);
662                 // Set language
663                 settingsMenu.add(makeMenuItem(FunctionLibrary.FUNCTION_SET_LANGUAGE));
664                 // Set altitude tolerance
665                 settingsMenu.add(makeMenuItem(new ChooseSingleParameter(_app, FunctionLibrary.FUNCTION_SET_ALTITUDE_TOLERANCE)));
666                 // Set timezone
667                 settingsMenu.add(makeMenuItem(FunctionLibrary.FUNCTION_SET_TIMEZONE));
668                 // Set Earthdata authentication
669                 settingsMenu.add(makeMenuItem(FunctionLibrary.FUNCTION_SET_EARTHDATA_AUTH));
670                 settingsMenu.addSeparator();
671                 // Save configuration
672                 settingsMenu.add(makeMenuItem(FunctionLibrary.FUNCTION_SAVECONFIG));
673                 _autosaveSettingsCheckbox = new JCheckBoxMenuItem(
674                         I18nManager.getText("menu.settings.autosave"), false);
675                 _autosaveSettingsCheckbox.setSelected(Config.getConfigBoolean(Config.KEY_AUTOSAVE_SETTINGS));
676                 _autosaveSettingsCheckbox.addActionListener(new ActionListener() {
677                         public void actionPerformed(ActionEvent e) {
678                                 final boolean autosaveOn = _autosaveSettingsCheckbox.isSelected();
679                                 Config.setConfigBoolean(Config.KEY_AUTOSAVE_SETTINGS, autosaveOn);
680                                 // Maybe want to save config?
681                                 new SaveConfig(_app).autosaveSwitched(autosaveOn);
682                         }
683                 });
684                 settingsMenu.add(_autosaveSettingsCheckbox);
685                 menubar.add(settingsMenu);
686
687                 // Help menu
688                 JMenu helpMenu = new JMenu(I18nManager.getText("menu.help"));
689                 setAltKey(helpMenu, "altkey.menu.help");
690                 JMenuItem helpItem = makeMenuItem(FunctionLibrary.FUNCTION_HELP);
691                 setShortcut(helpItem, "shortcut.menu.help.help");
692                 helpMenu.add(helpItem);
693                 helpMenu.add(makeMenuItem(FunctionLibrary.FUNCTION_SHOW_KEYS));
694                 helpMenu.add(makeMenuItem(FunctionLibrary.FUNCTION_ABOUT));
695                 helpMenu.add(makeMenuItem(FunctionLibrary.FUNCTION_CHECK_VERSION));
696                 menubar.add(helpMenu);
697
698                 return menubar;
699         }
700
701         /**
702          * Convenience method for making a menu item using a function
703          * @param inFunction function
704          * @param inEnabled flag to specify initial enabled state
705          * @return menu item using localized name of function
706          */
707         private static JMenuItem makeMenuItem(GenericFunction inFunction, boolean inEnabled)
708         {
709                 JMenuItem item = makeMenuItem(inFunction);
710                 item.setEnabled(inEnabled);
711                 return item;
712         }
713
714         /**
715          * Convenience method for making a menu item using a function
716          * @param inFunction function
717          * @return menu item using localized name of function
718          */
719         private static JMenuItem makeMenuItem(GenericFunction inFunction)
720         {
721                 JMenuItem item = new JMenuItem(I18nManager.getText(inFunction.getNameKey()));
722                 item.addActionListener(new FunctionLauncher(inFunction));
723                 return item;
724         }
725
726         /**
727          * Set the alt key for the given menu
728          * @param inMenu menu to set
729          * @param inKey key to lookup to get language-sensitive altkey
730          */
731         private static void setAltKey(JMenu inMenu, String inKey)
732         {
733                 // Lookup the key in the properties
734                 String altKey = I18nManager.getText(inKey);
735                 if (altKey != null && altKey.length() == 1)
736                 {
737                         int code = altKey.charAt(0) - 'A';
738                         if (code >= 0 && code < 26)
739                         {
740                                 // Found a valid code between A and Z
741                                 inMenu.setMnemonic(KEY_EVENTS[code]);
742                         }
743                 }
744         }
745
746         /**
747          * Set the shortcut key for the given menu item
748          * @param inMenuItem menu item to set
749          * @param inKey key to lookup to get language-sensitive shortcut
750          */
751         private static void setShortcut(JMenuItem inMenuItem, String inKey)
752         {
753                 // Lookup the key in the properties
754                 String altKey = I18nManager.getText(inKey);
755                 if (altKey != null && altKey.length() == 1)
756                 {
757                         int code = altKey.charAt(0) - 'A';
758                         if (code >= 0 && code < 26)
759                         {
760                                 // Found a valid code between A and Z
761                                 inMenuItem.setAccelerator(KeyStroke.getKeyStroke(KEY_EVENTS[code],
762                                         Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
763                                 // use platform-specific key mask so Ctrl on Linux/Win, Clover on Mac
764                         }
765                 }
766         }
767
768         /**
769          * Create a JToolBar containing all toolbar buttons
770          * @return toolbar containing buttons
771          */
772         public JToolBar createToolBar()
773         {
774                 JToolBar toolbar = new JToolBar();
775                 // Add text file
776                 JButton openFileButton = new JButton(IconManager.getImageIcon(IconManager.OPEN_FILE));
777                 openFileButton.setToolTipText(I18nManager.getText("function.open"));
778                 openFileButton.addActionListener(_openFileAction);
779                 toolbar.add(openFileButton);
780                 // Add photo
781                 JButton addPhotoButton = new JButton(IconManager.getImageIcon(IconManager.ADD_PHOTO));
782                 addPhotoButton.setToolTipText(I18nManager.getText("menu.file.addphotos"));
783                 addPhotoButton.addActionListener(_addPhotoAction);
784                 toolbar.add(addPhotoButton);
785                 // Save
786                 _saveButton = new JButton(IconManager.getImageIcon(IconManager.SAVE_FILE));
787                 _saveButton.setToolTipText(I18nManager.getText("menu.file.save"));
788                 _saveButton.addActionListener(_saveAction);
789                 _saveButton.setEnabled(false);
790                 toolbar.add(_saveButton);
791                 // Undo
792                 _undoButton = new JButton(IconManager.getImageIcon(IconManager.UNDO));
793                 _undoButton.setToolTipText(I18nManager.getText("menu.track.undo"));
794                 _undoButton.addActionListener(_undoAction);
795                 _undoButton.setEnabled(false);
796                 toolbar.add(_undoButton);
797                 // Edit point
798                 _editPointButton = new JButton(IconManager.getImageIcon(IconManager.EDIT_POINT));
799                 _editPointButton.setToolTipText(I18nManager.getText("menu.point.editpoint"));
800                 _editPointButton.addActionListener(_editPointAction);
801                 _editPointButton.setEnabled(false);
802                 toolbar.add(_editPointButton);
803                 // Delete point
804                 _deletePointButton = new JButton(IconManager.getImageIcon(IconManager.DELETE_POINT));
805                 _deletePointButton.setToolTipText(I18nManager.getText("menu.point.deletepoint"));
806                 _deletePointButton.addActionListener(_deletePointAction);
807                 _deletePointButton.setEnabled(false);
808                 toolbar.add(_deletePointButton);
809                 // Delete range
810                 _deleteRangeButton = new JButton(IconManager.getImageIcon(IconManager.DELETE_RANGE));
811                 _deleteRangeButton.setToolTipText(I18nManager.getText("function.deleterange"));
812                 _deleteRangeButton.addActionListener(new ActionListener() {
813                         public void actionPerformed(ActionEvent arg0) {
814                                 FunctionLibrary.FUNCTION_DELETE_RANGE.begin();
815                         }
816                 });
817                 _deleteRangeButton.setEnabled(false);
818                 toolbar.add(_deleteRangeButton);
819                 // Cut and move
820                 _cutAndMoveButton = new JButton(IconManager.getImageIcon(IconManager.CUT_AND_MOVE));
821                 _cutAndMoveButton.setToolTipText(I18nManager.getText("menu.range.cutandmove"));
822                 _cutAndMoveButton.addActionListener(new ActionListener() {
823                         public void actionPerformed(ActionEvent arg0) {
824                                 _app.cutAndMoveSelection();
825                         }
826                 });
827                 _cutAndMoveButton.setEnabled(false);
828                 toolbar.add(_cutAndMoveButton);
829                 // Select start, end
830                 _selectStartButton = new JButton(IconManager.getImageIcon(IconManager.SET_RANGE_START));
831                 _selectStartButton.setToolTipText(I18nManager.getText("menu.range.start"));
832                 _selectStartButton.addActionListener(_selectStartAction);
833                 _selectStartButton.setEnabled(false);
834                 toolbar.add(_selectStartButton);
835                 _selectEndButton = new JButton(IconManager.getImageIcon(IconManager.SET_RANGE_END));
836                 _selectEndButton.setToolTipText(I18nManager.getText("menu.range.end"));
837                 _selectEndButton.addActionListener(_selectEndAction);
838                 _selectEndButton.setEnabled(false);
839                 toolbar.add(_selectEndButton);
840                 // Connect to point
841                 _connectButton = new JButton(IconManager.getImageIcon(IconManager.CONNECT_PHOTO));
842                 _connectButton.setToolTipText(I18nManager.getText(FunctionLibrary.FUNCTION_CONNECT_TO_POINT.getNameKey()));
843                 _connectButton.addActionListener(new ActionListener() {
844                         public void actionPerformed(ActionEvent arg0) {
845                                 FunctionLibrary.FUNCTION_CONNECT_TO_POINT.begin();
846                         }
847                 });
848                 _connectButton.setEnabled(false);
849                 toolbar.add(_connectButton);
850                 // finish off
851                 toolbar.setFloatable(false);
852                 return toolbar;
853         }
854
855
856         /**
857          * Method to update menu when file loaded
858          */
859         public void informFileLoaded()
860         {
861                 // save, undo, delete enabled
862                 _sendGpsItem.setEnabled(true);
863                 _saveItem.setEnabled(true);
864                 _undoItem.setEnabled(true);
865                 _compressItem.setEnabled(true);
866                 _deleteMarkedPointsItem.setEnabled(false);
867         }
868
869
870         /**
871          * @see tim.prune.DataSubscriber#dataUpdated(tim.prune.data.Track)
872          */
873         public void dataUpdated(byte inUpdateType)
874         {
875                 final boolean hasData = _track != null && _track.getNumPoints() > 0;
876                 final boolean hasMultiplePoints = hasData && _track.getNumPoints() > 1;
877
878                 // set functions which require data
879                 _sendGpsItem.setEnabled(hasData);
880                 _saveItem.setEnabled(hasData);
881                 _saveButton.setEnabled(hasData);
882                 _exportKmlItem.setEnabled(hasData);
883                 _exportGpxItem.setEnabled(hasData);
884                 _exportPovItem.setEnabled(hasMultiplePoints);
885                 _exportImageItem.setEnabled(hasMultiplePoints);
886                 _compressItem.setEnabled(hasData);
887                 _markRectangleItem.setEnabled(hasData);
888                 _markUphillLiftsItem.setEnabled(hasData && _track.hasAltitudeData());
889                 _deleteMarkedPointsItem.setEnabled(hasData && _track.hasMarkedPoints());
890                 _rearrangeWaypointsItem.setEnabled(hasData && _track.hasWaypoints() && _track.getNumPoints() > 1);
891                 final boolean hasSeveralTrackPoints = hasData && _track.hasTrackPoints() && _track.getNumPoints() > 3;
892                 _splitSegmentsItem.setEnabled(hasSeveralTrackPoints);
893                 _sewSegmentsItem.setEnabled(hasSeveralTrackPoints);
894                 _createMarkerWaypointsItem.setEnabled(hasSeveralTrackPoints);
895                 _selectAllItem.setEnabled(hasData);
896                 _selectNoneItem.setEnabled(hasData);
897                 _show3dItem.setEnabled(hasMultiplePoints);
898                 _chartItem.setEnabled(hasData);
899                 _browserMapMenu.setEnabled(hasData);
900                 _distanceItem.setEnabled(hasData);
901                 _autoplayTrack.setEnabled(hasData && _track.getNumPoints() > 3);
902                 _lookupSrtmItem.setEnabled(hasData);
903                 _nearbyWikipediaItem.setEnabled(hasData);
904                 _nearbyOsmPoiItem.setEnabled(hasData);
905                 _downloadOsmItem.setEnabled(hasData);
906                 _getWeatherItem.setEnabled(hasData);
907                 _findWaypointItem.setEnabled(hasData && _track.hasWaypoints());
908                 // have we got a cache?
909                 _downloadSrtmMenu.setEnabled(hasData && Config.getConfigString(Config.KEY_DISK_CACHE) != null);
910                 // have we got any timestamps?
911                 _deleteByDateItem.setEnabled(hasData && _track.hasData(Field.TIMESTAMP));
912
913                 // is undo available?
914                 boolean hasUndo = !_app.getUndoStack().isEmpty();
915                 _undoItem.setEnabled(hasUndo);
916                 _undoButton.setEnabled(hasUndo);
917                 _clearUndoItem.setEnabled(hasUndo);
918                 // is there a current point?
919                 DataPoint currPoint = _app.getTrackInfo().getCurrentPoint();
920                 boolean hasPoint = (currPoint != null);
921                 _editPointItem.setEnabled(hasPoint);
922                 _editPointButton.setEnabled(hasPoint);
923                 _editWaypointNameItem.setEnabled(hasPoint);
924                 _deletePointItem.setEnabled(hasPoint);
925                 _deletePointButton.setEnabled(hasPoint);
926                 _selectStartItem.setEnabled(hasPoint);
927                 _selectStartButton.setEnabled(hasPoint);
928                 _selectEndItem.setEnabled(hasPoint);
929                 _selectEndButton.setEnabled(hasPoint);
930                 _duplicatePointItem.setEnabled(hasPoint);
931                 _projectPointItem.setEnabled(hasPoint);
932                 _showPeakfinderItem.setEnabled(hasPoint);
933                 _showGeohackItem.setEnabled(hasPoint);
934                 _searchOpencachingDeItem.setEnabled(hasPoint);
935                 _searchMapillaryItem.setEnabled(hasPoint);
936                 // is it a waypoint?
937                 _selectSegmentItem.setEnabled(hasPoint && !currPoint.isWaypoint());
938                 // are there any photos?
939                 boolean anyPhotos = _app.getTrackInfo().getPhotoList().getNumPhotos() > 0;
940                 _saveExifItem.setEnabled(anyPhotos && _app.getTrackInfo().getPhotoList().hasMediaWithFile());
941                 // is there a current photo, audio?
942                 Photo currentPhoto = _app.getTrackInfo().getCurrentPhoto();
943                 boolean hasPhoto = currentPhoto != null;
944                 AudioClip currentAudio = _app.getTrackInfo().getCurrentAudio();
945                 boolean hasAudio = currentAudio != null;
946                 // connect is available if (photo/audio) and point selected, and media has no point
947                 boolean connectAvailable = (hasPhoto && hasPoint && currentPhoto.getDataPoint() == null)
948                         || (hasAudio && hasPoint && currentAudio.getDataPoint() == null);
949                 _connectPhotoItem.setEnabled(hasPhoto && hasPoint && currentPhoto.getDataPoint() == null);
950                 _connectButton.setEnabled(connectAvailable);
951                 _disconnectPhotoItem.setEnabled(hasPhoto && currentPhoto.getDataPoint() != null);
952                 _correlatePhotosItem.setEnabled(anyPhotos && hasData);
953                 _rearrangePhotosItem.setEnabled(anyPhotos && hasMultiplePoints);
954                 _removePhotoItem.setEnabled(hasPhoto);
955                 _rotatePhotoLeft.setEnabled(hasPhoto);
956                 _rotatePhotoRight.setEnabled(hasPhoto);
957                 _photoPopupItem.setEnabled(hasPhoto);
958                 _ignoreExifThumb.setEnabled(hasPhoto && currentPhoto.getExifThumbnail() != null);
959                 _selectNoPhotoItem.setEnabled(hasPhoto);
960                 boolean anyAudios = _app.getTrackInfo().getAudioList().getNumAudios() > 0;
961                 _selectNoAudioItem.setEnabled(hasAudio);
962                 _removeAudioItem.setEnabled(hasAudio);
963                 _connectAudioItem.setEnabled(hasAudio && hasPoint && currentAudio.getDataPoint() == null);
964                 _disconnectAudioItem.setEnabled(hasAudio && currentAudio.getDataPoint() != null);
965                 _correlateAudiosItem.setEnabled(anyAudios && hasData);
966                 // is there a current range?
967                 boolean hasRange = (hasData && _selection.hasRangeSelected());
968                 _deleteRangeItem.setEnabled(hasRange);
969                 _deleteRangeButton.setEnabled(hasRange);
970                 _cropTrackItem.setEnabled(hasRange);
971                 _interpolateItem.setEnabled(hasRange);
972                 _averageItem.setEnabled(hasRange);
973                 _mergeSegmentsItem.setEnabled(hasRange);
974                 _reverseItem.setEnabled(hasRange);
975                 _addTimeOffsetItem.setEnabled(hasRange);
976                 _addAltitudeOffsetItem.setEnabled(hasRange);
977                 _convertNamesToTimesItem.setEnabled(hasRange && _track.hasWaypoints());
978                 _deleteFieldValuesItem.setEnabled(hasRange);
979                 _viewFullDetailsItem.setEnabled(hasRange || hasPoint);
980                 _estimateTimeItem.setEnabled(hasRange);
981                 _learnEstimationParams.setEnabled(hasData && _track.hasTrackPoints() && _track.hasData(Field.TIMESTAMP)
982                         && _track.hasAltitudeData());
983                 // Is the currently selected point outside the current range?
984                 boolean canCutAndMove = hasRange && hasPoint &&
985                         (_selection.getCurrentPointIndex() < _selection.getStart()
986                         || _selection.getCurrentPointIndex() > (_selection.getEnd()+1));
987                 _cutAndMoveItem.setEnabled(canCutAndMove);
988                 _cutAndMoveButton.setEnabled(canCutAndMove);
989                 final boolean isTrackLengthTwo = hasData && _track.getNumPoints() == 2;
990                 _routingGraphHopperItem.setEnabled(isTrackLengthTwo || (hasData && hasRange));
991                 // Has the map been switched on/off?
992                 boolean mapsOn = Config.getConfigBoolean(Config.KEY_SHOW_MAP);
993                 if (_mapCheckbox.isSelected() != mapsOn) {
994                         _mapCheckbox.setSelected(mapsOn);
995                 }
996                 // Are there any recently-used files?
997                 RecentFileList rfl = Config.getRecentFileList();
998                 final int numRecentFiles = rfl.getNumEntries();
999                 final boolean hasRecentFiles = numRecentFiles > 0;
1000                 _recentFileMenu.setEnabled(hasRecentFiles);
1001                 if (hasRecentFiles)
1002                 {
1003                         int numItems = _recentFileMenu.getMenuComponentCount();
1004                         if (numItems == numRecentFiles)
1005                         {
1006                                 // Right number of items, just change texts
1007                                 for (int i=0; i<numRecentFiles; i++)
1008                                 {
1009                                         JMenuItem item = _recentFileMenu.getItem(i);
1010                                         RecentFile rf = rfl.getFile(i);
1011                                         item.setText(rf==null?"":rf.getFile().getName());
1012                                         item.setToolTipText(rf==null?null:rf.getFile().getAbsolutePath());
1013                                 }
1014                         }
1015                         else
1016                         {
1017                                 // Rebuild menus
1018                                 _recentFileMenu.removeAll();
1019                                 for (int i=0; i<rfl.getSize(); i++)
1020                                 {
1021                                         RecentFile rf = rfl.getFile(i);
1022                                         if (rf != null && rf.isValid())
1023                                         {
1024                                                 JMenuItem menuItem = new JMenuItem(rf.getFile().getName());
1025                                                 menuItem.setToolTipText(rf.getFile().getAbsolutePath());
1026                                                 menuItem.addActionListener(new RecentFileTrigger(_app, i));
1027                                                 _recentFileMenu.add(menuItem);
1028                                         }
1029                                 }
1030                         }
1031                 }
1032         }
1033
1034
1035         /**
1036          * Ignore action completed signals
1037          * @see tim.prune.DataSubscriber#actionCompleted(java.lang.String)
1038          */
1039         public void actionCompleted(String inMessage)
1040         {}
1041 }