Search in sources :

Example 11 with JTextComponent

use of javax.swing.text.JTextComponent in project intellij-community by JetBrains.

the class SearchReplaceComponent method updateTextComponent.

private boolean updateTextComponent(boolean search) {
    JTextComponent oldComponent = search ? mySearchTextComponent : myReplaceTextComponent;
    if (oldComponent != null)
        return false;
    final MyTextComponentWrapper wrapper = search ? mySearchFieldWrapper : myReplaceFieldWrapper;
    final JTextComponent textComponent;
    SearchTextArea textArea = new SearchTextArea(search);
    textComponent = textArea.getTextArea();
    ((JTextArea) textComponent).setRows(isMultiline() ? 2 : 1);
    wrapper.setContent(textArea);
    UIUtil.addUndoRedoActions(textComponent);
    if (UIUtil.isUnderWindowsLookAndFeel()) {
        textComponent.setFont(UIManager.getFont("TextField.font"));
    } else {
        Utils.setSmallerFont(textComponent);
    }
    textComponent.putClientProperty("AuxEditorComponent", Boolean.TRUE);
    textComponent.setBackground(UIUtil.getTextFieldBackground());
    textComponent.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(final FocusEvent e) {
            textComponent.repaint();
        }

        @Override
        public void focusLost(final FocusEvent e) {
            textComponent.repaint();
        }
    });
    installCloseOnEscapeAction(textComponent);
    return true;
}
Also used : JTextComponent(javax.swing.text.JTextComponent)

Example 12 with JTextComponent

use of javax.swing.text.JTextComponent in project intellij-community by JetBrains.

the class Messages method showInputDialog.

@Nullable
public static String showInputDialog(Project project, @Nls String message, @Nls(capitalization = Nls.Capitalization.Title) String title, @Nullable Icon icon, @Nullable String initialValue, @Nullable InputValidator validator, @Nullable TextRange selection) {
    if (isApplicationInUnitTestOrHeadless()) {
        return ourTestInputImplementation.show(message, validator);
    } else {
        InputDialog dialog = new InputDialog(project, message, title, icon, initialValue, validator);
        final JTextComponent field = dialog.getTextField();
        if (selection != null) {
            // set custom selection
            field.select(selection.getStartOffset(), selection.getEndOffset());
        } else {
            // reset selection
            final int length = field.getDocument().getLength();
            field.select(length, length);
        }
        field.putClientProperty(DialogWrapperPeer.HAVE_INITIAL_SELECTION, true);
        dialog.show();
        return dialog.getInputString();
    }
}
Also used : JTextComponent(javax.swing.text.JTextComponent)

Example 13 with JTextComponent

use of javax.swing.text.JTextComponent in project intellij-community by JetBrains.

the class FindDialog method initCombobox.

private void initCombobox(@NotNull final ComboBox comboBox) {
    comboBox.setEditable(true);
    comboBox.setMaximumRowCount(8);
    comboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            validateFindButton();
        }
    });
    final Component editorComponent = comboBox.getEditor().getEditorComponent();
    if (editorComponent instanceof EditorTextField) {
        final EditorTextField etf = (EditorTextField) editorComponent;
        DocumentAdapter listener = new DocumentAdapter() {

            @Override
            public void documentChanged(final DocumentEvent e) {
                handleComboBoxValueChanged(comboBox);
            }
        };
        etf.addDocumentListener(listener);
        myComboBoxListeners.put(etf, listener);
    } else {
        if (editorComponent instanceof JTextComponent) {
            final javax.swing.text.Document document = ((JTextComponent) editorComponent).getDocument();
            final com.intellij.ui.DocumentAdapter documentAdapter = new com.intellij.ui.DocumentAdapter() {

                @Override
                protected void textChanged(javax.swing.event.DocumentEvent e) {
                    handleAnyComboBoxValueChanged(comboBox);
                }
            };
            document.addDocumentListener(documentAdapter);
            Disposer.register(myDisposable, new Disposable() {

                @Override
                public void dispose() {
                    document.removeDocumentListener(documentAdapter);
                }
            });
        } else {
            assert false;
        }
    }
    if (!myHelper.getModel().isReplaceState()) {
        makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "choosePrevious", () -> {
            int row = myResultsPreviewTable.getSelectedRow();
            if (row > 0)
                myResultsPreviewTable.setRowSelectionInterval(row - 1, row - 1);
            TableUtil.scrollSelectionToVisible(myResultsPreviewTable);
        });
        makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "chooseNext", () -> {
            int row = myResultsPreviewTable.getSelectedRow();
            if (row >= -1 && row + 1 < myResultsPreviewTable.getRowCount()) {
                myResultsPreviewTable.setRowSelectionInterval(row + 1, row + 1);
                TableUtil.scrollSelectionToVisible(myResultsPreviewTable);
            }
        });
        makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "scrollUp", () -> {
            ScrollingUtil.movePageUp(myResultsPreviewTable);
        });
        makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "scrollDown", () -> {
            ScrollingUtil.movePageDown(myResultsPreviewTable);
        });
        AnAction action = new AnAction() {

            @Override
            public void actionPerformed(AnActionEvent e) {
                if (isResultsPreviewTabActive()) {
                    navigateToSelectedUsage(myResultsPreviewTable);
                }
            }
        };
        action.registerCustomShortcutSet(CommonShortcuts.getEditSource(), comboBox, myDisposable);
        new AnAction() {

            @Override
            public void actionPerformed(AnActionEvent e) {
                if (!isResultsPreviewTabActive() || myResultsPreviewTable.getSelectedRowCount() == 0)
                    doOKAction();
                else
                    action.actionPerformed(e);
            }
        }.registerCustomShortcutSet(CommonShortcuts.ENTER, comboBox, myDisposable);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) JTextComponent(javax.swing.text.JTextComponent) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) javax.swing(javax.swing) com.intellij.ui(com.intellij.ui) com.intellij.openapi.ui(com.intellij.openapi.ui) JTextComponent(javax.swing.text.JTextComponent)

Example 14 with JTextComponent

use of javax.swing.text.JTextComponent in project intellij-community by JetBrains.

the class ScrollingUtil method installActions.

public static void installActions(final JTable table, final boolean cycleScrolling, JComponent focusParent) {
    ActionMap actionMap = table.getActionMap();
    actionMap.put(SCROLLUP_ACTION_ID, new MoveAction(SCROLLUP_ACTION_ID, table, cycleScrolling));
    actionMap.put(SCROLLDOWN_ACTION_ID, new MoveAction(SCROLLDOWN_ACTION_ID, table, cycleScrolling));
    actionMap.put(SELECT_PREVIOUS_ROW_ACTION_ID, new MoveAction(SELECT_PREVIOUS_ROW_ACTION_ID, table, cycleScrolling));
    actionMap.put(SELECT_NEXT_ROW_ACTION_ID, new MoveAction(SELECT_NEXT_ROW_ACTION_ID, table, cycleScrolling));
    actionMap.put(SELECT_LAST_ROW_ACTION_ID, new MoveAction(SELECT_LAST_ROW_ACTION_ID, table, cycleScrolling));
    actionMap.put(SELECT_FIRST_ROW_ACTION_ID, new MoveAction(SELECT_FIRST_ROW_ACTION_ID, table, cycleScrolling));
    maybeInstallDefaultShortcuts(table);
    JComponent target = focusParent == null ? table : focusParent;
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            moveHome(table);
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)), table);
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            moveEnd(table);
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)), table);
    if (!(focusParent instanceof JTextComponent)) {
        new MyScrollingAction(table) {

            @Override
            public void actionPerformed(AnActionEvent e) {
                moveHome(table);
            }
        }.registerCustomShortcutSet(CommonShortcuts.getMoveHome(), target);
        new MyScrollingAction(table) {

            @Override
            public void actionPerformed(AnActionEvent e) {
                moveEnd(table);
            }
        }.registerCustomShortcutSet(CommonShortcuts.getMoveEnd(), target);
    }
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            moveDown(table, e.getModifiers(), cycleScrolling);
        }
    }.registerCustomShortcutSet(CommonShortcuts.getMoveDown(), target);
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            moveUp(table, e.getModifiers(), cycleScrolling);
        }
    }.registerCustomShortcutSet(CommonShortcuts.getMoveUp(), target);
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            movePageUp(table);
        }
    }.registerCustomShortcutSet(CommonShortcuts.getMovePageUp(), target);
    new MyScrollingAction(table) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            movePageDown(table);
        }
    }.registerCustomShortcutSet(CommonShortcuts.getMovePageDown(), target);
}
Also used : CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) JTextComponent(javax.swing.text.JTextComponent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent)

Example 15 with JTextComponent

use of javax.swing.text.JTextComponent in project intellij-community by JetBrains.

the class JBList method installDefaultCopyAction.

private void installDefaultCopyAction() {
    final Action copy = getActionMap().get("copy");
    if (copy == null || copy instanceof UIResource) {
        Action newCopy = new AbstractAction() {

            @Override
            public boolean isEnabled() {
                return getSelectedIndex() != -1;
            }

            @Override
            public void actionPerformed(ActionEvent e) {
                ArrayList<String> selected = new ArrayList<>();
                JBList list = JBList.this;
                ListCellRenderer renderer = list.getCellRenderer();
                if (renderer != null) {
                    for (int index : getSelectedIndices()) {
                        Object value = list.getModel().getElementAt(index);
                        //noinspection unchecked
                        Component c = renderer.getListCellRendererComponent(list, value, index, true, true);
                        SimpleColoredComponent coloredComponent = null;
                        if (c instanceof JComponent) {
                            coloredComponent = UIUtil.findComponentOfType((JComponent) c, SimpleColoredComponent.class);
                        }
                        if (coloredComponent != null) {
                            selected.add(coloredComponent.toString());
                        } else if (c instanceof JTextComponent) {
                            selected.add(((JTextComponent) c).getText());
                        } else if (value != null) {
                            selected.add(value.toString());
                        }
                    }
                }
                if (selected.size() > 0) {
                    String text = StringUtil.join(selected, " ");
                    CopyPasteManager.getInstance().setContents(new StringSelection(text));
                }
            }
        };
        getActionMap().put("copy", newCopy);
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) JTextComponent(javax.swing.text.JTextComponent) UIResource(javax.swing.plaf.UIResource) StringSelection(java.awt.datatransfer.StringSelection) JTextComponent(javax.swing.text.JTextComponent)

Aggregations

JTextComponent (javax.swing.text.JTextComponent)82 NotNull (org.jetbrains.annotations.NotNull)9 Component (java.awt.Component)6 DocumentEvent (javax.swing.event.DocumentEvent)6 DocumentAdapter (com.intellij.ui.DocumentAdapter)5 Disposable (com.intellij.openapi.Disposable)3 JButton (javax.swing.JButton)3 Project (com.intellij.openapi.project.Project)2 GraphicsConfig (com.intellij.openapi.ui.GraphicsConfig)2 FocusEvent (java.awt.event.FocusEvent)2 KeyEvent (java.awt.event.KeyEvent)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Accessible (javax.accessibility.Accessible)2 Action (javax.swing.Action)2 JComboBox (javax.swing.JComboBox)2 JFrame (javax.swing.JFrame)2 JLabel (javax.swing.JLabel)2 JMenuItem (javax.swing.JMenuItem)2 JPopupMenu (javax.swing.JPopupMenu)2