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

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

give more control (esp. to plugins) where to add an entry in the main menu (i.e., add addAfter() method)

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