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