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