Changeset 11173 in josm


Ignore:
Timestamp:
2016-10-26T21:23:33+02:00 (8 years ago)
Author:
simon04
Message:

Shortcut.findShortcut: return Optional object

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r10851 r11173  
    284284        Main.getLayerManager().addActiveLayerChangeListener(this);
    285285
    286         boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0) != null;
     286        boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0).isPresent();
    287287        if (unregisterTab) {
    288288            for (JComponent c: allDialogButtons) {
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r11071 r11173  
    277277        });
    278278
    279         if (Shortcut.findShortcut(KeyEvent.VK_TAB, 0) != null) {
    280             setFocusTraversalKeysEnabled(false);
    281         }
     279        setFocusTraversalKeysEnabled(!Shortcut.findShortcut(KeyEvent.VK_TAB, 0).isPresent());
    282280
    283281        for (JComponent c : getMapNavigationComponents(this)) {
     
    297295        zoomSlider.setSize(size);
    298296        zoomSlider.setLocation(3, 0);
    299         zoomSlider.setFocusTraversalKeysEnabled(Shortcut.findShortcut(KeyEvent.VK_TAB, 0) == null);
     297        zoomSlider.setFocusTraversalKeysEnabled(!Shortcut.findShortcut(KeyEvent.VK_TAB, 0).isPresent());
    300298
    301299        MapScaler scaler = new MapScaler(forMapView);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r10755 r11173  
    799799            final int commandDownMask = GuiHelper.getMenuShortcutKeyMaskEx();
    800800            List<String> lines = new ArrayList<>();
    801             Shortcut sc = Shortcut.findShortcut(KeyEvent.VK_1, commandDownMask);
    802             if (sc != null) {
    803                 lines.add(sc.getKeyText() + ' ' + tr("to apply first suggestion"));
    804             }
     801            Shortcut.findShortcut(KeyEvent.VK_1, commandDownMask).ifPresent(sc ->
     802                    lines.add(sc.getKeyText() + ' ' + tr("to apply first suggestion"))
     803            );
    805804            lines.add(KeyEvent.getKeyModifiersText(KeyEvent.SHIFT_MASK)+'+'+KeyEvent.getKeyText(KeyEvent.VK_ENTER) + ' '
    806805                    +tr("to add without closing the dialog"));
    807             sc = Shortcut.findShortcut(KeyEvent.VK_1, commandDownMask | KeyEvent.SHIFT_DOWN_MASK);
    808             if (sc != null) {
    809                 lines.add(sc.getKeyText() + ' ' + tr("to add first suggestion without closing the dialog"));
    810             }
     806            Shortcut.findShortcut(KeyEvent.VK_1, commandDownMask | KeyEvent.SHIFT_DOWN_MASK).ifPresent(sc ->
     807                    lines.add(sc.getKeyText() + ' ' + tr("to add first suggestion without closing the dialog"))
     808            );
    811809            final JLabel helpLabel = new JLabel("<html>" + Utils.join("<br>", lines) + "</html>");
    812810            helpLabel.setFont(helpLabel.getFont().deriveFont(Font.PLAIN));
  • trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java

    r10662 r11173  
    10391039        control.removeAll();
    10401040        buttonActions.clear();
    1041         boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0) != null;
     1041        boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0).isPresent();
    10421042
    10431043        for (ActionDefinition action : getDefinedActions()) {
  • trunk/src/org/openstreetmap/josm/tools/Shortcut.java

    r11172 r11173  
    293293     * @param requestedKey the requested key
    294294     * @param modifier the modifier
    295      * @return the registered shortcut or {@code null}
    296      */
    297     public static Shortcut findShortcut(int requestedKey, int modifier) {
    298         return findShortcutByKeyOrShortText(requestedKey, modifier, null)
    299                 .orElse(null);
     295     * @return an {@link Optional} registered shortcut, never {@code null}
     296     */
     297    public static Optional<Shortcut> findShortcut(int requestedKey, int modifier) {
     298        return findShortcutByKeyOrShortText(requestedKey, modifier, null);
    300299    }
    301300
     
    368367        Main.pref.getAllPrefixCollectionKeys("shortcut.entry.").stream()
    369368                .map(Shortcut::new)
    370                 .filter(sc -> findShortcut(sc.getAssignedKey(), sc.getAssignedModifier()) == null)
     369                .filter(sc -> !findShortcut(sc.getAssignedKey(), sc.getAssignedModifier()).isPresent())
    371370                .sorted(Comparator.comparing(sc -> sc.isAssignedUser() ? 1 : sc.isAssignedDefault() ? 2 : 3))
    372371                .forEachOrdered(shortcuts::add);
     
    458457                // Try to reassign Meta to Ctrl
    459458                int newmodifier = findNewOsxModifier(requestedGroup);
    460                 if (findShortcut(requestedKey, newmodifier) == null) {
     459                if (!findShortcut(requestedKey, newmodifier).isPresent()) {
    461460                    Main.info("Reassigning OSX shortcut '" + shortText + "' from Meta to Ctrl because of conflict with " + conflict);
    462461                    return reassignShortcut(shortText, longText, requestedKey, conflict, requestedGroup, requestedKey, newmodifier);
     
    466465                for (int k : keys) {
    467466                    int newmodifier = getGroupModifier(m);
    468                     if (findShortcut(k, newmodifier) == null) {
     467                    if (!findShortcut(k, newmodifier).isPresent()) {
    469468                        Main.info("Reassigning shortcut '" + shortText + "' from " + modifier + " to " + newmodifier +
    470469                                " because of conflict with " + conflict);
Note: See TracChangeset for help on using the changeset viewer.