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