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