private boolean checkForOverwriteShortcut( final DefaultMutableTreeNode menubarNode, final KeyStroke keystroke) { final Node priorAssigned = MenuUtils.findAssignedMenuItemNodeRecursively(menubarNode, keystroke); if (priorAssigned == null || editedItem.equals(priorAssigned.getUserObject())) { return true; } return replaceOrCancel(priorAssigned, ((JMenuItem) priorAssigned.getUserObject()).getText()); }
public static Node findAssignedMenuItemNodeRecursively( final DefaultMutableTreeNode menubarNode, final KeyStroke keystroke) { final Enumeration<?> children = menubarNode.children(); while (children.hasMoreElements()) { final Node child = (Node) children.nextElement(); final Object childUserObject = child.getUserObject(); if (childUserObject instanceof JMenuItem) { final JMenuItem childMenuItem = (JMenuItem) childUserObject; if (keystroke.equals(childMenuItem.getAccelerator())) { return child; } } // recurse final Node assignedMenuItemNode = findAssignedMenuItemNodeRecursively(child, keystroke); if (assignedMenuItemNode != null) return assignedMenuItemNode; } return null; }
public boolean isValid(final KeyStroke keystroke, final Character keyChar) { if (keystroke == null) { return true; } final Node menuBarNode = menuBuilder.getMenuBar(menuBuilder.get(key)); if (menuBarNode == null) { return true; } if (keyChar != KeyEvent.CHAR_UNDEFINED && (keystroke.getModifiers() & (Event.ALT_MASK | Event.CTRL_MASK | Event.META_MASK)) == 0) { final String keyTypeActionString = ResourceController.getResourceController() .getProperty("key_type_action", FirstAction.EDIT_CURRENT.toString()); FirstAction keyTypeAction = FirstAction.valueOf(keyTypeActionString); return FirstAction.IGNORE.equals(keyTypeAction); } if ((keystroke.getModifiers() & (Event.ALT_MASK | Event.CTRL_MASK | Event.META_MASK)) == Event.ALT_MASK) { final JMenuBar menuBar = (JMenuBar) menuBarNode.getUserObject(); final int menuCount = menuBar.getMenuCount(); for (int i = 0; i < menuCount; i++) { final JMenu menu = menuBar.getMenu(i); final char c = (char) menu.getMnemonic(); if (Character.toLowerCase(keystroke.getKeyCode()) == Character.toLowerCase(c)) { JOptionPane.showMessageDialog( parentComponent, menu.getText(), TextUtils.getText("used_in_menu"), JOptionPane.WARNING_MESSAGE); return false; } } } if (!checkForOverwriteShortcut(menuBarNode, keystroke)) { return false; } final KeyStroke derivedKS = FreeplaneMenuBar.derive(keystroke, keyChar); if (derivedKS == keystroke) { return true; } return checkForOverwriteShortcut(menuBarNode, derivedKS); }
private boolean replaceOrCancel(Node menuItemNode, String oldMenuItemTitle) { if (askForReplaceShortcutViaDialog(oldMenuItemTitle, parentComponent)) { menuBuilder.setAccelerator(menuItemNode, null); final String shortcutKey = menuBuilder.getShortcutKey(menuItemNode.getKey().toString()); ResourceController.getResourceController().setProperty(shortcutKey, ""); return true; } else { return false; } }