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

Last change on this file since 3973 was 3969, checked in by bastiK, 13 years ago

MapCSS: fixe related to layers

  • Property svn:eol-style set to native
File size: 17.6 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 PasteAction 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 public final JosmAction search = new SearchAction();
136 public final JosmAction preferences = new PreferencesAction();
137
138 /* View menu */
139 public final WireframeToggleAction wireFrameToggleAction = new WireframeToggleAction();
140 public final JosmAction toggleGPXLines = new ToggleGPXLinesAction();
141 public final InfoAction info = new InfoAction();
142 public final HistoryInfoAction historyinfo = new HistoryInfoAction();
143
144 /* Tools menu */
145 public final JosmAction splitWay = new SplitWayAction();
146 public final JosmAction combineWay = new CombineWayAction();
147 public final JosmAction reverseWay = new ReverseWayAction();
148 public final JosmAction alignInCircle = new AlignInCircleAction();
149 public final JosmAction alignInLine = new AlignInLineAction();
150 public final JosmAction distribute = new DistributeAction();
151 public final OrthogonalizeAction ortho = new OrthogonalizeAction();
152 public final JosmAction orthoUndo = new Undo(); // action is not shown in the menu. Only triggered by shortcut
153 public final JosmAction mirror = new MirrorAction();
154 public final AddNodeAction addnode = new AddNodeAction();
155 public final MoveNodeAction movenode = new MoveNodeAction();
156 public final JosmAction createCircle = new CreateCircleAction();
157 public final JosmAction mergeNodes = new MergeNodesAction();
158 public final JosmAction joinNodeWay = new JoinNodeWayAction();
159 public final JosmAction unglueNodes = new UnGlueAction();
160 public final JosmAction simplifyWay = new SimplifyWayAction();
161 public final JosmAction joinAreas = new JoinAreasAction();
162 public final JosmAction createMultipolygon = new CreateMultipolygonAction();
163
164 /* Audio menu */
165 public final JosmAction audioPlayPause = new AudioPlayPauseAction();
166 public final JosmAction audioNext = new AudioNextAction();
167 public final JosmAction audioPrev = new AudioPrevAction();
168 public final JosmAction audioFwd = new AudioFwdAction();
169 public final JosmAction audioBack = new AudioBackAction();
170 public final JosmAction audioFaster = new AudioFasterAction();
171 public final JosmAction audioSlower = new AudioSlowerAction();
172
173 /* Help menu */
174 public final HelpAction help = new HelpAction();
175 public final JosmAction about = new AboutAction();
176 public final JosmAction statusreport = new ShowStatusReportAction();
177
178 public final JMenu fileMenu = addMenu(marktr("File"), KeyEvent.VK_F, 0, ht("/Menu/File"));
179 public final JMenu editMenu = addMenu(marktr("Edit"), KeyEvent.VK_E, 1, ht("/Menu/Edit"));
180 public final JMenu viewMenu = addMenu(marktr("View"), KeyEvent.VK_V, 2, ht("/Menu/View"));
181 public final JMenu toolsMenu = addMenu(marktr("Tools"), KeyEvent.VK_T, 3, ht("/Menu/Tools"));
182 public final JMenu presetsMenu = addMenu(marktr("Presets"), KeyEvent.VK_P, 4, ht("/Menu/Presets"));
183 public final ImageryMenu imageryMenu =
184 (ImageryMenu)addMenu(new ImageryMenu(), marktr("Imagery"), KeyEvent.VK_I, 5, ht("/Menu/Imagery"));
185 public JMenu audioMenu = null;
186 public final JMenu helpMenu = addMenu(marktr("Help"), KeyEvent.VK_H, 6, ht("/Menu/Help"));
187 public final int defaultMenuPos = 6;
188
189 public final JosmAction moveUpAction = new MoveAction(MoveAction.Direction.UP);
190 public final JosmAction moveDownAction = new MoveAction(MoveAction.Direction.DOWN);
191 public final JosmAction moveLeftAction = new MoveAction(MoveAction.Direction.LEFT);
192 public final JosmAction moveRightAction = new MoveAction(MoveAction.Direction.RIGHT);
193 public final JumpToAction jumpToAct = new JumpToAction();
194
195 public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction();
196
197 /**
198 * Add a JosmAction to a menu.
199 *
200 * This method handles all the shortcut handling. It also makes sure that actions that are
201 * handled by the OS are not duplicated on the menu.
202 */
203 public static JMenuItem add(JMenu menu, JosmAction action) {
204 JMenuItem menuitem = null;
205 if (!action.getShortcut().getAutomatic()) {
206 menuitem = menu.add(action);
207 KeyStroke ks = action.getShortcut().getKeyStroke();
208 if (ks != null) {
209 menuitem.setAccelerator(ks);
210 }
211 }
212 return menuitem;
213 }
214
215 public JMenu addMenu(String name, int mnemonicKey, int position, String relativeHelpTopic) {
216 return addMenu(new JMenu(tr(name)), name, mnemonicKey, position, relativeHelpTopic);
217 }
218
219 public JMenu addMenu(JMenu menu, String name, int mnemonicKey, int position, String relativeHelpTopic) {
220 Shortcut.registerShortcut("menu:" + name, tr("Menu: {0}", tr(name)), mnemonicKey,
221 Shortcut.GROUP_MNEMONIC).setMnemonic(menu);
222 add(menu, position);
223 menu.putClientProperty("help", relativeHelpTopic);
224 return menu;
225 }
226
227 public MainMenu() {
228 JMenuItem current;
229
230 add(fileMenu, newAction);
231 add(fileMenu, openFile);
232 fileMenu.add(recentlyOpened);
233 add(fileMenu, openLocation);
234 fileMenu.addSeparator();
235 add(fileMenu, save);
236 add(fileMenu, saveAs);
237 add(fileMenu, gpxExport);
238 fileMenu.addSeparator();
239 add(fileMenu, download);
240 add(fileMenu, downloadPrimitive);
241 add(fileMenu, downloadReferrers);
242 add(fileMenu, update);
243 add(fileMenu, updateSelection);
244 add(fileMenu, updateModified);
245 fileMenu.addSeparator();
246 add(fileMenu, upload);
247 add(fileMenu, uploadSelection);
248 fileMenu.addSeparator();
249 add(fileMenu, closeChangesetAction);
250 fileMenu.addSeparator();
251 add(fileMenu, exit);
252
253 add(editMenu, undo);
254 add(editMenu, redo);
255 editMenu.addSeparator();
256 add(editMenu, copy);
257 add(editMenu, paste);
258 add(editMenu, pasteTags);
259 add(editMenu, duplicate);
260 add(editMenu, delete);
261 add(editMenu, purge);
262 editMenu.addSeparator();
263 add(editMenu,merge);
264 add(editMenu,mergeSelected);
265 editMenu.addSeparator();
266 add(editMenu, selectAll);
267 add(editMenu, unselectAll);
268 editMenu.addSeparator();
269 add(editMenu, search);
270 editMenu.addSeparator();
271 add(editMenu, preferences);
272
273 // -- wireframe toggle action
274 final JCheckBoxMenuItem wireframe = new JCheckBoxMenuItem(wireFrameToggleAction);
275 viewMenu.add(wireframe);
276 wireframe.setAccelerator(wireFrameToggleAction.getShortcut().getKeyStroke());
277 wireFrameToggleAction.addButtonModel(wireframe.getModel());
278
279 viewMenu.addSeparator();
280 add(viewMenu, new ZoomInAction());
281 add(viewMenu, new ZoomOutAction());
282 viewMenu.addSeparator();
283 for (String mode : AutoScaleAction.MODES) {
284 JosmAction autoScaleAction = new AutoScaleAction(mode);
285 add(viewMenu, autoScaleAction);
286 }
287
288 // -- viewport follow toggle action
289 ViewportFollowToggleAction viewportFollowToggleAction = new ViewportFollowToggleAction();
290 final JCheckBoxMenuItem vft = new JCheckBoxMenuItem(viewportFollowToggleAction);
291 viewMenu.add(vft);
292 vft.setAccelerator(viewportFollowToggleAction.getShortcut().getKeyStroke());
293 viewportFollowToggleAction.addButtonModel(vft.getModel());
294
295 // -- changeset manager toggle action
296 ChangesetManagerToggleAction changesetManagerToggleAction = new ChangesetManagerToggleAction();
297 final JCheckBoxMenuItem mi = new JCheckBoxMenuItem(changesetManagerToggleAction);
298 viewMenu.addSeparator();
299 viewMenu.add(mi);
300 mi.setAccelerator(changesetManagerToggleAction.getShortcut().getKeyStroke());
301 changesetManagerToggleAction.addButtonModel(mi.getModel());
302
303 if(!Main.applet) {
304 // -- fullscreen toggle action
305 FullscreenToggleAction fullscreenToggleAction = new FullscreenToggleAction();
306 if (fullscreenToggleAction.canFullscreen()) {
307 final JCheckBoxMenuItem fullscreen = new JCheckBoxMenuItem(fullscreenToggleAction);
308 viewMenu.addSeparator();
309 viewMenu.add(fullscreen);
310 fullscreen.setAccelerator(fullscreenToggleAction.getShortcut().getKeyStroke());
311 fullscreenToggleAction.addButtonModel(fullscreen.getModel());
312 }
313 }
314 viewMenu.addSeparator();
315 add(viewMenu, info);
316 add(viewMenu, historyinfo);
317
318 add(presetsMenu, presetSearchAction);
319
320 add(toolsMenu, splitWay);
321 add(toolsMenu, combineWay);
322 toolsMenu.addSeparator();
323 add(toolsMenu, reverseWay);
324 add(toolsMenu, simplifyWay);
325 toolsMenu.addSeparator();
326 add(toolsMenu, alignInCircle);
327 add(toolsMenu, alignInLine);
328 add(toolsMenu, distribute);
329 add(toolsMenu, ortho);
330 add(toolsMenu, mirror);
331 toolsMenu.addSeparator();
332 add(toolsMenu, addnode);
333 add(toolsMenu, movenode);
334 add(toolsMenu, createCircle);
335 toolsMenu.addSeparator();
336 add(toolsMenu, mergeNodes);
337 add(toolsMenu, joinNodeWay);
338 add(toolsMenu, unglueNodes);
339 toolsMenu.addSeparator();
340 add(toolsMenu, joinAreas);
341 add(toolsMenu, createMultipolygon);
342
343 if (!Main.pref.getBoolean("audio.menuinvisible", false)) {
344 audioMenu = addMenu(marktr("Audio"), KeyEvent.VK_A, defaultMenuPos, ht("/Menu/Audio"));
345 add(audioMenu, audioPlayPause);
346 add(audioMenu, audioNext);
347 add(audioMenu, audioPrev);
348 add(audioMenu, audioFwd);
349 add(audioMenu, audioBack);
350 add(audioMenu, audioSlower);
351 add(audioMenu, audioFaster);
352 }
353
354 helpMenu.add(statusreport);
355
356 current = helpMenu.add(help); // FIXME why is help not a JosmAction?
357 current.setAccelerator(Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1,
358 Shortcut.GROUP_DIRECT).getKeyStroke());
359 add(helpMenu, about);
360
361 new PresetsMenuEnabler(presetsMenu).refreshEnabled();
362 }
363
364 static class PresetsMenuEnabler implements MapView.LayerChangeListener {
365 private JMenu presetsMenu;
366 public PresetsMenuEnabler(JMenu presetsMenu) {
367 MapView.addLayerChangeListener(this);
368 this.presetsMenu = presetsMenu;
369 }
370 /**
371 * Refreshes the enabled state
372 *
373 */
374 protected void refreshEnabled() {
375 presetsMenu.setEnabled(Main.map != null
376 && Main.map.mapView !=null
377 && Main.map.mapView.getEditLayer() != null
378 );
379 }
380
381 public void activeLayerChange(Layer oldLayer, Layer newLayer) {
382 refreshEnabled();
383 }
384
385 public void layerAdded(Layer newLayer) {
386 refreshEnabled();
387 }
388
389 public void layerRemoved(Layer oldLayer) {
390 refreshEnabled();
391 }
392 }
393}
Note: See TracBrowser for help on using the repository browser.