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

Last change on this file was 19547, checked in by stoecker, 5 weeks ago

fix #24420 - new local layer action, patch by aharvey

  • Property svn:eol-style set to native
File size: 46.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6import static org.openstreetmap.josm.tools.I18n.trc;
7
8import java.awt.Component;
9import java.awt.GraphicsEnvironment;
10import java.awt.event.KeyEvent;
11import java.util.ArrayList;
12import java.util.Arrays;
13import java.util.Collection;
14import java.util.EnumMap;
15import java.util.List;
16import java.util.Locale;
17import java.util.Map;
18import java.util.Objects;
19import java.util.Optional;
20
21import javax.swing.JCheckBoxMenuItem;
22import javax.swing.JMenu;
23import javax.swing.JMenuBar;
24import javax.swing.JMenuItem;
25import javax.swing.JPopupMenu;
26import javax.swing.JSeparator;
27import javax.swing.KeyStroke;
28import javax.swing.event.MenuEvent;
29import javax.swing.event.MenuListener;
30
31import org.openstreetmap.josm.actions.AboutAction;
32import org.openstreetmap.josm.actions.AddNodeAction;
33import org.openstreetmap.josm.actions.AlignInCircleAction;
34import org.openstreetmap.josm.actions.AlignInLineAction;
35import org.openstreetmap.josm.actions.AutoScaleAction;
36import org.openstreetmap.josm.actions.AutoScaleAction.AutoScaleMode;
37import org.openstreetmap.josm.actions.ChangesetManagerToggleAction;
38import org.openstreetmap.josm.actions.CloseChangesetAction;
39import org.openstreetmap.josm.actions.CombineWayAction;
40import org.openstreetmap.josm.actions.CopyAction;
41import org.openstreetmap.josm.actions.CopyCoordinatesAction;
42import org.openstreetmap.josm.actions.CopyUrlAction;
43import org.openstreetmap.josm.actions.CreateCircleAction;
44import org.openstreetmap.josm.actions.CreateMultipolygonAction;
45import org.openstreetmap.josm.actions.DeleteAction;
46import org.openstreetmap.josm.actions.DeleteLayerAction;
47import org.openstreetmap.josm.actions.DialogsToggleAction;
48import org.openstreetmap.josm.actions.DistributeAction;
49import org.openstreetmap.josm.actions.DownloadAction;
50import org.openstreetmap.josm.actions.DownloadAlongWayAction;
51import org.openstreetmap.josm.actions.DownloadNotesInViewAction;
52import org.openstreetmap.josm.actions.DownloadOsmInViewAction;
53import org.openstreetmap.josm.actions.DownloadPrimitiveAction;
54import org.openstreetmap.josm.actions.DownloadReferrersAction;
55import org.openstreetmap.josm.actions.DrawBoundariesOfDownloadedDataAction;
56import org.openstreetmap.josm.actions.DuplicateAction;
57import org.openstreetmap.josm.actions.ExitAction;
58import org.openstreetmap.josm.actions.ExpertToggleAction;
59import org.openstreetmap.josm.actions.FollowLineAction;
60import org.openstreetmap.josm.actions.FullscreenToggleAction;
61import org.openstreetmap.josm.actions.GpxExportAction;
62import org.openstreetmap.josm.actions.HelpAction;
63import org.openstreetmap.josm.actions.HistoryInfoAction;
64import org.openstreetmap.josm.actions.HistoryInfoWebAction;
65import org.openstreetmap.josm.actions.InfoAction;
66import org.openstreetmap.josm.actions.InfoWebAction;
67import org.openstreetmap.josm.actions.InvertSelectionAction;
68import org.openstreetmap.josm.actions.JoinAreasAction;
69import org.openstreetmap.josm.actions.JoinNodeWayAction;
70import org.openstreetmap.josm.actions.JosmAction;
71import org.openstreetmap.josm.actions.JumpToAction;
72import org.openstreetmap.josm.actions.MergeLayerAction;
73import org.openstreetmap.josm.actions.MergeNodesAction;
74import org.openstreetmap.josm.actions.MergeSelectionAction;
75import org.openstreetmap.josm.actions.MirrorAction;
76import org.openstreetmap.josm.actions.MoveAction;
77import org.openstreetmap.josm.actions.MoveNodeAction;
78import org.openstreetmap.josm.actions.NewAction;
79import org.openstreetmap.josm.actions.NewLocalAction;
80import org.openstreetmap.josm.actions.OpenFileAction;
81import org.openstreetmap.josm.actions.OpenLocationAction;
82import org.openstreetmap.josm.actions.OrthogonalizeAction;
83import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo;
84import org.openstreetmap.josm.actions.PasteAction;
85import org.openstreetmap.josm.actions.PasteAtSourcePositionAction;
86import org.openstreetmap.josm.actions.PasteTagsAction;
87import org.openstreetmap.josm.actions.PreferenceToggleAction;
88import org.openstreetmap.josm.actions.PreferencesAction;
89import org.openstreetmap.josm.actions.PurgeAction;
90import org.openstreetmap.josm.actions.RedoAction;
91import org.openstreetmap.josm.actions.ReorderImageryLayersAction;
92import org.openstreetmap.josm.actions.ReportBugAction;
93import org.openstreetmap.josm.actions.RestartAction;
94import org.openstreetmap.josm.actions.ReverseWayAction;
95import org.openstreetmap.josm.actions.SaveAction;
96import org.openstreetmap.josm.actions.SaveAsAction;
97import org.openstreetmap.josm.actions.SearchNotesDownloadAction;
98import org.openstreetmap.josm.actions.SelectAllAction;
99import org.openstreetmap.josm.actions.SelectNonBranchingWaySequencesAction;
100import org.openstreetmap.josm.actions.SelectSharedChildObjectsAction;
101import org.openstreetmap.josm.actions.SessionSaveAction;
102import org.openstreetmap.josm.actions.SessionSaveAsAction;
103import org.openstreetmap.josm.actions.ShowStatusReportAction;
104import org.openstreetmap.josm.actions.SimplifyWayAction;
105import org.openstreetmap.josm.actions.SplitWayAction;
106import org.openstreetmap.josm.actions.TaggingPresetSearchAction;
107import org.openstreetmap.josm.actions.TiledRenderToggleAction;
108import org.openstreetmap.josm.actions.UnGlueAction;
109import org.openstreetmap.josm.actions.UnJoinNodeWayAction;
110import org.openstreetmap.josm.actions.UndoAction;
111import org.openstreetmap.josm.actions.UnselectAllAction;
112import org.openstreetmap.josm.actions.UpdateDataAction;
113import org.openstreetmap.josm.actions.UpdateModifiedAction;
114import org.openstreetmap.josm.actions.UpdateSelectionAction;
115import org.openstreetmap.josm.actions.UploadAction;
116import org.openstreetmap.josm.actions.UploadSelectionAction;
117import org.openstreetmap.josm.actions.ViewportFollowToggleAction;
118import org.openstreetmap.josm.actions.WireframeToggleAction;
119import org.openstreetmap.josm.actions.ZoomInAction;
120import org.openstreetmap.josm.actions.ZoomOutAction;
121import org.openstreetmap.josm.actions.audio.AudioBackAction;
122import org.openstreetmap.josm.actions.audio.AudioFasterAction;
123import org.openstreetmap.josm.actions.audio.AudioFwdAction;
124import org.openstreetmap.josm.actions.audio.AudioNextAction;
125import org.openstreetmap.josm.actions.audio.AudioPlayPauseAction;
126import org.openstreetmap.josm.actions.audio.AudioPrevAction;
127import org.openstreetmap.josm.actions.audio.AudioSlowerAction;
128import org.openstreetmap.josm.actions.mapmode.MapMode;
129import org.openstreetmap.josm.actions.search.SearchAction;
130import org.openstreetmap.josm.data.UndoRedoHandler;
131import org.openstreetmap.josm.gui.dialogs.MenuItemSearchDialog;
132import org.openstreetmap.josm.gui.io.OnlineResourceMenu;
133import org.openstreetmap.josm.gui.io.RecentlyOpenedFilesMenu;
134import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
135import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
136import org.openstreetmap.josm.gui.layer.geoimage.WikimediaCommonsLoader.WikimediaCommonsLoadImagesAction;
137import org.openstreetmap.josm.gui.mappaint.MapPaintMenu;
138import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference;
139import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetSearchPrimitiveDialog;
140import org.openstreetmap.josm.spi.preferences.Config;
141import org.openstreetmap.josm.tools.ImageProvider;
142import org.openstreetmap.josm.tools.PlatformManager;
143import org.openstreetmap.josm.tools.Shortcut;
144
145/**
146 * This is the JOSM main menu bar. It is overwritten to initialize itself and provide all menu
147 * entries as member variables (sort of collect them).
148 * <p>
149 * It also provides possibilities to attach new menu entries (used by plugins).
150 *
151 * @author Immanuel.Scholz
152 */
153public class MainMenu extends JMenuBar {
154
155 /**
156 * The possible item groups of the Windows menu.
157 * @see MainMenu#addWithCheckbox
158 */
159 public enum WINDOW_MENU_GROUP {
160 /** Entries always displayed, at the top */
161 ALWAYS,
162 /** Entries displayed only for visible toggle dialogs */
163 TOGGLE_DIALOG,
164 /** Volatile entries displayed at the end */
165 VOLATILE
166 }
167
168 /* File menu */
169 /** File / New Layer **/
170 public final NewAction newAction = new NewAction();
171 /** File / New Local Layer **/
172 public final NewLocalAction newLocalAction = new NewLocalAction();
173 /** File / Open... **/
174 public final OpenFileAction openFile = new OpenFileAction();
175 /** File / Open Recent &gt; **/
176 public final RecentlyOpenedFilesMenu recentlyOpened = new RecentlyOpenedFilesMenu();
177 /** File / Open Location... **/
178 public final OpenLocationAction openLocation = new OpenLocationAction();
179 /** File / Delete Layer **/
180 public final DeleteLayerAction deleteLayerAction = new DeleteLayerAction();
181 /** File / Save **/
182 public final SaveAction save = SaveAction.getInstance();
183 /** File / Save As... **/
184 public final SaveAsAction saveAs = SaveAsAction.getInstance();
185 /** File / Session &gt; Save Session **/
186 public final SessionSaveAction sessionSave = SessionSaveAction.getInstance();
187 /** File / Session &gt; Save Session As... **/
188 public final SessionSaveAsAction sessionSaveAs = new SessionSaveAsAction();
189 /** File / Export to GPX... **/
190 public final GpxExportAction gpxExport = new GpxExportAction();
191 /** File / Download from OSM... **/
192 public final DownloadAction download = new DownloadAction();
193 /** File / Download in current view **/
194 public final DownloadOsmInViewAction downloadInView = new DownloadOsmInViewAction();
195 /** File / Download object... **/
196 public final DownloadPrimitiveAction downloadPrimitive = new DownloadPrimitiveAction();
197 /** File / Download notes in current view **/
198 public final DownloadNotesInViewAction downloadNotesInView = DownloadNotesInViewAction.newActionWithNoteIcon();
199 /** File / Search Notes... **/
200 public final SearchNotesDownloadAction searchNotes = new SearchNotesDownloadAction();
201 /** File / Download parent ways/relations... **/
202 public final DownloadReferrersAction downloadReferrers = new DownloadReferrersAction();
203 /** File / Close open changesets... **/
204 public final CloseChangesetAction closeChangesetAction = new CloseChangesetAction();
205 /** File / Update data **/
206 public final JosmAction update = new UpdateDataAction();
207 /** File / Update selection **/
208 public final JosmAction updateSelection = new UpdateSelectionAction();
209 /** File / Update modified **/
210 public final JosmAction updateModified = new UpdateModifiedAction();
211 /** File / Upload data **/
212 public final JosmAction upload = new UploadAction();
213 /** File / Upload selection **/
214 public final JosmAction uploadSelection = new UploadSelectionAction();
215 /** File / Restart **/
216 public final RestartAction restart = new RestartAction();
217 /** File / Exit **/
218 public final ExitAction exit = new ExitAction();
219
220 /* Edit menu */
221 /** Edit / Undo... */
222 public final UndoAction undo = new UndoAction();
223 /** Edit / Redo */
224 public final RedoAction redo = new RedoAction();
225 /** Edit / Copy */
226 public final CopyAction copy = new CopyAction();
227 /** Edit / Copy URLs*/
228 public final CopyUrlAction copyUrl = new CopyUrlAction();
229 /** Edit / Copy Coordinates */
230 public final JosmAction copyCoordinates = new CopyCoordinatesAction();
231 /** Edit / Paste */
232 public final PasteAction paste = new PasteAction();
233 /** Edit / Paste at source */
234 private final PasteAtSourcePositionAction pasteAtSource = new PasteAtSourcePositionAction();
235 /** Edit / Paste Tags */
236 public final PasteTagsAction pasteTags = new PasteTagsAction();
237 /** Edit / Duplicate */
238 public final DuplicateAction duplicate = new DuplicateAction();
239 /** Edit / Delete */
240 public final DeleteAction delete = new DeleteAction();
241 /** Edit / Purge... */
242 public final JosmAction purge = new PurgeAction();
243 /** Edit / Merge layer */
244 public final MergeLayerAction merge = new MergeLayerAction();
245 /** Edit / Merge selection */
246 public final MergeSelectionAction mergeSelected = new MergeSelectionAction();
247 /** Edit / Search... */
248 public final SearchAction search = new SearchAction();
249 /** Edit / Preferences */
250 public final PreferencesAction preferences = new PreferencesAction();
251
252 /* View menu */
253 /** View / Wireframe View */
254 public final WireframeToggleAction wireFrameToggleAction = new WireframeToggleAction();
255 /** View / Tiled Rendering */
256 public final TiledRenderToggleAction tiledRenderToggleAction = new TiledRenderToggleAction();
257 /** View / Hatch area outside download */
258 public final DrawBoundariesOfDownloadedDataAction drawBoundariesOfDownloadedDataAction = new DrawBoundariesOfDownloadedDataAction();
259 /** View / Advanced info */
260 public final InfoAction info = new InfoAction();
261 /** View / Advanced info (web) */
262 public final InfoWebAction infoweb = new InfoWebAction();
263 /** View / History */
264 public final HistoryInfoAction historyinfo = new HistoryInfoAction();
265 /** View / History (web) */
266 public final HistoryInfoWebAction historyinfoweb = new HistoryInfoWebAction();
267 /** View / "Zoom to"... actions */
268 public final Map<AutoScaleMode, AutoScaleAction> autoScaleActions = new EnumMap<>(AutoScaleMode.class);
269 /** View / Jump to position */
270 public final JumpToAction jumpToAct = new JumpToAction();
271
272 /* Tools menu */
273 /** Tools / Split Way */
274 public final SplitWayAction splitWay = new SplitWayAction();
275 /** Tools / Combine Way */
276 public final CombineWayAction combineWay = new CombineWayAction();
277 /** Tools / Reverse Ways */
278 public final ReverseWayAction reverseWay = new ReverseWayAction();
279 /** Tools / Simplify Way */
280 public final SimplifyWayAction simplifyWay = new SimplifyWayAction();
281 /** Tools / Align Nodes in Circle */
282 public final AlignInCircleAction alignInCircle = new AlignInCircleAction();
283 /** Tools / Align Nodes in Line */
284 public final AlignInLineAction alignInLine = new AlignInLineAction();
285 /** Tools / Distribute Nodes */
286 public final DistributeAction distribute = new DistributeAction();
287 /** Tools / Orthogonalize Shape */
288 public final OrthogonalizeAction ortho = new OrthogonalizeAction();
289 /** Orthogonalize undo. Action is not shown in the menu. Only triggered by shortcut */
290 public final Undo orthoUndo = new Undo();
291 /** Tools / Mirror */
292 public final MirrorAction mirror = new MirrorAction();
293 /** Tools / Follow line */
294 public final FollowLineAction followLine = new FollowLineAction();
295 /** Tools / Add Node... */
296 public final AddNodeAction addNode = new AddNodeAction();
297 /** Tools / Move Node... */
298 public final MoveNodeAction moveNode = new MoveNodeAction();
299 /** Tools / Create Circle */
300 public final CreateCircleAction createCircle = new CreateCircleAction();
301 /** Tools / Merge Nodes */
302 public final MergeNodesAction mergeNodes = new MergeNodesAction();
303 /** Tools / Join Node to Way */
304 public final JoinNodeWayAction joinNodeWay = JoinNodeWayAction.createJoinNodeToWayAction();
305 /** Tools / Join Way to Node */
306 public final JoinNodeWayAction moveNodeOntoWay = JoinNodeWayAction.createMoveNodeOntoWayAction();
307 /** Tools / Disconnect Node from Way */
308 public final UnJoinNodeWayAction unJoinNodeWay = new UnJoinNodeWayAction();
309 /** Tools / Unglue Ways */
310 public final UnGlueAction unglueNodes = new UnGlueAction();
311 /** Tools / Join overlapping Areas */
312 public final JoinAreasAction joinAreas = new JoinAreasAction();
313 /** Tools / Create multipolygon */
314 public final CreateMultipolygonAction createMultipolygon = new CreateMultipolygonAction(false);
315 /** Tools / Update multipolygon */
316 public final CreateMultipolygonAction updateMultipolygon = new CreateMultipolygonAction(true);
317 /** Tools / Download along way */
318 public final DownloadAlongWayAction downloadAlongWay = new DownloadAlongWayAction();
319
320 /* Selection menu */
321 /** Selection / Select All */
322 public final SelectAllAction selectAll = new SelectAllAction();
323 /** Selection / Unselect All */
324 public final UnselectAllAction unselectAll = new UnselectAllAction();
325 /** Selection / Invert Selection */
326 public final InvertSelectionAction invertSelection = new InvertSelectionAction();
327 /** Selection / Non-branching way sequences */
328 public final SelectNonBranchingWaySequencesAction nonBranchingWaySequences = new SelectNonBranchingWaySequencesAction();
329 /** Selection / Shared Child Objects */
330 public final SelectSharedChildObjectsAction sharedChildObjects = new SelectSharedChildObjectsAction();
331
332 /* Audio menu */
333 /** Audio / Play/Pause */
334 public final JosmAction audioPlayPause = new AudioPlayPauseAction();
335 /** Audio / Next marker */
336 public final JosmAction audioNext = new AudioNextAction();
337 /** Audio / Previous Marker */
338 public final JosmAction audioPrev = new AudioPrevAction();
339 /** Audio / Forward */
340 public final JosmAction audioFwd = new AudioFwdAction();
341 /** Audio / Back */
342 public final JosmAction audioBack = new AudioBackAction();
343 /** Audio / Faster */
344 public final JosmAction audioFaster = new AudioFasterAction();
345 /** Audio / Slower */
346 public final JosmAction audioSlower = new AudioSlowerAction();
347
348 /* Windows Menu */
349 /** Windows / Changeset Manager */
350 public final ChangesetManagerToggleAction changesetManager = new ChangesetManagerToggleAction();
351
352 /* Help menu */
353 /** Help / Help */
354 public final HelpAction help = new HelpAction();
355 /** Help / About */
356 public final AboutAction about = new AboutAction();
357 /** Help / Show Status Report */
358 public final ShowStatusReportAction statusreport = new ShowStatusReportAction();
359 /** Help / Report bug */
360 public final ReportBugAction reportbug = new ReportBugAction();
361
362 /**
363 * fileMenu contains I/O actions
364 */
365 public final JMenu fileMenu = addMenu("File", /* I18N: mnemonic: F */ trc("menu", "File"), KeyEvent.VK_F, 0, ht("/Menu/File"));
366 /**
367 * editMenu contains editing actions
368 */
369 public final JMenu editMenu = addMenu("Edit", /* I18N: mnemonic: E */ trc("menu", "Edit"), KeyEvent.VK_E, 1, ht("/Menu/Edit"));
370 /**
371 * viewMenu contains display actions (zoom, map styles, etc.)
372 */
373 public final JMenu viewMenu = addMenu("View", /* I18N: mnemonic: V */ trc("menu", "View"), KeyEvent.VK_V, 2, ht("/Menu/View"));
374 /**
375 * modeMenu contains map modes
376 */
377 public final JMenu modeMenu = addMenu(new ModeMenu(), /* I18N: mnemonic: M */ trc("menu", "Mode"), KeyEvent.VK_M, 3, ht("/Menu/Mode"));
378 /**
379 * toolsMenu contains different geometry manipulation actions from JOSM core (most used)
380 * The plugins should use other menus
381 */
382 public final JMenu toolsMenu = addMenu("Tools", /* I18N: mnemonic: T */ trc("menu", "Tools"), KeyEvent.VK_T, 4, ht("/Menu/Tools"));
383 /**
384 * moreToolsMenu contains geometry-related actions from all the plugins
385 * @since 6082 (moved from Utilsplugin2)
386 */
387 // CHECKSTYLE.OFF: LineLength
388 public final JMenu moreToolsMenu = addMenu("More tools", /* I18N: mnemonic: O */ trc("menu", "More tools"), KeyEvent.VK_O, 5, ht("/Menu/MoreTools"));
389 /**
390 * dataMenu contains plugin actions that are related to certain tagging schemes (addressing opening hours),
391 * importing external data and using external web APIs
392 * @since 6082
393 */
394 public final JMenu dataMenu = addMenu("Data", /* I18N: mnemonic: D */ trc("menu", "Data"), KeyEvent.VK_D, 6, ht("/Menu/Data"));
395 /**
396 * selectionMenu contains all actions related to selecting different objects
397 * @since 6082 (moved from Utilsplugin2)
398 */
399 public final JMenu selectionMenu = addMenu("Selection", /* I18N: mnemonic: N */ trc("menu", "Selection"), KeyEvent.VK_N, 7, ht("/Menu/Selection"));
400 /**
401 * presetsMenu contains presets actions (search, presets tree)
402 */
403 public final JMenu presetsMenu = addMenu("Presets", /* I18N: mnemonic: P */ trc("menu", "Presets"), KeyEvent.VK_P, 8, ht("/Menu/Presets"));
404 /**
405 * submenu in Imagery menu that contains plugin-managed additional imagery layers
406 * @since 6097
407 */
408 public final JMenu imagerySubMenu = new JMenu(tr("More..."));
409 /**
410 * imageryMenu contains all imagery-related actions
411 */
412 public final ImageryMenu imageryMenu = addMenu(new ImageryMenu(imagerySubMenu), /* untranslated name */ "Imagery", KeyEvent.VK_I, 9, ht("/Menu/Imagery"));
413 /**
414 * gpsMenu contains all plugin actions that are related
415 * to using GPS data, including opening, uploading and real-time tracking
416 * @since 6082
417 */
418 public final JMenu gpsMenu = addMenu("GPS", /* I18N: mnemonic: G */ trc("menu", "GPS"), KeyEvent.VK_G, 10, ht("/Menu/GPS"));
419 /** the window menu is split into several groups. The first is for windows that can be opened from
420 * this menu any time, e.g. the changeset editor. The second group is for toggle dialogs and the third
421 * group is for currently open windows that cannot be toggled, e.g. relation editors. It's recommended
422 * to use WINDOW_MENU_GROUP to determine the group integer.
423 */
424 public final WindowMenu windowMenu = addMenu(new WindowMenu(), /* untranslated name */ "Windows", KeyEvent.VK_W, 11, ht("/Menu/Windows"));
425 // CHECKSTYLE.ON: LineLength
426
427 /**
428 * audioMenu contains all audio-related actions. Be careful, this menu is not guaranteed to be displayed at all
429 */
430 public JMenu audioMenu;
431 /**
432 * helpMenu contains JOSM general actions (Help, About, etc.)
433 */
434 public final JMenu helpMenu = addMenu("Help", /* I18N: mnemonic: H */ trc("menu", "Help"), KeyEvent.VK_H, 12, ht("/Menu/Help"));
435
436 private static final int defaultMenuPos = 12;
437
438 /** Move the selection up */
439 public final JosmAction moveUpAction = new MoveAction(MoveAction.Direction.UP);
440 /** Move the selection down */
441 public final JosmAction moveDownAction = new MoveAction(MoveAction.Direction.DOWN);
442 /** Move the selection left */
443 public final JosmAction moveLeftAction = new MoveAction(MoveAction.Direction.LEFT);
444 /** Move the selection right */
445 public final JosmAction moveRightAction = new MoveAction(MoveAction.Direction.RIGHT);
446
447 /** Reorder imagery layers */
448 public final ReorderImageryLayersAction reorderImageryLayersAction = new ReorderImageryLayersAction();
449
450 /** Search tagging presets */
451 public final TaggingPresetSearchAction presetSearchAction = new TaggingPresetSearchAction();
452 /** Search objects by their tagging preset */
453 public final TaggingPresetSearchPrimitiveDialog.Action presetSearchPrimitiveAction = new TaggingPresetSearchPrimitiveDialog.Action();
454 /** Toggle visibility of dialogs panel */
455 public final DialogsToggleAction dialogsToggleAction = new DialogsToggleAction();
456 /** Toggle the full-screen mode */
457 public FullscreenToggleAction fullscreenToggleAction;
458
459 /** this menu listener hides unnecessary JSeparators in a menu list but does not remove them.
460 * If at a later time the separators are required, they will be made visible again. Intended
461 * usage is make menus not look broken if separators are used to group the menu and some of
462 * these groups are empty.
463 */
464 public static final MenuListener menuSeparatorHandler = new MenuListener() {
465 @Override
466 public void menuCanceled(MenuEvent e) {
467 // Do nothing
468 }
469
470 @Override
471 public void menuDeselected(MenuEvent e) {
472 // Do nothing
473 }
474
475 @Override
476 public void menuSelected(MenuEvent a) {
477 if (!(a.getSource() instanceof JMenu))
478 return;
479 final JPopupMenu m = ((JMenu) a.getSource()).getPopupMenu();
480 for (int i = 0; i < m.getComponentCount()-1; i++) {
481 // hide separator if the next menu item is one as well
482 if (m.getComponent(i) instanceof JSeparator && m.getComponent(i + 1) instanceof JSeparator) {
483 m.getComponent(i).setVisible(false);
484 }
485 }
486 // hide separator at the end of the menu
487 if (m.getComponent(m.getComponentCount() - 1) instanceof JSeparator) {
488 m.getComponent(m.getComponentCount() - 1).setVisible(false);
489 }
490 }
491 };
492
493 /**
494 * Returns the default position of new top-level menus.
495 * @return the default position of new top-level menus
496 * @since 6088
497 */
498 public int getDefaultMenuPos() {
499 return defaultMenuPos;
500 }
501
502 /**
503 * Add a JosmAction at the end of a menu.
504 * <p>
505 * This method handles all the shortcut handling. It also makes sure that actions that are
506 * handled by the OS are not duplicated on the menu.
507 * @param menu the menu to add the action to
508 * @param action the action that should get a menu item
509 * @return the created menu item
510 */
511 public static JMenuItem add(JMenu menu, JosmAction action) {
512 return add(menu, action, false);
513 }
514
515 /**
516 * Add a JosmAction at the end of a menu.
517 * <p>
518 * This method handles all the shortcut handling. It also makes sure that actions that are
519 * handled by the OS are not duplicated on the menu.
520 * @param menu the menu to add the action to
521 * @param action the action that should get a menu item
522 * @param isExpert whether the entry should only be visible if the expert mode is activated
523 * @return the created menu item
524 */
525 public static JMenuItem add(JMenu menu, JosmAction action, boolean isExpert) {
526 return add(menu, action, isExpert, null);
527 }
528
529 /**
530 * Add a JosmAction at the end of a menu.
531 * <p>
532 * This method handles all the shortcut handling. It also makes sure that actions that are
533 * handled by the OS are not duplicated on the menu.
534 * @param menu the menu to add the action to
535 * @param action the action that should get a menu item
536 * @param isExpert whether the entry should only be visible if the expert mode is activated
537 * @param index an integer specifying the position at which to add the action
538 * @return the created menu item
539 */
540 public static JMenuItem add(JMenu menu, JosmAction action, boolean isExpert, Integer index) {
541 if (action.getShortcut().isAutomatic())
542 return null;
543 final JMenuItem menuitem;
544 if (index == null) {
545 menuitem = menu.add(action);
546 } else {
547 menuitem = menu.insert(action, index);
548 }
549 if (isExpert) {
550 ExpertToggleAction.addVisibilitySwitcher(menuitem);
551 }
552 KeyStroke ks = action.getShortcut().getKeyStroke();
553 if (ks != null) {
554 menuitem.setAccelerator(ks);
555 }
556 // some menus are hidden before they are populated with some items by plugins
557 if (!menu.isVisible()) menu.setVisible(true);
558 return menuitem;
559 }
560
561 /**
562 * Add the JosmAction {@code actionToBeInserted} directly below {@code existingMenuEntryAction}.
563 * <p>
564 * This method handles all the shortcut handling. It also makes sure that actions that are
565 * handled by the OS are not duplicated on the menu.
566 * @param menu the menu to add the action to
567 * @param actionToBeInserted the action that should get a menu item directly below {@code existingMenuEntryAction}
568 * @param isExpert whether the entry should only be visible if the expert mode is activated
569 * @param existingMenuEntryAction an action already added to the menu {@code menu},
570 * the action {@code actionToBeInserted} is added directly below
571 * @return the created menu item
572 */
573 public static JMenuItem addAfter(JMenu menu, JosmAction actionToBeInserted, boolean isExpert, JosmAction existingMenuEntryAction) {
574 int i = 0;
575 for (Component c : menu.getMenuComponents()) {
576 if (c instanceof JMenuItem && ((JMenuItem) c).getAction() == existingMenuEntryAction) {
577 break;
578 }
579 i++;
580 }
581 return add(menu, actionToBeInserted, isExpert, i + 1);
582 }
583
584 /**
585 * Add a JosmAction to a menu.
586 * <p>
587 * This method handles all the shortcut handling. It also makes sure that actions that are
588 * handled by the OS are not duplicated on the menu.
589 * @param <E> group item enum type
590 * @param menu to add the action to
591 * @param action the action that should get a menu item
592 * @param group the item should be added to. Groups are split by a separator. null will add the item to the end.
593 * @return The created menu item
594 */
595 public static <E extends Enum<E>> JMenuItem add(JMenu menu, JosmAction action, Enum<E> group) {
596 if (action.getShortcut().isAutomatic())
597 return null;
598 int i = group != null ? getInsertionIndexForGroup(menu, group.ordinal(), false) : -1;
599 JMenuItem menuitem = (JMenuItem) menu.add(new JMenuItem(action), i);
600 KeyStroke ks = action.getShortcut().getKeyStroke();
601 if (ks != null) {
602 menuitem.setAccelerator(ks);
603 }
604 return menuitem;
605 }
606
607 /**
608 * Add a JosmAction to a menu and automatically prints accelerator if available.
609 * Also adds a checkbox that may be toggled.
610 * @param <E> group enum item type
611 * @param menu to add the action to
612 * @param action the action that should get a menu item
613 * @param group the item should be added to. Groups are split by a separator. Use
614 * one of the enums that are defined for some of the menus to tell in which
615 * group the item should go.
616 * @return The created menu item
617 */
618 public static <E extends Enum<E>> JCheckBoxMenuItem addWithCheckbox(JMenu menu, JosmAction action, Enum<E> group) {
619 return addWithCheckbox(menu, action, group, false, false);
620 }
621
622 /**
623 * Add a JosmAction to a menu and automatically prints accelerator if available.
624 * Also adds a checkbox that may be toggled.
625 * @param <E> group enum item type
626 * @param menu to add the action to
627 * @param action the action that should get a menu item
628 * @param group the item should be added to. Groups are split by a separator. Use
629 * one of the enums that are defined for some of the menus to tell in which
630 * group the item should go. null will add the item to the end.
631 * @param isEntryExpert whether the entry should only be visible if the expert mode is activated
632 * @param isGroupSeparatorExpert whether the group separator should only be visible if the expert mode is activated
633 * @return The created menu item
634 * @since 15633
635 */
636 public static <E extends Enum<E>> JCheckBoxMenuItem addWithCheckbox(JMenu menu, JosmAction action, Enum<E> group,
637 boolean isEntryExpert, boolean isGroupSeparatorExpert) {
638 int i = group != null ? getInsertionIndexForGroup(menu, group.ordinal(), isGroupSeparatorExpert) : -1;
639 return addWithCheckbox(menu, action, i, isEntryExpert);
640 }
641
642 /**
643 * Add a JosmAction to a menu and automatically prints accelerator if available.
644 * Also adds a checkbox that may be toggled.
645 * @param <E> group enum item type
646 * @param menu to add the action to
647 * @param action the action that should get a menu item
648 * @param i the item position in the menu. -1 will add the item to the end.
649 * @param isEntryExpert whether the entry should only be visible if the expert mode is activated
650 * @return The created menu item
651 * @since 15655
652 */
653 public static <E extends Enum<E>> JCheckBoxMenuItem addWithCheckbox(JMenu menu, JosmAction action, int i, boolean isEntryExpert) {
654 final JCheckBoxMenuItem mi = new JCheckBoxMenuItem(action);
655 final KeyStroke ks = action.getShortcut().getKeyStroke();
656 if (ks != null) {
657 mi.setAccelerator(ks);
658 }
659 if (isEntryExpert) {
660 ExpertToggleAction.addVisibilitySwitcher(mi);
661 }
662 return (JCheckBoxMenuItem) menu.add(mi, i);
663 }
664
665 /**
666 * Finds the correct insertion index for a given group and adds separators if necessary
667 * @param menu menu
668 * @param group group number
669 * @param isGroupSeparatorExpert whether the added separators should only be visible if the expert mode is activated
670 * @return correct insertion index
671 */
672 private static int getInsertionIndexForGroup(JMenu menu, int group, boolean isGroupSeparatorExpert) {
673 if (group < 0)
674 return -1;
675 // look for separator that *ends* the group (or stop at end of menu)
676 int i;
677 for (i = 0; i < menu.getItemCount() && group >= 0; i++) {
678 if (menu.getItem(i) == null) {
679 group--;
680 }
681 }
682 // insert before separator that ends the group
683 if (group < 0) {
684 i--;
685 }
686 // not enough separators have been found, add them
687 while (group > 0) {
688 menu.addSeparator();
689 if (isGroupSeparatorExpert) {
690 ExpertToggleAction.addVisibilitySwitcher(menu.getMenuComponent(menu.getMenuComponentCount() - 1));
691 }
692 group--;
693 i++;
694 }
695 return i;
696 }
697
698 /**
699 * Creates a menu and adds it on the given position to the main menu.
700 *
701 * @param name the untranslated name (used as identifier for shortcut registration)
702 * @param translatedName the translated menu name (use {@code I18n.trc("menu", name)} to allow better internationalization
703 * @param mnemonicKey the mnemonic key to register
704 * @param position the position in the main menu
705 * @param relativeHelpTopic the relative help topic
706 * @return the newly created menu
707 */
708 public JMenu addMenu(String name, String translatedName, int mnemonicKey, int position, String relativeHelpTopic) {
709 final JMenu menu = new JMenu(translatedName);
710 if (!GraphicsEnvironment.isHeadless()) {
711 MenuScroller.setScrollerFor(menu);
712 }
713 return addMenu(menu, name, mnemonicKey, position, relativeHelpTopic);
714 }
715
716 /**
717 * Adds the given menu on the given position to the main menu.
718 * @param <T> menu type
719 *
720 * @param menu the menu to add
721 * @param name the untranslated name (used as identifier for shortcut registration)
722 * @param mnemonicKey the mnemonic key to register
723 * @param position the position in the main menu
724 * @param relativeHelpTopic the relative help topic
725 * @return the given {@code }menu}
726 */
727 public <T extends JMenu> T addMenu(T menu, String name, int mnemonicKey, int position, String relativeHelpTopic) {
728 Shortcut.registerShortcut("menu:" + name, tr("Menu: {0}", name), mnemonicKey,
729 Shortcut.MNEMONIC).setMnemonic(menu);
730 add(menu, position);
731 menu.putClientProperty("help", relativeHelpTopic);
732 return menu;
733 }
734
735 /**
736 * Initialize the main menu.
737 * @since 10340
738 */
739 // CHECKSTYLE.OFF: ExecutableStatementCountCheck
740 public void initialize() {
741 moreToolsMenu.setVisible(false);
742 dataMenu.setVisible(false);
743 gpsMenu.setVisible(false);
744
745 add(fileMenu, newAction);
746 add(fileMenu, newLocalAction);
747 add(fileMenu, openFile);
748 fileMenu.add(recentlyOpened);
749 add(fileMenu, openLocation);
750 add(fileMenu, deleteLayerAction);
751 fileMenu.addSeparator();
752 add(fileMenu, save);
753 add(fileMenu, saveAs);
754 add(fileMenu, sessionSave);
755 add(fileMenu, sessionSaveAs);
756 add(fileMenu, gpxExport, true);
757 fileMenu.addSeparator();
758 add(fileMenu, download);
759 add(fileMenu, downloadInView, true);
760 add(fileMenu, downloadAlongWay);
761 add(fileMenu, downloadPrimitive);
762 add(fileMenu, searchNotes);
763 add(fileMenu, downloadNotesInView);
764 add(fileMenu, new WikimediaCommonsLoadImagesAction());
765 add(fileMenu, downloadReferrers);
766 add(fileMenu, update);
767 add(fileMenu, updateSelection);
768 add(fileMenu, updateModified);
769 fileMenu.addSeparator();
770 add(fileMenu, upload);
771 add(fileMenu, uploadSelection);
772 Component sep = new JPopupMenu.Separator();
773 fileMenu.add(sep);
774 ExpertToggleAction.addVisibilitySwitcher(sep);
775 add(fileMenu, closeChangesetAction, true);
776 fileMenu.addSeparator();
777 fileMenu.add(new OnlineResourceMenu());
778 add(fileMenu, restart);
779 add(fileMenu, exit);
780
781 add(editMenu, undo);
782 UndoRedoHandler.getInstance().addCommandQueueListener(undo);
783 add(editMenu, redo);
784 UndoRedoHandler.getInstance().addCommandQueueListener(redo);
785 editMenu.addSeparator();
786 add(editMenu, copy);
787 add(editMenu, copyCoordinates, true);
788 add(editMenu, copyUrl, true);
789 add(editMenu, paste);
790 add(editMenu, pasteAtSource, true);
791 add(editMenu, pasteTags);
792 add(editMenu, duplicate);
793 add(editMenu, delete);
794 add(editMenu, purge, true);
795 editMenu.addSeparator();
796 add(editMenu, merge);
797 add(editMenu, mergeSelected);
798 editMenu.addSeparator();
799 add(editMenu, search);
800 add(editMenu, presetSearchPrimitiveAction);
801 editMenu.addSeparator();
802 add(editMenu, preferences);
803
804 // -- wireframe toggle action
805 final JCheckBoxMenuItem wireframe = new JCheckBoxMenuItem(wireFrameToggleAction);
806 viewMenu.add(wireframe);
807 wireframe.setAccelerator(wireFrameToggleAction.getShortcut().getKeyStroke());
808 wireFrameToggleAction.addButtonModel(wireframe.getModel());
809 // -- tiled render toggle action -- not intended to be permanently an "Expert" mode option
810 final JCheckBoxMenuItem tiledRender = new JCheckBoxMenuItem(tiledRenderToggleAction);
811 viewMenu.add(tiledRender);
812 tiledRenderToggleAction.addButtonModel(tiledRender.getModel());
813 ExpertToggleAction.addVisibilitySwitcher(tiledRender);
814 // -- hatch toggle action
815 final JCheckBoxMenuItem hatchAreaOutsideDownloadMenuItem = drawBoundariesOfDownloadedDataAction.getCheckbox();
816 viewMenu.add(hatchAreaOutsideDownloadMenuItem);
817 ExpertToggleAction.addVisibilitySwitcher(hatchAreaOutsideDownloadMenuItem);
818
819 viewMenu.add(new MapPaintMenu());
820 viewMenu.addSeparator();
821 add(viewMenu, new ZoomInAction());
822 add(viewMenu, new ZoomOutAction());
823 viewMenu.addSeparator();
824 for (AutoScaleMode mode : AutoScaleMode.values()) {
825 AutoScaleAction autoScaleAction = new AutoScaleAction(mode);
826 autoScaleActions.put(mode, autoScaleAction);
827 add(viewMenu, autoScaleAction);
828 }
829
830 // -- viewport follow toggle action
831 ViewportFollowToggleAction viewportFollowToggleAction = new ViewportFollowToggleAction();
832 final JCheckBoxMenuItem vft = new JCheckBoxMenuItem(viewportFollowToggleAction);
833 ExpertToggleAction.addVisibilitySwitcher(vft);
834 viewMenu.add(vft);
835 vft.setAccelerator(viewportFollowToggleAction.getShortcut().getKeyStroke());
836 viewportFollowToggleAction.addButtonModel(vft.getModel());
837
838 if (PlatformManager.getPlatform().canFullscreen()) {
839 // -- fullscreen toggle action
840 fullscreenToggleAction = new FullscreenToggleAction();
841 final JCheckBoxMenuItem fullscreen = new JCheckBoxMenuItem(fullscreenToggleAction);
842 viewMenu.addSeparator();
843 viewMenu.add(fullscreen);
844 fullscreen.setAccelerator(fullscreenToggleAction.getShortcut().getKeyStroke());
845 fullscreenToggleAction.addButtonModel(fullscreen.getModel());
846 }
847
848 add(viewMenu, jumpToAct, true);
849 viewMenu.addSeparator();
850 add(viewMenu, info);
851 add(viewMenu, infoweb);
852 add(viewMenu, historyinfo);
853 add(viewMenu, historyinfoweb);
854 viewMenu.addSeparator();
855 viewMenu.add(new PreferenceToggleAction(tr("Main toolbar"),
856 new ImageProvider("dialogs/main_toolbar.svg"),
857 tr("Toggles the visibility of the main toolbar (i.e., the horizontal toolbar)"),
858 MapFrame.TOOLBAR_VISIBLE).getCheckbox());
859 viewMenu.add(new PreferenceToggleAction(tr("Edit toolbar"),
860 new ImageProvider("dialogs/edit_toolbar.svg"),
861 tr("Toggles the visibility of the edit toolbar (i.e., the vertical tool)"),
862 MapFrame.SIDE_TOOLBAR_VISIBLE).getCheckbox());
863 // -- dialogs panel toggle action
864 final JCheckBoxMenuItem dialogsToggle = new JCheckBoxMenuItem(dialogsToggleAction);
865 dialogsToggle.setAccelerator(dialogsToggleAction.getShortcut().getKeyStroke());
866 dialogsToggleAction.addButtonModel(dialogsToggle.getModel());
867 viewMenu.add(dialogsToggle);
868 viewMenu.addSeparator();
869 // -- expert mode toggle action
870 final JCheckBoxMenuItem expertItem = new JCheckBoxMenuItem(ExpertToggleAction.getInstance());
871 viewMenu.add(expertItem);
872 ExpertToggleAction.getInstance().addButtonModel(expertItem.getModel());
873
874 add(imageryMenu, reorderImageryLayersAction);
875 add(imageryMenu, PreferencesAction.forPreferenceTab(tr("Imagery preferences..."),
876 tr("Click to open the imagery tab in the preferences"), ImageryPreference.class));
877
878 add(selectionMenu, selectAll);
879 add(selectionMenu, unselectAll);
880 add(selectionMenu, invertSelection, true);
881 add(selectionMenu, nonBranchingWaySequences);
882 add(selectionMenu, sharedChildObjects, true);
883
884 add(toolsMenu, splitWay);
885 add(toolsMenu, combineWay);
886 toolsMenu.addSeparator();
887 add(toolsMenu, reverseWay);
888 add(toolsMenu, simplifyWay);
889 toolsMenu.addSeparator();
890 add(toolsMenu, alignInCircle);
891 add(toolsMenu, alignInLine);
892 add(toolsMenu, distribute);
893 add(toolsMenu, ortho);
894 add(toolsMenu, mirror, true);
895 toolsMenu.addSeparator();
896 add(toolsMenu, followLine, true);
897 add(toolsMenu, addNode, true);
898 add(toolsMenu, moveNode, true);
899 add(toolsMenu, createCircle);
900 toolsMenu.addSeparator();
901 add(toolsMenu, mergeNodes);
902 add(toolsMenu, joinNodeWay);
903 add(toolsMenu, moveNodeOntoWay);
904 add(toolsMenu, unJoinNodeWay);
905 add(toolsMenu, unglueNodes);
906 toolsMenu.addSeparator();
907 add(toolsMenu, joinAreas);
908 add(toolsMenu, createMultipolygon);
909 add(toolsMenu, updateMultipolygon);
910
911 // -- changeset manager toggle action
912 final JCheckBoxMenuItem mi = MainMenu.addWithCheckbox(windowMenu, changesetManager,
913 WINDOW_MENU_GROUP.ALWAYS, true, false);
914 changesetManager.addButtonModel(mi.getModel());
915
916 if (!Config.getPref().getBoolean("audio.menuinvisible", false)) {
917 showAudioMenu(true);
918 }
919
920 Config.getPref().addPreferenceChangeListener(e -> {
921 if ("audio.menuinvisible".equals(e.getKey())) {
922 showAudioMenu(!Boolean.parseBoolean(e.getNewValue().toString()));
923 }
924 });
925
926 add(helpMenu, new MenuItemSearchDialog.Action());
927 helpMenu.addSeparator();
928 add(helpMenu, statusreport);
929 add(helpMenu, reportbug);
930 helpMenu.addSeparator();
931
932 add(helpMenu, help);
933 add(helpMenu, about);
934
935 windowMenu.addMenuListener(menuSeparatorHandler);
936
937 new EditLayerMenuEnabler(Arrays.asList(modeMenu, toolsMenu, moreToolsMenu, selectionMenu));
938 }
939 // CHECKSTYLE.ON: ExecutableStatementCountCheck
940
941 /**
942 * Search main menu for items with {@code textToFind} in title.
943 * @param textToFind The text to find
944 * @param skipPresets whether to skip the {@link #presetsMenu} in the search
945 * @return not null list of found menu items.
946 */
947 public List<JMenuItem> findMenuItems(String textToFind, boolean skipPresets) {
948 // Explicitly use default locale in this case, because we're looking for translated strings
949 textToFind = textToFind.toLowerCase(Locale.getDefault());
950 List<JMenuItem> result = new ArrayList<>();
951 for (int i = 0; i < getMenuCount(); i++) {
952 if (getMenu(i) != null && (!skipPresets || presetsMenu != getMenu(i))) {
953 findMenuItems(getMenu(i), textToFind, result);
954 }
955 }
956 return result;
957 }
958
959 /**
960 * Returns the {@link JCheckBoxMenuItem} for the given {@link MapMode}.
961 * @param mode map mode
962 * @return the {@code JCheckBoxMenuItem} for the given {@code MapMode}
963 * @since 15438
964 */
965 public Optional<JCheckBoxMenuItem> findMapModeMenuItem(MapMode mode) {
966 return Arrays.stream(modeMenu.getMenuComponents())
967 .filter(JCheckBoxMenuItem.class::isInstance)
968 .map(JCheckBoxMenuItem.class::cast)
969 .filter(m -> Objects.equals(mode, m.getAction()))
970 .findFirst();
971 }
972
973 /**
974 * Recursive walker for menu items. Only menu items with action are selected. If menu item
975 * contains {@code textToFind} it's appended to result.
976 * @param menu menu in which search will be performed
977 * @param textToFind The text to find
978 * @param result resulting list of menu items
979 */
980 private static void findMenuItems(final JMenu menu, final String textToFind, final List<JMenuItem> result) {
981 for (int i = 0; i < menu.getItemCount(); i++) {
982 JMenuItem menuItem = menu.getItem(i);
983 if (menuItem == null) continue;
984
985 // Explicitly use default locale in this case, because we're looking for translated strings
986 if (menuItem.getAction() != null && menuItem.getText().toLowerCase(Locale.getDefault()).contains(textToFind)) {
987 result.add(menuItem);
988 }
989
990 // Go recursive if needed
991 if (menuItem instanceof JMenu) {
992 findMenuItems((JMenu) menuItem, textToFind, result);
993 }
994 }
995 }
996
997 protected void showAudioMenu(boolean showMenu) {
998 if (showMenu && audioMenu == null) {
999 audioMenu = addMenu("Audio", /* I18N: mnemonic: U */ trc("menu", "Audio"), KeyEvent.VK_U, defaultMenuPos, ht("/Menu/Audio"));
1000 add(audioMenu, audioPlayPause);
1001 add(audioMenu, audioNext);
1002 add(audioMenu, audioPrev);
1003 add(audioMenu, audioFwd);
1004 add(audioMenu, audioBack);
1005 add(audioMenu, audioSlower);
1006 add(audioMenu, audioFaster);
1007 validate();
1008 } else if (!showMenu && audioMenu != null) {
1009 remove(audioMenu);
1010 audioMenu.removeAll();
1011 audioMenu = null;
1012 validate();
1013 }
1014 }
1015
1016 static class EditLayerMenuEnabler implements ActiveLayerChangeListener {
1017 private final Collection<JMenu> menus;
1018
1019 EditLayerMenuEnabler(Collection<JMenu> menus) {
1020 this.menus = Objects.requireNonNull(menus);
1021 MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(this);
1022 }
1023
1024 @Override
1025 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
1026 menus.forEach(m -> m.setEnabled(e.getSource().getEditLayer() != null));
1027 }
1028 }
1029}
Note: See TracBrowser for help on using the repository browser.