Example usage for com.intellij.openapi.actionSystem IdeActions ACTION_EDITOR_MOVE_CARET_UP

List of usage examples for com.intellij.openapi.actionSystem IdeActions ACTION_EDITOR_MOVE_CARET_UP

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem IdeActions ACTION_EDITOR_MOVE_CARET_UP.

Prototype

String ACTION_EDITOR_MOVE_CARET_UP

To view the source code for com.intellij.openapi.actionSystem IdeActions ACTION_EDITOR_MOVE_CARET_UP.

Click Source Link

Usage

From source file:com.intellij.codeInsight.CodeInsightTestCase.java

License:Apache License

protected void caretUp() {
    EditorActionManager actionManager = EditorActionManager.getInstance();
    EditorActionHandler action = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_UP);
    action.execute(getEditor(), DataManager.getInstance().getDataContext());
}

From source file:com.intellij.codeInsight.documentation.DocumentationManager.java

License:Apache License

public DocumentationManager(final Project project, ActionManagerEx managerEx) {
    super(project);
    myActionManagerEx = managerEx;/*w ww  .jav a  2  s.c  o  m*/
    final AnActionListener actionListener = new AnActionListener() {
        @Override
        public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
            final JBPopup hint = getDocInfoHint();
            if (hint != null) {
                if (action instanceof HintManagerImpl.ActionToIgnore) {
                    ((AbstractPopup) hint).focusPreferredComponent();
                    return;
                }
                if (action instanceof ListScrollingUtil.ListScrollAction)
                    return;
                if (action == myActionManagerEx.getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN))
                    return;
                if (action == myActionManagerEx.getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP))
                    return;
                if (action == myActionManagerEx.getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_PAGE_DOWN))
                    return;
                if (action == myActionManagerEx.getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_PAGE_UP))
                    return;
                if (action == ActionManagerEx.getInstanceEx().getAction(IdeActions.ACTION_EDITOR_ESCAPE))
                    return;
                if (ActionPlaces.JAVADOC_INPLACE_SETTINGS.equals(event.getPlace()))
                    return;
                if (action instanceof BaseNavigateToSourceAction)
                    return;
                closeDocHint();
            }
        }

        @Override
        public void beforeEditorTyping(char c, DataContext dataContext) {
            final JBPopup hint = getDocInfoHint();
            if (hint != null && LookupManager.getActiveLookup(myEditor) == null) {
                hint.cancel();
            }
        }

        @Override
        public void afterActionPerformed(final AnAction action, final DataContext dataContext,
                AnActionEvent event) {
        }
    };
    myActionManagerEx.addAnActionListener(actionListener, project);
    myUpdateDocAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, myProject);
}

From source file:com.intellij.codeInsight.navigation.IncrementalSearchHandler.java

License:Apache License

public void invoke(Project project, final Editor editor) {
    if (!ourActionsRegistered) {
        ourActionsRegistered = true;//from w  w w .  j  a  va 2  s .c o  m

        EditorActionManager actionManager = EditorActionManager.getInstance();

        TypedAction typedAction = actionManager.getTypedAction();
        typedAction.setupHandler(new MyTypedHandler(typedAction.getHandler()));

        actionManager.setActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE,
                new BackSpaceHandler(actionManager.getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE)));
        actionManager.setActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_UP,
                new UpHandler(actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_UP)));
        actionManager.setActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN,
                new DownHandler(actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN)));
    }

    FeatureUsageTracker.getInstance().triggerFeatureUsed("editing.incremental.search");

    String selection = editor.getSelectionModel().getSelectedText();
    JLabel label2 = new MyLabel(selection == null ? "" : selection);

    PerEditorSearchData data = editor.getUserData(SEARCH_DATA_IN_EDITOR_VIEW_KEY);
    if (data == null) {
        data = new PerEditorSearchData();
    } else {
        if (data.hint != null) {
            if (data.lastSearch != null) {
                PerHintSearchData hintData = data.hint.getUserData(SEARCH_DATA_IN_HINT_KEY);
                //The user has not started typing
                if ("".equals(hintData.label.getText())) {
                    label2 = new MyLabel(data.lastSearch);
                }
            }
            data.hint.hide();
        }
    }

    JLabel label1 = new MyLabel(" " + CodeInsightBundle.message("incremental.search.tooltip.prefix"));
    label1.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));

    JPanel panel = new MyPanel(label1);
    panel.add(label1, BorderLayout.WEST);
    panel.add(label2, BorderLayout.CENTER);
    panel.setBorder(BorderFactory.createLineBorder(Color.black));

    final DocumentListener[] documentListener = new DocumentListener[1];
    final CaretListener[] caretListener = new CaretListener[1];
    final Document document = editor.getDocument();

    final LightweightHint hint = new LightweightHint(panel) {
        @Override
        public void hide() {
            PerHintSearchData data = getUserData(SEARCH_DATA_IN_HINT_KEY);
            LOG.assertTrue(data != null);
            String prefix = data.label.getText();

            super.hide();

            if (data.segmentHighlighter != null) {
                data.segmentHighlighter.dispose();
            }
            PerEditorSearchData editorData = editor.getUserData(SEARCH_DATA_IN_EDITOR_VIEW_KEY);
            editorData.hint = null;
            editorData.lastSearch = prefix;

            if (documentListener[0] != null) {
                document.removeDocumentListener(documentListener[0]);
            }

            if (caretListener[0] != null) {
                CaretListener listener = caretListener[0];
                editor.getCaretModel().removeCaretListener(listener);
            }
        }
    };

    documentListener[0] = new DocumentAdapter() {
        @Override
        public void documentChanged(DocumentEvent e) {
            if (!hint.isVisible())
                return;
            hint.hide();
        }
    };
    document.addDocumentListener(documentListener[0]);

    caretListener[0] = new CaretAdapter() {
        @Override
        public void caretPositionChanged(CaretEvent e) {
            PerHintSearchData data = hint.getUserData(SEARCH_DATA_IN_HINT_KEY);
            if (data != null && data.ignoreCaretMove)
                return;
            if (!hint.isVisible())
                return;
            hint.hide();
        }
    };
    CaretListener listener = caretListener[0];
    editor.getCaretModel().addCaretListener(listener);

    final JComponent component = editor.getComponent();
    int x = SwingUtilities.convertPoint(component, 0, 0, component).x;
    int y = -hint.getComponent().getPreferredSize().height;
    Point p = SwingUtilities.convertPoint(component, x, y, component.getRootPane().getLayeredPane());

    HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, p,
            HintManagerImpl.HIDE_BY_ESCAPE | HintManagerImpl.HIDE_BY_TEXT_CHANGE, 0, false,
            new HintHint(editor, p).setAwtTooltip(false));

    PerHintSearchData hintData = new PerHintSearchData(project, label2);
    hintData.searchStart = editor.getCaretModel().getOffset();
    hint.putUserData(SEARCH_DATA_IN_HINT_KEY, hintData);

    data.hint = hint;
    editor.putUserData(SEARCH_DATA_IN_EDITOR_VIEW_KEY, data);

    if (hintData.label.getText().length() > 0) {
        updatePosition(editor, hintData, true, false);
    }
}

From source file:com.intellij.find.editorHeaderActions.PrevOccurrenceAction.java

License:Apache License

public PrevOccurrenceAction(EditorSearchComponent editorSearchComponent,
        Getter<JTextComponent> editorTextField) {
    super(editorSearchComponent);

    copyFrom(ActionManager.getInstance().getAction(IdeActions.ACTION_PREVIOUS_OCCURENCE));

    ArrayList<Shortcut> shortcuts = new ArrayList<Shortcut>();
    ContainerUtil.addAll(shortcuts, ActionManager.getInstance().getAction(IdeActions.ACTION_FIND_PREVIOUS)
            .getShortcutSet().getShortcuts());
    if (!editorSearchComponent.getFindModel().isMultiline()) {
        ContainerUtil.addAll(shortcuts, ActionManager.getInstance()
                .getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP).getShortcutSet().getShortcuts());

        shortcuts.add(new KeyboardShortcut(
                KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK), null));
    }//from w  ww.ja v a  2s .c om
    registerShortcutsForComponent(shortcuts, editorTextField.get());
}

From source file:com.intellij.ide.util.gotoByName.ChooseByNameBase.java

License:Apache License

/**
 * @param modalityState          - if not null rebuilds list in given {@link ModalityState}
 *///from  w w  w.j a v  a  2s  .  c  o m
protected void initUI(final ChooseByNamePopupComponent.Callback callback, final ModalityState modalityState,
        final boolean allowMultipleSelection) {
    myPreviouslyFocusedComponent = WindowManagerEx.getInstanceEx().getFocusedComponent(myProject);

    myActionListener = callback;
    myTextFieldPanel.setLayout(new BoxLayout(myTextFieldPanel, BoxLayout.Y_AXIS));

    final JPanel hBox = new JPanel();
    hBox.setLayout(new BoxLayout(hBox, BoxLayout.X_AXIS));

    JPanel caption2Tools = new JPanel(new BorderLayout());

    if (myModel.getPromptText() != null) {
        JLabel label = new JLabel(myModel.getPromptText());
        if (UIUtil.isUnderAquaLookAndFeel()) {
            label.setBorder(new CompoundBorder(new EmptyBorder(0, 9, 0, 0), label.getBorder()));
        }
        label.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
        caption2Tools.add(label, BorderLayout.WEST);
    }

    caption2Tools.add(hBox, BorderLayout.EAST);

    myCardContainer.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 4)); // space between checkbox and filter/show all in view buttons

    final String checkBoxName = myModel.getCheckBoxName();
    myCheckBox = new JCheckBox(checkBoxName != null ? checkBoxName + (myCheckBoxShortcut != null
            ? " (" + KeymapUtil.getShortcutsText(myCheckBoxShortcut.getShortcuts()) + ")"
            : "") : "");
    myCheckBox.setAlignmentX(SwingConstants.RIGHT);

    if (!SystemInfo.isMac) {
        myCheckBox.setBorder(null);
    }

    myCheckBox.setSelected(myModel.loadInitialCheckBoxState());

    if (checkBoxName == null) {
        myCheckBox.setVisible(false);
    }

    addCard(myCheckBox, CHECK_BOX_CARD);

    addCard(new HintLabel(myModel.getNotInMessage()), NOT_FOUND_IN_PROJECT_CARD);
    addCard(new HintLabel(IdeBundle.message("label.choosebyname.no.matches.found")), NOT_FOUND_CARD);
    JPanel searching = new JPanel(new BorderLayout(5, 0));
    searching.add(new AsyncProcessIcon("searching"), BorderLayout.WEST);
    searching.add(new HintLabel(IdeBundle.message("label.choosebyname.searching")), BorderLayout.CENTER);
    addCard(searching, SEARCHING_CARD);
    myCard.show(myCardContainer, CHECK_BOX_CARD);

    if (isCheckboxVisible()) {
        hBox.add(myCardContainer);
    }

    final DefaultActionGroup group = new DefaultActionGroup();
    group.add(new ShowFindUsagesAction() {
        @Override
        public PsiElement[][] getElements() {
            final Object[] objects = myListModel.toArray();
            final List<PsiElement> prefixMatchElements = new ArrayList<PsiElement>(objects.length);
            final List<PsiElement> nonPrefixMatchElements = new ArrayList<PsiElement>(objects.length);
            List<PsiElement> curElements = prefixMatchElements;
            for (Object object : objects) {
                if (object instanceof PsiElement) {
                    curElements.add((PsiElement) object);
                } else if (object instanceof DataProvider) {
                    final PsiElement psi = CommonDataKeys.PSI_ELEMENT.getData((DataProvider) object);
                    if (psi != null) {
                        curElements.add(psi);
                    }
                } else if (object == NON_PREFIX_SEPARATOR) {
                    curElements = nonPrefixMatchElements;
                }
            }
            return new PsiElement[][] { PsiUtilCore.toPsiElementArray(prefixMatchElements),
                    PsiUtilCore.toPsiElementArray(nonPrefixMatchElements) };
        }
    });
    final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN,
            group, true);
    actionToolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY);
    final JComponent toolbarComponent = actionToolbar.getComponent();
    toolbarComponent.setBorder(null);

    if (myToolArea == null) {
        myToolArea = new JLabel(EmptyIcon.create(1, 24));
    }
    hBox.add(myToolArea);
    hBox.add(toolbarComponent);

    myTextFieldPanel.add(caption2Tools);

    final ActionMap actionMap = new ActionMap();
    actionMap.setParent(myTextField.getActionMap());
    actionMap.put(DefaultEditorKit.copyAction, new AbstractAction() {
        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            if (myTextField.getSelectedText() != null) {
                actionMap.getParent().get(DefaultEditorKit.copyAction).actionPerformed(e);
                return;
            }
            final Object chosenElement = getChosenElement();
            if (chosenElement instanceof PsiElement) {
                CopyReferenceAction.doCopy((PsiElement) chosenElement, myProject);
            }
        }
    });
    myTextField.setActionMap(actionMap);

    myTextFieldPanel.add(myTextField);
    Font editorFont = getEditorFont();
    myTextField.setFont(editorFont);

    if (checkBoxName != null) {
        if (myCheckBox != null && myCheckBoxShortcut != null) {
            new AnAction("change goto check box", null, null) {
                @RequiredDispatchThread
                @Override
                public void actionPerformed(@NotNull AnActionEvent e) {
                    myCheckBox.setSelected(!myCheckBox.isSelected());
                }
            }.registerCustomShortcutSet(myCheckBoxShortcut, myTextField);
        }
    }

    if (isCloseByFocusLost()) {
        myTextField.addFocusListener(new FocusAdapter() {
            @Override
            public void focusLost(@NotNull final FocusEvent e) {
                cancelListUpdater(); // cancel thread as early as possible
                myHideAlarm.addRequest(new Runnable() {
                    @Override
                    public void run() {
                        JBPopup popup = JBPopupFactory.getInstance().getChildFocusedPopup(e.getComponent());
                        if (popup != null) {
                            popup.addListener(new JBPopupListener.Adapter() {
                                @Override
                                public void onClosed(@NotNull LightweightWindowEvent event) {
                                    if (event.isOk()) {
                                        hideHint();
                                    }
                                }
                            });
                        } else {
                            Component oppositeComponent = e.getOppositeComponent();
                            if (oppositeComponent == myCheckBox) {
                                IdeFocusManager.getInstance(myProject).requestFocus(myTextField, true);
                                return;
                            }
                            if (oppositeComponent != null && !(oppositeComponent instanceof JFrame)
                                    && myList.isShowing() && (oppositeComponent == myList
                                            || SwingUtilities.isDescendingFrom(myList, oppositeComponent))) {
                                IdeFocusManager.getInstance(myProject).requestFocus(myTextField, true);// Otherwise me may skip some KeyEvents
                                return;
                            }

                            if (oppositeComponent != null) {
                                ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
                                ToolWindow toolWindow = toolWindowManager
                                        .getToolWindow(toolWindowManager.getActiveToolWindowId());
                                if (toolWindow != null) {
                                    JComponent toolWindowComponent = toolWindow.getComponent();
                                    if (SwingUtilities.isDescendingFrom(oppositeComponent,
                                            toolWindowComponent)) {
                                        return; // Allow toolwindows to gain focus (used by QuickDoc shown in a toolwindow)
                                    }
                                }
                            }

                            EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
                            if (queue instanceof IdeEventQueue) {
                                if (!((IdeEventQueue) queue).wasRootRecentlyClicked(oppositeComponent)) {
                                    Component root = SwingUtilities.getRoot(myTextField);
                                    if (root != null && root.isShowing()) {
                                        IdeFocusManager.getInstance(myProject).requestFocus(myTextField, true);
                                        return;
                                    }
                                }
                            }

                            hideHint();
                        }
                    }
                }, 5);
            }
        });
    }

    if (myCheckBox != null) {
        myCheckBox.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(@NotNull ItemEvent e) {
                rebuildList(false);
            }
        });
        myCheckBox.setFocusable(false);
    }

    myTextField.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent e) {
            clearPostponedOkAction(false);
            rebuildList(false);
        }
    });

    final Set<KeyStroke> upShortcuts = getShortcuts(IdeActions.ACTION_EDITOR_MOVE_CARET_UP);
    final Set<KeyStroke> downShortcuts = getShortcuts(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN);
    myTextField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(@NotNull KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER && (e.getModifiers() & InputEvent.SHIFT_MASK) != 0) {
                myClosedByShiftEnter = true;
                close(true);
            }
            if (!myListScrollPane.isVisible()) {
                return;
            }
            final int keyCode;

            // Add support for user-defined 'caret up/down' shortcuts.
            KeyStroke stroke = KeyStroke.getKeyStrokeForEvent(e);
            if (upShortcuts.contains(stroke)) {
                keyCode = KeyEvent.VK_UP;
            } else if (downShortcuts.contains(stroke)) {
                keyCode = KeyEvent.VK_DOWN;
            } else {
                keyCode = e.getKeyCode();
            }
            switch (keyCode) {
            case KeyEvent.VK_DOWN:
                ListScrollingUtil.moveDown(myList, e.getModifiersEx());
                break;
            case KeyEvent.VK_UP:
                ListScrollingUtil.moveUp(myList, e.getModifiersEx());
                break;
            case KeyEvent.VK_PAGE_UP:
                ListScrollingUtil.movePageUp(myList);
                break;
            case KeyEvent.VK_PAGE_DOWN:
                ListScrollingUtil.movePageDown(myList);
                break;
            case KeyEvent.VK_TAB:
                close(true);
                break;
            case KeyEvent.VK_ENTER:
                if (myList.getSelectedValue() == EXTRA_ELEM) {
                    myMaximumListSizeLimit += myListSizeIncreasing;
                    rebuildList(myList.getSelectedIndex(), myRebuildDelay, ModalityState.current(), null);
                    e.consume();
                }
                break;
            }

            if (myList.getSelectedValue() == NON_PREFIX_SEPARATOR) {
                if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_PAGE_UP) {
                    ListScrollingUtil.moveUp(myList, e.getModifiersEx());
                } else {
                    ListScrollingUtil.moveDown(myList, e.getModifiersEx());
                }
            }
        }
    });

    myTextField.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(@NotNull ActionEvent actionEvent) {
            doClose(true);
        }
    });

    myList.setFocusable(false);
    myList.setSelectionMode(allowMultipleSelection ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
            : ListSelectionModel.SINGLE_SELECTION);
    new ClickListener() {
        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            if (!myTextField.hasFocus()) {
                IdeFocusManager.getInstance(myProject).requestFocus(myTextField, true);
            }

            if (clickCount == 2) {
                int selectedIndex = myList.getSelectedIndex();
                Rectangle selectedCellBounds = myList.getCellBounds(selectedIndex, selectedIndex);

                if (selectedCellBounds != null && selectedCellBounds.contains(e.getPoint())) { // Otherwise it was reselected in the selection listener
                    if (myList.getSelectedValue() == EXTRA_ELEM) {
                        myMaximumListSizeLimit += myListSizeIncreasing;
                        rebuildList(selectedIndex, myRebuildDelay, ModalityState.current(), null);
                    } else {
                        doClose(true);
                    }
                }
                return true;
            }

            return false;
        }
    }.installOn(myList);

    myList.setCellRenderer(myModel.getListCellRenderer());
    myList.setFont(editorFont);

    myList.addListSelectionListener(new ListSelectionListener() {
        private int myPreviousSelectionIndex = 0;

        @Override
        public void valueChanged(@NotNull ListSelectionEvent e) {
            if (myList.getSelectedValue() != NON_PREFIX_SEPARATOR) {
                myPreviousSelectionIndex = myList.getSelectedIndex();
                chosenElementMightChange();
                updateDocumentation();
            } else if (allowMultipleSelection) {
                myList.setSelectedIndex(myPreviousSelectionIndex);
            }
        }
    });

    myListScrollPane = ScrollPaneFactory.createScrollPane(myList);
    myListScrollPane.setViewportBorder(new EmptyBorder(0, 0, 0, 0));

    myTextFieldPanel.setBorder(new EmptyBorder(2, 2, 2, 2));

    showTextFieldPanel();

    myInitialized = true;

    if (modalityState != null) {
        rebuildList(myInitialIndex, 0, modalityState, null);
    }
}

From source file:com.intellij.translation.TranslationManager.java

License:Apache License

public TranslationManager(final Project project, ActionManager manager) {
    super(project);

    myActionManager = manager;// w ww  .j  a v  a2 s .c  om
    final AnActionListener actionListener = new AnActionListener() {
        @Override
        public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
            final JBPopup hint = getTranslationHint();
            if (hint != null) {
                if (action instanceof HintManagerImpl.ActionToIgnore) {
                    ((AbstractPopup) hint).focusPreferredComponent();
                    return;
                }
                if (action instanceof ScrollingUtil.ListScrollAction)
                    return;
                if (action == myActionManager.getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN))
                    return;
                if (action == myActionManager.getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP))
                    return;
                if (action == myActionManager.getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_PAGE_DOWN))
                    return;
                if (action == myActionManager.getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_PAGE_UP))
                    return;
                if (TranslationConstants.TRANSLATION_INPLACE_SETTINGS.equals(event.getPlace()))
                    return;
                if (action instanceof BaseNavigateToSourceAction)
                    return;
                closeTranslationHint();
            }
        }

        @Override
        public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
        }

        @Override
        public void beforeEditorTyping(char c, DataContext dataContext) {
            final JBPopup hint = getTranslationHint();
            // todo when typing
            if (hint != null) {
                hint.cancel();
            }
        }
    };

    myActionManager.addAnActionListener(actionListener, project);
    myUpdateTranslationAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, myProject);
}

From source file:com.intellij.uiDesigner.designSurface.GlassLayer.java

License:Apache License

public GlassLayer(final GuiEditor editor) {
    myEditor = editor;/*from   w w  w  .java  2s .co m*/
    enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);

    registerKeyboardAction(new MoveSelectionToRightAction(myEditor, false, false),
            IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT);
    registerKeyboardAction(new MoveSelectionToLeftAction(myEditor, false, false),
            IdeActions.ACTION_EDITOR_MOVE_CARET_LEFT);
    registerKeyboardAction(new MoveSelectionToUpAction(myEditor, false, false),
            IdeActions.ACTION_EDITOR_MOVE_CARET_UP);
    registerKeyboardAction(new MoveSelectionToDownAction(myEditor, false, false),
            IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN);

    registerKeyboardAction(new MoveSelectionToRightAction(myEditor, true, false), "EditorRightWithSelection");
    registerKeyboardAction(new MoveSelectionToLeftAction(myEditor, true, false), "EditorLeftWithSelection");
    registerKeyboardAction(new MoveSelectionToUpAction(myEditor, true, false), "EditorUpWithSelection");
    registerKeyboardAction(new MoveSelectionToDownAction(myEditor, true, false), "EditorDownWithSelection");

    registerKeyboardAction(new MoveSelectionToRightAction(myEditor, false, true), "EditorLineEnd");
    registerKeyboardAction(new MoveSelectionToLeftAction(myEditor, false, true), "EditorLineStart");
    registerKeyboardAction(new MoveSelectionToUpAction(myEditor, false, true), "EditorPageUp");
    registerKeyboardAction(new MoveSelectionToDownAction(myEditor, false, true), "EditorPageDown");

    registerKeyboardAction(new MoveSelectionToRightAction(myEditor, true, true), "EditorLineEndWithSelection");
    registerKeyboardAction(new MoveSelectionToLeftAction(myEditor, true, true), "EditorLineStartWithSelection");
    registerKeyboardAction(new MoveSelectionToUpAction(myEditor, true, true), "EditorPageUpWithSelection");
    registerKeyboardAction(new MoveSelectionToDownAction(myEditor, true, true), "EditorPageDownWithSelection");

    registerKeyboardAction(new MoveComponentAction(-1, 0, 0, 0), "EditorScrollUp");
    registerKeyboardAction(new MoveComponentAction(1, 0, 0, 0), "EditorScrollDown");
    registerKeyboardAction(new MoveComponentAction(0, -1, 0, 0), "EditorPreviousWord");
    registerKeyboardAction(new MoveComponentAction(0, 1, 0, 0), "EditorNextWord");

    registerKeyboardAction(new MoveComponentAction(0, 0, -1, 0), IdeActions.ACTION_MOVE_STATEMENT_UP_ACTION);
    registerKeyboardAction(new MoveComponentAction(0, 0, 1, 0), IdeActions.ACTION_MOVE_STATEMENT_DOWN_ACTION);
    registerKeyboardAction(new MoveComponentAction(0, 0, 0, -1), "EditorPreviousWordWithSelection");
    registerKeyboardAction(new MoveComponentAction(0, 0, 0, 1), "EditorNextWordWithSelection");

    registerKeyboardAction(new SelectAllComponentsAction(), "$SelectAll");

    // F2 should start inplace editing
    final StartInplaceEditingAction startInplaceEditingAction = new StartInplaceEditingAction(editor);
    startInplaceEditingAction
            .registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0)), this);
}