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