Search in sources :

Example 1 with EditorTextField

use of com.intellij.ui.EditorTextField in project intellij-community by JetBrains.

the class PyDataViewerPanel method createEditorField.

@NotNull
private EditorTextField createEditorField() {
    return new EditorTextField(EditorFactory.getInstance().createDocument(""), myProject, PythonFileType.INSTANCE, false, true) {

        @Override
        protected EditorEx createEditor() {
            EditorEx editor = super.createEditor();
            editor.getContentComponent().addKeyListener(new KeyAdapter() {

                @Override
                public void keyPressed(KeyEvent e) {
                    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                        apply(mySliceTextField.getText());
                    }
                }
            });
            return editor;
        }
    };
}
Also used : KeyEvent(java.awt.event.KeyEvent) EditorEx(com.intellij.openapi.editor.ex.EditorEx) EditorTextField(com.intellij.ui.EditorTextField) KeyAdapter(java.awt.event.KeyAdapter) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with EditorTextField

use of com.intellij.ui.EditorTextField in project intellij-community by JetBrains.

the class EditorTextFieldControl method navigate.

@Override
public void navigate(final DomElement element) {
    final EditorTextField field = getEditorTextField(getComponent());
    SwingUtilities.invokeLater(() -> {
        IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
            IdeFocusManager.getGlobalInstance().requestFocus(field, true);
        });
        field.selectAll();
    });
}
Also used : EditorTextField(com.intellij.ui.EditorTextField)

Example 3 with EditorTextField

use of com.intellij.ui.EditorTextField in project intellij-community by JetBrains.

the class EditorTextFieldControl method createMainComponent.

@Override
protected T createMainComponent(T boundedComponent) {
    final Project project = getProject();
    boundedComponent = createMainComponent(boundedComponent, project);
    final EditorTextField editorTextField = getEditorTextField(boundedComponent);
    editorTextField.setSupplementary(true);
    editorTextField.getDocument().addDocumentListener(myListener);
    return boundedComponent;
}
Also used : Project(com.intellij.openapi.project.Project) EditorTextField(com.intellij.ui.EditorTextField)

Example 4 with EditorTextField

use of com.intellij.ui.EditorTextField in project intellij-community by JetBrains.

the class EditorTextFieldControl method updateComponent.

@Override
protected void updateComponent() {
    final DomElement domElement = getDomElement();
    if (domElement == null || !domElement.isValid())
        return;
    final EditorTextField textField = getEditorTextField(getComponent());
    final Project project = getProject();
    ApplicationManager.getApplication().invokeLater(() -> {
        if (!project.isOpen())
            return;
        if (!getDomWrapper().isValid())
            return;
        final DomElement domElement1 = getDomElement();
        if (domElement1 == null || !domElement1.isValid())
            return;
        final DomElementAnnotationsManager manager = DomElementAnnotationsManager.getInstance(project);
        final DomElementsProblemsHolder holder = manager.getCachedProblemHolder(domElement1);
        final List<DomElementProblemDescriptor> errorProblems = holder.getProblems(domElement1);
        final List<DomElementProblemDescriptor> warningProblems = new ArrayList<>(holder.getProblems(domElement1, true, HighlightSeverity.WARNING));
        warningProblems.removeAll(errorProblems);
        Color background = getDefaultBackground();
        if (errorProblems.size() > 0 && textField.getText().trim().length() == 0) {
            background = getErrorBackground();
        } else if (warningProblems.size() > 0) {
            background = getWarningBackground();
        }
        final Editor editor = textField.getEditor();
        if (editor != null) {
            final MarkupModel markupModel = editor.getMarkupModel();
            markupModel.removeAllHighlighters();
            if (!errorProblems.isEmpty() && editor.getDocument().getLineCount() > 0) {
                final TextAttributes attributes = SimpleTextAttributes.ERROR_ATTRIBUTES.toTextAttributes();
                attributes.setEffectType(EffectType.WAVE_UNDERSCORE);
                attributes.setEffectColor(attributes.getForegroundColor());
                markupModel.addLineHighlighter(0, 0, attributes);
                editor.getContentComponent().setToolTipText(errorProblems.get(0).getDescriptionTemplate());
            }
        }
        textField.setBackground(background);
    });
}
Also used : Project(com.intellij.openapi.project.Project) DomElementsProblemsHolder(com.intellij.util.xml.highlighting.DomElementsProblemsHolder) DomElement(com.intellij.util.xml.DomElement) EditorTextField(com.intellij.ui.EditorTextField) DomElementProblemDescriptor(com.intellij.util.xml.highlighting.DomElementProblemDescriptor) ArrayList(java.util.ArrayList) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Editor(com.intellij.openapi.editor.Editor) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) DomElementAnnotationsManager(com.intellij.util.xml.highlighting.DomElementAnnotationsManager)

Example 5 with EditorTextField

use of com.intellij.ui.EditorTextField in project intellij-community by JetBrains.

the class PyIntroduceDialog method setUpNameComboBox.

private void setUpNameComboBox(Collection<String> possibleNames) {
    final EditorComboBoxEditor comboEditor = new StringComboboxEditor(myProject, PythonFileType.INSTANCE, myNameComboBox);
    myNameComboBox.setEditor(comboEditor);
    myNameComboBox.setRenderer(new EditorComboBoxRenderer(comboEditor));
    myNameComboBox.setEditable(true);
    myNameComboBox.setMaximumRowCount(8);
    myNameComboBox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            updateControls();
        }
    });
    ((EditorTextField) myNameComboBox.getEditor().getEditorComponent()).addDocumentListener(new DocumentListener() {

        public void beforeDocumentChange(DocumentEvent event) {
        }

        public void documentChanged(DocumentEvent event) {
            updateControls();
        }
    });
    myContentPane.registerKeyboardAction(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                IdeFocusManager.getGlobalInstance().requestFocus(myNameComboBox, true);
            });
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.ALT_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
    for (String possibleName : possibleNames) {
        myNameComboBox.addItem(possibleName);
    }
}
Also used : EditorComboBoxEditor(com.intellij.ui.EditorComboBoxEditor) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) StringComboboxEditor(com.intellij.ui.StringComboboxEditor) EditorTextField(com.intellij.ui.EditorTextField) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) EditorComboBoxRenderer(com.intellij.ui.EditorComboBoxRenderer)

Aggregations

EditorTextField (com.intellij.ui.EditorTextField)52 Document (com.intellij.openapi.editor.Document)12 NotNull (org.jetbrains.annotations.NotNull)12 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)9 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)7 EditorEx (com.intellij.openapi.editor.ex.EditorEx)6 Project (com.intellij.openapi.project.Project)5 EditorComboBoxEditor (com.intellij.ui.EditorComboBoxEditor)5 EditorComboBoxRenderer (com.intellij.ui.EditorComboBoxRenderer)5 StringComboboxEditor (com.intellij.ui.StringComboboxEditor)5 ComboBox (com.intellij.openapi.ui.ComboBox)4 Editor (com.intellij.openapi.editor.Editor)3 ExternalSystemUiAware (com.intellij.openapi.externalSystem.ExternalSystemUiAware)3 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)3 FixedSizeButton (com.intellij.openapi.ui.FixedSizeButton)3 VerticalFlowLayout (com.intellij.openapi.ui.VerticalFlowLayout)3 PsiFile (com.intellij.psi.PsiFile)3 LanguageTextField (com.intellij.ui.LanguageTextField)3 JBLabel (com.intellij.ui.components.JBLabel)3 Nullable (org.jetbrains.annotations.Nullable)3