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

Last change on this file since 3966 was 3954, checked in by stoecker, 13 years ago

disable fullscreen action for applet

  • Property svn:eol-style set to native
File size: 17.7 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.event.KeyEvent;
9
10import javax.swing.JCheckBoxMenuItem;
11import javax.swing.JMenu;
12import javax.swing.JMenuBar;
13import javax.swing.JMenuItem;
14import javax.swing.KeyStroke;
15
16import org.openstreetmap.josm.Main;
17import org.openstreetmap.josm.actions.AboutAction;
18import org.openstreetmap.josm.actions.AddNodeAction;
19import org.openstreetmap.josm.actions.AlignInCircleAction;
20import org.openstreetmap.josm.actions.AlignInLineAction;
21import org.openstreetmap.josm.actions.AutoScaleAction;
22import org.openstreetmap.josm.actions.ChangesetManagerToggleAction;
23import org.openstreetmap.josm.actions.CloseChangesetAction;
24import org.openstreetmap.josm.actions.CombineWayAction;
25import org.openstreetmap.josm.actions.CopyAction;
26import org.openstreetmap.josm.actions.CreateCircleAction;
27import org.openstreetmap.josm.actions.CreateMultipolygonAction;
28import org.openstreetmap.josm.actions.DeleteAction;
29import org.openstreetmap.josm.actions.DistributeAction;
30import org.openstreetmap.josm.actions.DownloadAction;
31import org.openstreetmap.josm.actions.DownloadPrimitiveAction;
32import org.openstreetmap.josm.actions.DownloadReferrersAction;
33import org.openstreetmap.josm.actions.DuplicateAction;
34import org.openstreetmap.josm.actions.ExitAction;
35import org.openstreetmap.josm.actions.FullscreenToggleAction;
36import org.openstreetmap.josm.actions.GpxExportAction;
37import org.openstreetmap.josm.actions.HelpAction;
38import org.openstreetmap.josm.actions.HistoryInfoAction;
39import org.openstreetmap.josm.actions.InfoAction;
40import org.openstreetmap.josm.actions.JoinAreasAction;
41import org.openstreetmap.josm.actions.JoinNodeWayAction;
42import org.openstreetmap.josm.actions.JosmAction;
43import org.openstreetmap.josm.actions.JumpToAction;
44import org.openstreetmap.josm.actions.MergeLayerAction;
45import org.openstreetmap.josm.actions.MergeNodesAction;
46import org.openstreetmap.josm.actions.MergeSelectionAction;
47import org.openstreetmap.josm.actions.MirrorAction;
48import org.openstreetmap.josm.actions.MoveAction;
49import org.openstreetmap.josm.actions.MoveNodeAction;
50import org.openstreetmap.josm.actions.NewAction;
51import org.openstreetmap.josm.actions.OpenFileAction;
52import org.openstreetmap.josm.actions.OpenLocationAction;
53import org.openstreetmap.josm.actions.OrthogonalizeAction;
54import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo;
55import org.openstreetmap.josm.actions.PasteAction;
56import org.openstreetmap.josm.actions.PasteTagsAction;
57import org.openstreetmap.josm.actions.PreferencesAction;
58import org.openstreetmap.josm.actions.PurgeAction;
59import org.openstreetmap.josm.actions.RedoAction;
60import org.openstreetmap.josm.actions.ReverseWayAction;
61import org.openstreetmap.josm.actions.SaveAction;
62import org.openstreetmap.josm.actions.SaveAsAction;
63import org.openstreetmap.josm.actions.SelectAllAction;
64import org.openstreetmap.josm.actions.ShowStatusReportAction;
65import org.openstreetmap.josm.actions.SimplifyWayAction;
66import org.openstreetmap.josm.actions.SplitWayAction;
67import org.openstreetmap.josm.actions.ToggleGPXLinesAction;
68import org.openstreetmap.josm.actions.UnGlueAction;
69import org.openstreetmap.josm.actions.UndoAction;
70import org.openstreetmap.josm.actions.UnselectAllAction;
71import org.openstreetmap.josm.actions.UpdateDataAction;
72import org.openstreetmap.josm.actions.UpdateModifiedAction;
73import org.openstreetmap.josm.actions.UpdateSelectionAction;
74import org.openstreetmap.josm.actions.UploadAction;
75import org.openstreetmap.josm.actions.UploadSelectionAction;
76import org.openstreetmap.josm.actions.ViewportFollowToggleAction;
77import org.openstreetmap.josm.actions.WireframeToggleAction;
78import org.openstreetmap.josm.actions.ZoomInAction;
79import org.openstreetmap.josm.actions.ZoomOutAction;
80import org.openstreetmap.josm.actions.audio.AudioBackAction;
81import org.openstreetmap.josm.actions.audio.AudioFasterAction;
82import org.openstreetmap.josm.actions.audio.AudioFwdAction;
83import org.openstreetmap.josm.actions.audio.AudioNextAction;
84import org.openstreetmap.josm.actions.audio.AudioPlayPauseAction;
85import org.openstreetmap.josm.actions.audio.AudioPrevAction;
86import org.openstreetmap.josm.actions.audio.AudioSlowerAction;
87import org.openstreetmap.josm.actions.search.SearchAction;
88import org.openstreetmap.josm.gui.io.RecentlyOpenedFilesMenu;
89import org.openstreetmap.josm.gui.layer.Layer;
90import org.openstreetmap.josm.gui.tagging.TaggingPresetSearchAction;
91import org.openstreetmap.josm.tools.Shortcut;
92
93/**
94 * This is the JOSM main menu bar. It is overwritten to initialize itself and provide all menu
95 * entries as member variables (sort of collect them).
96 *
97 * It also provides possibilities to attach new menu entries (used by plugins).
98 *
99 * @author Immanuel.Scholz
100 */
101public class MainMenu extends JMenuBar {
102
103 /* File menu */
104 public final NewAction newAction = new NewAction();
105 public final OpenFileAction openFile = new OpenFileAction();
106 public final RecentlyOpenedFilesMenu recentlyOpened = new RecentlyOpenedFilesMenu();
107 public final OpenLocationAction openLocation = new OpenLocationAction();
108 public final JosmAction save = new SaveAction();
109 public final JosmAction saveAs = new SaveAsAction();
110 public final JosmAction gpxExport = new GpxExportAction();
111 public final DownloadAction download = new DownloadAction();
112 public final DownloadPrimitiveAction downloadPrimitive = new DownloadPrimitiveAction();
113 public final DownloadReferrersAction downloadReferrers = new DownloadReferrersAction();
114 public final CloseChangesetAction closeChangesetAction = new CloseChangesetAction();
115 public final JosmAction update = new UpdateDataAction();
116 public final JosmAction updateSelection = new UpdateSelectionAction();
117 public final JosmAction updateModified = new UpdateModifiedAction();
118 public final JosmAction upload = new UploadAction();
119 public final JosmAction uploadSelection = new UploadSelectionAction();
120 public final JosmAction exit = new ExitAction();
121
122 /* Edit menu */
123 public final UndoAction undo = new UndoAction();
124 public final RedoAction redo = new RedoAction();
125 public final JosmAction copy = new CopyAction();
126 public final JosmAction paste = new PasteAction();
127 public final JosmAction pasteTags = new PasteTagsAction();
128 public final JosmAction duplicate = new DuplicateAction();
129 public final JosmAction delete = new DeleteAction();
130 public final JosmAction purge = new PurgeAction();
131 public final JosmAction merge = new MergeLayerAction();
132 public final JosmAction mergeSelected = new MergeSelectionAction();
133 public final JosmAction selectAll = new SelectAllAction();
134 public final JosmAction unselectAll = new UnselectAllAction();
135 /* crashes when loading data, if using JosmAction for search */
136 public final JosmAction search = new SearchAction();
137 public final JosmAction preferences = new PreferencesAction();
138
139 /* View menu */
140 public final WireframeToggleAction wireFrameToggleAction = new WireframeToggleAction();
141 public final JosmAction toggleGPXLines = new ToggleGPXLinesAction();
142 public final InfoAction info = new InfoAction();
143 public final HistoryInfoAction historyinfo = new HistoryInfoAction();
144
145 /* Tools menu */
146 public final JosmAction splitWay = new SplitWayAction();
147 public final JosmAction combineWay = new CombineWayAction();
148 public final JosmAction reverseWay = new ReverseWayAction();
149 public final JosmAction alignInCircle = new AlignInCircleAction();
150 public final JosmAction alignInLine = new AlignInLineAction();
151 public final JosmAction distribute = new DistributeAction();
152 public final OrthogonalizeAction ortho = new OrthogonalizeAction();
153 public final JosmAction orthoUndo = new Undo(); // action is not shown in the menu. Only triggered by shortcut
154 public final JosmAction mirror = new MirrorAction();
155 public final AddNodeAction addnode = new AddNodeAction();
156 public final MoveNodeAction movenode = new MoveNodeAction();
157 public final JosmAction createCircle = new CreateCircleAction();
158 public final JosmAction mergeNodes = new MergeNodesAction();
159 public final JosmAction joinNodeWay = new JoinNodeWayAction();
160 public final JosmAction unglueNodes = new UnGlueAction();
161 public final JosmAction simplifyWay = new SimplifyWayAction();
162 public final JosmAction joinAreas = new JoinAreasAction();
163 public final JosmAction createMultipolygon = new CreateMultipolygonAction();
164
165 /* Audio menu */
166 public final JosmAction audioPlayPause = new AudioPlayPauseAction();
167 public final JosmAction audioNext = new AudioNextAction();
168 public final JosmAction audioPrev = new AudioPrevAction();
169 public final JosmAction audioFwd = new AudioFwdAction();
170 public final JosmAction audioBack = new AudioBackAction();
171 public final JosmAction audioFaster = new AudioFasterAction();
172 public final JosmAction audioSlower = new AudioSlowerAction();
173
174 /* Help menu */
175 public final HelpAction help = new HelpAction();
176 public final JosmAction about = new AboutAction();
177 public final JosmAction statusreport = new ShowStatusReportAction();
178
179 public final JMenu fileMenu = addMenu(marktr("File"), KeyEvent.VK_F, 0, ht("/Menu/File"));
180 public final JMenu editMenu = addMenu(marktr("Edit"), KeyEvent.VK_E, 1, ht("/Menu/Edit"));
181 public final JMenu viewMenu = addMenu(marktr("View"), KeyEvent.VK_V, 2, ht("/Menu/View"));
182 public final JMenu toolsMenu = addMenu(marktr("Tools"), KeyEvent.VK_T, 3, ht("/Menu/Tools"));
183 public final JMenu presetsMenu = addMenu(marktr("Presets"), KeyEvent.VK_P, 4, ht("/Menu/Presets"));
184 public final ImageryMenu imageryMenu =
185 (ImageryMenu)addMenu(new ImageryMenu(), marktr("Imagery"), KeyEvent.VK_I, 5, ht("/Menu/Imagery"));
186 public JMenu audioMenu = null;
187 public final JMenu helpMenu = addMenu(marktr("Help"), KeyEvent.VK_H, 6, ht("/Menu/Help"));
188 public final int defaultMenuPos = 6;
189
190 public final JosmAction moveUpAction = new MoveAction(MoveAction.Direction.UP);
191 public final JosmAction moveDownAction = new MoveAction(MoveAction.Direction.DOWN);
192 public final JosmAction moveLeftAction = new MoveAction(MoveAction.Direction.LEFT);
193 public final JosmAction moveRightAction = new MoveAction(MoveAction.Direction.RIGHT);
194 public final JumpToAction jumpToAct = new JumpToAction();
195
196 public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction();
197
198 /**
199 * Add a JosmAction to a menu.
200 *
201 * This method handles all the shortcut handling. It also makes sure that actions that are
202 * handled by the OS are not duplicated on the menu.
203 */
204 public static JMenuItem add(JMenu menu, JosmAction action) {
205 JMenuItem menuitem = null;
206 if (!action.getShortcut().getAutomatic()) {
207 menuitem = menu.add(action);
208 KeyStroke ks = action.getShortcut().getKeyStroke();
209 if (ks != null) {
210 menuitem.setAccelerator(ks);
211 }
212 }
213 return menuitem;
214 }
215
216 public JMenu addMenu(String name, int mnemonicKey, int position, String relativeHelpTopic) {
217 return addMenu(new JMenu(tr(name)), name, mnemonicKey, position, relativeHelpTopic);
218 }
219
220 public JMenu addMenu(JMenu menu, String name, int mnemonicKey, int position, String relativeHelpTopic) {
221 Shortcut.registerShortcut("menu:" + name, tr("Menu: {0}", tr(name)), mnemonicKey,
222 Shortcut.GROUP_MNEMONIC).setMnemonic(menu);
223 add(menu, position);
224 menu.putClientProperty("help", relativeHelpTopic);
225 return menu;
226 }
227
228 public MainMenu() {
229 JMenuItem current;
230
231 add(fileMenu, newAction);
232 add(fileMenu, openFile);
233 fileMenu.add(recentlyOpened);
234 add(fileMenu, openLocation);
235 fileMenu.addSeparator();
236 add(fileMenu, save);
237 add(fileMenu, saveAs);
238 add(fileMenu, gpxExport);
239 fileMenu.addSeparator();
240 add(fileMenu, download);
241 add(fileMenu, downloadPrimitive);
242 add(fileMenu, downloadReferrers);
243 add(fileMenu, update);
244 add(fileMenu, updateSelection);
245 add(fileMenu, updateModified);
246 fileMenu.addSeparator();
247 add(fileMenu, upload);
248 add(fileMenu, uploadSelection);
249 fileMenu.addSeparator();
250 add(fileMenu, closeChangesetAction);
251 fileMenu.addSeparator();
252 add(fileMenu, exit);
253
254 add(editMenu, undo);
255 add(editMenu, redo);
256 editMenu.addSeparator();
257 add(editMenu, copy);
258 add(editMenu, paste);
259 add(editMenu, pasteTags);
260 add(editMenu, duplicate);
261 add(editMenu, delete);
262 add(editMenu, purge);
263 editMenu.addSeparator();
264 add(editMenu,merge);
265 add(editMenu,mergeSelected);
266 editMenu.addSeparator();
267 add(editMenu, selectAll);
268 add(editMenu, unselectAll);
269 editMenu.addSeparator();
270 add(editMenu, search);
271 editMenu.addSeparator();
272 add(editMenu, preferences);
273
274 // -- wireframe toggle action
275 final JCheckBoxMenuItem wireframe = new JCheckBoxMenuItem(wireFrameToggleAction);
276 viewMenu.add(wireframe);
277 wireframe.setAccelerator(wireFrameToggleAction.getShortcut().getKeyStroke());
278 wireFrameToggleAction.addButtonModel(wireframe.getModel());
279
280 viewMenu.addSeparator();
281 add(viewMenu, new ZoomInAction());
282 add(viewMenu, new ZoomOutAction());
283 viewMenu.addSeparator();
284 for (String mode : AutoScaleAction.MODES) {
285 JosmAction autoScaleAction = new AutoScaleAction(mode);
286 add(viewMenu, autoScaleAction);
287 }
288
289 // -- viewport follow toggle action
290 ViewportFollowToggleAction viewportFollowToggleAction = new ViewportFollowToggleAction();
291 final JCheckBoxMenuItem vft = new JCheckBoxMenuItem(viewportFollowToggleAction);
292 viewMenu.add(vft);
293 vft.setAccelerator(viewportFollowToggleAction.getShortcut().getKeyStroke());
294 viewportFollowToggleAction.addButtonModel(vft.getModel());
295
296 // -- changeset manager toggle action
297 ChangesetManagerToggleAction changesetManagerToggleAction = new ChangesetManagerToggleAction();
298 final JCheckBoxMenuItem mi = new JCheckBoxMenuItem(changesetManagerToggleAction);
299 viewMenu.addSeparator();
300 viewMenu.add(mi);
301 mi.setAccelerator(changesetManagerToggleAction.getShortcut().getKeyStroke());
302 changesetManagerToggleAction.addButtonModel(mi.getModel());
303
304 if(!Main.applet) {
305 // -- fullscreen toggle action
306 FullscreenToggleAction fullscreenToggleAction = new FullscreenToggleAction();
307 if (fullscreenToggleAction.canFullscreen()) {
308 final JCheckBoxMenuItem fullscreen = new JCheckBoxMenuItem(fullscreenToggleAction);
309 viewMenu.addSeparator();
310 viewMenu.add(fullscreen);
311 fullscreen.setAccelerator(fullscreenToggleAction.getShortcut().getKeyStroke());
312 fullscreenToggleAction.addButtonModel(fullscreen.getModel());
313 }
314 }
315 viewMenu.addSeparator();
316 add(viewMenu, info);
317 add(viewMenu, historyinfo);
318
319 add(presetsMenu, presetSearchAction);
320
321 add(toolsMenu, splitWay);
322 add(toolsMenu, combineWay);
323 toolsMenu.addSeparator();
324 add(toolsMenu, reverseWay);
325 add(toolsMenu, simplifyWay);
326 toolsMenu.addSeparator();
327 add(toolsMenu, alignInCircle);
328 add(toolsMenu, alignInLine);
329 add(toolsMenu, distribute);
330 add(toolsMenu, ortho);
331 add(toolsMenu, mirror);
332 toolsMenu.addSeparator();
333 add(toolsMenu, addnode);
334 add(toolsMenu, movenode);
335 add(toolsMenu, createCircle);
336 toolsMenu.addSeparator();
337 add(toolsMenu, mergeNodes);
338 add(toolsMenu, joinNodeWay);
339 add(toolsMenu, unglueNodes);
340 toolsMenu.addSeparator();
341 add(toolsMenu, joinAreas);
342 add(toolsMenu, createMultipolygon);
343
344 if (!Main.pref.getBoolean("audio.menuinvisible", false)) {
345 audioMenu = addMenu(marktr("Audio"), KeyEvent.VK_A, defaultMenuPos, ht("/Menu/Audio"));
346 add(audioMenu, audioPlayPause);
347 add(audioMenu, audioNext);
348 add(audioMenu, audioPrev);
349 add(audioMenu, audioFwd);
350 add(audioMenu, audioBack);
351 add(audioMenu, audioSlower);
352 add(audioMenu, audioFaster);
353 }
354
355 helpMenu.add(statusreport);
356
357 current = helpMenu.add(help); // FIXME why is help not a JosmAction?
358 current.setAccelerator(Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1,
359 Shortcut.GROUP_DIRECT).getKeyStroke());
360 add(helpMenu, about);
361
362 new PresetsMenuEnabler(presetsMenu).refreshEnabled();
363 }
364
365 static class PresetsMenuEnabler implements MapView.LayerChangeListener {
366 private JMenu presetsMenu;
367 public PresetsMenuEnabler(JMenu presetsMenu) {
368 MapView.addLayerChangeListener(this);
369 this.presetsMenu = presetsMenu;
370 }
371 /**
372 * Refreshes the enabled state
373 *
374 */
375 protected void refreshEnabled() {
376 presetsMenu.setEnabled(Main.map != null
377 && Main.map.mapView !=null
378 && Main.map.mapView.getEditLayer() != null
379 );
380 }
381
382 public void activeLayerChange(Layer oldLayer, Layer newLayer) {
383 refreshEnabled();
384 }
385
386 public void layerAdded(Layer newLayer) {
387 refreshEnabled();
388 }
389
390 public void layerRemoved(Layer oldLayer) {
391 refreshEnabled();
392 }
393 }
394}
Note: See TracBrowser for help on using the repository browser.