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

Last change on this file since 6040 was 5965, checked in by akks, 11 years ago

see #8652 (patch by cmuelle8, part 1, modified): add "toggle panels" action (soon will be on Tab)
rework all toolbar context menus (add "do not hide" item and remove PopupMenuLauncher usage)
fixing minor warnings (@Override, private final)

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