]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/gui/MenuManager.java
Version 6, October 2008
[GpsPrune.git] / tim / prune / gui / MenuManager.java
1 package tim.prune.gui;
2
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5 import java.awt.event.InputEvent;
6 import java.awt.event.KeyEvent;
7 import javax.swing.JButton;
8 import javax.swing.JFrame;
9 import javax.swing.JMenu;
10 import javax.swing.JMenuBar;
11 import javax.swing.JMenuItem;
12 import javax.swing.JToolBar;
13 import javax.swing.KeyStroke;
14
15 import tim.prune.App;
16 import tim.prune.DataSubscriber;
17 import tim.prune.I18nManager;
18 import tim.prune.browser.UrlGenerator;
19 import tim.prune.data.PhotoList;
20 import tim.prune.data.Selection;
21 import tim.prune.data.Track;
22 import tim.prune.data.TrackInfo;
23
24 /**
25  * Class to manage the menu bar and tool bar,
26  * including enabling and disabling the items
27  */
28 public class MenuManager implements DataSubscriber
29 {
30         private JFrame _parent = null;
31         private App _app = null;
32         private Track _track = null;
33         private Selection _selection = null;
34         private PhotoList _photos = null;
35
36         // Menu items which need enabling/disabling
37         private JMenuItem _saveItem = null;
38         private JMenuItem _exportKmlItem = null;
39         private JMenuItem _exportGpxItem = null;
40         private JMenuItem _exportPovItem = null;
41         private JMenuItem _undoItem = null;
42         private JMenuItem _clearUndoItem = null;
43         private JMenuItem _editPointItem = null;
44         private JMenuItem _editWaypointNameItem = null;
45         private JMenuItem _deletePointItem = null;
46         private JMenuItem _deleteRangeItem = null;
47         private JMenuItem _deleteDuplicatesItem = null;
48         private JMenuItem _compressItem = null;
49         private JMenuItem _interpolateItem = null;
50         private JMenuItem _selectAllItem = null;
51         private JMenuItem _selectNoneItem = null;
52         private JMenuItem _selectStartItem = null;
53         private JMenuItem _selectEndItem = null;
54         private JMenuItem _reverseItem = null;
55         private JMenuItem _addTimeOffsetItem = null;
56         private JMenuItem _mergeSegmentsItem = null;
57         private JMenu     _rearrangeMenu = null;
58         private JMenuItem _cutAndMoveItem = null;
59         private JMenuItem _show3dItem = null;
60         private JMenu     _browserMapMenu = null;
61         private JMenuItem _saveExifItem = null;
62         private JMenuItem _connectPhotoItem = null;
63         private JMenuItem _deletePhotoItem = null;
64         private JMenuItem _disconnectPhotoItem = null;
65         private JMenuItem _correlatePhotosItem = null;
66
67         // ActionListeners for reuse by menu and toolbar
68         private ActionListener _openFileAction = null;
69         private ActionListener _addPhotoAction = null;
70         private ActionListener _saveAction = null;
71         private ActionListener _undoAction = null;
72         private ActionListener _editPointAction = null;
73         private ActionListener _deletePointAction = null;
74         private ActionListener _deleteRangeAction = null;
75         private ActionListener _selectStartAction = null;
76         private ActionListener _selectEndAction = null;
77         private ActionListener _connectPhotoAction = null;
78
79         // Toolbar buttons which need enabling/disabling
80         private JButton _saveButton = null;
81         private JButton _undoButton = null;
82         private JButton _editPointButton = null;
83         private JButton _deletePointButton = null;
84         private JButton _deleteRangeButton = null;
85         private JButton _selectStartButton = null;
86         private JButton _selectEndButton = null;
87         private JButton _connectPhotoButton = null;
88
89
90         /**
91          * Constructor
92          * @param inParent parent object for dialogs
93          * @param inApp application to call on menu actions
94          * @param inTrackInfo track info object
95          */
96         public MenuManager(JFrame inParent, App inApp, TrackInfo inTrackInfo)
97         {
98                 _parent = inParent;
99                 _app = inApp;
100                 _track = inTrackInfo.getTrack();
101                 _selection = inTrackInfo.getSelection();
102                 _photos = inTrackInfo.getPhotoList();
103         }
104
105
106         /**
107          * Create a JMenuBar containing all menu items
108          * @return JMenuBar
109          */
110         public JMenuBar createMenuBar()
111         {
112                 JMenuBar menubar = new JMenuBar();
113                 JMenu fileMenu = new JMenu(I18nManager.getText("menu.file"));
114                 // Open file
115                 JMenuItem openMenuItem = new JMenuItem(I18nManager.getText("menu.file.open"));
116                 openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK));
117                 _openFileAction = new ActionListener() {
118                         public void actionPerformed(ActionEvent e)
119                         {
120                                 _app.openFile();
121                         }
122                 };
123                 openMenuItem.addActionListener(_openFileAction);
124                 fileMenu.add(openMenuItem);
125                 // Add photos
126                 JMenuItem addPhotosMenuItem = new JMenuItem(I18nManager.getText("menu.file.addphotos"));
127                 _addPhotoAction = new ActionListener() {
128                         public void actionPerformed(ActionEvent e)
129                         {
130                                 _app.addPhotos();
131                         }
132                 };
133                 addPhotosMenuItem.addActionListener(_addPhotoAction);
134                 fileMenu.add(addPhotosMenuItem);
135                 // Add photos
136                 JMenuItem loadFromGpsMenuItem = new JMenuItem(I18nManager.getText("menu.file.loadfromgps"));
137                 loadFromGpsMenuItem.addActionListener(new ActionListener() {
138                         public void actionPerformed(ActionEvent e)
139                         {
140                                 _app.beginLoadFromGps();
141                         }
142                 });
143                 fileMenu.add(loadFromGpsMenuItem);
144                 fileMenu.addSeparator();
145                 // Save
146                 _saveItem = new JMenuItem(I18nManager.getText("menu.file.save"), KeyEvent.VK_S);
147                 _saveAction = new ActionListener() {
148                         public void actionPerformed(ActionEvent e)
149                         {
150                                 _app.saveFile();
151                         }
152                 };
153                 _saveItem.addActionListener(_saveAction);
154                 _saveItem.setEnabled(false);
155                 fileMenu.add(_saveItem);
156                 // Export - Kml
157                 _exportKmlItem = new JMenuItem(I18nManager.getText("menu.file.exportkml"));
158                 _exportKmlItem.addActionListener(new ActionListener() {
159                         public void actionPerformed(ActionEvent e)
160                         {
161                                 _app.exportKml();
162                         }
163                 });
164                 _exportKmlItem.setEnabled(false);
165                 fileMenu.add(_exportKmlItem);
166                 // Gpx
167                 _exportGpxItem = new JMenuItem(I18nManager.getText("menu.file.exportgpx"));
168                 _exportGpxItem.addActionListener(new ActionListener() {
169                         public void actionPerformed(ActionEvent e)
170                         {
171                                 _app.exportGpx();
172                         }
173                 });
174                 _exportGpxItem.setEnabled(false);
175                 fileMenu.add(_exportGpxItem);
176                 // Pov
177                 _exportPovItem = new JMenuItem(I18nManager.getText("menu.file.exportpov"));
178                 _exportPovItem.addActionListener(new ActionListener() {
179                         public void actionPerformed(ActionEvent e)
180                         {
181                                 _app.exportPov();
182                         }
183                 });
184                 _exportPovItem.setEnabled(false);
185                 fileMenu.add(_exportPovItem);
186                 fileMenu.addSeparator();
187                 JMenuItem exitMenuItem = new JMenuItem(I18nManager.getText("menu.file.exit"));
188                 exitMenuItem.addActionListener(new ActionListener() {
189                         public void actionPerformed(ActionEvent e)
190                         {
191                                 _app.exit();
192                         }
193                 });
194                 fileMenu.add(exitMenuItem);
195                 menubar.add(fileMenu);
196                 // Edit menu
197                 JMenu editMenu = new JMenu(I18nManager.getText("menu.edit"));
198                 editMenu.setMnemonic(KeyEvent.VK_E);
199                 _undoItem = new JMenuItem(I18nManager.getText("menu.edit.undo"));
200                 _undoAction = new ActionListener() {
201                         public void actionPerformed(ActionEvent e)
202                         {
203                                 _app.beginUndo();
204                         }
205                 };
206                 _undoItem.addActionListener(_undoAction);
207                 _undoItem.setEnabled(false);
208                 editMenu.add(_undoItem);
209                 _clearUndoItem = new JMenuItem(I18nManager.getText("menu.edit.clearundo"));
210                 _clearUndoItem.addActionListener(new ActionListener() {
211                         public void actionPerformed(ActionEvent e)
212                         {
213                                 _app.clearUndo();
214                         }
215                 });
216                 _clearUndoItem.setEnabled(false);
217                 editMenu.add(_clearUndoItem);
218                 editMenu.addSeparator();
219                 _editPointItem = new JMenuItem(I18nManager.getText("menu.edit.editpoint"));
220                 _editPointAction = new ActionListener() {
221                         public void actionPerformed(ActionEvent e)
222                         {
223                                 _app.editCurrentPoint();
224                         }
225                 };
226                 _editPointItem.addActionListener(_editPointAction);
227                 _editPointItem.setEnabled(false);
228                 editMenu.add(_editPointItem);
229                 _editWaypointNameItem = new JMenuItem(I18nManager.getText("menu.edit.editwaypointname"));
230                 _editWaypointNameItem.addActionListener(new ActionListener() {
231                         public void actionPerformed(ActionEvent e)
232                         {
233                                 _app.editCurrentPointName();
234                         }
235                 });
236                 _editWaypointNameItem.setEnabled(false);
237                 editMenu.add(_editWaypointNameItem);
238                 _deletePointItem = new JMenuItem(I18nManager.getText("menu.edit.deletepoint"));
239                 _deletePointAction = new ActionListener() {
240                         public void actionPerformed(ActionEvent e)
241                         {
242                                 _app.deleteCurrentPoint();
243                         }
244                 };
245                 _deletePointItem.addActionListener(_deletePointAction);
246                 _deletePointItem.setEnabled(false);
247                 editMenu.add(_deletePointItem);
248                 _deleteRangeItem = new JMenuItem(I18nManager.getText("menu.edit.deleterange"));
249                 _deleteRangeAction = new ActionListener() {
250                         public void actionPerformed(ActionEvent e)
251                         {
252                                 _app.deleteSelectedRange();
253                         }
254                 };
255                 _deleteRangeItem.addActionListener(_deleteRangeAction);
256                 _deleteRangeItem.setEnabled(false);
257                 editMenu.add(_deleteRangeItem);
258                 _deleteDuplicatesItem = new JMenuItem(I18nManager.getText("menu.edit.deleteduplicates"));
259                 _deleteDuplicatesItem.addActionListener(new ActionListener() {
260                         public void actionPerformed(ActionEvent e)
261                         {
262                                 _app.deleteDuplicates();
263                         }
264                 });
265                 _deleteDuplicatesItem.setEnabled(false);
266                 editMenu.add(_deleteDuplicatesItem);
267                 _compressItem = new JMenuItem(I18nManager.getText("menu.edit.compress"));
268                 _compressItem.addActionListener(new ActionListener() {
269                         public void actionPerformed(ActionEvent e)
270                         {
271                                 _app.compressTrack();
272                         }
273                 });
274                 _compressItem.setEnabled(false);
275                 editMenu.add(_compressItem);
276                 editMenu.addSeparator();
277                 _interpolateItem = new JMenuItem(I18nManager.getText("menu.edit.interpolate"));
278                 _interpolateItem.addActionListener(new ActionListener() {
279                         public void actionPerformed(ActionEvent e)
280                         {
281                                 _app.interpolateSelection();
282                         }
283                 });
284                 _interpolateItem.setEnabled(false);
285                 editMenu.add(_interpolateItem);
286                 _reverseItem = new JMenuItem(I18nManager.getText("menu.edit.reverse"));
287                 _reverseItem.addActionListener(new ActionListener() {
288                         public void actionPerformed(ActionEvent e)
289                         {
290                                 _app.reverseRange();
291                         }
292                 });
293                 _reverseItem.setEnabled(false);
294                 editMenu.add(_reverseItem);
295                 _addTimeOffsetItem = new JMenuItem(I18nManager.getText("menu.edit.addtimeoffset"));
296                 _addTimeOffsetItem.addActionListener(new ActionListener() {
297                         public void actionPerformed(ActionEvent e)
298                         {
299                                 _app.beginAddTimeOffset();
300                         }
301                 });
302                 _addTimeOffsetItem.setEnabled(false);
303                 editMenu.add(_addTimeOffsetItem);
304                 _mergeSegmentsItem = new JMenuItem(I18nManager.getText("menu.edit.mergetracksegments"));
305                 _mergeSegmentsItem.addActionListener(new ActionListener() {
306                         public void actionPerformed(ActionEvent e)
307                         {
308                                 _app.mergeTrackSegments();
309                         }
310                 });
311                 _mergeSegmentsItem.setEnabled(false);
312                 editMenu.add(_mergeSegmentsItem);
313                 // Rearrange waypoints
314                 _rearrangeMenu = new JMenu(I18nManager.getText("menu.edit.rearrange"));
315                 _rearrangeMenu.setEnabled(false);
316                 JMenuItem  rearrangeStartItem = new JMenuItem(I18nManager.getText("menu.edit.rearrange.start"));
317                 rearrangeStartItem.addActionListener(new ActionListener() {
318                         public void actionPerformed(ActionEvent e)
319                         {
320                                 _app.rearrangeWaypoints(App.REARRANGE_TO_START);
321                         }
322                 });
323                 rearrangeStartItem.setEnabled(true);
324                 _rearrangeMenu.add(rearrangeStartItem);
325                 JMenuItem rearrangeEndItem = new JMenuItem(I18nManager.getText("menu.edit.rearrange.end"));
326                 rearrangeEndItem.addActionListener(new ActionListener() {
327                         public void actionPerformed(ActionEvent e)
328                         {
329                                 _app.rearrangeWaypoints(App.REARRANGE_TO_END);
330                         }
331                 });
332                 rearrangeEndItem.setEnabled(true);
333                 _rearrangeMenu.add(rearrangeEndItem);
334                 JMenuItem rearrangeNearestItem = new JMenuItem(I18nManager.getText("menu.edit.rearrange.nearest"));
335                 rearrangeNearestItem.addActionListener(new ActionListener() {
336                         public void actionPerformed(ActionEvent e)
337                         {
338                                 _app.rearrangeWaypoints(App.REARRANGE_TO_NEAREST);
339                         }
340                 });
341                 rearrangeNearestItem.setEnabled(true);
342                 _rearrangeMenu.add(rearrangeNearestItem);
343                 editMenu.add(_rearrangeMenu);
344                 _cutAndMoveItem = new JMenuItem(I18nManager.getText("menu.edit.cutandmove"));
345                 _cutAndMoveItem.addActionListener(new ActionListener() {
346                         public void actionPerformed(ActionEvent e)
347                         {
348                                 _app.cutAndMoveSelection();
349                         }
350                 });
351                 _cutAndMoveItem.setEnabled(false);
352                 editMenu.add(_cutAndMoveItem);
353                 menubar.add(editMenu);
354
355                 // Select menu
356                 JMenu selectMenu = new JMenu(I18nManager.getText("menu.select"));
357                 _selectAllItem = new JMenuItem(I18nManager.getText("menu.select.all"));
358                 _selectAllItem.setEnabled(false);
359                 _selectAllItem.addActionListener(new ActionListener() {
360                         public void actionPerformed(ActionEvent e)
361                         {
362                                 _app.selectAll();
363                         }
364                 });
365                 selectMenu.add(_selectAllItem);
366                 _selectNoneItem = new JMenuItem(I18nManager.getText("menu.select.none"));
367                 _selectNoneItem.setEnabled(false);
368                 _selectNoneItem.addActionListener(new ActionListener() {
369                         public void actionPerformed(ActionEvent e)
370                         {
371                                 _app.selectNone();
372                         }
373                 });
374                 selectMenu.add(_selectNoneItem);
375                 selectMenu.addSeparator();
376                 _selectStartItem = new JMenuItem(I18nManager.getText("menu.select.start"));
377                 _selectStartItem.setEnabled(false);
378                 _selectStartAction = new ActionListener() {
379                         public void actionPerformed(ActionEvent e)
380                         {
381                                 _selection.selectRangeStart();
382                         }
383                 };
384                 _selectStartItem.addActionListener(_selectStartAction);
385                 selectMenu.add(_selectStartItem);
386                 _selectEndItem = new JMenuItem(I18nManager.getText("menu.select.end"));
387                 _selectEndItem.setEnabled(false);
388                 _selectEndAction = new ActionListener() {
389                         public void actionPerformed(ActionEvent e)
390                         {
391                                 _selection.selectRangeEnd();
392                         }
393                 };
394                 _selectEndItem.addActionListener(_selectEndAction);
395                 selectMenu.add(_selectEndItem);
396                 menubar.add(selectMenu);
397
398                 // Add view menu
399                 JMenu viewMenu = new JMenu(I18nManager.getText("menu.view"));
400                 _show3dItem = new JMenuItem(I18nManager.getText("menu.view.show3d"));
401                 _show3dItem.addActionListener(new ActionListener() {
402                         public void actionPerformed(ActionEvent e)
403                         {
404                                 _app.show3dWindow();
405                         }
406                 });
407                 _show3dItem.setEnabled(false);
408                 viewMenu.add(_show3dItem);
409                 // browser submenu
410                 _browserMapMenu = new JMenu(I18nManager.getText("menu.view.browser"));
411                 _browserMapMenu.setEnabled(false);
412                 JMenuItem googleMapsItem = new JMenuItem(I18nManager.getText("menu.view.browser.google"));
413                 googleMapsItem.addActionListener(new ActionListener() {
414                         public void actionPerformed(ActionEvent e)
415                         {
416                                 _app.showExternalMap(UrlGenerator.MAP_SOURCE_GOOGLE);
417                         }
418                 });
419                 _browserMapMenu.add(googleMapsItem);
420                 JMenuItem openMapsItem = new JMenuItem(I18nManager.getText("menu.view.browser.openstreetmap"));
421                 openMapsItem.addActionListener(new ActionListener() {
422                         public void actionPerformed(ActionEvent e)
423                         {
424                                 _app.showExternalMap(UrlGenerator.MAP_SOURCE_OSM);
425                         }
426                 });
427                 _browserMapMenu.add(openMapsItem);
428                 viewMenu.add(_browserMapMenu);
429                 menubar.add(viewMenu);
430
431                 // Add photo menu
432                 JMenu photoMenu = new JMenu(I18nManager.getText("menu.photo"));
433                 addPhotosMenuItem = new JMenuItem(I18nManager.getText("menu.file.addphotos"));
434                 addPhotosMenuItem.addActionListener(_addPhotoAction);
435                 photoMenu.add(addPhotosMenuItem);
436                 _saveExifItem = new JMenuItem(I18nManager.getText("menu.photo.saveexif"));
437                 _saveExifItem.addActionListener(new ActionListener() {
438                         public void actionPerformed(ActionEvent e)
439                         {
440                                 _app.saveExif();
441                         }
442                 });
443                 _saveExifItem.setEnabled(false);
444                 photoMenu.add(_saveExifItem);
445                 _connectPhotoItem = new JMenuItem(I18nManager.getText("menu.photo.connect"));
446                 _connectPhotoAction = new ActionListener() {
447                         public void actionPerformed(ActionEvent e)
448                         {
449                                 _app.connectPhotoToPoint();
450                         }
451                 };
452                 _connectPhotoItem.addActionListener(_connectPhotoAction);
453                 _connectPhotoItem.setEnabled(false);
454                 photoMenu.addSeparator();
455                 photoMenu.add(_connectPhotoItem);
456                 // disconnect photo
457                 _disconnectPhotoItem = new JMenuItem(I18nManager.getText("menu.photo.disconnect"));
458                 _disconnectPhotoItem.addActionListener(new ActionListener() {
459                         public void actionPerformed(ActionEvent e)
460                         {
461                                 _app.disconnectPhotoFromPoint();
462                         }
463                 });
464                 _disconnectPhotoItem.setEnabled(false);
465                 photoMenu.add(_disconnectPhotoItem);
466                 _deletePhotoItem = new JMenuItem(I18nManager.getText("menu.photo.delete"));
467                 _deletePhotoItem.addActionListener(new ActionListener() {
468                         public void actionPerformed(ActionEvent e)
469                         {
470                                 _app.deleteCurrentPhoto();
471                         }
472                 });
473                 _deletePhotoItem.setEnabled(false);
474                 photoMenu.add(_deletePhotoItem);
475                 photoMenu.addSeparator();
476                 // correlate all photos
477                 _correlatePhotosItem = new JMenuItem(I18nManager.getText("menu.photo.correlate"));
478                 _correlatePhotosItem.addActionListener(new ActionListener() {
479                         public void actionPerformed(ActionEvent e)
480                         {
481                                 _app.beginCorrelatePhotos();
482                         }
483                 });
484                 _correlatePhotosItem.setEnabled(false);
485                 photoMenu.add(_correlatePhotosItem);
486                 menubar.add(photoMenu);
487
488                 // Help menu
489                 JMenu helpMenu = new JMenu(I18nManager.getText("menu.help"));
490                 JMenuItem helpItem = new JMenuItem(I18nManager.getText("menu.help"));
491                 helpItem.addActionListener(new ActionListener() {
492                         public void actionPerformed(ActionEvent e)
493                         {
494                                 _app.showHelp();
495                         }
496                 });
497                 helpMenu.add(helpItem);
498                 JMenuItem aboutItem = new JMenuItem(I18nManager.getText("menu.help.about"));
499                 aboutItem.addActionListener(new ActionListener() {
500                         public void actionPerformed(ActionEvent e)
501                         {
502                                 new AboutScreen(_parent).show();
503                         }
504                 });
505                 helpMenu.add(aboutItem);
506                 JMenuItem checkVersionItem = new JMenuItem(I18nManager.getText("menu.help.checkversion"));
507                 checkVersionItem.addActionListener(new ActionListener() {
508                         public void actionPerformed(ActionEvent e)
509                         {
510                                 CheckVersionScreen.show(_parent);
511                         }
512                 });
513                 helpMenu.add(checkVersionItem);
514                 menubar.add(helpMenu);
515
516                 return menubar;
517         }
518
519
520         /**
521          * Create a JToolBar containing all toolbar buttons
522          * @return toolbar containing buttons
523          */
524         public JToolBar createToolBar()
525         {
526                 JToolBar toolbar = new JToolBar();
527                 // Add text file
528                 JButton openFileButton = new JButton(IconManager.getImageIcon(IconManager.OPEN_FILE));
529                 openFileButton.setToolTipText(I18nManager.getText("menu.file.open"));
530                 openFileButton.addActionListener(_openFileAction);
531                 toolbar.add(openFileButton);
532                 // Add photo
533                 JButton addPhotoButton = new JButton(IconManager.getImageIcon(IconManager.ADD_PHOTO));
534                 addPhotoButton.setToolTipText(I18nManager.getText("menu.file.addphotos"));
535                 addPhotoButton.addActionListener(_addPhotoAction);
536                 toolbar.add(addPhotoButton);
537                 // Save
538                 _saveButton = new JButton(IconManager.getImageIcon(IconManager.SAVE_FILE));
539                 _saveButton.setToolTipText(I18nManager.getText("menu.file.save"));
540                 _saveButton.addActionListener(_saveAction);
541                 _saveButton.setEnabled(false);
542                 toolbar.add(_saveButton);
543                 // Undo
544                 _undoButton = new JButton(IconManager.getImageIcon(IconManager.UNDO));
545                 _undoButton.setToolTipText(I18nManager.getText("menu.edit.undo"));
546                 _undoButton.addActionListener(_undoAction);
547                 _undoButton.setEnabled(false);
548                 toolbar.add(_undoButton);
549                 // Edit point
550                 _editPointButton = new JButton(IconManager.getImageIcon(IconManager.EDIT_POINT));
551                 _editPointButton.setToolTipText(I18nManager.getText("menu.edit.editpoint"));
552                 _editPointButton.addActionListener(_editPointAction);
553                 _editPointButton.setEnabled(false);
554                 toolbar.add(_editPointButton);
555                 // Delete point
556                 _deletePointButton = new JButton(IconManager.getImageIcon(IconManager.DELETE_POINT));
557                 _deletePointButton.setToolTipText(I18nManager.getText("menu.edit.deletepoint"));
558                 _deletePointButton.addActionListener(_deletePointAction);
559                 _deletePointButton.setEnabled(false);
560                 toolbar.add(_deletePointButton);
561                 // Delete range
562                 _deleteRangeButton = new JButton(IconManager.getImageIcon(IconManager.DELETE_RANGE));
563                 _deleteRangeButton.setToolTipText(I18nManager.getText("menu.edit.deleterange"));
564                 _deleteRangeButton.addActionListener(_deleteRangeAction);
565                 _deleteRangeButton.setEnabled(false);
566                 toolbar.add(_deleteRangeButton);
567                 // Select start, end
568                 _selectStartButton = new JButton(IconManager.getImageIcon(IconManager.SET_RANGE_START));
569                 _selectStartButton.setToolTipText(I18nManager.getText("menu.select.start"));
570                 _selectStartButton.addActionListener(_selectStartAction);
571                 _selectStartButton.setEnabled(false);
572                 toolbar.add(_selectStartButton);
573                 _selectEndButton = new JButton(IconManager.getImageIcon(IconManager.SET_RANGE_END));
574                 _selectEndButton.setToolTipText(I18nManager.getText("menu.select.end"));
575                 _selectEndButton.addActionListener(_selectEndAction);
576                 _selectEndButton.setEnabled(false);
577                 toolbar.add(_selectEndButton);
578                 _connectPhotoButton = new JButton(IconManager.getImageIcon(IconManager.CONNECT_PHOTO));
579                 _connectPhotoButton.setToolTipText(I18nManager.getText("menu.photo.connect"));
580                 _connectPhotoButton.addActionListener(_connectPhotoAction);
581                 _connectPhotoButton.setEnabled(false);
582                 toolbar.add(_connectPhotoButton);
583                 // finish off
584                 toolbar.setFloatable(false);
585                 return toolbar;
586         }
587
588
589         /**
590          * Method to update menu when file loaded
591          */
592         public void informFileLoaded()
593         {
594                 // save, undo, delete enabled
595                 _saveItem.setEnabled(true);
596                 _undoItem.setEnabled(true);
597                 _deleteDuplicatesItem.setEnabled(true);
598                 _compressItem.setEnabled(true);
599         }
600
601
602         /**
603          * @see tim.prune.DataSubscriber#dataUpdated(tim.prune.data.Track)
604          */
605         public void dataUpdated(byte inUpdateType)
606         {
607                 boolean hasData = (_track != null && _track.getNumPoints() > 0);
608                 // set functions which require data
609                 _saveItem.setEnabled(hasData);
610                 _saveButton.setEnabled(hasData);
611                 _exportKmlItem.setEnabled(hasData);
612                 _exportGpxItem.setEnabled(hasData);
613                 _exportPovItem.setEnabled(hasData);
614                 _deleteDuplicatesItem.setEnabled(hasData);
615                 _compressItem.setEnabled(hasData);
616                 _rearrangeMenu.setEnabled(hasData && _track.hasMixedData());
617                 _selectAllItem.setEnabled(hasData);
618                 _selectNoneItem.setEnabled(hasData);
619                 if (_show3dItem != null)
620                         _show3dItem.setEnabled(hasData);
621                 _browserMapMenu.setEnabled(hasData);
622                 // is undo available?
623                 boolean hasUndo = !_app.getUndoStack().isEmpty();
624                 _undoItem.setEnabled(hasUndo);
625                 _undoButton.setEnabled(hasUndo);
626                 _clearUndoItem.setEnabled(hasUndo);
627                 // is there a current point?
628                 boolean hasPoint = (hasData && _selection.getCurrentPointIndex() >= 0);
629                 _editPointItem.setEnabled(hasPoint);
630                 _editPointButton.setEnabled(hasPoint);
631                 _editWaypointNameItem.setEnabled(hasPoint);
632                 _deletePointItem.setEnabled(hasPoint);
633                 _deletePointButton.setEnabled(hasPoint);
634                 _selectStartItem.setEnabled(hasPoint);
635                 _selectStartButton.setEnabled(hasPoint);
636                 _selectEndItem.setEnabled(hasPoint);
637                 _selectEndButton.setEnabled(hasPoint);
638                 // are there any photos?
639                 boolean anyPhotos = _photos != null && _photos.getNumPhotos() > 0;
640                 _saveExifItem.setEnabled(anyPhotos);
641                 // is there a current photo?
642                 boolean hasPhoto = anyPhotos && _selection.getCurrentPhotoIndex() >= 0;
643                 // connect is available if photo and point selected, and photo has no point
644                 boolean connectAvailable = hasPhoto && hasPoint && _photos.getPhoto(_selection.getCurrentPhotoIndex()) != null
645                         && _photos.getPhoto(_selection.getCurrentPhotoIndex()).getDataPoint() == null;
646                 _connectPhotoItem.setEnabled(connectAvailable);
647                 _connectPhotoButton.setEnabled(connectAvailable);
648                 _disconnectPhotoItem.setEnabled(hasPhoto && _photos.getPhoto(_selection.getCurrentPhotoIndex()) != null
649                         && _photos.getPhoto(_selection.getCurrentPhotoIndex()).getDataPoint() != null);
650                 _correlatePhotosItem.setEnabled(anyPhotos && hasData);
651                 _deletePhotoItem.setEnabled(hasPhoto);
652                 // is there a current range?
653                 boolean hasRange = (hasData && _selection.hasRangeSelected());
654                 _deleteRangeItem.setEnabled(hasRange);
655                 _deleteRangeButton.setEnabled(hasRange);
656                 _interpolateItem.setEnabled(hasRange
657                         && (_selection.getEnd() - _selection.getStart()) == 1);
658                 _mergeSegmentsItem.setEnabled(hasRange);
659                 _reverseItem.setEnabled(hasRange);
660                 _addTimeOffsetItem.setEnabled(hasRange);
661                 // Is the currently selected point outside the current range?
662                 _cutAndMoveItem.setEnabled(hasRange && hasPoint &&
663                         (_selection.getCurrentPointIndex() < _selection.getStart()
664                                 || _selection.getCurrentPointIndex() > (_selection.getEnd()+1)));
665         }
666
667
668         /**
669          * Ignore action completed signals
670          * @see tim.prune.DataSubscriber#actionCompleted(java.lang.String)
671          */
672         public void actionCompleted(String inMessage)
673         {}
674 }