- Timestamp:
- 2019-10-07T01:41:24+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r15028 r15438 10 10 import java.awt.event.KeyEvent; 11 11 import java.util.ArrayList; 12 import java.util.Arrays; 13 import java.util.Collection; 12 14 import java.util.HashMap; 13 15 import java.util.List; 14 16 import java.util.Locale; 15 17 import java.util.Map; 18 import java.util.Objects; 19 import java.util.Optional; 16 20 17 21 import javax.swing.JCheckBoxMenuItem; … … 116 120 import org.openstreetmap.josm.actions.audio.AudioPrevAction; 117 121 import org.openstreetmap.josm.actions.audio.AudioSlowerAction; 122 import org.openstreetmap.josm.actions.mapmode.MapMode; 118 123 import org.openstreetmap.josm.actions.search.SearchAction; 119 124 import org.openstreetmap.josm.data.UndoRedoHandler; … … 337 342 public final JMenu viewMenu = addMenu("View", /* I18N: mnemonic: V */ trc("menu", "View"), KeyEvent.VK_V, 2, ht("/Menu/View")); 338 343 /** 344 * modeMenu contains map modes 345 */ 346 public final JMenu modeMenu = addMenu("Mode", /* I18N: mnemonic: M */ trc("menu", "Mode"), KeyEvent.VK_M, 3, ht("/Menu/Mode")); 347 /** 339 348 * toolsMenu contains different geometry manipulation actions from JOSM core (most used) 340 349 * The plugins should use other menus 341 350 */ 342 public final JMenu toolsMenu = addMenu("Tools", /* I18N: mnemonic: T */ trc("menu", "Tools"), KeyEvent.VK_T, 3, ht("/Menu/Tools"));351 public final JMenu toolsMenu = addMenu("Tools", /* I18N: mnemonic: T */ trc("menu", "Tools"), KeyEvent.VK_T, 4, ht("/Menu/Tools")); 343 352 /** 344 353 * moreToolsMenu contains geometry-related actions from all the plugins … … 346 355 */ 347 356 // CHECKSTYLE.OFF: LineLength 348 public final JMenu moreToolsMenu = addMenu("More tools", /* I18N: mnemonic: M */ trc("menu", "More tools"), KeyEvent.VK_M, 4, ht("/Menu/MoreTools"));357 public final JMenu moreToolsMenu = addMenu("More tools", /* I18N: mnemonic: O */ trc("menu", "More tools"), KeyEvent.VK_O, 5, ht("/Menu/MoreTools")); 349 358 /** 350 359 * dataMenu contains plugin actions that are related to certain tagging schemes (addressing opening hours), … … 352 361 * @since 6082 353 362 */ 354 public final JMenu dataMenu = addMenu("Data", /* I18N: mnemonic: D */ trc("menu", "Data"), KeyEvent.VK_D, 5, ht("/Menu/Data"));363 public final JMenu dataMenu = addMenu("Data", /* I18N: mnemonic: D */ trc("menu", "Data"), KeyEvent.VK_D, 6, ht("/Menu/Data")); 355 364 /** 356 365 * selectionMenu contains all actions related to selecting different objects 357 366 * @since 6082 (moved from Utilsplugin2) 358 367 */ 359 public final JMenu selectionMenu = addMenu("Selection", /* I18N: mnemonic: N */ trc("menu", "Selection"), KeyEvent.VK_N, 6, ht("/Menu/Selection"));368 public final JMenu selectionMenu = addMenu("Selection", /* I18N: mnemonic: N */ trc("menu", "Selection"), KeyEvent.VK_N, 7, ht("/Menu/Selection")); 360 369 /** 361 370 * presetsMenu contains presets actions (search, presets tree) 362 371 */ 363 public final JMenu presetsMenu = addMenu("Presets", /* I18N: mnemonic: P */ trc("menu", "Presets"), KeyEvent.VK_P, 7, ht("/Menu/Presets"));372 public final JMenu presetsMenu = addMenu("Presets", /* I18N: mnemonic: P */ trc("menu", "Presets"), KeyEvent.VK_P, 8, ht("/Menu/Presets")); 364 373 /** 365 374 * submenu in Imagery menu that contains plugin-managed additional imagery layers … … 370 379 * imageryMenu contains all imagery-related actions 371 380 */ 372 public final ImageryMenu imageryMenu = addMenu(new ImageryMenu(imagerySubMenu), /* untranslated name */ "Imagery", KeyEvent.VK_I, 8, ht("/Menu/Imagery"));381 public final ImageryMenu imageryMenu = addMenu(new ImageryMenu(imagerySubMenu), /* untranslated name */ "Imagery", KeyEvent.VK_I, 9, ht("/Menu/Imagery")); 373 382 // CHECKSTYLE.ON: LineLength 374 383 /** … … 377 386 * @since 6082 378 387 */ 379 public final JMenu gpsMenu = addMenu("GPS", /* I18N: mnemonic: G */ trc("menu", "GPS"), KeyEvent.VK_G, 9, ht("/Menu/GPS"));388 public final JMenu gpsMenu = addMenu("GPS", /* I18N: mnemonic: G */ trc("menu", "GPS"), KeyEvent.VK_G, 10, ht("/Menu/GPS")); 380 389 /** the window menu is split into several groups. The first is for windows that can be opened from 381 390 * this menu any time, e.g. the changeset editor. The second group is for toggle dialogs and the third … … 383 392 * to use WINDOW_MENU_GROUP to determine the group integer. 384 393 */ 385 public final JMenu windowMenu = addMenu("Windows", /* I18N: mnemonic: W */ trc("menu", "Windows"), KeyEvent.VK_W, 1 0, ht("/ToggleDialogs"));394 public final JMenu windowMenu = addMenu("Windows", /* I18N: mnemonic: W */ trc("menu", "Windows"), KeyEvent.VK_W, 11, ht("/ToggleDialogs")); 386 395 387 396 /** … … 392 401 * helpMenu contains JOSM general actions (Help, About, etc.) 393 402 */ 394 public final JMenu helpMenu = addMenu("Help", /* I18N: mnemonic: H */ trc("menu", "Help"), KeyEvent.VK_H, 1 1, ht("/Menu/Help"));395 396 private static final int defaultMenuPos = 1 1;403 public final JMenu helpMenu = addMenu("Help", /* I18N: mnemonic: H */ trc("menu", "Help"), KeyEvent.VK_H, 12, ht("/Menu/Help")); 404 405 private static final int defaultMenuPos = 12; 397 406 398 407 /** Move the selection up */ … … 847 856 windowMenu.addMenuListener(menuSeparatorHandler); 848 857 849 new PresetsMenuEnabler(presetsMenu);858 new EditLayerMenuEnabler(Arrays.asList(modeMenu, presetsMenu)); 850 859 } 851 860 // CHECKSTYLE.ON: ExecutableStatementCountCheck … … 867 876 } 868 877 return result; 878 } 879 880 /** 881 * Returns the {@link JCheckBoxMenuItem} for the given {@link MapMode}. 882 * @param mode map mode 883 * @return the {@code JCheckBoxMenuItem} for the given {@code MapMode} 884 * @since 15438 885 */ 886 public Optional<JCheckBoxMenuItem> findMapModeMenuItem(MapMode mode) { 887 return Arrays.stream(modeMenu.getMenuComponents()) 888 .filter(m -> m instanceof JCheckBoxMenuItem) 889 .map(m -> (JCheckBoxMenuItem) m) 890 .filter(m -> Objects.equals(mode, m.getAction())) 891 .findFirst(); 869 892 } 870 893 … … 912 935 } 913 936 914 static class PresetsMenuEnabler implements ActiveLayerChangeListener {915 private final JMenu presetsMenu;916 917 PresetsMenuEnabler(JMenu presetsMenu) {918 this. presetsMenu = presetsMenu;937 static class EditLayerMenuEnabler implements ActiveLayerChangeListener { 938 private final Collection<JMenu> menus; 939 940 EditLayerMenuEnabler(Collection<JMenu> menus) { 941 this.menus = Objects.requireNonNull(menus); 919 942 MainApplication.getLayerManager().addAndFireActiveLayerChangeListener(this); 920 943 } … … 922 945 @Override 923 946 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 924 presetsMenu.setEnabled(e.getSource().getEditLayer() != null);947 menus.forEach(m -> m.setEnabled(e.getSource().getEditLayer() != null)); 925 948 } 926 949 } -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r14248 r15438 18 18 import java.util.List; 19 19 import java.util.Map; 20 import java.util.Optional; 20 21 import java.util.concurrent.CopyOnWriteArrayList; 21 22 … … 83 84 import org.openstreetmap.josm.tools.GBC; 84 85 import org.openstreetmap.josm.tools.ImageProvider; 86 import org.openstreetmap.josm.tools.Logging; 85 87 import org.openstreetmap.josm.tools.Shortcut; 86 88 … … 345 347 MainApplication.getLayerManager().removeLayerChangeListener(this); 346 348 MainApplication.getLayerManager().removeActiveLayerChangeListener(this); 349 MainApplication.getMenu().modeMenu.removeAll(); 347 350 dialogsPanel.destroy(); 348 351 Config.getPref().removePreferenceChangeListener(sidetoolbarPreferencesChangedListener); … … 436 439 if (!(b.getAction() instanceof MapMode)) 437 440 throw new IllegalArgumentException("MapMode action must be subclass of MapMode"); 441 MainApplication.getMenu().modeMenu.add(new JCheckBoxMenuItem(b.getAction())); 438 442 allMapModeButtons.add(b); 439 443 toolBarActionsGroup.add(b); … … 481 485 newMapMode = null; 482 486 } 487 Logging.info("Switching map mode from {0} to {1}", 488 Optional.ofNullable(oldMapMode).map(m -> m.getClass().getSimpleName()).orElse("(none)"), 489 Optional.ofNullable(newMapMode).map(m -> m.getClass().getSimpleName()).orElse("(none)")); 483 490 484 491 if (oldMapMode != null) { 492 MainApplication.getMenu().findMapModeMenuItem(oldMapMode).ifPresent(m -> m.setSelected(false)); 485 493 oldMapMode.exitMode(); 486 494 } … … 488 496 if (newMapMode != null) { 489 497 newMapMode.enterMode(); 498 MainApplication.getMenu().findMapModeMenuItem(newMapMode).ifPresent(m -> m.setSelected(true)); 490 499 } 491 500 lastMapMode.put(newLayer, newMapMode);
Note:
See TracChangeset
for help on using the changeset viewer.