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

Last change on this file since 12652 was 12652, checked in by michael2402, 7 years ago

Apply #15167: Merge OSM and overpass download dialog. Patch by bafonins

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