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