1 | // License: GPL. See LICENSE file for details.
|
---|
2 | package org.openstreetmap.josm.gui;
|
---|
3 |
|
---|
4 | import java.awt.Toolkit;
|
---|
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.JPopupMenu;
|
---|
16 | import javax.swing.JSeparator;
|
---|
17 | import javax.swing.KeyStroke;
|
---|
18 | import javax.swing.event.MenuEvent;
|
---|
19 | import javax.swing.event.MenuListener;
|
---|
20 |
|
---|
21 | import org.openstreetmap.josm.Main;
|
---|
22 | import org.openstreetmap.josm.actions.AboutAction;
|
---|
23 | import org.openstreetmap.josm.actions.AddNodeAction;
|
---|
24 | import org.openstreetmap.josm.actions.AlignInCircleAction;
|
---|
25 | import org.openstreetmap.josm.actions.AlignInLineAction;
|
---|
26 | import org.openstreetmap.josm.actions.AutoScaleAction;
|
---|
27 | import org.openstreetmap.josm.actions.ChangesetManagerToggleAction;
|
---|
28 | import org.openstreetmap.josm.actions.CloseChangesetAction;
|
---|
29 | import org.openstreetmap.josm.actions.CombineWayAction;
|
---|
30 | import org.openstreetmap.josm.actions.CopyAction;
|
---|
31 | import org.openstreetmap.josm.actions.CopyCoordinatesAction;
|
---|
32 | import org.openstreetmap.josm.actions.CreateCircleAction;
|
---|
33 | import org.openstreetmap.josm.actions.CreateMultipolygonAction;
|
---|
34 | import org.openstreetmap.josm.actions.DeleteAction;
|
---|
35 | import org.openstreetmap.josm.actions.DistributeAction;
|
---|
36 | import org.openstreetmap.josm.actions.DownloadAction;
|
---|
37 | import org.openstreetmap.josm.actions.DownloadPrimitiveAction;
|
---|
38 | import org.openstreetmap.josm.actions.DownloadReferrersAction;
|
---|
39 | import org.openstreetmap.josm.actions.DuplicateAction;
|
---|
40 | import org.openstreetmap.josm.actions.ExitAction;
|
---|
41 | import org.openstreetmap.josm.actions.FollowLineAction;
|
---|
42 | import org.openstreetmap.josm.actions.FullscreenToggleAction;
|
---|
43 | import org.openstreetmap.josm.actions.GpxExportAction;
|
---|
44 | import org.openstreetmap.josm.actions.HelpAction;
|
---|
45 | import org.openstreetmap.josm.actions.HistoryInfoAction;
|
---|
46 | import org.openstreetmap.josm.actions.HistoryInfoWebAction;
|
---|
47 | import org.openstreetmap.josm.actions.InfoAction;
|
---|
48 | import org.openstreetmap.josm.actions.InfoWebAction;
|
---|
49 | import org.openstreetmap.josm.actions.JoinAreasAction;
|
---|
50 | import org.openstreetmap.josm.actions.JoinNodeWayAction;
|
---|
51 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
52 | import org.openstreetmap.josm.actions.JumpToAction;
|
---|
53 | import org.openstreetmap.josm.actions.MergeLayerAction;
|
---|
54 | import org.openstreetmap.josm.actions.MergeNodesAction;
|
---|
55 | import org.openstreetmap.josm.actions.MergeSelectionAction;
|
---|
56 | import org.openstreetmap.josm.actions.MirrorAction;
|
---|
57 | import org.openstreetmap.josm.actions.MoveAction;
|
---|
58 | import org.openstreetmap.josm.actions.MoveNodeAction;
|
---|
59 | import org.openstreetmap.josm.actions.NewAction;
|
---|
60 | import org.openstreetmap.josm.actions.OpenFileAction;
|
---|
61 | import org.openstreetmap.josm.actions.OpenLocationAction;
|
---|
62 | import org.openstreetmap.josm.actions.OrthogonalizeAction;
|
---|
63 | import org.openstreetmap.josm.actions.PasteAction;
|
---|
64 | import org.openstreetmap.josm.actions.PasteTagsAction;
|
---|
65 | import org.openstreetmap.josm.actions.PreferencesAction;
|
---|
66 | import org.openstreetmap.josm.actions.PurgeAction;
|
---|
67 | import org.openstreetmap.josm.actions.RedoAction;
|
---|
68 | import org.openstreetmap.josm.actions.ReverseWayAction;
|
---|
69 | import org.openstreetmap.josm.actions.SaveAction;
|
---|
70 | import org.openstreetmap.josm.actions.SaveAsAction;
|
---|
71 | import org.openstreetmap.josm.actions.SelectAllAction;
|
---|
72 | import org.openstreetmap.josm.actions.SessionLoadAction;
|
---|
73 | import org.openstreetmap.josm.actions.SessionSaveAsAction;
|
---|
74 | import org.openstreetmap.josm.actions.ShowStatusReportAction;
|
---|
75 | import org.openstreetmap.josm.actions.SimplifyWayAction;
|
---|
76 | import org.openstreetmap.josm.actions.SplitWayAction;
|
---|
77 | import org.openstreetmap.josm.actions.ToggleGPXLinesAction;
|
---|
78 | import org.openstreetmap.josm.actions.UnGlueAction;
|
---|
79 | import org.openstreetmap.josm.actions.UndoAction;
|
---|
80 | import org.openstreetmap.josm.actions.UnselectAllAction;
|
---|
81 | import org.openstreetmap.josm.actions.UpdateDataAction;
|
---|
82 | import org.openstreetmap.josm.actions.UpdateModifiedAction;
|
---|
83 | import org.openstreetmap.josm.actions.UpdateSelectionAction;
|
---|
84 | import org.openstreetmap.josm.actions.UploadAction;
|
---|
85 | import org.openstreetmap.josm.actions.UploadSelectionAction;
|
---|
86 | import org.openstreetmap.josm.actions.ViewportFollowToggleAction;
|
---|
87 | import org.openstreetmap.josm.actions.WireframeToggleAction;
|
---|
88 | import org.openstreetmap.josm.actions.ZoomInAction;
|
---|
89 | import org.openstreetmap.josm.actions.ZoomOutAction;
|
---|
90 | import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo;
|
---|
91 | import org.openstreetmap.josm.actions.audio.AudioBackAction;
|
---|
92 | import org.openstreetmap.josm.actions.audio.AudioFasterAction;
|
---|
93 | import org.openstreetmap.josm.actions.audio.AudioFwdAction;
|
---|
94 | import org.openstreetmap.josm.actions.audio.AudioNextAction;
|
---|
95 | import org.openstreetmap.josm.actions.audio.AudioPlayPauseAction;
|
---|
96 | import org.openstreetmap.josm.actions.audio.AudioPrevAction;
|
---|
97 | import org.openstreetmap.josm.actions.audio.AudioSlowerAction;
|
---|
98 | import org.openstreetmap.josm.actions.search.SearchAction;
|
---|
99 | import org.openstreetmap.josm.gui.io.RecentlyOpenedFilesMenu;
|
---|
100 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
101 | import org.openstreetmap.josm.gui.tagging.TaggingPresetSearchAction;
|
---|
102 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
103 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * This is the JOSM main menu bar. It is overwritten to initialize itself and provide all menu
|
---|
107 | * entries as member variables (sort of collect them).
|
---|
108 | *
|
---|
109 | * It also provides possibilities to attach new menu entries (used by plugins).
|
---|
110 | *
|
---|
111 | * @author Immanuel.Scholz
|
---|
112 | */
|
---|
113 | public class MainMenu extends JMenuBar {
|
---|
114 |
|
---|
115 | /* File menu */
|
---|
116 | public final NewAction newAction = new NewAction();
|
---|
117 | public final OpenFileAction openFile = new OpenFileAction();
|
---|
118 | public final RecentlyOpenedFilesMenu recentlyOpened = new RecentlyOpenedFilesMenu();
|
---|
119 | public final OpenLocationAction openLocation = new OpenLocationAction();
|
---|
120 | public final JosmAction save = new SaveAction();
|
---|
121 | public final JosmAction saveAs = new SaveAsAction();
|
---|
122 | public JosmAction sessionLoad;
|
---|
123 | public JosmAction sessionSaveAs;
|
---|
124 | public final JosmAction gpxExport = new GpxExportAction();
|
---|
125 | public final DownloadAction download = new DownloadAction();
|
---|
126 | public final DownloadPrimitiveAction downloadPrimitive = new DownloadPrimitiveAction();
|
---|
127 | public final DownloadReferrersAction downloadReferrers = new DownloadReferrersAction();
|
---|
128 | public final CloseChangesetAction closeChangesetAction = new CloseChangesetAction();
|
---|
129 | public final JosmAction update = new UpdateDataAction();
|
---|
130 | public final JosmAction updateSelection = new UpdateSelectionAction();
|
---|
131 | public final JosmAction updateModified = new UpdateModifiedAction();
|
---|
132 | public final JosmAction upload = new UploadAction();
|
---|
133 | public final JosmAction uploadSelection = new UploadSelectionAction();
|
---|
134 | public final JosmAction exit = new ExitAction();
|
---|
135 |
|
---|
136 | /* Edit menu */
|
---|
137 | public final UndoAction undo = new UndoAction();
|
---|
138 | public final RedoAction redo = new RedoAction();
|
---|
139 | public final JosmAction copy = new CopyAction();
|
---|
140 | public final JosmAction copyCoordinates = new CopyCoordinatesAction();
|
---|
141 | public final PasteAction paste = new PasteAction();
|
---|
142 | public final JosmAction pasteTags = new PasteTagsAction();
|
---|
143 | public final JosmAction duplicate = new DuplicateAction();
|
---|
144 | public final JosmAction delete = new DeleteAction();
|
---|
145 | public final JosmAction purge = new PurgeAction();
|
---|
146 | public final JosmAction merge = new MergeLayerAction();
|
---|
147 | public final JosmAction mergeSelected = new MergeSelectionAction();
|
---|
148 | public final JosmAction selectAll = new SelectAllAction();
|
---|
149 | public final JosmAction unselectAll = new UnselectAllAction();
|
---|
150 | public final JosmAction search = new SearchAction();
|
---|
151 | public final JosmAction preferences = new PreferencesAction();
|
---|
152 |
|
---|
153 | /* View menu */
|
---|
154 | public final WireframeToggleAction wireFrameToggleAction = new WireframeToggleAction();
|
---|
155 | public final JosmAction toggleGPXLines = new ToggleGPXLinesAction();
|
---|
156 | public final InfoAction info = new InfoAction();
|
---|
157 | public final InfoWebAction infoweb = new InfoWebAction();
|
---|
158 | public final HistoryInfoAction historyinfo = new HistoryInfoAction();
|
---|
159 | public final HistoryInfoWebAction historyinfoweb = new HistoryInfoWebAction();
|
---|
160 |
|
---|
161 | /* Tools menu */
|
---|
162 | public final JosmAction splitWay = new SplitWayAction();
|
---|
163 | public final JosmAction combineWay = new CombineWayAction();
|
---|
164 | public final JosmAction reverseWay = new ReverseWayAction();
|
---|
165 | public final JosmAction alignInCircle = new AlignInCircleAction();
|
---|
166 | public final JosmAction alignInLine = new AlignInLineAction();
|
---|
167 | public final JosmAction distribute = new DistributeAction();
|
---|
168 | public final OrthogonalizeAction ortho = new OrthogonalizeAction();
|
---|
169 | public final JosmAction orthoUndo = new Undo(); // action is not shown in the menu. Only triggered by shortcut
|
---|
170 | public final JosmAction mirror = new MirrorAction();
|
---|
171 | public final AddNodeAction addnode = new AddNodeAction();
|
---|
172 | public final MoveNodeAction movenode = new MoveNodeAction();
|
---|
173 | public final JosmAction createCircle = new CreateCircleAction();
|
---|
174 | public final JosmAction mergeNodes = new MergeNodesAction();
|
---|
175 | public final JosmAction joinNodeWay = new JoinNodeWayAction();
|
---|
176 | public final JosmAction unglueNodes = new UnGlueAction();
|
---|
177 | public final JosmAction simplifyWay = new SimplifyWayAction();
|
---|
178 | public final JosmAction joinAreas = new JoinAreasAction();
|
---|
179 | public final JosmAction createMultipolygon = new CreateMultipolygonAction();
|
---|
180 | public final JosmAction followLine = new FollowLineAction();
|
---|
181 |
|
---|
182 | /* Audio menu */
|
---|
183 | public final JosmAction audioPlayPause = new AudioPlayPauseAction();
|
---|
184 | public final JosmAction audioNext = new AudioNextAction();
|
---|
185 | public final JosmAction audioPrev = new AudioPrevAction();
|
---|
186 | public final JosmAction audioFwd = new AudioFwdAction();
|
---|
187 | public final JosmAction audioBack = new AudioBackAction();
|
---|
188 | public final JosmAction audioFaster = new AudioFasterAction();
|
---|
189 | public final JosmAction audioSlower = new AudioSlowerAction();
|
---|
190 |
|
---|
191 | /* Help menu */
|
---|
192 | public final HelpAction help = new HelpAction();
|
---|
193 | public final JosmAction about = new AboutAction();
|
---|
194 | public final JosmAction statusreport = new ShowStatusReportAction();
|
---|
195 |
|
---|
196 | public final JMenu fileMenu = addMenu(marktr("File"), KeyEvent.VK_F, 0, ht("/Menu/File"));
|
---|
197 | public final JMenu sessionMenu = new JMenu(tr("Session")); // submenu of the file menu
|
---|
198 | public final JMenu editMenu = addMenu(marktr("Edit"), KeyEvent.VK_E, 1, ht("/Menu/Edit"));
|
---|
199 | public final JMenu viewMenu = addMenu(marktr("View"), KeyEvent.VK_V, 2, ht("/Menu/View"));
|
---|
200 | public final JMenu toolsMenu = addMenu(marktr("Tools"), KeyEvent.VK_T, 3, ht("/Menu/Tools"));
|
---|
201 | public final JMenu presetsMenu = addMenu(marktr("Presets"), KeyEvent.VK_P, 4, ht("/Menu/Presets"));
|
---|
202 | public final ImageryMenu imageryMenu =
|
---|
203 | (ImageryMenu)addMenu(new ImageryMenu(), marktr("Imagery"), KeyEvent.VK_I, 5, ht("/Menu/Imagery"));
|
---|
204 | /** the window menu is split into several groups. The first is for windows that can be opened from
|
---|
205 | * this menu any time, e.g. the changeset editor. The second group is for toggle dialogs and the third
|
---|
206 | * group is for currently open windows that cannot be toggled, e.g. relation editors. It's recommended
|
---|
207 | * to use WINDOW_MENU_GROUP to determine the group integer.
|
---|
208 | */
|
---|
209 | public final JMenu windowMenu = addMenu(marktr("Windows"), KeyEvent.VK_W, 6, ht("/Menu/Windows"));
|
---|
210 | public static enum WINDOW_MENU_GROUP { ALWAYS, TOGGLE_DIALOG, VOLATILE }
|
---|
211 |
|
---|
212 | public JMenu audioMenu = null;
|
---|
213 | public final JMenu helpMenu = addMenu(marktr("Help"), KeyEvent.VK_H, 7, ht("/Menu/Help"));
|
---|
214 |
|
---|
215 | public final int defaultMenuPos = 7;
|
---|
216 |
|
---|
217 | public final JosmAction moveUpAction = new MoveAction(MoveAction.Direction.UP);
|
---|
218 | public final JosmAction moveDownAction = new MoveAction(MoveAction.Direction.DOWN);
|
---|
219 | public final JosmAction moveLeftAction = new MoveAction(MoveAction.Direction.LEFT);
|
---|
220 | public final JosmAction moveRightAction = new MoveAction(MoveAction.Direction.RIGHT);
|
---|
221 | public final JumpToAction jumpToAct = new JumpToAction();
|
---|
222 |
|
---|
223 | public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction();
|
---|
224 | public FullscreenToggleAction fullscreenToggleAction = null;
|
---|
225 |
|
---|
226 | /** this menu listener hides unnecessary JSeparators in a menu list but does not remove them.
|
---|
227 | * If at a later time the separators are required, they will be made visible again. Intended
|
---|
228 | * usage is make menus not look broken if separators are used to group the menu and some of
|
---|
229 | * these groups are empty.
|
---|
230 | */
|
---|
231 | public final static MenuListener menuSeparatorHandler = new MenuListener() {
|
---|
232 | @Override
|
---|
233 | public void menuCanceled(MenuEvent arg0) {}
|
---|
234 | @Override
|
---|
235 | public void menuDeselected(MenuEvent arg0) {}
|
---|
236 | @Override
|
---|
237 | public void menuSelected(MenuEvent a) {
|
---|
238 | if(!(a.getSource() instanceof JMenu))
|
---|
239 | return;
|
---|
240 | final JPopupMenu m = ((JMenu) a.getSource()).getPopupMenu();
|
---|
241 | for(int i=0; i < m.getComponentCount()-1; i++) {
|
---|
242 | if(!(m.getComponent(i) instanceof JSeparator)) {
|
---|
243 | continue;
|
---|
244 | }
|
---|
245 | // hide separator if the next menu item is one as well
|
---|
246 | ((JSeparator) m.getComponent(i)).setVisible(!(m.getComponent(i+1) instanceof JSeparator));
|
---|
247 | }
|
---|
248 | // hide separator at the end of the menu
|
---|
249 | if(m.getComponent(m.getComponentCount()-1) instanceof JSeparator) {
|
---|
250 | ((JSeparator) m.getComponent(m.getComponentCount()-1)).setVisible(false);
|
---|
251 | }
|
---|
252 | }
|
---|
253 | };
|
---|
254 |
|
---|
255 | /**
|
---|
256 | * Add a JosmAction to a menu.
|
---|
257 | *
|
---|
258 | * This method handles all the shortcut handling. It also makes sure that actions that are
|
---|
259 | * handled by the OS are not duplicated on the menu. Menu item will be added at the end of
|
---|
260 | * the menu.
|
---|
261 | * @param menu to add the action to
|
---|
262 | * @param the action that should get a menu item
|
---|
263 | */
|
---|
264 | public static JMenuItem add(JMenu menu, JosmAction action) {
|
---|
265 | if (action.getShortcut().getAutomatic())
|
---|
266 | return null;
|
---|
267 | JMenuItem menuitem = menu.add(action);
|
---|
268 | KeyStroke ks = action.getShortcut().getKeyStroke();
|
---|
269 | if (ks != null) {
|
---|
270 | menuitem.setAccelerator(ks);
|
---|
271 | }
|
---|
272 | return menuitem;
|
---|
273 | }
|
---|
274 |
|
---|
275 | /**
|
---|
276 | * Add a JosmAction to a menu.
|
---|
277 | *
|
---|
278 | * This method handles all the shortcut handling. It also makes sure that actions that are
|
---|
279 | * handled by the OS are not duplicated on the menu.
|
---|
280 | * @param menu to add the action to
|
---|
281 | * @param the action that should get a menu item
|
---|
282 | * @param group the item should be added to. Groups are split by a separator.
|
---|
283 | * 0 is the first group, -1 will add the item to the end.
|
---|
284 | */
|
---|
285 | public static <E extends Enum<E>> JMenuItem add(JMenu menu, JosmAction action, Enum<E> group) {
|
---|
286 | if (action.getShortcut().getAutomatic())
|
---|
287 | return null;
|
---|
288 | int i = getInsertionIndexForGroup(menu, group.ordinal());
|
---|
289 | JMenuItem menuitem = (JMenuItem) menu.add(new JMenuItem(action), i);
|
---|
290 | KeyStroke ks = action.getShortcut().getKeyStroke();
|
---|
291 | if (ks != null) {
|
---|
292 | menuitem.setAccelerator(ks);
|
---|
293 | }
|
---|
294 | return menuitem;
|
---|
295 | }
|
---|
296 |
|
---|
297 | /**
|
---|
298 | * Add a JosmAction to a menu and automatically prints accelerator if available.
|
---|
299 | * Also adds a checkbox that may be toggled.
|
---|
300 | * @param menu to add the action to
|
---|
301 | * @param the action that should get a menu item
|
---|
302 | * @param group the item should be added to. Groups are split by a separator. Use
|
---|
303 | * one of the enums that are defined for some of the menus to tell in which
|
---|
304 | * group the item should go.
|
---|
305 | */
|
---|
306 | public static <E extends Enum<E>> JCheckBoxMenuItem addWithCheckbox(JMenu menu, JosmAction action, Enum<E> group) {
|
---|
307 | int i = getInsertionIndexForGroup(menu, group.ordinal());
|
---|
308 | final JCheckBoxMenuItem mi = (JCheckBoxMenuItem) menu.add(new JCheckBoxMenuItem(action), i);
|
---|
309 | final KeyStroke ks = action.getShortcut().getKeyStroke();
|
---|
310 | if (ks != null) {
|
---|
311 | mi.setAccelerator(ks);
|
---|
312 | }
|
---|
313 | return mi;
|
---|
314 | }
|
---|
315 |
|
---|
316 | /** finds the correct insertion index for a given group and adds separators if necessary */
|
---|
317 | private static int getInsertionIndexForGroup(JMenu menu, int group) {
|
---|
318 | if(group < 0)
|
---|
319 | return -1;
|
---|
320 | // look for separator that *ends* the group (or stop at end of menu)
|
---|
321 | int i;
|
---|
322 | for(i=0; i < menu.getItemCount() && group >= 0; i++) {
|
---|
323 | if(menu.getItem(i) == null) {
|
---|
324 | group--;
|
---|
325 | }
|
---|
326 | }
|
---|
327 | // insert before separator that ends the group
|
---|
328 | if(group < 0) {
|
---|
329 | i--;
|
---|
330 | }
|
---|
331 | // not enough separators have been found, add them
|
---|
332 | while(group > 0) {
|
---|
333 | menu.addSeparator();
|
---|
334 | group--;
|
---|
335 | i++;
|
---|
336 | }
|
---|
337 | return i;
|
---|
338 | }
|
---|
339 |
|
---|
340 | public JMenu addMenu(String name, int mnemonicKey, int position, String relativeHelpTopic) {
|
---|
341 | final JMenu menu = new JMenu(tr(name));
|
---|
342 | int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
|
---|
343 | int menuItemHeight = new JMenu().add(newAction).getPreferredSize().height;
|
---|
344 | MenuScroller.setScrollerFor(menu, screenHeight / menuItemHeight);
|
---|
345 | return addMenu(menu, name, mnemonicKey, position, relativeHelpTopic);
|
---|
346 | }
|
---|
347 |
|
---|
348 | public JMenu addMenu(JMenu menu, String name, int mnemonicKey, int position, String relativeHelpTopic) {
|
---|
349 | Shortcut.registerShortcut("menu:" + name, tr("Menu: {0}", tr(name)), mnemonicKey,
|
---|
350 | Shortcut.GROUP_MNEMONIC).setMnemonic(menu);
|
---|
351 | add(menu, position);
|
---|
352 | menu.putClientProperty("help", relativeHelpTopic);
|
---|
353 | return menu;
|
---|
354 | }
|
---|
355 |
|
---|
356 | public MainMenu() {
|
---|
357 | JMenuItem current;
|
---|
358 |
|
---|
359 | add(fileMenu, newAction);
|
---|
360 | add(fileMenu, openFile);
|
---|
361 | fileMenu.add(recentlyOpened);
|
---|
362 | add(fileMenu, openLocation);
|
---|
363 | fileMenu.addSeparator();
|
---|
364 | add(fileMenu, save);
|
---|
365 | add(fileMenu, saveAs);
|
---|
366 | if (Main.pref.getBoolean("session")) {
|
---|
367 | sessionMenu.setToolTipText(tr("Save and load the current session (list of layers, etc.)"));
|
---|
368 | sessionMenu.setIcon(ImageProvider.get("session"));
|
---|
369 | sessionSaveAs = new SessionSaveAsAction();
|
---|
370 | sessionLoad = new SessionLoadAction();
|
---|
371 | add(sessionMenu, sessionSaveAs);
|
---|
372 | add(sessionMenu, sessionLoad);
|
---|
373 | fileMenu.add(sessionMenu);
|
---|
374 | }
|
---|
375 | add(fileMenu, gpxExport);
|
---|
376 | fileMenu.addSeparator();
|
---|
377 | add(fileMenu, download);
|
---|
378 | add(fileMenu, downloadPrimitive);
|
---|
379 | add(fileMenu, downloadReferrers);
|
---|
380 | add(fileMenu, update);
|
---|
381 | add(fileMenu, updateSelection);
|
---|
382 | add(fileMenu, updateModified);
|
---|
383 | fileMenu.addSeparator();
|
---|
384 | add(fileMenu, upload);
|
---|
385 | add(fileMenu, uploadSelection);
|
---|
386 | fileMenu.addSeparator();
|
---|
387 | add(fileMenu, closeChangesetAction);
|
---|
388 | fileMenu.addSeparator();
|
---|
389 | add(fileMenu, exit);
|
---|
390 |
|
---|
391 | add(editMenu, undo);
|
---|
392 | add(editMenu, redo);
|
---|
393 | editMenu.addSeparator();
|
---|
394 | add(editMenu, copy);
|
---|
395 | add(editMenu, copyCoordinates);
|
---|
396 | add(editMenu, paste);
|
---|
397 | add(editMenu, pasteTags);
|
---|
398 | add(editMenu, duplicate);
|
---|
399 | add(editMenu, delete);
|
---|
400 | add(editMenu, purge);
|
---|
401 | editMenu.addSeparator();
|
---|
402 | add(editMenu,merge);
|
---|
403 | add(editMenu,mergeSelected);
|
---|
404 | editMenu.addSeparator();
|
---|
405 | add(editMenu, selectAll);
|
---|
406 | add(editMenu, unselectAll);
|
---|
407 | editMenu.addSeparator();
|
---|
408 | add(editMenu, search);
|
---|
409 | editMenu.addSeparator();
|
---|
410 | add(editMenu, preferences);
|
---|
411 |
|
---|
412 | // -- wireframe toggle action
|
---|
413 | final JCheckBoxMenuItem wireframe = new JCheckBoxMenuItem(wireFrameToggleAction);
|
---|
414 | viewMenu.add(wireframe);
|
---|
415 | wireframe.setAccelerator(wireFrameToggleAction.getShortcut().getKeyStroke());
|
---|
416 | wireFrameToggleAction.addButtonModel(wireframe.getModel());
|
---|
417 |
|
---|
418 | viewMenu.addSeparator();
|
---|
419 | add(viewMenu, new ZoomInAction());
|
---|
420 | add(viewMenu, new ZoomOutAction());
|
---|
421 | viewMenu.addSeparator();
|
---|
422 | for (String mode : AutoScaleAction.MODES) {
|
---|
423 | JosmAction autoScaleAction = new AutoScaleAction(mode);
|
---|
424 | add(viewMenu, autoScaleAction);
|
---|
425 | }
|
---|
426 |
|
---|
427 | // -- viewport follow toggle action
|
---|
428 | ViewportFollowToggleAction viewportFollowToggleAction = new ViewportFollowToggleAction();
|
---|
429 | final JCheckBoxMenuItem vft = new JCheckBoxMenuItem(viewportFollowToggleAction);
|
---|
430 | viewMenu.add(vft);
|
---|
431 | vft.setAccelerator(viewportFollowToggleAction.getShortcut().getKeyStroke());
|
---|
432 | viewportFollowToggleAction.addButtonModel(vft.getModel());
|
---|
433 |
|
---|
434 | if(!Main.applet && Main.platform.canFullscreen()) {
|
---|
435 | // -- fullscreen toggle action
|
---|
436 | fullscreenToggleAction = new FullscreenToggleAction();
|
---|
437 | final JCheckBoxMenuItem fullscreen = new JCheckBoxMenuItem(fullscreenToggleAction);
|
---|
438 | viewMenu.addSeparator();
|
---|
439 | viewMenu.add(fullscreen);
|
---|
440 | fullscreen.setAccelerator(fullscreenToggleAction.getShortcut().getKeyStroke());
|
---|
441 | fullscreenToggleAction.addButtonModel(fullscreen.getModel());
|
---|
442 | }
|
---|
443 | viewMenu.addSeparator();
|
---|
444 | add(viewMenu, info);
|
---|
445 | add(viewMenu, infoweb);
|
---|
446 | add(viewMenu, historyinfo);
|
---|
447 | add(viewMenu, historyinfoweb);
|
---|
448 |
|
---|
449 | add(presetsMenu, presetSearchAction);
|
---|
450 | presetsMenu.addSeparator();
|
---|
451 |
|
---|
452 | add(toolsMenu, splitWay);
|
---|
453 | add(toolsMenu, combineWay);
|
---|
454 | toolsMenu.addSeparator();
|
---|
455 | add(toolsMenu, reverseWay);
|
---|
456 | add(toolsMenu, simplifyWay);
|
---|
457 | toolsMenu.addSeparator();
|
---|
458 | add(toolsMenu, alignInCircle);
|
---|
459 | add(toolsMenu, alignInLine);
|
---|
460 | add(toolsMenu, distribute);
|
---|
461 | add(toolsMenu, ortho);
|
---|
462 | add(toolsMenu, mirror);
|
---|
463 | toolsMenu.addSeparator();
|
---|
464 | add(toolsMenu, followLine);
|
---|
465 | add(toolsMenu, addnode);
|
---|
466 | add(toolsMenu, movenode);
|
---|
467 | add(toolsMenu, createCircle);
|
---|
468 | toolsMenu.addSeparator();
|
---|
469 | add(toolsMenu, mergeNodes);
|
---|
470 | add(toolsMenu, joinNodeWay);
|
---|
471 | add(toolsMenu, unglueNodes);
|
---|
472 | toolsMenu.addSeparator();
|
---|
473 | add(toolsMenu, joinAreas);
|
---|
474 | add(toolsMenu, createMultipolygon);
|
---|
475 |
|
---|
476 | // -- changeset manager toggle action
|
---|
477 | ChangesetManagerToggleAction changesetManagerToggleAction = new ChangesetManagerToggleAction();
|
---|
478 | final JCheckBoxMenuItem mi = MainMenu.addWithCheckbox(windowMenu, changesetManagerToggleAction,
|
---|
479 | MainMenu.WINDOW_MENU_GROUP.ALWAYS);
|
---|
480 | changesetManagerToggleAction.addButtonModel(mi.getModel());
|
---|
481 |
|
---|
482 |
|
---|
483 | if (!Main.pref.getBoolean("audio.menuinvisible", false)) {
|
---|
484 | audioMenu = addMenu(marktr("Audio"), KeyEvent.VK_U, defaultMenuPos, ht("/Menu/Audio"));
|
---|
485 | add(audioMenu, audioPlayPause);
|
---|
486 | add(audioMenu, audioNext);
|
---|
487 | add(audioMenu, audioPrev);
|
---|
488 | add(audioMenu, audioFwd);
|
---|
489 | add(audioMenu, audioBack);
|
---|
490 | add(audioMenu, audioSlower);
|
---|
491 | add(audioMenu, audioFaster);
|
---|
492 | }
|
---|
493 |
|
---|
494 | helpMenu.add(statusreport);
|
---|
495 |
|
---|
496 | current = helpMenu.add(help); // FIXME why is help not a JosmAction?
|
---|
497 | current.setAccelerator(Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1,
|
---|
498 | Shortcut.GROUP_DIRECT).getKeyStroke());
|
---|
499 | add(helpMenu, about);
|
---|
500 |
|
---|
501 |
|
---|
502 | windowMenu.addMenuListener(menuSeparatorHandler);
|
---|
503 |
|
---|
504 | new PresetsMenuEnabler(presetsMenu).refreshEnabled();
|
---|
505 | }
|
---|
506 |
|
---|
507 | static class PresetsMenuEnabler implements MapView.LayerChangeListener {
|
---|
508 | private JMenu presetsMenu;
|
---|
509 | public PresetsMenuEnabler(JMenu presetsMenu) {
|
---|
510 | MapView.addLayerChangeListener(this);
|
---|
511 | this.presetsMenu = presetsMenu;
|
---|
512 | }
|
---|
513 | /**
|
---|
514 | * Refreshes the enabled state
|
---|
515 | *
|
---|
516 | */
|
---|
517 | protected void refreshEnabled() {
|
---|
518 | presetsMenu.setEnabled(Main.map != null
|
---|
519 | && Main.map.mapView !=null
|
---|
520 | && Main.map.mapView.getEditLayer() != null
|
---|
521 | );
|
---|
522 | }
|
---|
523 |
|
---|
524 | public void activeLayerChange(Layer oldLayer, Layer newLayer) {
|
---|
525 | refreshEnabled();
|
---|
526 | }
|
---|
527 |
|
---|
528 | public void layerAdded(Layer newLayer) {
|
---|
529 | refreshEnabled();
|
---|
530 | }
|
---|
531 |
|
---|
532 | public void layerRemoved(Layer oldLayer) {
|
---|
533 | refreshEnabled();
|
---|
534 | }
|
---|
535 | }
|
---|
536 | }
|
---|