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