source: josm/trunk/src/org/openstreetmap/josm/gui/MainMenu.java@ 4932

Last change on this file since 4932 was 4908, checked in by simon04, 12 years ago

fix #7327 - show hint in undo-menu which action will be undone (from event stack)

  • Property svn:eol-style set to native
File size: 24.9 KB
Line 
1// License: GPL. See LICENSE file for details.
2package org.openstreetmap.josm.gui;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.marktr;
6import static org.openstreetmap.josm.tools.I18n.tr;
7
8import java.awt.Component;
9import java.awt.Toolkit;
10import java.awt.event.KeyEvent;
11
12import javax.swing.JCheckBoxMenuItem;
13import javax.swing.JMenu;
14import javax.swing.JMenuBar;
15import javax.swing.JMenuItem;
16import javax.swing.JPopupMenu;
17import javax.swing.JSeparator;
18import javax.swing.KeyStroke;
19import javax.swing.event.MenuEvent;
20import javax.swing.event.MenuListener;
21
22import org.openstreetmap.josm.Main;
23import org.openstreetmap.josm.actions.AboutAction;
24import org.openstreetmap.josm.actions.AddNodeAction;
25import org.openstreetmap.josm.actions.AlignInCircleAction;
26import org.openstreetmap.josm.actions.AlignInLineAction;
27import org.openstreetmap.josm.actions.AutoScaleAction;
28import org.openstreetmap.josm.actions.ChangesetManagerToggleAction;
29import org.openstreetmap.josm.actions.CloseChangesetAction;
30import org.openstreetmap.josm.actions.CombineWayAction;
31import org.openstreetmap.josm.actions.CopyAction;
32import org.openstreetmap.josm.actions.CopyCoordinatesAction;
33import org.openstreetmap.josm.actions.CreateCircleAction;
34import org.openstreetmap.josm.actions.CreateMultipolygonAction;
35import org.openstreetmap.josm.actions.DeleteAction;
36import org.openstreetmap.josm.actions.DistributeAction;
37import org.openstreetmap.josm.actions.DownloadAction;
38import org.openstreetmap.josm.actions.DownloadPrimitiveAction;
39import org.openstreetmap.josm.actions.DownloadReferrersAction;
40import org.openstreetmap.josm.actions.DuplicateAction;
41import org.openstreetmap.josm.actions.ExitAction;
42import org.openstreetmap.josm.actions.ExpertToggleAction;
43import org.openstreetmap.josm.actions.FollowLineAction;
44import org.openstreetmap.josm.actions.FullscreenToggleAction;
45import org.openstreetmap.josm.actions.GpxExportAction;
46import org.openstreetmap.josm.actions.HelpAction;
47import org.openstreetmap.josm.actions.HistoryInfoAction;
48import org.openstreetmap.josm.actions.HistoryInfoWebAction;
49import org.openstreetmap.josm.actions.InfoAction;
50import org.openstreetmap.josm.actions.InfoWebAction;
51import org.openstreetmap.josm.actions.JoinAreasAction;
52import org.openstreetmap.josm.actions.JoinNodeWayAction;
53import org.openstreetmap.josm.actions.JosmAction;
54import org.openstreetmap.josm.actions.JumpToAction;
55import org.openstreetmap.josm.actions.MergeLayerAction;
56import org.openstreetmap.josm.actions.MergeNodesAction;
57import org.openstreetmap.josm.actions.MergeSelectionAction;
58import org.openstreetmap.josm.actions.MirrorAction;
59import org.openstreetmap.josm.actions.MoveAction;
60import org.openstreetmap.josm.actions.MoveNodeAction;
61import org.openstreetmap.josm.actions.NewAction;
62import org.openstreetmap.josm.actions.OpenFileAction;
63import org.openstreetmap.josm.actions.OpenLocationAction;
64import org.openstreetmap.josm.actions.OrthogonalizeAction;
65import org.openstreetmap.josm.actions.PasteAction;
66import org.openstreetmap.josm.actions.PasteTagsAction;
67import org.openstreetmap.josm.actions.PreferencesAction;
68import org.openstreetmap.josm.actions.PurgeAction;
69import org.openstreetmap.josm.actions.RedoAction;
70import org.openstreetmap.josm.actions.ReverseWayAction;
71import org.openstreetmap.josm.actions.SaveAction;
72import org.openstreetmap.josm.actions.SaveAsAction;
73import org.openstreetmap.josm.actions.SelectAllAction;
74import org.openstreetmap.josm.actions.SessionLoadAction;
75import org.openstreetmap.josm.actions.SessionSaveAsAction;
76import org.openstreetmap.josm.actions.ShowStatusReportAction;
77import org.openstreetmap.josm.actions.SimplifyWayAction;
78import org.openstreetmap.josm.actions.SplitWayAction;
79import org.openstreetmap.josm.actions.ToggleGPXLinesAction;
80import org.openstreetmap.josm.actions.UnGlueAction;
81import org.openstreetmap.josm.actions.UndoAction;
82import org.openstreetmap.josm.actions.UnselectAllAction;
83import org.openstreetmap.josm.actions.UpdateDataAction;
84import org.openstreetmap.josm.actions.UpdateModifiedAction;
85import org.openstreetmap.josm.actions.UpdateSelectionAction;
86import org.openstreetmap.josm.actions.UploadAction;
87import org.openstreetmap.josm.actions.UploadSelectionAction;
88import org.openstreetmap.josm.actions.ViewportFollowToggleAction;
89import org.openstreetmap.josm.actions.WireframeToggleAction;
90import org.openstreetmap.josm.actions.ZoomInAction;
91import org.openstreetmap.josm.actions.ZoomOutAction;
92import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo;
93import org.openstreetmap.josm.actions.audio.AudioBackAction;
94import org.openstreetmap.josm.actions.audio.AudioFasterAction;
95import org.openstreetmap.josm.actions.audio.AudioFwdAction;
96import org.openstreetmap.josm.actions.audio.AudioNextAction;
97import org.openstreetmap.josm.actions.audio.AudioPlayPauseAction;
98import org.openstreetmap.josm.actions.audio.AudioPrevAction;
99import org.openstreetmap.josm.actions.audio.AudioSlowerAction;
100import org.openstreetmap.josm.actions.search.SearchAction;
101import org.openstreetmap.josm.gui.io.RecentlyOpenedFilesMenu;
102import org.openstreetmap.josm.gui.layer.Layer;
103import org.openstreetmap.josm.gui.tagging.TaggingPresetSearchAction;
104import org.openstreetmap.josm.tools.ImageProvider;
105import org.openstreetmap.josm.tools.Shortcut;
106
107/**
108 * This is the JOSM main menu bar. It is overwritten to initialize itself and provide all menu
109 * entries as member variables (sort of collect them).
110 *
111 * It also provides possibilities to attach new menu entries (used by plugins).
112 *
113 * @author Immanuel.Scholz
114 */
115public class MainMenu extends JMenuBar {
116
117 /* File menu */
118 public final NewAction newAction = new NewAction();
119 public final OpenFileAction openFile = new OpenFileAction();
120 public final RecentlyOpenedFilesMenu recentlyOpened = new RecentlyOpenedFilesMenu();
121 public final OpenLocationAction openLocation = new OpenLocationAction();
122 public final JosmAction save = new SaveAction();
123 public final JosmAction saveAs = new SaveAsAction();
124 public JosmAction sessionLoad;
125 public JosmAction sessionSaveAs;
126 public final JosmAction gpxExport = new GpxExportAction();
127 public final DownloadAction download = new DownloadAction();
128 public final DownloadPrimitiveAction downloadPrimitive = new DownloadPrimitiveAction();
129 public final DownloadReferrersAction downloadReferrers = new DownloadReferrersAction();
130 public final CloseChangesetAction closeChangesetAction = new CloseChangesetAction();
131 public final JosmAction update = new UpdateDataAction();
132 public final JosmAction updateSelection = new UpdateSelectionAction();
133 public final JosmAction updateModified = new UpdateModifiedAction();
134 public final JosmAction upload = new UploadAction();
135 public final JosmAction uploadSelection = new UploadSelectionAction();
136 public final JosmAction exit = new ExitAction();
137
138 /* Edit menu */
139 public final UndoAction undo = new UndoAction();
140 public final RedoAction redo = new RedoAction();
141 public final JosmAction copy = new CopyAction();
142 public final JosmAction copyCoordinates = new CopyCoordinatesAction();
143 public final PasteAction paste = new PasteAction();
144 public final JosmAction pasteTags = new PasteTagsAction();
145 public final JosmAction duplicate = new DuplicateAction();
146 public final JosmAction delete = new DeleteAction();
147 public final JosmAction purge = new PurgeAction();
148 public final JosmAction merge = new MergeLayerAction();
149 public final JosmAction mergeSelected = new MergeSelectionAction();
150 public final JosmAction selectAll = new SelectAllAction();
151 public final JosmAction unselectAll = new UnselectAllAction();
152 public final JosmAction search = new SearchAction();
153 public final JosmAction preferences = new PreferencesAction();
154
155 /* View menu */
156 public final WireframeToggleAction wireFrameToggleAction = new WireframeToggleAction();
157 public final JosmAction toggleGPXLines = new ToggleGPXLinesAction();
158 public final InfoAction info = new InfoAction();
159 public final InfoWebAction infoweb = new InfoWebAction();
160 public final HistoryInfoAction historyinfo = new HistoryInfoAction();
161 public final HistoryInfoWebAction historyinfoweb = new HistoryInfoWebAction();
162
163 /* Tools menu */
164 public final JosmAction splitWay = new SplitWayAction();
165 public final JosmAction combineWay = new CombineWayAction();
166 public final JosmAction reverseWay = new ReverseWayAction();
167 public final JosmAction alignInCircle = new AlignInCircleAction();
168 public final JosmAction alignInLine = new AlignInLineAction();
169 public final JosmAction distribute = new DistributeAction();
170 public final OrthogonalizeAction ortho = new OrthogonalizeAction();
171 public final JosmAction orthoUndo = new Undo(); // action is not shown in the menu. Only triggered by shortcut
172 public final JosmAction mirror = new MirrorAction();
173 public final AddNodeAction addnode = new AddNodeAction();
174 public final MoveNodeAction movenode = new MoveNodeAction();
175 public final JosmAction createCircle = new CreateCircleAction();
176 public final JosmAction mergeNodes = new MergeNodesAction();
177 public final JosmAction joinNodeWay = new JoinNodeWayAction();
178 public final JosmAction unglueNodes = new UnGlueAction();
179 public final JosmAction simplifyWay = new SimplifyWayAction();
180 public final JosmAction joinAreas = new JoinAreasAction();
181 public final JosmAction createMultipolygon = new CreateMultipolygonAction();
182 public final JosmAction followLine = new FollowLineAction();
183
184 /* Audio menu */
185 public final JosmAction audioPlayPause = new AudioPlayPauseAction();
186 public final JosmAction audioNext = new AudioNextAction();
187 public final JosmAction audioPrev = new AudioPrevAction();
188 public final JosmAction audioFwd = new AudioFwdAction();
189 public final JosmAction audioBack = new AudioBackAction();
190 public final JosmAction audioFaster = new AudioFasterAction();
191 public final JosmAction audioSlower = new AudioSlowerAction();
192
193 /* Help menu */
194 public final HelpAction help = new HelpAction();
195 public final JosmAction about = new AboutAction();
196 public final JosmAction statusreport = new ShowStatusReportAction();
197
198 public final JMenu fileMenu = addMenu(marktr("File"), KeyEvent.VK_F, 0, ht("/Menu/File"));
199 public final JMenu sessionMenu = new JMenu(tr("Session")); // submenu of the file menu
200 public final JMenu editMenu = addMenu(marktr("Edit"), KeyEvent.VK_E, 1, ht("/Menu/Edit"));
201 public final JMenu viewMenu = addMenu(marktr("View"), KeyEvent.VK_V, 2, ht("/Menu/View"));
202 public final JMenu toolsMenu = addMenu(marktr("Tools"), KeyEvent.VK_T, 3, ht("/Menu/Tools"));
203 public final JMenu presetsMenu = addMenu(marktr("Presets"), KeyEvent.VK_P, 4, ht("/Menu/Presets"));
204 public final ImageryMenu imageryMenu =
205 (ImageryMenu)addMenu(new ImageryMenu(), marktr("Imagery"), KeyEvent.VK_I, 5, ht("/Menu/Imagery"));
206 /** the window menu is split into several groups. The first is for windows that can be opened from
207 * this menu any time, e.g. the changeset editor. The second group is for toggle dialogs and the third
208 * group is for currently open windows that cannot be toggled, e.g. relation editors. It's recommended
209 * to use WINDOW_MENU_GROUP to determine the group integer.
210 */
211 public final JMenu windowMenu = addMenu(marktr("Windows"), KeyEvent.VK_W, 6, ht("/Menu/Windows"));
212 public static enum WINDOW_MENU_GROUP { ALWAYS, TOGGLE_DIALOG, VOLATILE }
213
214 public JMenu audioMenu = null;
215 public final JMenu helpMenu = addMenu(marktr("Help"), KeyEvent.VK_H, 7, ht("/Menu/Help"));
216
217 public final int defaultMenuPos = 7;
218
219 public final JosmAction moveUpAction = new MoveAction(MoveAction.Direction.UP);
220 public final JosmAction moveDownAction = new MoveAction(MoveAction.Direction.DOWN);
221 public final JosmAction moveLeftAction = new MoveAction(MoveAction.Direction.LEFT);
222 public final JosmAction moveRightAction = new MoveAction(MoveAction.Direction.RIGHT);
223 public final JumpToAction jumpToAct = new JumpToAction();
224
225 public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction();
226 public FullscreenToggleAction fullscreenToggleAction = null;
227
228 /** this menu listener hides unnecessary JSeparators in a menu list but does not remove them.
229 * If at a later time the separators are required, they will be made visible again. Intended
230 * usage is make menus not look broken if separators are used to group the menu and some of
231 * these groups are empty.
232 */
233 public final static MenuListener menuSeparatorHandler = new MenuListener() {
234 @Override
235 public void menuCanceled(MenuEvent arg0) {}
236 @Override
237 public void menuDeselected(MenuEvent arg0) {}
238 @Override
239 public void menuSelected(MenuEvent a) {
240 if(!(a.getSource() instanceof JMenu))
241 return;
242 final JPopupMenu m = ((JMenu) a.getSource()).getPopupMenu();
243 for(int i=0; i < m.getComponentCount()-1; i++) {
244 if(!(m.getComponent(i) instanceof JSeparator)) {
245 continue;
246 }
247 // hide separator if the next menu item is one as well
248 ((JSeparator) m.getComponent(i)).setVisible(!(m.getComponent(i+1) instanceof JSeparator));
249 }
250 // hide separator at the end of the menu
251 if(m.getComponent(m.getComponentCount()-1) instanceof JSeparator) {
252 ((JSeparator) m.getComponent(m.getComponentCount()-1)).setVisible(false);
253 }
254 }
255 };
256
257 /**
258 * Add a JosmAction to a menu.
259 *
260 * This method handles all the shortcut handling. It also makes sure that actions that are
261 * handled by the OS are not duplicated on the menu. Menu item will be added at the end of
262 * the menu.
263 * @param menu to add the action to
264 * @param the action that should get a menu item
265 */
266 public static JMenuItem add(JMenu menu, JosmAction action) {
267 return add(menu, action, false);
268 }
269
270 public static JMenuItem add(JMenu menu, JosmAction action, boolean isExpert) {
271 if (action.getShortcut().getAutomatic())
272 return null;
273 JMenuItem menuitem = menu.add(action);
274 if (isExpert) {
275 ExpertToggleAction.addVisibilitySwitcher(menuitem);
276 }
277 KeyStroke ks = action.getShortcut().getKeyStroke();
278 if (ks != null) {
279 menuitem.setAccelerator(ks);
280 }
281 return menuitem;
282 }
283
284 /**
285 * Add a JosmAction to a menu.
286 *
287 * This method handles all the shortcut handling. It also makes sure that actions that are
288 * handled by the OS are not duplicated on the menu.
289 * @param menu to add the action to
290 * @param the action that should get a menu item
291 * @param group the item should be added to. Groups are split by a separator.
292 * 0 is the first group, -1 will add the item to the end.
293 */
294 public static <E extends Enum<E>> JMenuItem add(JMenu menu, JosmAction action, Enum<E> group) {
295 if (action.getShortcut().getAutomatic())
296 return null;
297 int i = getInsertionIndexForGroup(menu, group.ordinal());
298 JMenuItem menuitem = (JMenuItem) menu.add(new JMenuItem(action), i);
299 KeyStroke ks = action.getShortcut().getKeyStroke();
300 if (ks != null) {
301 menuitem.setAccelerator(ks);
302 }
303 return menuitem;
304 }
305
306 /**
307 * Add a JosmAction to a menu and automatically prints accelerator if available.
308 * Also adds a checkbox that may be toggled.
309 * @param menu to add the action to
310 * @param the action that should get a menu item
311 * @param group the item should be added to. Groups are split by a separator. Use
312 * one of the enums that are defined for some of the menus to tell in which
313 * group the item should go.
314 */
315 public static <E extends Enum<E>> JCheckBoxMenuItem addWithCheckbox(JMenu menu, JosmAction action, Enum<E> group) {
316 int i = getInsertionIndexForGroup(menu, group.ordinal());
317 final JCheckBoxMenuItem mi = (JCheckBoxMenuItem) menu.add(new JCheckBoxMenuItem(action), i);
318 final KeyStroke ks = action.getShortcut().getKeyStroke();
319 if (ks != null) {
320 mi.setAccelerator(ks);
321 }
322 return mi;
323 }
324
325 /** finds the correct insertion index for a given group and adds separators if necessary */
326 private static int getInsertionIndexForGroup(JMenu menu, int group) {
327 if(group < 0)
328 return -1;
329 // look for separator that *ends* the group (or stop at end of menu)
330 int i;
331 for(i=0; i < menu.getItemCount() && group >= 0; i++) {
332 if(menu.getItem(i) == null) {
333 group--;
334 }
335 }
336 // insert before separator that ends the group
337 if(group < 0) {
338 i--;
339 }
340 // not enough separators have been found, add them
341 while(group > 0) {
342 menu.addSeparator();
343 group--;
344 i++;
345 }
346 return i;
347 }
348
349 public JMenu addMenu(String name, int mnemonicKey, int position, String relativeHelpTopic) {
350 final JMenu menu = new JMenu(tr(name));
351 int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
352 int menuItemHeight = new JMenu().add(newAction).getPreferredSize().height;
353 MenuScroller.setScrollerFor(menu, screenHeight / menuItemHeight);
354 return addMenu(menu, name, mnemonicKey, position, relativeHelpTopic);
355 }
356
357 public JMenu addMenu(JMenu menu, String name, int mnemonicKey, int position, String relativeHelpTopic) {
358 Shortcut.registerShortcut("menu:" + name, tr("Menu: {0}", tr(name)), mnemonicKey,
359 Shortcut.GROUP_MNEMONIC).setMnemonic(menu);
360 add(menu, position);
361 menu.putClientProperty("help", relativeHelpTopic);
362 return menu;
363 }
364
365 public MainMenu() {
366 JMenuItem current;
367
368 add(fileMenu, newAction);
369 add(fileMenu, openFile);
370 fileMenu.add(recentlyOpened);
371 add(fileMenu, openLocation);
372 fileMenu.addSeparator();
373 add(fileMenu, save);
374 add(fileMenu, saveAs);
375 if (Main.pref.getBoolean("session")) {
376 sessionMenu.setToolTipText(tr("Save and load the current session (list of layers, etc.)"));
377 sessionMenu.setIcon(ImageProvider.get("session"));
378 sessionSaveAs = new SessionSaveAsAction();
379 sessionLoad = new SessionLoadAction();
380 add(sessionMenu, sessionSaveAs);
381 add(sessionMenu, sessionLoad);
382 fileMenu.add(sessionMenu);
383 }
384 add(fileMenu, gpxExport, true);
385 fileMenu.addSeparator();
386 add(fileMenu, download);
387 add(fileMenu, downloadPrimitive);
388 add(fileMenu, downloadReferrers);
389 add(fileMenu, update);
390 add(fileMenu, updateSelection);
391 add(fileMenu, updateModified);
392 fileMenu.addSeparator();
393 add(fileMenu, upload);
394 add(fileMenu, uploadSelection);
395 Component sep = new JPopupMenu.Separator();
396 fileMenu.add(sep);
397 ExpertToggleAction.addVisibilitySwitcher(sep);
398 add(fileMenu, closeChangesetAction, true);
399 fileMenu.addSeparator();
400 add(fileMenu, exit);
401
402 add(editMenu, undo);
403 Main.main.undoRedo.addCommandQueueListener(undo);
404 add(editMenu, redo);
405 Main.main.undoRedo.addCommandQueueListener(redo);
406 editMenu.addSeparator();
407 add(editMenu, copy);
408 add(editMenu, copyCoordinates, true);
409 add(editMenu, paste);
410 add(editMenu, pasteTags);
411 add(editMenu, duplicate);
412 add(editMenu, delete);
413 add(editMenu, purge, true);
414 editMenu.addSeparator();
415 add(editMenu,merge);
416 add(editMenu,mergeSelected);
417 editMenu.addSeparator();
418 add(editMenu, selectAll);
419 add(editMenu, unselectAll);
420 editMenu.addSeparator();
421 add(editMenu, search);
422 editMenu.addSeparator();
423 add(editMenu, preferences);
424
425 // -- wireframe toggle action
426 final JCheckBoxMenuItem wireframe = new JCheckBoxMenuItem(wireFrameToggleAction);
427 viewMenu.add(wireframe);
428 wireframe.setAccelerator(wireFrameToggleAction.getShortcut().getKeyStroke());
429 wireFrameToggleAction.addButtonModel(wireframe.getModel());
430
431 viewMenu.addSeparator();
432 add(viewMenu, new ZoomInAction());
433 add(viewMenu, new ZoomOutAction());
434 viewMenu.addSeparator();
435 for (String mode : AutoScaleAction.MODES) {
436 JosmAction autoScaleAction = new AutoScaleAction(mode);
437 add(viewMenu, autoScaleAction);
438 }
439
440 // -- viewport follow toggle action
441 ViewportFollowToggleAction viewportFollowToggleAction = new ViewportFollowToggleAction();
442 final JCheckBoxMenuItem vft = new JCheckBoxMenuItem(viewportFollowToggleAction);
443 ExpertToggleAction.addVisibilitySwitcher(vft);
444 viewMenu.add(vft);
445 vft.setAccelerator(viewportFollowToggleAction.getShortcut().getKeyStroke());
446 viewportFollowToggleAction.addButtonModel(vft.getModel());
447
448 if(!Main.applet && Main.platform.canFullscreen()) {
449 // -- fullscreen toggle action
450 fullscreenToggleAction = new FullscreenToggleAction();
451 final JCheckBoxMenuItem fullscreen = new JCheckBoxMenuItem(fullscreenToggleAction);
452 viewMenu.addSeparator();
453 viewMenu.add(fullscreen);
454 fullscreen.setAccelerator(fullscreenToggleAction.getShortcut().getKeyStroke());
455 fullscreenToggleAction.addButtonModel(fullscreen.getModel());
456 }
457 viewMenu.addSeparator();
458 add(viewMenu, info);
459 add(viewMenu, infoweb);
460 add(viewMenu, historyinfo);
461 add(viewMenu, historyinfoweb);
462 viewMenu.addSeparator();
463 // -- expert mode toggle action
464 final JCheckBoxMenuItem expertItem = new JCheckBoxMenuItem(ExpertToggleAction.getInstance());
465 viewMenu.add(expertItem);
466 ExpertToggleAction.getInstance().addButtonModel(expertItem.getModel());
467
468 add(presetsMenu, presetSearchAction);
469 presetsMenu.addSeparator();
470
471 add(toolsMenu, splitWay);
472 add(toolsMenu, combineWay);
473 toolsMenu.addSeparator();
474 add(toolsMenu, reverseWay);
475 add(toolsMenu, simplifyWay);
476 toolsMenu.addSeparator();
477 add(toolsMenu, alignInCircle);
478 add(toolsMenu, alignInLine);
479 add(toolsMenu, distribute);
480 add(toolsMenu, ortho);
481 add(toolsMenu, mirror, true);
482 toolsMenu.addSeparator();
483 add(toolsMenu, followLine, true);
484 add(toolsMenu, addnode, true);
485 add(toolsMenu, movenode, true);
486 add(toolsMenu, createCircle);
487 toolsMenu.addSeparator();
488 add(toolsMenu, mergeNodes);
489 add(toolsMenu, joinNodeWay);
490 add(toolsMenu, unglueNodes);
491 toolsMenu.addSeparator();
492 add(toolsMenu, joinAreas);
493 add(toolsMenu, createMultipolygon);
494
495 // -- changeset manager toggle action
496 ChangesetManagerToggleAction changesetManagerToggleAction = new ChangesetManagerToggleAction();
497 final JCheckBoxMenuItem mi = MainMenu.addWithCheckbox(windowMenu, changesetManagerToggleAction,
498 MainMenu.WINDOW_MENU_GROUP.ALWAYS);
499 changesetManagerToggleAction.addButtonModel(mi.getModel());
500
501
502 if (!Main.pref.getBoolean("audio.menuinvisible", false)) {
503 audioMenu = addMenu(marktr("Audio"), KeyEvent.VK_U, defaultMenuPos, ht("/Menu/Audio"));
504 add(audioMenu, audioPlayPause);
505 add(audioMenu, audioNext);
506 add(audioMenu, audioPrev);
507 add(audioMenu, audioFwd);
508 add(audioMenu, audioBack);
509 add(audioMenu, audioSlower);
510 add(audioMenu, audioFaster);
511 }
512
513 helpMenu.add(statusreport);
514
515 current = helpMenu.add(help); // FIXME why is help not a JosmAction?
516 current.setAccelerator(Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1,
517 Shortcut.GROUP_DIRECT).getKeyStroke());
518 add(helpMenu, about);
519
520
521 windowMenu.addMenuListener(menuSeparatorHandler);
522
523 new PresetsMenuEnabler(presetsMenu).refreshEnabled();
524 }
525
526 static class PresetsMenuEnabler implements MapView.LayerChangeListener {
527 private JMenu presetsMenu;
528 public PresetsMenuEnabler(JMenu presetsMenu) {
529 MapView.addLayerChangeListener(this);
530 this.presetsMenu = presetsMenu;
531 }
532 /**
533 * Refreshes the enabled state
534 *
535 */
536 protected void refreshEnabled() {
537 presetsMenu.setEnabled(Main.map != null
538 && Main.map.mapView !=null
539 && Main.map.mapView.getEditLayer() != null
540 );
541 }
542
543 public void activeLayerChange(Layer oldLayer, Layer newLayer) {
544 refreshEnabled();
545 }
546
547 public void layerAdded(Layer newLayer) {
548 refreshEnabled();
549 }
550
551 public void layerRemoved(Layer oldLayer) {
552 refreshEnabled();
553 }
554 }
555}
Note: See TracBrowser for help on using the repository browser.