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