ShortcutFilteringPanel() {
    super(new VerticalLayout(JBUI.scale(2)));

    myKeyboardPanel.myFirstStroke.setColumns(13);
    myKeyboardPanel.myFirstStroke.putClientProperty("JTextField.variant", "search");
    myKeyboardPanel.mySecondStroke.setColumns(13);
    myKeyboardPanel.mySecondStroke.putClientProperty("JTextField.variant", "search");
    myKeyboardPanel.mySecondStroke.setVisible(false);
    myKeyboardPanel.mySecondStrokeEnable.setText(
        KeyMapBundle.message("filter.enable.second.stroke.checkbox"));
    myKeyboardPanel.mySecondStrokeEnable.addChangeListener(myChangeListener);
    myKeyboardPanel.add(VerticalLayout.TOP, myKeyboardPanel.myFirstStroke);
    myKeyboardPanel.add(VerticalLayout.TOP, myKeyboardPanel.mySecondStrokeEnable);
    myKeyboardPanel.add(VerticalLayout.TOP, myKeyboardPanel.mySecondStroke);
    myKeyboardPanel.addPropertyChangeListener("shortcut", myPropertyListener);
    myKeyboardPanel.setBorder(JBUI.Borders.empty(4));

    JLabel label = new JLabel(KeyMapBundle.message("filter.mouse.pad.label"));
    label.setOpaque(false);
    label.setIcon(AllIcons.General.MouseShortcut);
    label.setForeground(MouseShortcutPanel.FOREGROUND);
    label.setBorder(JBUI.Borders.empty(14, 4));
    myMousePanel.add(BorderLayout.CENTER, label);
    myMousePanel.addPropertyChangeListener("shortcut", myPropertyListener);
    myMousePanel.setBorder(JBUI.Borders.customLine(MouseShortcutPanel.BORDER, 1, 0, 0, 0));

    add(VerticalLayout.TOP, myKeyboardPanel);
    add(VerticalLayout.TOP, myMousePanel);
    addPropertyChangeListener("shortcut", myPropertyListener);
  }
Пример #2
0
 public String getColumnName(int column) {
   switch (column) {
     case 0:
       return KeyMapBundle.message("action.column.name");
     case 1:
       return KeyMapBundle.message("shortcuts.column.name");
   }
   return "";
 }
  /**
   * @param shortcut dialog will be initialized with this <code>shortcut</code>. It can be <code>
   *     null</code> if dialog is used to create new mouse shortcut.
   */
  public MouseShortcutDialog(
      JComponent parentComponent,
      MouseShortcut shortcut,
      @NotNull Keymap keymap,
      @NotNull String actiondId,
      @NotNull Group mainGroup) {
    super(parentComponent, true);
    setTitle(KeyMapBundle.message("mouse.shortcut.dialog.title"));

    myKeymap = keymap;
    myActionId = actiondId;
    myMainGroup = mainGroup;

    myRbSingleClick =
        new JRadioButton(KeyMapBundle.message("mouse.shortcut.dialog.single.click.radio"));
    myRbDoubleClick =
        new JRadioButton(KeyMapBundle.message("mouse.shortcut.dialog.double.click.radio"));
    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(myRbSingleClick);
    buttonGroup.add(myRbDoubleClick);

    myLblPreview = new JLabel(" ");

    myClickPad = new MyClickPad();

    myTarConflicts = new JTextArea();
    myTarConflicts.setFocusable(false);
    myTarConflicts.setEditable(false);
    myTarConflicts.setBackground(UIUtil.getPanelBackground());
    myTarConflicts.setLineWrap(true);
    myTarConflicts.setWrapStyleWord(true);

    if (shortcut != null) {
      if (shortcut.getClickCount() == 1) {
        myRbSingleClick.setSelected(true);
      } else {
        myRbDoubleClick.setSelected(true);
      }
      myButton = shortcut.getButton();
      myModifiers = shortcut.getModifiers();
    } else {
      myRbSingleClick.setSelected(true);
      myButton = -1;
      myModifiers = -1;
    }

    updatePreviewAndConflicts();

    init();
  }
 public MyClickPad() {
   super(
       KeyMapBundle.message("mouse.shortcut.label"),
       IconLoader.getIcon("/general/mouse.png"),
       SwingConstants.CENTER);
   // It's very imporatant that MouseListener is added to the Dialog. If you add
   // the same listener, for example, into the MyClickPad component you get fake
   // Alt and Meta modifiers. I means that pressing of middle button causes
   // Alt+Button2 event.
   // See bug ID 4109826 on Sun's bug parade.
   // cast is needed in order to compile with mustang
   MouseShortcutDialog.this.addMouseListener(
       (MouseListener)
           new MouseAdapter() {
             public void mouseReleased(MouseEvent e) {
               Component component =
                   SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
               if (component == MyClickPad.this) {
                 e.consume();
                 myButton = e.getButton();
                 myModifiers = e.getModifiersEx();
                 updatePreviewAndConflicts();
               }
             }
           });
 }
  void showPopup(Component component) {
    if (myPopup == null || myPopup.getContent() == null) {
      myPopup =
          JBPopupFactory.getInstance()
              .createComponentPopupBuilder(this, myKeyboardPanel.myFirstStroke)
              .setRequestFocus(true)
              .setTitle(KeyMapBundle.message("filter.settings.popup.title"))
              .setCancelKeyEnabled(false)
              .setMovable(true)
              .createPopup();
      IdeEventQueue.getInstance()
          .addPostprocessor(
              new IdeEventQueue.EventDispatcher() {
                boolean isEscWasPressed = false;

                @Override
                public boolean dispatch(AWTEvent e) {
                  if (e instanceof KeyEvent && e.getID() == KeyEvent.KEY_PRESSED) {
                    boolean isEsc = ((KeyEvent) e).getKeyCode() == KeyEvent.VK_ESCAPE;
                    if (isEscWasPressed && isEsc) {
                      myPopup.cancel();
                    }
                    isEscWasPressed = isEsc;
                  }
                  return false;
                }
              },
              myPopup);
    }
    myPopup.showUnderneathOf(component);
  }
  /** Updates all UI controls */
  private void updatePreviewAndConflicts() {
    if (myButton == -1 || myModifiers == -1) {
      return;
    }

    myTarConflicts.setText(null);

    // Set text into preview area

    // empty string should have same height
    myLblPreview.setText(
        KeymapUtil.getMouseShortcutText(myButton, myModifiers, myRbSingleClick.isSelected() ? 1 : 2)
            + " ");

    // Detect conflicts

    final MouseShortcut mouseShortcut;
    if (myRbSingleClick.isSelected()) {
      mouseShortcut = new MouseShortcut(myButton, myModifiers, 1);
    } else {
      mouseShortcut = new MouseShortcut(myButton, myModifiers, 2);
    }

    StringBuilder buffer = new StringBuilder();
    String[] actionIds = myKeymap.getActionIds(mouseShortcut);
    for (String actionId : actionIds) {
      if (actionId.equals(myActionId)) {
        continue;
      }

      String actionPath = myMainGroup.getActionQualifiedPath(actionId);
      // actionPath == null for editor actions having corresponding $-actions
      if (actionPath == null) {
        continue;
      }

      Shortcut[] shortcuts = myKeymap.getShortcuts(actionId);
      for (Shortcut shortcut1 : shortcuts) {
        if (!(shortcut1 instanceof MouseShortcut)) {
          continue;
        }

        MouseShortcut shortcut = (MouseShortcut) shortcut1;

        if (shortcut.getButton() != mouseShortcut.getButton()
            || shortcut.getModifiers() != mouseShortcut.getModifiers()) {
          continue;
        }

        if (buffer.length() > 1) {
          buffer.append('\n');
        }
        buffer.append('[');
        buffer.append(actionPath);
        buffer.append(']');
        break;
      }
    }

    if (buffer.length() == 0) {
      myTarConflicts.setForeground(UIUtil.getTextAreaForeground());
      myTarConflicts.setText(KeyMapBundle.message("mouse.shortcut.dialog.no.conflicts.area"));
    } else {
      myTarConflicts.setForeground(Color.red);
      myTarConflicts.setText(
          KeyMapBundle.message("mouse.shortcut.dialog.assigned.to.area", buffer.toString()));
    }
  }
  protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new GridBagLayout());

    // Single/Double click

    JPanel clickCountPanel = new JPanel(new GridBagLayout());
    clickCountPanel.setBorder(
        IdeBorderFactory.createTitledBorder(
            KeyMapBundle.message("mouse.shortcut.dialog.click.count.border"), false, true, true));
    panel.add(
        clickCountPanel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0));
    clickCountPanel.add(
        myRbSingleClick,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1,
            0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 10),
            0,
            0));
    clickCountPanel.add(
        myRbDoubleClick,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            1,
            0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));

    ActionListener listener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            updatePreviewAndConflicts();
          }
        };
    myRbSingleClick.addActionListener(listener);
    myRbDoubleClick.addActionListener(listener);

    // Click pad

    JPanel clickPadPanel = new JPanel(new BorderLayout());
    panel.add(
        clickPadPanel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 4, 0),
            0,
            0));
    clickPadPanel.setBorder(
        IdeBorderFactory.createTitledBorder(
            KeyMapBundle.message("mouse.shortcut.dialog.click.pad.border"), false, true, true));
    myClickPad.setPreferredSize(new Dimension(260, 60));
    clickPadPanel.add(myClickPad, BorderLayout.CENTER);

    // Shortcut preview

    JPanel previewPanel = new JPanel(new GridBagLayout());
    previewPanel.setBorder(
        IdeBorderFactory.createTitledBorder(
            KeyMapBundle.message("mouse.shortcut.dialog.shortcut.preview.border"),
            false,
            true,
            true));
    panel.add(
        previewPanel,
        new GridBagConstraints(
            0,
            2,
            1,
            1,
            1,
            0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 4, 0),
            0,
            0));
    previewPanel.add(
        myLblPreview,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1,
            1,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(2, 2, 2, 2),
            0,
            0));

    // Conflicts panel

    JPanel conflictsPanel = new JPanel(new GridBagLayout());
    conflictsPanel.setBorder(
        IdeBorderFactory.createTitledBorder(
            KeyMapBundle.message("mouse.shortcut.dialog.conflicts.border"), false, true, true));
    panel.add(
        conflictsPanel,
        new GridBagConstraints(
            0,
            3,
            1,
            1,
            1,
            1,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    myTarConflicts.setPreferredSize(new Dimension(260, 60));
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTarConflicts);
    scrollPane.setBorder(null);
    conflictsPanel.add(
        scrollPane,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            1,
            1,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));

    return panel;
  }
  private boolean inInitState() {
    Component focusOwner = myContext.getFocusOwner();
    boolean isModalContext = myContext.isModalContext();
    DataContext dataContext = myContext.getDataContext();
    KeyEvent e = myContext.getInputEvent();

    // http://www.jetbrains.net/jira/browse/IDEADEV-12372
    if (myLeftCtrlPressed
        && myRightAltPressed
        && focusOwner != null
        && e.getModifiers() == (InputEvent.CTRL_MASK | InputEvent.ALT_MASK)) {
      if (Registry.is("actionSystem.force.alt.gr")) {
        return false;
      }
      final InputContext inputContext = focusOwner.getInputContext();
      if (inputContext != null) {
        Locale locale = inputContext.getLocale();
        if (locale != null) {
          @NonNls final String language = locale.getLanguage();
          if (ALT_GR_LAYOUTS.contains(language)) {
            // don't search for shortcuts
            return false;
          }
        }
      }
    }

    KeyStroke originalKeyStroke = KeyStroke.getKeyStrokeForEvent(e);
    KeyStroke keyStroke = getKeyStrokeWithoutMouseModifiers(originalKeyStroke);

    if (myKeyGestureProcessor.processInitState()) {
      return true;
    }

    if (SystemInfo.isMac) {
      boolean keyTyped = e.getID() == KeyEvent.KEY_TYPED;
      boolean hasMnemonicsInWindow =
          e.getID() == KeyEvent.KEY_PRESSED && hasMnemonicInWindow(focusOwner, e.getKeyCode())
              || keyTyped && hasMnemonicInWindow(focusOwner, e.getKeyChar());
      boolean imEnabled = IdeEventQueue.getInstance().isInputMethodEnabled();

      if (e.getModifiersEx() == InputEvent.ALT_DOWN_MASK
          && (hasMnemonicsInWindow || (!imEnabled && keyTyped))) {
        setPressedWasProcessed(true);
        setState(KeyState.STATE_PROCESSED);
        return false;
      }
    }

    updateCurrentContext(focusOwner, new KeyboardShortcut(keyStroke, null), isModalContext);
    if (myContext.getActions().isEmpty()) {
      // there's nothing mapped for this stroke
      return false;
    }

    if (myContext.isHasSecondStroke()) {
      myFirstKeyStroke = keyStroke;
      final ArrayList<Pair<AnAction, KeyStroke>> secondKeyStrokes = getSecondKeystrokeActions();

      final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
      StringBuilder message = new StringBuilder();
      message.append(KeyMapBundle.message("prefix.key.pressed.message"));
      message.append(' ');
      for (int i = 0; i < secondKeyStrokes.size(); i++) {
        Pair<AnAction, KeyStroke> pair = secondKeyStrokes.get(i);
        if (i > 0) message.append(", ");
        message.append(pair.getFirst().getTemplatePresentation().getText());
        message.append(" (");
        message.append(KeymapUtil.getKeystrokeText(pair.getSecond()));
        message.append(")");
      }

      StatusBar.Info.set(message.toString(), project);

      mySecondStrokeTimeout.cancelAllRequests();
      mySecondStrokeTimeout.addRequest(
          mySecondStrokeTimeoutRunnable, Registry.intValue("actionSystem.secondKeystrokeTimeout"));

      if (Registry.is("actionSystem.secondKeystrokeAutoPopupEnabled")) {
        mySecondKeystrokePopupTimeout.cancelAllRequests();
        if (secondKeyStrokes.size() > 1) {
          final DataContext oldContext = myContext.getDataContext();
          mySecondKeystrokePopupTimeout.addRequest(
              new Runnable() {
                @Override
                public void run() {
                  if (myState == KeyState.STATE_WAIT_FOR_SECOND_KEYSTROKE) {
                    StatusBar.Info.set(null, PlatformDataKeys.PROJECT.getData(oldContext));
                    new SecondaryKeystrokePopup(myFirstKeyStroke, secondKeyStrokes, oldContext)
                        .showInBestPositionFor(oldContext);
                  }
                }
              },
              Registry.intValue("actionSystem.secondKeystrokePopupTimeout"));
        }
      }

      setState(KeyState.STATE_WAIT_FOR_SECOND_KEYSTROKE);
      return true;
    } else {
      return processAction(e, myActionProcessor);
    }
  }