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