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