예제 #1
0
 // -------->
 // original code:
 // ftp://ftp.oreilly.de/pub/examples/english_examples/jswing2/code/goodies/Mapper.java
 // modified by terai
 //     private Hashtable<Object, ArrayList<KeyStroke>> buildReverseMap(InputMap im) {
 //         Hashtable<Object, ArrayList<KeyStroke>> h = new Hashtable<>();
 //         if (Objects.isNull(im.allKeys())) {
 //             return h;
 //         }
 //         for (KeyStroke ks: im.allKeys()) {
 //             Object name = im.get(ks);
 //             if (h.containsKey(name)) {
 //                 h.get(name).add(ks);
 //             } else {
 //                 ArrayList<KeyStroke> keylist = new ArrayList<>();
 //                 keylist.add(ks);
 //                 h.put(name, keylist);
 //             }
 //         }
 //         return h;
 //     }
 private void loadBindingMap(Integer focusType, InputMap im, ActionMap am) {
   if (Objects.isNull(im.allKeys())) {
     return;
   }
   ActionMap tmpAm = new ActionMap();
   for (Object actionMapKey : am.allKeys()) {
     tmpAm.put(actionMapKey, am.get(actionMapKey));
   }
   for (KeyStroke ks : im.allKeys()) {
     Object actionMapKey = im.get(ks);
     Action action = am.get(actionMapKey);
     if (Objects.isNull(action)) {
       model.addBinding(new Binding(focusType, "____" + actionMapKey.toString(), ks.toString()));
     } else {
       model.addBinding(new Binding(focusType, actionMapKey.toString(), ks.toString()));
     }
     tmpAm.remove(actionMapKey);
   }
   if (Objects.isNull(tmpAm.allKeys())) {
     return;
   }
   for (Object actionMapKey : tmpAm.allKeys()) {
     model.addBinding(new Binding(focusType, actionMapKey.toString(), ""));
   }
 }
 /**
  * This is hack. AWT doesn't allow to create KeyStroke with specified key code and key char
  * simultaneously. Therefore we are using reflection.
  */
 private static KeyStroke getKeyStrokeWithoutMouseModifiers(KeyStroke originalKeyStroke) {
   int modifier =
       originalKeyStroke.getModifiers()
           & ~InputEvent.BUTTON1_DOWN_MASK
           & ~InputEvent.BUTTON1_MASK
           & ~InputEvent.BUTTON2_DOWN_MASK
           & ~InputEvent.BUTTON2_MASK
           & ~InputEvent.BUTTON3_DOWN_MASK
           & ~InputEvent.BUTTON3_MASK;
   try {
     Method[] methods = AWTKeyStroke.class.getDeclaredMethods();
     Method getCachedStrokeMethod = null;
     for (Method method : methods) {
       if (GET_CACHED_STROKE_METHOD_NAME.equals(method.getName())) {
         getCachedStrokeMethod = method;
         getCachedStrokeMethod.setAccessible(true);
         break;
       }
     }
     if (getCachedStrokeMethod == null) {
       throw new IllegalStateException("not found method with name getCachedStrokeMethod");
     }
     Object[] getCachedStrokeMethodArgs =
         new Object[] {
           originalKeyStroke.getKeyChar(),
           originalKeyStroke.getKeyCode(),
           modifier,
           originalKeyStroke.isOnKeyRelease()
         };
     return (KeyStroke) getCachedStrokeMethod.invoke(originalKeyStroke, getCachedStrokeMethodArgs);
   } catch (Exception exc) {
     throw new IllegalStateException(exc.getMessage());
   }
 }
 private static void installActions(JTable table) {
   InputMap inputMap = table.getInputMap(WHEN_FOCUSED);
   inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_END, 0), "selectLastRow");
   inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0), "selectFirstRow");
   inputMap.put(
       KeyStroke.getKeyStroke(KeyEvent.VK_HOME, KeyEvent.SHIFT_DOWN_MASK),
       "selectFirstRowExtendSelection");
   inputMap.put(
       KeyStroke.getKeyStroke(KeyEvent.VK_END, KeyEvent.SHIFT_DOWN_MASK),
       "selectLastRowExtendSelection");
 }
예제 #4
0
 /**
  * The Excel Adapter is constructed with a JTable on which it enables Copy-Paste and acts as a
  * Clipboard listener.
  */
 public ExcelAdapter(JTable myJTable) {
   jTable1 = myJTable;
   KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK, false);
   // Identifying the copy KeyStroke user can modify this
   // to copy on some other Key combination.
   KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK, false);
   // Identifying the Paste KeyStroke user can modify this
   // to copy on some other Key combination.
   jTable1.registerKeyboardAction(this, "Copy", copy, JComponent.WHEN_FOCUSED);
   jTable1.registerKeyboardAction(this, "Paste", paste, JComponent.WHEN_FOCUSED);
   system = Toolkit.getDefaultToolkit().getSystemClipboard();
 }
예제 #5
0
  public DiffContentPanel(EditableDiffView master, boolean isFirst) {
    this.master = master;
    this.isFirst = isFirst;

    setLayout(new BorderLayout());

    editorPane = new DecoratedEditorPane(this);
    editorPane.setEditable(false);
    scrollPane = new JScrollPane(editorPane);
    add(scrollPane);

    linesActions = new LineNumbersActionsBar(this, master.isActionsEnabled());
    actionsScrollPane = new JScrollPane(linesActions);
    actionsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    actionsScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
    actionsScrollPane.setBorder(null);
    add(actionsScrollPane, isFirst ? BorderLayout.LINE_END : BorderLayout.LINE_START);

    editorPane.putClientProperty(DiffHighlightsLayerFactory.HIGHLITING_LAYER_ID, this);
    if (!isFirst) {
      // disable focus traversal, but permit just the up-cycle on ESC key
      editorPane.setFocusTraversalKeys(
          KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
      editorPane.setFocusTraversalKeys(
          KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
      editorPane.setFocusTraversalKeys(
          KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS,
          Collections.singleton(KeyStroke.getAWTKeyStroke(KeyEvent.VK_ESCAPE, 0)));

      editorPane.putClientProperty("errorStripeOnly", Boolean.TRUE);
      editorPane.putClientProperty("code-folding-enable", false);
    }
  }
예제 #6
0
  private void addShortcutBlinker() {
    getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(KeyStroke.getKeyStroke("ctrl B"), "Blink Function");
    getActionMap()
        .put(
            "Blink Function",
            new AbstractAction() {

              @Override
              public void actionPerformed(ActionEvent e) {
                if (ACTIVE_FUNCTION == null) return;

                setEnabled(false);
                final Color3f oldColor = ACTIVE_FUNCTION.getColor();
                ACTIVE_FUNCTION.setColor(Colors.WHITE);

                Timer timer =
                    new Timer(
                        300,
                        new ActionListener() {

                          @Override
                          public void actionPerformed(ActionEvent e) {
                            ACTIVE_FUNCTION.setColor(oldColor);
                            setEnabled(true);
                          }
                        });

                timer.setRepeats(false);
                timer.start();
              }
            });
  }
 /**
  * This method updates the input and action maps with new ToggleAction.
  *
  * @param isToggleDynamic
  * @param isToggleLarger
  * @param key
  * @param keyStroke
  */
 private void installToggleAction(
     boolean isToggleDynamic, boolean isToggleLarger, String key, String keyStroke) {
   Action action = new ToggleAction(isToggleDynamic, isToggleLarger);
   KeyStroke ks = KeyStroke.getKeyStroke(keyStroke);
   table.getInputMap().put(ks, key);
   table.getActionMap().put(key, action);
 }
 /**
  * This method updates the input and action maps with a new ColumnAction.
  *
  * @param isSelectedColumn
  * @param isAdjust
  * @param key
  * @param keyStroke
  */
 private void installColumnAction(
     boolean isSelectedColumn, boolean isAdjust, String key, String keyStroke) {
   Action action = new ColumnAction(isSelectedColumn, isAdjust);
   KeyStroke ks = KeyStroke.getKeyStroke(keyStroke);
   table.getInputMap().put(ks, key);
   table.getActionMap().put(key, action);
 }
  @SuppressWarnings("HardCodedStringLiteral")
  private boolean togglePopup(KeyEvent e) {
    final KeyStroke stroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());
    final Object action = ((InputMap) UIManager.get("ComboBox.ancestorInputMap")).get(stroke);
    if ("selectNext".equals(action)) {
      if (!isPopupShowing()) {
        return true;
      } else {
        return false;
      }
    } else if ("togglePopup".equals(action)) {
      if (isPopupShowing()) {
        closePopup();
      } else {
        suggestCompletion(true, true);
      }
      return true;
    } else {
      final Keymap active = KeymapManager.getInstance().getActiveKeymap();
      final String[] ids = active.getActionIds(stroke);
      if (ids.length > 0 && IdeActions.ACTION_CODE_COMPLETION.equals(ids[0])) {
        suggestCompletion(true, true);
      }
    }

    return false;
  }
예제 #10
0
 public void unbindKey(String keySequence) {
   KeyStroke ks = KeyStroke.getKeyStroke(keySequence);
   if (ks == null) {
     throw new Error("Invalid key sequence \"" + keySequence + "\"");
   }
   textView.getKeymap().removeKeyStrokeBinding(ks);
 }
예제 #11
0
 // Adds a new keybinding equal to the character provided and the default super key (ctrl/cmd)
 private static void bind(int Character) {
   frame
       .getRootPane()
       .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
       .put(
           KeyStroke.getKeyStroke(Character, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
           "console");
 }
 private MergeDupLines() {
   super(
       UsageViewImpl.this,
       UsageViewBundle.message("action.merge.same.line"),
       IconLoader.getIcon("/toolbar/filterdups.png"));
   setShortcutSet(
       new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_DOWN_MASK)));
 }
예제 #13
0
 public void bindKeyToCommand(String keySequence, LispExpr cmd) {
   // 	see Java API for info on keySequence format
   KeyStroke ks = KeyStroke.getKeyStroke(keySequence);
   if (ks == null) {
     throw new Error("Invalid key sequence \"" + keySequence + "\"");
   }
   textView.getKeymap().addActionForKeyStroke(ks, new KeyAction(cmd));
 }
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (myCurrentWindow == null || myCurrentWindow.getFiles().length == 0) {
      g.setColor(UIUtil.isUnderDarcula() ? UIUtil.getBorderColor() : new Color(0, 0, 0, 50));
      g.drawLine(0, 0, getWidth(), 0);
    }

    if (showEmptyText()) {
      UIUtil.applyRenderingHints(g);
      g.setColor(new JBColor(Gray._100, Gray._160));
      g.setFont(UIUtil.getLabelFont().deriveFont(UIUtil.isUnderDarcula() ? 24f : 18f));

      final UIUtil.TextPainter painter =
          new UIUtil.TextPainter().withShadow(true).withLineSpacing(1.4f);
      painter.appendLine("No files are open").underlined(new JBColor(Gray._150, Gray._100));

      if (!isProjectViewVisible()) {
        painter
            .appendLine(
                "Open Project View with "
                    + KeymapUtil.getShortcutText(
                        new KeyboardShortcut(
                            KeyStroke.getKeyStroke((SystemInfo.isMac ? "meta" : "alt") + " 1"),
                            null)))
            .smaller()
            .withBullet();
      }

      painter
          .appendLine("Open a file by name with " + getActionShortcutText("GotoFile"))
          .smaller()
          .withBullet()
          .appendLine(
              "Open Recent files with " + getActionShortcutText(IdeActions.ACTION_RECENT_FILES))
          .smaller()
          .withBullet()
          .appendLine("Open Navigation Bar with " + getActionShortcutText("ShowNavBar"))
          .smaller()
          .withBullet()
          .appendLine("Drag'n'Drop file(s) here from " + ShowFilePathAction.getFileManagerName())
          .smaller()
          .withBullet()
          .draw(
              g,
              new PairFunction<Integer, Integer, Pair<Integer, Integer>>() {
                @Override
                public Pair<Integer, Integer> fun(Integer width, Integer height) {
                  final Dimension s = getSize();
                  return Pair.create((s.width - width) / 2, (s.height - height) / 2);
                }
              });
    }
  }
예제 #15
0
  // ------------------------------------------------------------------
  // from Java Swing 1.2 Orielly - Robert Eckstein
  // ------------------------------------------------------------------
  protected JTextComponent updateKeymapForWord(JTextComponent textComp) {
    // create a new child keymap
    Keymap map = JTextComponent.addKeymap("NslmMap", textComp.getKeymap());

    // define the keystrokeds to be added
    KeyStroke next = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.CTRL_MASK, false);
    // add the new mappings used DefaultEditorKit actions
    map.addActionForKeyStroke(next, getAction(DefaultEditorKit.nextWordAction));

    KeyStroke prev = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(prev, getAction(DefaultEditorKit.previousWordAction));

    KeyStroke selNext =
        KeyStroke.getKeyStroke(
            KeyEvent.VK_RIGHT, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, false);
    map.addActionForKeyStroke(selNext, getAction(DefaultEditorKit.selectionNextWordAction));
    KeyStroke selPrev =
        KeyStroke.getKeyStroke(
            KeyEvent.VK_LEFT, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, false);
    map.addActionForKeyStroke(selPrev, getAction(DefaultEditorKit.selectionPreviousWordAction));

    KeyStroke find = KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(find, getAction("find"));

    KeyStroke findAgain = KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(findAgain, getAction("findAgain"));

    // set the keymap for the text component
    textComp.setKeymap(map);
    return (textComp);
  } // end updateKeymapForWord
예제 #16
0
 private static void installCutCopyPasteShortcuts(InputMap inputMap, boolean useSimpleActionKeys) {
   String copyActionKey = useSimpleActionKeys ? "copy" : DefaultEditorKit.copyAction;
   String pasteActionKey = useSimpleActionKeys ? "paste" : DefaultEditorKit.pasteAction;
   String cutActionKey = useSimpleActionKeys ? "cut" : DefaultEditorKit.cutAction;
   // Ctrl+Ins, Shift+Ins, Shift+Del
   inputMap.put(
       KeyStroke.getKeyStroke(
           KeyEvent.VK_INSERT, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK),
       copyActionKey);
   inputMap.put(
       KeyStroke.getKeyStroke(
           KeyEvent.VK_INSERT, InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK),
       pasteActionKey);
   inputMap.put(
       KeyStroke.getKeyStroke(
           KeyEvent.VK_DELETE, InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK),
       cutActionKey);
   // Ctrl+C, Ctrl+V, Ctrl+X
   inputMap.put(
       KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK),
       copyActionKey);
   inputMap.put(
       KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK),
       pasteActionKey);
   inputMap.put(
       KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK),
       DefaultEditorKit.cutAction);
 }
예제 #17
0
 public ReferencePropertyWidget(boolean containedByListReferenceGUI) {
   this.containedByListReferenceGUI = containedByListReferenceGUI;
   // get Options
   m_comboBox = new JComboBox();
   m_comboBox.setEditable(false);
   m_comboBox.setPreferredSize(new Dimension(300, 20));
   // m_comboBox.setMinimumSize(new Dimension(260, 20));
   m_comboBox.setMaximumSize(new Dimension(Short.MAX_VALUE, 20));
   KeyStroke controlT = KeyStroke.getKeyStroke("control SPACE");
   getTextField().getInputMap().put(controlT, controlT);
   getTextField().getActionMap().put(controlT, new CodeCompleteAction());
   ToolTipManager.sharedInstance().registerComponent(m_comboBox);
 }
  // Private helper methods
  private void createMenuBar() {
    menuBar = new JMenuBar();
    fileMenu = new JMenu("File");

    miOpen = new JMenuItem("Open...");
    miOpen.setAccelerator(
        KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.Event.META_MASK));
    fileMenu.add(miOpen).setEnabled(false);
    miOpen.addActionListener(new MenuActionListener());

    miSave = new JMenuItem("Save Selected...");
    miSave.setAccelerator(
        KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.Event.META_MASK));
    fileMenu.add(miSave).setEnabled(false);
    miSave.addActionListener(new MenuActionListener());

    miSaveAll = new JMenuItem("Save All...");
    fileMenu.add(miSaveAll).setEnabled(false);
    miSaveAll.addActionListener(new MenuActionListener());

    menuBar.add(fileMenu);
  }
예제 #19
0
  public TetrisComponent(Board board) {
    this.board = board;
    setPreferredSize(getPreferredSize());
    SQUARE_COLOR.put(SquareType.I, Color.CYAN);
    SQUARE_COLOR.put(SquareType.S, Color.RED);
    SQUARE_COLOR.put(SquareType.Z, Color.GREEN);
    SQUARE_COLOR.put(SquareType.T, Color.MAGENTA);
    SQUARE_COLOR.put(SquareType.L, Color.ORANGE);
    SQUARE_COLOR.put(SquareType.J, Color.BLUE);
    SQUARE_COLOR.put(SquareType.O, Color.YELLOW);
    SQUARE_COLOR.put(SquareType.EMPTY, Color.WHITE);
    SQUARE_COLOR.put(SquareType.OUTSIDE, Color.BLACK);

    getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "moveLeft");
    getActionMap().put("moveLeft", moveLeft);
    getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "moveRight");
    getActionMap().put("moveRight", moveRight);
    getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "rotate");
    getActionMap().put("rotate", rotateBlock);
  }
예제 #20
0
  private void addShortcutDelete() {
    getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(KeyStroke.getKeyStroke("ctrl D"), "Delete Function");
    getActionMap()
        .put(
            "Delete Function",
            new AbstractAction() {

              public void actionPerformed(ActionEvent e) {
                if (ACTIVE_FUNCTION == null) return;

                deletePlot(ACTIVE_FUNCTION);
              };
            });
  }
예제 #21
0
  /**
   * Returns a keystroke for the specified string.
   *
   * @param cmd command
   * @return keystroke
   */
  public static KeyStroke keyStroke(final GUICommand cmd) {
    final Object sc = cmd.shortcuts();
    if (sc == null) return null;

    final String scut;
    if (sc instanceof BaseXKeys[]) {
      final BaseXKeys[] scs = (BaseXKeys[]) sc;
      if (scs.length == 0) return null;
      scut = scs[0].shortCut();
    } else {
      scut = Util.info(sc, META);
    }
    final KeyStroke ks = KeyStroke.getKeyStroke(scut);
    if (ks == null) Util.errln("Could not assign shortcut: " + sc + " / " + scut);
    return ks;
  }
  protected void fillToolbarActions(DefaultActionGroup group) {
    final boolean alphabeticallySorted = PropertiesComponent.getInstance().isTrueValue(PROP_SORTED);
    if (alphabeticallySorted) {
      setSortComparator(new OrderComparator());
    }
    myAlphabeticallySorted = alphabeticallySorted;
    group.add(mySortAction);

    if (!supportsNestedContainers()) {
      ShowContainersAction showContainersAction = getShowContainersAction();
      showContainersAction.registerCustomShortcutSet(
          new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK)),
          myTree);
      setShowClasses(PropertiesComponent.getInstance().isTrueValue(PROP_SHOWCLASSES));
      group.add(showContainersAction);
    }
  }
예제 #23
0
  public void addDialogCloser(JComponent comp) {
    AbstractAction closeAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            setVisible(false);
          }
        };

    // Then create a keystroke to use for it
    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);

    // Finally, bind the keystroke and the action to *any* component
    // within the dialog. Note the WHEN_IN_FOCUSED bit...this is what
    // stops you having to do it for all components

    comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ks, "close");
    comp.getActionMap().put("close", closeAction);
  }
예제 #24
0
 @Override
 public void keyPressed(KeyEvent e) {
   // Accept "copy" key strokes
   KeyStroke ks = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());
   JComponent comp = (JComponent) e.getSource();
   for (int i = 0; i < 3; i++) {
     InputMap im = comp.getInputMap(i);
     Object key = im.get(ks);
     if (defaultEditorKitCopyActionName.equals(key)
         || transferHandlerCopyActionName.equals(key)) {
       return;
     }
   }
   // Accept JTable navigation key strokes
   if (!tableNavigationKeys.contains(e.getKeyCode())) {
     e.consume();
   }
 }
예제 #25
0
  @Override
  public void initUI() {
    super.initUI();

    if (Registry.is("tests.view.old.statistics.panel")) {
      final KeyStroke shiftEnterKey =
          KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_MASK);
      SMRunnerUtil.registerAsAction(
          shiftEnterKey,
          "show-statistics-for-test-proxy",
          new Runnable() {
            public void run() {
              showStatisticsForSelectedProxy();
            }
          },
          myTreeView);
    }
  }
 protected MemberChooser(
     boolean allowEmptySelection,
     boolean allowMultiSelection,
     @NotNull Project project,
     boolean isInsertOverrideVisible,
     @Nullable JComponent headerPanel,
     @Nullable JComponent[] optionControls) {
   super(project, true);
   myAllowEmptySelection = allowEmptySelection;
   myAllowMultiSelection = allowMultiSelection;
   myProject = project;
   myIsInsertOverrideVisible = isInsertOverrideVisible;
   myHeaderPanel = headerPanel;
   myTree = createTree();
   myOptionControls = optionControls;
   mySortAction = new SortEmAction();
   mySortAction.registerCustomShortcutSet(
       new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.ALT_MASK)), myTree);
 }
예제 #27
0
  public TextAreaCellEditor() {
    super();
    scroll = new JScrollPane(this);
    scroll.setBorder(BorderFactory.createEmptyBorder());
    // scroll.setViewportBorder(BorderFactory.createEmptyBorder());

    setLineWrap(true);
    setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4));

    KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK);
    getInputMap(JComponent.WHEN_FOCUSED).put(enter, KEY);
    getActionMap()
        .put(
            KEY,
            new AbstractAction() {
              @Override
              public void actionPerformed(ActionEvent e) {
                stopCellEditing();
              }
            });
  }
  @SuppressWarnings("HardCodedStringLiteral")
  private void processListSelection(final KeyEvent e) {
    if (togglePopup(e)) return;

    if (!isPopupShowing()) return;

    final InputMap map = myPathTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    if (map != null) {
      final Object object = map.get(KeyStroke.getKeyStrokeForEvent(e));
      if (object instanceof Action) {
        final Action action = (Action) object;
        if (action.isEnabled()) {
          action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "action"));
          e.consume();
          return;
        }
      }
    }

    final Object action = getAction(e, myList);

    if ("selectNextRow".equals(action)) {
      if (ensureSelectionExists()) {
        ListScrollingUtil.moveDown(myList, e.getModifiersEx());
      }
    } else if ("selectPreviousRow".equals(action)) {
      ListScrollingUtil.moveUp(myList, e.getModifiersEx());
    } else if ("scrollDown".equals(action)) {
      ListScrollingUtil.movePageDown(myList);
    } else if ("scrollUp".equals(action)) {
      ListScrollingUtil.movePageUp(myList);
    } else if (getSelectedFileFromCompletionPopup() != null
        && (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_TAB)
        && e.getModifiers() == 0) {
      hideCurrentPopup();
      e.consume();
      processChosenFromCompletion(e.getKeyCode() == KeyEvent.VK_TAB);
    }
  }
  private boolean inSecondStrokeInProgressState() {
    KeyEvent e = myContext.getInputEvent();

    // when any key is released, we stop waiting for the second stroke
    if (KeyEvent.KEY_RELEASED == e.getID()) {
      myFirstKeyStroke = null;
      setState(KeyState.STATE_INIT);
      Project project = PlatformDataKeys.PROJECT.getData(myContext.getDataContext());
      StatusBar.Info.set(null, project);
      return false;
    }

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

    updateCurrentContext(
        myContext.getFoundComponent(),
        new KeyboardShortcut(myFirstKeyStroke, keyStroke),
        myContext.isModalContext());

    // consume the wrong second stroke and keep on waiting
    if (myContext.getActions().isEmpty()) {
      return true;
    }

    // finally user had managed to enter the second keystroke, so let it be processed
    Project project = PlatformDataKeys.PROJECT.getData(myContext.getDataContext());
    StatusBarEx statusBar = (StatusBarEx) WindowManager.getInstance().getStatusBar(project);
    if (processAction(e, myActionProcessor)) {
      if (statusBar != null) {
        statusBar.setInfo(null);
      }
      return true;
    } else {
      return false;
    }
  }
예제 #30
0
 @SuppressWarnings({"HardCodedStringLiteral"})
 public static void initInputMapDefaults(UIDefaults defaults) {
   // Make ENTER work in JTrees
   InputMap treeInputMap = (InputMap) defaults.get("Tree.focusInputMap");
   if (treeInputMap != null) { // it's really possible. For example,  GTK+ doesn't have such map
     treeInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "toggle");
   }
   // Cut/Copy/Paste in JTextAreas
   InputMap textAreaInputMap = (InputMap) defaults.get("TextArea.focusInputMap");
   if (textAreaInputMap
       != null) { // It really can be null, for example when LAF isn't properly initialized (Alloy
                  // license problem)
     installCutCopyPasteShortcuts(textAreaInputMap, false);
   }
   // Cut/Copy/Paste in JTextFields
   InputMap textFieldInputMap = (InputMap) defaults.get("TextField.focusInputMap");
   if (textFieldInputMap
       != null) { // It really can be null, for example when LAF isn't properly initialized (Alloy
                  // license problem)
     installCutCopyPasteShortcuts(textFieldInputMap, false);
   }
   // Cut/Copy/Paste in JPasswordField
   InputMap passwordFieldInputMap = (InputMap) defaults.get("PasswordField.focusInputMap");
   if (passwordFieldInputMap
       != null) { // It really can be null, for example when LAF isn't properly initialized (Alloy
                  // license problem)
     installCutCopyPasteShortcuts(passwordFieldInputMap, false);
   }
   // Cut/Copy/Paste in JTables
   InputMap tableInputMap = (InputMap) defaults.get("Table.ancestorInputMap");
   if (tableInputMap
       != null) { // It really can be null, for example when LAF isn't properly initialized (Alloy
                  // license problem)
     installCutCopyPasteShortcuts(tableInputMap, true);
   }
 }