Esempio n. 1
0
  private static void doInit() {
    if (initdone) return;
    initdone = true;
    int commandDownMask = GuiHelper.getMenuShortcutKeyMaskEx();
    groups.put(NONE, -1);
    groups.put(MNEMONIC, KeyEvent.ALT_DOWN_MASK);
    groups.put(DIRECT, 0);
    groups.put(ALT, KeyEvent.ALT_DOWN_MASK);
    groups.put(SHIFT, KeyEvent.SHIFT_DOWN_MASK);
    groups.put(CTRL, commandDownMask);
    groups.put(ALT_SHIFT, KeyEvent.ALT_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);
    groups.put(ALT_CTRL, KeyEvent.ALT_DOWN_MASK | commandDownMask);
    groups.put(CTRL_SHIFT, commandDownMask | KeyEvent.SHIFT_DOWN_MASK);
    groups.put(ALT_CTRL_SHIFT, KeyEvent.ALT_DOWN_MASK | commandDownMask | KeyEvent.SHIFT_DOWN_MASK);

    // (1) System reserved shortcuts
    Main.platform.initSystemShortcuts();
    // (2) User defined shortcuts
    List<Shortcut> newshortcuts = new LinkedList<>();
    for (String s : Main.pref.getAllPrefixCollectionKeys("shortcut.entry.")) {
      newshortcuts.add(new Shortcut(s));
    }

    for (Shortcut sc : newshortcuts) {
      if (sc.isAssignedUser()
          && findShortcut(sc.getAssignedKey(), sc.getAssignedModifier()) == null) {
        shortcuts.put(sc.getShortText(), sc);
      }
    }
    // Shortcuts at their default values
    for (Shortcut sc : newshortcuts) {
      if (!sc.isAssignedUser()
          && sc.isAssignedDefault()
          && findShortcut(sc.getAssignedKey(), sc.getAssignedModifier()) == null) {
        shortcuts.put(sc.getShortText(), sc);
      }
    }
    // Shortcuts that were automatically moved
    for (Shortcut sc : newshortcuts) {
      if (!sc.isAssignedUser()
          && !sc.isAssignedDefault()
          && findShortcut(sc.getAssignedKey(), sc.getAssignedModifier()) == null) {
        shortcuts.put(sc.getShortText(), sc);
      }
    }
  }
Esempio n. 2
0
 @Override
 public void valueChanged(ListSelectionEvent e) {
   ListSelectionModel lsm = panel.shortcutTable.getSelectionModel(); // can't use e here
   if (!lsm.isSelectionEmpty()) {
     int row = panel.shortcutTable.convertRowIndexToModel(lsm.getMinSelectionIndex());
     Shortcut sc = (Shortcut) panel.model.getValueAt(row, -1);
     panel.cbDefault.setSelected(!sc.getAssignedUser());
     panel.cbDisable.setSelected(sc.getKeyStroke() == null);
     panel.cbShift.setSelected(
         sc.getAssignedModifier() != -1
             && (sc.getAssignedModifier() & KeyEvent.SHIFT_DOWN_MASK) != 0);
     panel.cbCtrl.setSelected(
         sc.getAssignedModifier() != -1
             && (sc.getAssignedModifier() & KeyEvent.CTRL_DOWN_MASK) != 0);
     panel.cbAlt.setSelected(
         sc.getAssignedModifier() != -1
             && (sc.getAssignedModifier() & KeyEvent.ALT_DOWN_MASK) != 0);
     panel.cbMeta.setSelected(
         sc.getAssignedModifier() != -1
             && (sc.getAssignedModifier() & KeyEvent.META_DOWN_MASK) != 0);
     if (sc.getKeyStroke() != null) {
       tfKey.setSelectedItem(keyList.get(sc.getKeyStroke().getKeyCode()));
     } else {
       tfKey.setSelectedItem(keyList.get(-1));
     }
     if (!sc.isChangeable()) {
       disableAllModifierCheckboxes();
       panel.tfKey.setEnabled(false);
     } else {
       panel.cbDefault.setEnabled(true);
       actionPerformed(null);
     }
     model.fireTableRowsUpdated(row, row);
   } else {
     panel.disableAllModifierCheckboxes();
     panel.tfKey.setEnabled(false);
   }
 }