1 | // License: GPL. See LICENSE file for details.
|
---|
2 |
|
---|
3 | package org.openstreetmap.josm.gui;
|
---|
4 |
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.ActionListener;
|
---|
9 |
|
---|
10 | import javax.swing.JCheckBoxMenuItem;
|
---|
11 | import javax.swing.JMenu;
|
---|
12 | import javax.swing.JMenuBar;
|
---|
13 | import javax.swing.JMenuItem;
|
---|
14 | import javax.swing.KeyStroke;
|
---|
15 | import java.awt.event.KeyEvent;
|
---|
16 |
|
---|
17 | import org.openstreetmap.josm.Main;
|
---|
18 | import org.openstreetmap.josm.actions.AboutAction;
|
---|
19 | import org.openstreetmap.josm.actions.AlignInCircleAction;
|
---|
20 | import org.openstreetmap.josm.actions.AlignInLineAction;
|
---|
21 | import org.openstreetmap.josm.actions.AlignInRectangleAction;
|
---|
22 | import org.openstreetmap.josm.actions.AutoScaleAction;
|
---|
23 | import org.openstreetmap.josm.actions.CombineWayAction;
|
---|
24 | import org.openstreetmap.josm.actions.CopyAction;
|
---|
25 | import org.openstreetmap.josm.actions.CreateCircleAction;
|
---|
26 | import org.openstreetmap.josm.actions.DeleteAction;
|
---|
27 | import org.openstreetmap.josm.actions.DownloadAction;
|
---|
28 | import org.openstreetmap.josm.actions.DuplicateAction;
|
---|
29 | import org.openstreetmap.josm.actions.ExitAction;
|
---|
30 | import org.openstreetmap.josm.actions.GpxExportAction;
|
---|
31 | import org.openstreetmap.josm.actions.HelpAction;
|
---|
32 | import org.openstreetmap.josm.actions.HistoryInfoAction;
|
---|
33 | import org.openstreetmap.josm.actions.JoinNodeWayAction;
|
---|
34 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
35 | import org.openstreetmap.josm.actions.MergeNodesAction;
|
---|
36 | import org.openstreetmap.josm.actions.NewAction;
|
---|
37 | import org.openstreetmap.josm.actions.OpenAction;
|
---|
38 | import org.openstreetmap.josm.actions.PasteAction;
|
---|
39 | import org.openstreetmap.josm.actions.PasteTagsAction;
|
---|
40 | import org.openstreetmap.josm.actions.PreferencesAction;
|
---|
41 | import org.openstreetmap.josm.actions.RedoAction;
|
---|
42 | import org.openstreetmap.josm.actions.ReverseWayAction;
|
---|
43 | import org.openstreetmap.josm.actions.SaveAction;
|
---|
44 | import org.openstreetmap.josm.actions.SaveAsAction;
|
---|
45 | import org.openstreetmap.josm.actions.SelectAllAction;
|
---|
46 | import org.openstreetmap.josm.actions.SplitWayAction;
|
---|
47 | import org.openstreetmap.josm.actions.UnGlueAction;
|
---|
48 | import org.openstreetmap.josm.actions.UndoAction;
|
---|
49 | import org.openstreetmap.josm.actions.UnselectAllAction;
|
---|
50 | import org.openstreetmap.josm.actions.UploadAction;
|
---|
51 | import org.openstreetmap.josm.actions.ZoomInAction;
|
---|
52 | import org.openstreetmap.josm.actions.ZoomOutAction;
|
---|
53 | import org.openstreetmap.josm.actions.audio.AudioBackAction;
|
---|
54 | import org.openstreetmap.josm.actions.audio.AudioFasterAction;
|
---|
55 | import org.openstreetmap.josm.actions.audio.AudioFwdAction;
|
---|
56 | import org.openstreetmap.josm.actions.audio.AudioNextAction;
|
---|
57 | import org.openstreetmap.josm.actions.audio.AudioPlayPauseAction;
|
---|
58 | import org.openstreetmap.josm.actions.audio.AudioPrevAction;
|
---|
59 | import org.openstreetmap.josm.actions.audio.AudioSlowerAction;
|
---|
60 | import org.openstreetmap.josm.actions.search.SearchAction;
|
---|
61 | import org.openstreetmap.josm.data.DataSetChecker;
|
---|
62 | import org.openstreetmap.josm.tools.ShortCut;
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * This is the JOSM main menu bar. It is overwritten to initialize itself and provide
|
---|
66 | * all menu entries as member variables (sort of collect them).
|
---|
67 | *
|
---|
68 | * It also provides possibilities to attach new menu entries (used by plugins).
|
---|
69 | *
|
---|
70 | * @author Immanuel.Scholz
|
---|
71 | */
|
---|
72 | public class MainMenu extends JMenuBar {
|
---|
73 |
|
---|
74 | /* File menu */
|
---|
75 | public final NewAction newAction = new NewAction();
|
---|
76 | public final OpenAction open = new OpenAction();
|
---|
77 | public final JosmAction save = new SaveAction(null);
|
---|
78 | public final JosmAction saveAs = new SaveAsAction(null);
|
---|
79 | public final JosmAction gpxExport = new GpxExportAction(null);
|
---|
80 | public final DownloadAction download = new DownloadAction();
|
---|
81 | public final JosmAction upload = new UploadAction();
|
---|
82 | public final JosmAction exit = new ExitAction();
|
---|
83 |
|
---|
84 | /* Edit menu */
|
---|
85 | public final UndoAction undo = new UndoAction();
|
---|
86 | public final RedoAction redo = new RedoAction();
|
---|
87 | public final JosmAction copy = new CopyAction();
|
---|
88 | public final JosmAction paste = new PasteAction();
|
---|
89 | public final JosmAction delete = new DeleteAction();
|
---|
90 | public final JosmAction pasteTags = new PasteTagsAction(copy);
|
---|
91 | public final JosmAction duplicate = new DuplicateAction();
|
---|
92 | public final JosmAction selectAll = new SelectAllAction();
|
---|
93 | public final JosmAction unselectAll = new UnselectAllAction();
|
---|
94 | /* crashes when loading data, if using JosmAction for search */
|
---|
95 | public final JosmAction search = new SearchAction();
|
---|
96 | public final JosmAction preferences = new PreferencesAction();
|
---|
97 |
|
---|
98 | /* View menu */
|
---|
99 |
|
---|
100 | /* Tools menu */
|
---|
101 | public final JosmAction splitWay = new SplitWayAction();
|
---|
102 | public final JosmAction combineWay = new CombineWayAction();
|
---|
103 | public final JosmAction reverseWay = new ReverseWayAction();
|
---|
104 | public final JosmAction alignInCircle = new AlignInCircleAction();
|
---|
105 | public final JosmAction alignInLine = new AlignInLineAction();
|
---|
106 | public final JosmAction alignInRect = new AlignInRectangleAction();
|
---|
107 | public final JosmAction createCircle = new CreateCircleAction();
|
---|
108 | public final JosmAction mergeNodes = new MergeNodesAction();
|
---|
109 | public final JosmAction joinNodeWay = new JoinNodeWayAction();
|
---|
110 | public final JosmAction unglueNodes = new UnGlueAction();
|
---|
111 |
|
---|
112 | /* Audio menu */
|
---|
113 | public final JosmAction audioPlayPause = new AudioPlayPauseAction();
|
---|
114 | public final JosmAction audioNext = new AudioNextAction();
|
---|
115 | public final JosmAction audioPrev = new AudioPrevAction();
|
---|
116 | public final JosmAction audioFwd = new AudioFwdAction();
|
---|
117 | public final JosmAction audioBack = new AudioBackAction();
|
---|
118 | public final JosmAction audioFaster = new AudioFasterAction();
|
---|
119 | public final JosmAction audioSlower = new AudioSlowerAction();
|
---|
120 |
|
---|
121 | /* Help menu */
|
---|
122 | public final HelpAction help = new HelpAction();
|
---|
123 | public final JosmAction about = new AboutAction();
|
---|
124 | public final HistoryInfoAction historyinfo = new HistoryInfoAction();
|
---|
125 |
|
---|
126 | public final JMenu fileMenu = new JMenu(tr("File"));
|
---|
127 | public final JMenu editMenu = new JMenu(tr("Edit"));
|
---|
128 | public final JMenu viewMenu = new JMenu(tr("View"));
|
---|
129 | public final JMenu toolsMenu = new JMenu(tr("Tools"));
|
---|
130 | public final JMenu audioMenu = new JMenu(tr("Audio"));
|
---|
131 | public final JMenu presetsMenu = new JMenu(tr("Presets"));
|
---|
132 | public final JMenu helpMenu = new JMenu(tr("Help"));
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Add a JosmAction to a menu.
|
---|
136 | *
|
---|
137 | * This method handles all the shortcut handling.
|
---|
138 | * It also makes sure that actions that are handled by the
|
---|
139 | * OS are not duplicated on the menu.
|
---|
140 | */
|
---|
141 | public static void add(JMenu menu, JosmAction action) {
|
---|
142 | if (!action.getShortCut().getAutomatic()) {
|
---|
143 | JMenuItem menuitem = menu.add(action);
|
---|
144 | KeyStroke ks = action.getShortCut().getKeyStroke();
|
---|
145 | if (ks != null) {
|
---|
146 | menuitem.setAccelerator(ks);
|
---|
147 | }
|
---|
148 | }
|
---|
149 | }
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * Add a menu to the main menu.
|
---|
153 | *
|
---|
154 | * This method handles all the shortcut handling.
|
---|
155 | */
|
---|
156 | public void add(JMenu menu, int mnemonicKey, String shortName) {
|
---|
157 | ShortCut.registerShortCut("menu:"+shortName, shortName+" menu", mnemonicKey, ShortCut.GROUP_MNEMONIC).setMnemonic(menu);
|
---|
158 | add(menu);
|
---|
159 | }
|
---|
160 |
|
---|
161 | public MainMenu() {
|
---|
162 | JMenuItem current;
|
---|
163 |
|
---|
164 | add(fileMenu, newAction);
|
---|
165 | add(fileMenu, open);
|
---|
166 | fileMenu.addSeparator();
|
---|
167 | add(fileMenu, save);
|
---|
168 | add(fileMenu, saveAs);
|
---|
169 | add(fileMenu, gpxExport);
|
---|
170 | fileMenu.addSeparator();
|
---|
171 | add(fileMenu, download);
|
---|
172 | add(fileMenu, upload);
|
---|
173 | add(fileMenu, exit);
|
---|
174 | add(fileMenu, KeyEvent.VK_F, "file");
|
---|
175 |
|
---|
176 | add(editMenu, undo);
|
---|
177 | add(editMenu, redo);
|
---|
178 | editMenu.addSeparator();
|
---|
179 | add(editMenu, copy);
|
---|
180 | add(editMenu, delete);
|
---|
181 | add(editMenu, paste);
|
---|
182 | add(editMenu, pasteTags);
|
---|
183 | add(editMenu, duplicate);
|
---|
184 | editMenu.addSeparator();
|
---|
185 | add(editMenu, selectAll);
|
---|
186 | add(editMenu, unselectAll);
|
---|
187 | editMenu.addSeparator();
|
---|
188 | add(editMenu, search);
|
---|
189 | editMenu.addSeparator();
|
---|
190 | add(editMenu, preferences);
|
---|
191 | add(editMenu, KeyEvent.VK_E, "edit");
|
---|
192 |
|
---|
193 | for (String mode : AutoScaleAction.modes) {
|
---|
194 | JosmAction autoScaleAction = new AutoScaleAction(mode);
|
---|
195 | add(viewMenu, autoScaleAction);
|
---|
196 | }
|
---|
197 | viewMenu.addSeparator();
|
---|
198 | add(viewMenu, new ZoomOutAction());
|
---|
199 | add(viewMenu, new ZoomInAction());
|
---|
200 | viewMenu.addSeparator();
|
---|
201 | // TODO move code to an "action" like the others?
|
---|
202 | final JCheckBoxMenuItem wireframe = new JCheckBoxMenuItem(tr("Wireframe view"));
|
---|
203 | wireframe.setSelected(Main.pref.getBoolean("draw.wireframe", false));
|
---|
204 | wireframe.setAccelerator(ShortCut.registerShortCut("menu:view:wireframe", "Toggle Wireframe view", KeyEvent.VK_W, ShortCut.GROUP_MENU).getKeyStroke());
|
---|
205 | wireframe.addActionListener(new ActionListener() {
|
---|
206 | public void actionPerformed(ActionEvent ev) {
|
---|
207 | Main.pref.put("draw.wireframe", wireframe.isSelected());
|
---|
208 | if (Main.map != null) {
|
---|
209 | Main.map.mapView.repaint();
|
---|
210 | }
|
---|
211 | }
|
---|
212 | });
|
---|
213 | viewMenu.add(wireframe);
|
---|
214 | add(viewMenu, KeyEvent.VK_V, "view");
|
---|
215 |
|
---|
216 | add(toolsMenu, splitWay);
|
---|
217 | add(toolsMenu, combineWay);
|
---|
218 | toolsMenu.addSeparator();
|
---|
219 | add(toolsMenu, reverseWay);
|
---|
220 | toolsMenu.addSeparator();
|
---|
221 | add(toolsMenu, alignInCircle);
|
---|
222 | add(toolsMenu, alignInLine);
|
---|
223 | add(toolsMenu, alignInRect);
|
---|
224 | toolsMenu.addSeparator();
|
---|
225 | add(toolsMenu, createCircle);
|
---|
226 | toolsMenu.addSeparator();
|
---|
227 | add(toolsMenu, mergeNodes);
|
---|
228 | add(toolsMenu, joinNodeWay);
|
---|
229 | add(toolsMenu, unglueNodes);
|
---|
230 | add(toolsMenu, KeyEvent.VK_T, "tools");
|
---|
231 |
|
---|
232 | if (! Main.pref.getBoolean("audio.menuinvisible")) {
|
---|
233 | add(audioMenu, audioPlayPause);
|
---|
234 | add(audioMenu, audioNext);
|
---|
235 | add(audioMenu, audioPrev);
|
---|
236 | add(audioMenu, audioFwd);
|
---|
237 | add(audioMenu, audioBack);
|
---|
238 | add(audioMenu, audioSlower);
|
---|
239 | add(audioMenu, audioFaster);
|
---|
240 | add(audioMenu, KeyEvent.VK_A, "audio");
|
---|
241 | }
|
---|
242 |
|
---|
243 | add(presetsMenu, KeyEvent.VK_P, "presets");
|
---|
244 |
|
---|
245 | JMenuItem check = new JMenuItem("DEBUG: Check Dataset");
|
---|
246 | check.addActionListener(new ActionListener(){
|
---|
247 | public void actionPerformed(ActionEvent e) {
|
---|
248 | DataSetChecker.check();
|
---|
249 | }
|
---|
250 | });
|
---|
251 | helpMenu.add(check);
|
---|
252 | current = helpMenu.add(help); // why is help not a JosmAction?
|
---|
253 | current.setAccelerator(ShortCut.registerShortCut("system:help", tr("Help"), KeyEvent.VK_F1, ShortCut.GROUP_DIRECT).getKeyStroke());
|
---|
254 | add(helpMenu, about);
|
---|
255 | add(helpMenu, historyinfo);
|
---|
256 | add(helpMenu, KeyEvent.VK_H, "help");
|
---|
257 | }
|
---|
258 | }
|
---|