コード例 #1
0
ファイル: Shortcut.java プロジェクト: uazure/josm
  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);
      }
    }
  }
コード例 #2
0
ファイル: ToolbarPreferences.java プロジェクト: windu2b/josm
  private JButton addButtonAndShortcut(ActionDefinition action) {
    Action act = action.getParametrizedAction();
    JButton b = control.add(act);

    Shortcut sc = null;
    if (action.getAction() instanceof JosmAction) {
      sc = ((JosmAction) action.getAction()).getShortcut();
      if (sc.getAssignedKey() == KeyEvent.CHAR_UNDEFINED) {
        sc = null;
      }
    }

    long paramCode = 0;
    if (action.hasParameters()) {
      paramCode = action.parameters.hashCode();
    }

    String tt = action.getDisplayTooltip();
    if (tt == null) {
      tt = "";
    }

    if (sc == null || paramCode != 0) {
      String name = (String) action.getAction().getValue("toolbar");
      if (name == null) {
        name = action.getDisplayName();
      }
      if (paramCode != 0) {
        name = name + paramCode;
      }
      String desc =
          action.getDisplayName() + ((paramCode == 0) ? "" : action.parameters.toString());
      sc =
          Shortcut.registerShortcut(
              "toolbar:" + name, tr("Toolbar: {0}", desc), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE);
      Main.unregisterShortcut(sc);
      Main.registerActionShortcut(act, sc);

      // add shortcut info to the tooltip if needed
      if (sc.getAssignedUser()) {
        if (tt.startsWith("<html>") && tt.endsWith("</html>")) {
          tt = tt.substring(6, tt.length() - 6);
        }
        tt = Main.platform.makeTooltip(tt, sc);
      }
    }

    if (!tt.isEmpty()) {
      b.setToolTipText(tt);
    }
    return b;
  }