| 1 | // License: GPL. See LICENSE file for details.
|
|---|
| 2 |
|
|---|
| 3 | package org.openstreetmap.josm.gui;
|
|---|
| 4 |
|
|---|
| 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.KeyStroke;
|
|---|
| 16 |
|
|---|
| 17 | import org.openstreetmap.josm.Main;
|
|---|
| 18 | import org.openstreetmap.josm.actions.AboutAction;
|
|---|
| 19 | import org.openstreetmap.josm.actions.AddNodeAction;
|
|---|
| 20 | import org.openstreetmap.josm.actions.AlignInCircleAction;
|
|---|
| 21 | import org.openstreetmap.josm.actions.AlignInLineAction;
|
|---|
| 22 | import org.openstreetmap.josm.actions.AutoScaleAction;
|
|---|
| 23 | import org.openstreetmap.josm.actions.ChangesetManagerToggleAction;
|
|---|
| 24 | import org.openstreetmap.josm.actions.CloseChangesetAction;
|
|---|
| 25 | import org.openstreetmap.josm.actions.CombineWayAction;
|
|---|
| 26 | import org.openstreetmap.josm.actions.CopyAction;
|
|---|
| 27 | import org.openstreetmap.josm.actions.CreateCircleAction;
|
|---|
| 28 | import org.openstreetmap.josm.actions.DeleteAction;
|
|---|
| 29 | import org.openstreetmap.josm.actions.DistributeAction;
|
|---|
| 30 | import org.openstreetmap.josm.actions.DownloadAction;
|
|---|
| 31 | import org.openstreetmap.josm.actions.DownloadReferrersAction;
|
|---|
| 32 | import org.openstreetmap.josm.actions.DuplicateAction;
|
|---|
| 33 | import org.openstreetmap.josm.actions.ExitAction;
|
|---|
| 34 | import org.openstreetmap.josm.actions.FullscreenToggleAction;
|
|---|
| 35 | import org.openstreetmap.josm.actions.GpxExportAction;
|
|---|
| 36 | import org.openstreetmap.josm.actions.HelpAction;
|
|---|
| 37 | import org.openstreetmap.josm.actions.HistoryInfoAction;
|
|---|
| 38 | import org.openstreetmap.josm.actions.InfoAction;
|
|---|
| 39 | import org.openstreetmap.josm.actions.JoinAreasAction;
|
|---|
| 40 | import org.openstreetmap.josm.actions.JoinNodeWayAction;
|
|---|
| 41 | import org.openstreetmap.josm.actions.JosmAction;
|
|---|
| 42 | import org.openstreetmap.josm.actions.MergeLayerAction;
|
|---|
| 43 | import org.openstreetmap.josm.actions.MergeNodesAction;
|
|---|
| 44 | import org.openstreetmap.josm.actions.MergeSelectionAction;
|
|---|
| 45 | import org.openstreetmap.josm.actions.MirrorAction;
|
|---|
| 46 | import org.openstreetmap.josm.actions.NewAction;
|
|---|
| 47 | import org.openstreetmap.josm.actions.OpenFileAction;
|
|---|
| 48 | import org.openstreetmap.josm.actions.OpenLocationAction;
|
|---|
| 49 | import org.openstreetmap.josm.actions.OrthogonalizeAction;
|
|---|
| 50 | import org.openstreetmap.josm.actions.PasteAction;
|
|---|
| 51 | import org.openstreetmap.josm.actions.PasteTagsAction;
|
|---|
| 52 | import org.openstreetmap.josm.actions.PreferencesAction;
|
|---|
| 53 | import org.openstreetmap.josm.actions.RedoAction;
|
|---|
| 54 | import org.openstreetmap.josm.actions.ReverseWayAction;
|
|---|
| 55 | import org.openstreetmap.josm.actions.SaveAction;
|
|---|
| 56 | import org.openstreetmap.josm.actions.SaveAsAction;
|
|---|
| 57 | import org.openstreetmap.josm.actions.SelectAllAction;
|
|---|
| 58 | import org.openstreetmap.josm.actions.ShowStatusReportAction;
|
|---|
| 59 | import org.openstreetmap.josm.actions.SimplifyWayAction;
|
|---|
| 60 | import org.openstreetmap.josm.actions.SplitWayAction;
|
|---|
| 61 | import org.openstreetmap.josm.actions.ToggleGPXLinesAction;
|
|---|
| 62 | import org.openstreetmap.josm.actions.UnGlueAction;
|
|---|
| 63 | import org.openstreetmap.josm.actions.UndoAction;
|
|---|
| 64 | import org.openstreetmap.josm.actions.UnselectAllAction;
|
|---|
| 65 | import org.openstreetmap.josm.actions.UpdateDataAction;
|
|---|
| 66 | import org.openstreetmap.josm.actions.UpdateModifiedAction;
|
|---|
| 67 | import org.openstreetmap.josm.actions.UpdateSelectionAction;
|
|---|
| 68 | import org.openstreetmap.josm.actions.UploadAction;
|
|---|
| 69 | import org.openstreetmap.josm.actions.UploadSelectionAction;
|
|---|
| 70 | import org.openstreetmap.josm.actions.WireframeToggleAction;
|
|---|
| 71 | import org.openstreetmap.josm.actions.ZoomInAction;
|
|---|
| 72 | import org.openstreetmap.josm.actions.ZoomOutAction;
|
|---|
| 73 | import org.openstreetmap.josm.actions.OrthogonalizeAction.Undo;
|
|---|
| 74 | import org.openstreetmap.josm.actions.audio.AudioBackAction;
|
|---|
| 75 | import org.openstreetmap.josm.actions.audio.AudioFasterAction;
|
|---|
| 76 | import org.openstreetmap.josm.actions.audio.AudioFwdAction;
|
|---|
| 77 | import org.openstreetmap.josm.actions.audio.AudioNextAction;
|
|---|
| 78 | import org.openstreetmap.josm.actions.audio.AudioPlayPauseAction;
|
|---|
| 79 | import org.openstreetmap.josm.actions.audio.AudioPrevAction;
|
|---|
| 80 | import org.openstreetmap.josm.actions.audio.AudioSlowerAction;
|
|---|
| 81 | import org.openstreetmap.josm.actions.search.SearchAction;
|
|---|
| 82 | import org.openstreetmap.josm.gui.layer.Layer;
|
|---|
| 83 | import org.openstreetmap.josm.tools.Shortcut;
|
|---|
| 84 | /**
|
|---|
| 85 | * This is the JOSM main menu bar. It is overwritten to initialize itself and provide all menu
|
|---|
| 86 | * entries as member variables (sort of collect them).
|
|---|
| 87 | *
|
|---|
| 88 | * It also provides possibilities to attach new menu entries (used by plugins).
|
|---|
| 89 | *
|
|---|
| 90 | * @author Immanuel.Scholz
|
|---|
| 91 | */
|
|---|
| 92 | public class MainMenu extends JMenuBar {
|
|---|
| 93 |
|
|---|
| 94 | /* File menu */
|
|---|
| 95 | public final NewAction newAction = new NewAction();
|
|---|
| 96 | public final OpenFileAction openFile = new OpenFileAction();
|
|---|
| 97 | public final OpenLocationAction openLocation = new OpenLocationAction();
|
|---|
| 98 | public final JosmAction save = new SaveAction();
|
|---|
| 99 | public final JosmAction saveAs = new SaveAsAction();
|
|---|
| 100 | public final JosmAction gpxExport = new GpxExportAction();
|
|---|
| 101 | public final DownloadAction download = new DownloadAction();
|
|---|
| 102 | public final DownloadReferrersAction downloadReferrers = new DownloadReferrersAction();
|
|---|
| 103 | public final CloseChangesetAction closeChangesetAction = new CloseChangesetAction();
|
|---|
| 104 | public final JosmAction update = new UpdateDataAction();
|
|---|
| 105 | public final JosmAction updateSelection = new UpdateSelectionAction();
|
|---|
| 106 | public final JosmAction updateModified = new UpdateModifiedAction();
|
|---|
| 107 | public final JosmAction upload = new UploadAction();
|
|---|
| 108 | public final JosmAction uploadSelection = new UploadSelectionAction();
|
|---|
| 109 | public final JosmAction exit = new ExitAction();
|
|---|
| 110 |
|
|---|
| 111 | /* Edit menu */
|
|---|
| 112 | public final UndoAction undo = new UndoAction();
|
|---|
| 113 | public final RedoAction redo = new RedoAction();
|
|---|
| 114 | public final JosmAction copy = new CopyAction();
|
|---|
| 115 | public final JosmAction paste = new PasteAction();
|
|---|
| 116 | public final JosmAction pasteTags = new PasteTagsAction(copy);
|
|---|
| 117 | public final JosmAction duplicate = new DuplicateAction();
|
|---|
| 118 | public final JosmAction delete = new DeleteAction();
|
|---|
| 119 | public final JosmAction merge = new MergeLayerAction();
|
|---|
| 120 | public final JosmAction mergeSelected = new MergeSelectionAction();
|
|---|
| 121 | public final JosmAction selectAll = new SelectAllAction();
|
|---|
| 122 | public final JosmAction unselectAll = new UnselectAllAction();
|
|---|
| 123 | /* crashes when loading data, if using JosmAction for search */
|
|---|
| 124 | public final JosmAction search = new SearchAction();
|
|---|
| 125 | public final JosmAction preferences = new PreferencesAction();
|
|---|
| 126 |
|
|---|
| 127 | /* View menu */
|
|---|
| 128 | public final JosmAction toggleGPXLines = new ToggleGPXLinesAction();
|
|---|
| 129 |
|
|---|
| 130 | /* Tools menu */
|
|---|
| 131 | public final JosmAction splitWay = new SplitWayAction();
|
|---|
| 132 | public final JosmAction combineWay = new CombineWayAction();
|
|---|
| 133 | public final JosmAction reverseWay = new ReverseWayAction();
|
|---|
| 134 | public final JosmAction alignInCircle = new AlignInCircleAction();
|
|---|
| 135 | public final JosmAction alignInLine = new AlignInLineAction();
|
|---|
| 136 | public final JosmAction distribute = new DistributeAction();
|
|---|
| 137 | public final OrthogonalizeAction ortho = new OrthogonalizeAction();
|
|---|
| 138 | public final JosmAction orthoUndo = new Undo(); // action is not shown in the menu. Only triggered by shortcut
|
|---|
| 139 | public final JosmAction mirror = new MirrorAction();
|
|---|
| 140 | public final AddNodeAction addnode = new AddNodeAction();
|
|---|
| 141 | public final JosmAction createCircle = new CreateCircleAction();
|
|---|
| 142 | public final JosmAction mergeNodes = new MergeNodesAction();
|
|---|
| 143 | public final JosmAction joinNodeWay = new JoinNodeWayAction();
|
|---|
| 144 | public final JosmAction unglueNodes = new UnGlueAction();
|
|---|
| 145 | public final JosmAction simplifyWay = new SimplifyWayAction();
|
|---|
| 146 | public final JosmAction joinAreas = new JoinAreasAction();
|
|---|
| 147 | public final InfoAction info = new InfoAction();
|
|---|
| 148 | public final HistoryInfoAction historyinfo = new HistoryInfoAction();
|
|---|
| 149 |
|
|---|
| 150 | /* Audio menu */
|
|---|
| 151 | public final JosmAction audioPlayPause = new AudioPlayPauseAction();
|
|---|
| 152 | public final JosmAction audioNext = new AudioNextAction();
|
|---|
| 153 | public final JosmAction audioPrev = new AudioPrevAction();
|
|---|
| 154 | public final JosmAction audioFwd = new AudioFwdAction();
|
|---|
| 155 | public final JosmAction audioBack = new AudioBackAction();
|
|---|
| 156 | public final JosmAction audioFaster = new AudioFasterAction();
|
|---|
| 157 | public final JosmAction audioSlower = new AudioSlowerAction();
|
|---|
| 158 |
|
|---|
| 159 | /* Help menu */
|
|---|
| 160 | public final HelpAction help = new HelpAction();
|
|---|
| 161 | public final JosmAction about = new AboutAction();
|
|---|
| 162 | public final JosmAction statusreport = new ShowStatusReportAction();
|
|---|
| 163 |
|
|---|
| 164 | public final JMenu fileMenu = addMenu(marktr("File"), KeyEvent.VK_F, 0, ht("/Menu/File"));
|
|---|
| 165 | public final JMenu editMenu = addMenu(marktr("Edit"), KeyEvent.VK_E, 1, ht("/Menu/Edit"));
|
|---|
| 166 | public final JMenu viewMenu = addMenu(marktr("View"), KeyEvent.VK_V, 2, ht("/Menu/View"));
|
|---|
| 167 | public final JMenu toolsMenu = addMenu(marktr("Tools"), KeyEvent.VK_T, 3, ht("/Menu/Tools"));
|
|---|
| 168 | public final JMenu presetsMenu = addMenu(marktr("Presets"), KeyEvent.VK_P, 4, ht("/Menu/Presets"));
|
|---|
| 169 | public JMenu audioMenu = null;
|
|---|
| 170 | public final JMenu helpMenu = addMenu(marktr("Help"), KeyEvent.VK_H, 5, ht("/Menu/Help"));
|
|---|
| 171 | public final int defaultMenuPos = 5;
|
|---|
| 172 |
|
|---|
| 173 | /**
|
|---|
| 174 | * Add a JosmAction to a menu.
|
|---|
| 175 | *
|
|---|
| 176 | * This method handles all the shortcut handling. It also makes sure that actions that are
|
|---|
| 177 | * handled by the OS are not duplicated on the menu.
|
|---|
| 178 | */
|
|---|
| 179 | public static JMenuItem add(JMenu menu, JosmAction action) {
|
|---|
| 180 | JMenuItem menuitem = null;
|
|---|
| 181 | if (!action.getShortcut().getAutomatic()) {
|
|---|
| 182 | menuitem = menu.add(action);
|
|---|
| 183 | KeyStroke ks = action.getShortcut().getKeyStroke();
|
|---|
| 184 | if (ks != null) {
|
|---|
| 185 | menuitem.setAccelerator(ks);
|
|---|
| 186 | }
|
|---|
| 187 | }
|
|---|
| 188 | return menuitem;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | public JMenu addMenu(String name, int mnemonicKey, int position, String relativeHelpTopic) {
|
|---|
| 192 | JMenu menu = new JMenu(tr(name));
|
|---|
| 193 | Shortcut.registerShortcut("menu:" + name, tr("Menu: {0}", tr(name)), mnemonicKey,
|
|---|
| 194 | Shortcut.GROUP_MNEMONIC).setMnemonic(menu);
|
|---|
| 195 | add(menu, position);
|
|---|
| 196 | menu.putClientProperty("help", relativeHelpTopic);
|
|---|
| 197 | return menu;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | public MainMenu() {
|
|---|
| 201 | JMenuItem current;
|
|---|
| 202 |
|
|---|
| 203 | add(fileMenu, newAction);
|
|---|
| 204 | add(fileMenu, openFile);
|
|---|
| 205 | add(fileMenu, openLocation);
|
|---|
| 206 | fileMenu.addSeparator();
|
|---|
| 207 | add(fileMenu, save);
|
|---|
| 208 | add(fileMenu, saveAs);
|
|---|
| 209 | add(fileMenu, gpxExport);
|
|---|
| 210 | fileMenu.addSeparator();
|
|---|
| 211 | add(fileMenu, download);
|
|---|
| 212 | add(fileMenu, downloadReferrers);
|
|---|
| 213 | add(fileMenu, update);
|
|---|
| 214 | add(fileMenu, updateSelection);
|
|---|
| 215 | add(fileMenu, updateModified);
|
|---|
| 216 | fileMenu.addSeparator();
|
|---|
| 217 | add(fileMenu, upload);
|
|---|
| 218 | add(fileMenu, uploadSelection);
|
|---|
| 219 | fileMenu.addSeparator();
|
|---|
| 220 | add(fileMenu, closeChangesetAction);
|
|---|
| 221 | fileMenu.addSeparator();
|
|---|
| 222 | add(fileMenu, exit);
|
|---|
| 223 |
|
|---|
| 224 | add(editMenu, undo);
|
|---|
| 225 | add(editMenu, redo);
|
|---|
| 226 | editMenu.addSeparator();
|
|---|
| 227 | add(editMenu, copy);
|
|---|
| 228 | add(editMenu, paste);
|
|---|
| 229 | add(editMenu, pasteTags);
|
|---|
| 230 | add(editMenu, duplicate);
|
|---|
| 231 | add(editMenu, delete);
|
|---|
| 232 | editMenu.addSeparator();
|
|---|
| 233 | add(editMenu,merge);
|
|---|
| 234 | add(editMenu,mergeSelected);
|
|---|
| 235 | editMenu.addSeparator();
|
|---|
| 236 | add(editMenu, selectAll);
|
|---|
| 237 | add(editMenu, unselectAll);
|
|---|
| 238 | editMenu.addSeparator();
|
|---|
| 239 | add(editMenu, search);
|
|---|
| 240 | editMenu.addSeparator();
|
|---|
| 241 | add(editMenu, preferences);
|
|---|
| 242 |
|
|---|
| 243 | // -- wireframe toggle action
|
|---|
| 244 | WireframeToggleAction wireFrameToggleAction = new WireframeToggleAction();
|
|---|
| 245 | final JCheckBoxMenuItem wireframe = new JCheckBoxMenuItem(wireFrameToggleAction);
|
|---|
| 246 | viewMenu.add(wireframe);
|
|---|
| 247 | wireframe.setAccelerator(wireFrameToggleAction.getShortcut().getKeyStroke());
|
|---|
| 248 | wireFrameToggleAction.addButtonModel(wireframe.getModel());
|
|---|
| 249 |
|
|---|
| 250 | viewMenu.addSeparator();
|
|---|
| 251 | add(viewMenu, new ZoomInAction());
|
|---|
| 252 | add(viewMenu, new ZoomOutAction());
|
|---|
| 253 | viewMenu.addSeparator();
|
|---|
| 254 | for (String mode : AutoScaleAction.MODES) {
|
|---|
| 255 | JosmAction autoScaleAction = new AutoScaleAction(mode);
|
|---|
| 256 | add(viewMenu, autoScaleAction);
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | // -- changeset manager toggle action
|
|---|
| 260 | ChangesetManagerToggleAction changesetManagerToggleAction = new ChangesetManagerToggleAction();
|
|---|
| 261 | final JCheckBoxMenuItem mi = new JCheckBoxMenuItem(changesetManagerToggleAction);
|
|---|
| 262 | viewMenu.addSeparator();
|
|---|
| 263 | viewMenu.add(mi);
|
|---|
| 264 | mi.setAccelerator(changesetManagerToggleAction.getShortcut().getKeyStroke());
|
|---|
| 265 | changesetManagerToggleAction.addButtonModel(mi.getModel());
|
|---|
| 266 |
|
|---|
| 267 | // -- fullscreen toggle action
|
|---|
| 268 | FullscreenToggleAction fullscreenToggleAction = new FullscreenToggleAction();
|
|---|
| 269 | if (fullscreenToggleAction.canFullscreen()) {
|
|---|
| 270 | final JCheckBoxMenuItem fullscreen = new JCheckBoxMenuItem(fullscreenToggleAction);
|
|---|
| 271 | viewMenu.addSeparator();
|
|---|
| 272 | viewMenu.add(fullscreen);
|
|---|
| 273 | fullscreen.setAccelerator(fullscreenToggleAction.getShortcut().getKeyStroke());
|
|---|
| 274 | fullscreenToggleAction.addButtonModel(fullscreen.getModel());
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | add(toolsMenu, splitWay);
|
|---|
| 278 | add(toolsMenu, combineWay);
|
|---|
| 279 | toolsMenu.addSeparator();
|
|---|
| 280 | add(toolsMenu, reverseWay);
|
|---|
| 281 | add(toolsMenu, simplifyWay);
|
|---|
| 282 | toolsMenu.addSeparator();
|
|---|
| 283 | add(toolsMenu, alignInCircle);
|
|---|
| 284 | add(toolsMenu, alignInLine);
|
|---|
| 285 | add(toolsMenu, distribute);
|
|---|
| 286 | add(toolsMenu, ortho);
|
|---|
| 287 | add(toolsMenu, mirror);
|
|---|
| 288 | toolsMenu.addSeparator();
|
|---|
| 289 | add(toolsMenu, addnode);
|
|---|
| 290 | add(toolsMenu, createCircle);
|
|---|
| 291 | toolsMenu.addSeparator();
|
|---|
| 292 | add(toolsMenu, mergeNodes);
|
|---|
| 293 | add(toolsMenu, joinNodeWay);
|
|---|
| 294 | add(toolsMenu, unglueNodes);
|
|---|
| 295 | add(toolsMenu, joinAreas);
|
|---|
| 296 | toolsMenu.addSeparator();
|
|---|
| 297 | add(toolsMenu, info);
|
|---|
| 298 | add(toolsMenu, historyinfo);
|
|---|
| 299 |
|
|---|
| 300 | if (!Main.pref.getBoolean("audio.menuinvisible", false)) {
|
|---|
| 301 | audioMenu = addMenu(marktr("Audio"), KeyEvent.VK_A, 5, ht("/Menu/Audio"));
|
|---|
| 302 | add(audioMenu, audioPlayPause);
|
|---|
| 303 | add(audioMenu, audioNext);
|
|---|
| 304 | add(audioMenu, audioPrev);
|
|---|
| 305 | add(audioMenu, audioFwd);
|
|---|
| 306 | add(audioMenu, audioBack);
|
|---|
| 307 | add(audioMenu, audioSlower);
|
|---|
| 308 | add(audioMenu, audioFaster);
|
|---|
| 309 | }
|
|---|
| 310 |
|
|---|
| 311 | helpMenu.add(statusreport);
|
|---|
| 312 |
|
|---|
| 313 | current = helpMenu.add(help); // FIXME why is help not a JosmAction?
|
|---|
| 314 | current.setAccelerator(Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1,
|
|---|
| 315 | Shortcut.GROUP_DIRECT).getKeyStroke());
|
|---|
| 316 | add(helpMenu, about);
|
|---|
| 317 |
|
|---|
| 318 | new PresetsMenuEnabler(presetsMenu).refreshEnabled();
|
|---|
| 319 | }
|
|---|
| 320 |
|
|---|
| 321 | static class PresetsMenuEnabler implements MapView.LayerChangeListener {
|
|---|
| 322 | private JMenu presetsMenu;
|
|---|
| 323 | public PresetsMenuEnabler(JMenu presetsMenu) {
|
|---|
| 324 | MapView.addLayerChangeListener(this);
|
|---|
| 325 | this.presetsMenu = presetsMenu;
|
|---|
| 326 | }
|
|---|
| 327 | /**
|
|---|
| 328 | * Refreshes the enabled state
|
|---|
| 329 | *
|
|---|
| 330 | */
|
|---|
| 331 | protected void refreshEnabled() {
|
|---|
| 332 | presetsMenu.setEnabled(Main.map != null
|
|---|
| 333 | && Main.map.mapView !=null
|
|---|
| 334 | && Main.map.mapView.getEditLayer() != null
|
|---|
| 335 | );
|
|---|
| 336 | }
|
|---|
| 337 |
|
|---|
| 338 | public void activeLayerChange(Layer oldLayer, Layer newLayer) {
|
|---|
| 339 | refreshEnabled();
|
|---|
| 340 | }
|
|---|
| 341 |
|
|---|
| 342 | public void layerAdded(Layer newLayer) {
|
|---|
| 343 | refreshEnabled();
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | public void layerRemoved(Layer oldLayer) {
|
|---|
| 347 | refreshEnabled();
|
|---|
| 348 | }
|
|---|
| 349 | }
|
|---|
| 350 | }
|
|---|