Search in sources :

Example 11 with EditorTextField

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

the class CodeFragmentTableCellEditorBase method createEditorField.

protected EditorTextField createEditorField(Document document) {
    EditorTextField field = new EditorTextField(document, myProject, myFileType) {

        @Override
        protected boolean shouldHaveBorder() {
            return false;
        }
    };
    field.setBorder(new EmptyBorder(1, 1, 1, 1));
    return field;
}
Also used : EditorTextField(com.intellij.ui.EditorTextField) EmptyBorder(javax.swing.border.EmptyBorder)

Example 12 with EditorTextField

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

the class CodeFragmentTableCellRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, final boolean hasFocus, int row, int column) {
    PsiCodeFragment codeFragment = (PsiCodeFragment) value;
    final EditorTextField editorTextField;
    Document document = null;
    if (codeFragment != null) {
        document = PsiDocumentManager.getInstance(myProject).getDocument(codeFragment);
        editorTextField = new EditorTextField(document, myProject, myFileType) {

            @Override
            protected boolean shouldHaveBorder() {
                return false;
            }
        };
    } else {
        editorTextField = new EditorTextField("", myProject, myFileType) {

            @Override
            protected boolean shouldHaveBorder() {
                return false;
            }
        };
    }
    if (!table.isShowing()) {
        editorTextField.ensureWillComputePreferredSize();
    }
    editorTextField.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
    editorTextField.setBorder((hasFocus || isSelected) ? BorderFactory.createLineBorder(table.getSelectionBackground()) : IdeBorderFactory.createEmptyBorder(1));
    if (isSelected && document != null) {
        final Color bg = table.getSelectionBackground();
        final Color fg = table.getSelectionForeground();
        editorTextField.setBackground(bg);
        editorTextField.setForeground(fg);
        editorTextField.setAsRendererWithSelection(bg, fg);
    }
    return editorTextField;
}
Also used : EditorTextField(com.intellij.ui.EditorTextField) PsiCodeFragment(com.intellij.psi.PsiCodeFragment) Document(com.intellij.openapi.editor.Document)

Example 13 with EditorTextField

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

the class NameSuggestionsField method createTextFieldForName.

private JComponent createTextFieldForName(String[] nameSuggestions, FileType fileType) {
    final String text;
    if (nameSuggestions != null && nameSuggestions.length > 0 && nameSuggestions[0] != null) {
        text = nameSuggestions[0];
    } else {
        text = "";
    }
    EditorTextField field = new EditorTextField(text, myProject, fileType);
    field.selectAll();
    return field;
}
Also used : EditorTextField(com.intellij.ui.EditorTextField)

Example 14 with EditorTextField

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

the class StringTableCellEditor method getTableCellEditorComponent.

@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    final EditorTextField editorTextField = new EditorTextField((String) value, myProject, StdFileTypes.JAVA) {

        @Override
        protected boolean shouldHaveBorder() {
            return false;
        }
    };
    myDocument = editorTextField.getDocument();
    if (myDocument != null) {
        for (DocumentListener listener : myListeners) {
            editorTextField.addDocumentListener(listener);
        }
    }
    return editorTextField;
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) EditorTextField(com.intellij.ui.EditorTextField)

Example 15 with EditorTextField

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

the class PsiClassTableCellEditor method getTableCellEditorComponent.

public final Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    final Document document = JavaReferenceEditorUtil.createDocument(value == null ? "" : (String) value, myProject, true);
    myEditor = new EditorTextField(document, myProject, StdFileTypes.JAVA) {

        protected boolean shouldHaveBorder() {
            return false;
        }

        public void addNotify() {
            super.addNotify();
            final JComponent editorComponent = getEditor().getContentComponent();
            editorComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ENTER");
            editorComponent.getActionMap().put("ENTER", new AbstractAction() {

                public void actionPerformed(ActionEvent e) {
                    stopCellEditing();
                }
            });
        }
    };
    final JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(myEditor);
    final FixedSizeButton button = new FixedSizeButton(myEditor);
    panel.add(button, BorderLayout.EAST);
    button.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            TreeClassChooser chooser = TreeClassChooserFactory.getInstance(myProject).createInheritanceClassChooser(UIBundle.message("choose.class"), mySearchScope, null, true, true, Conditions.alwaysTrue());
            chooser.showDialog();
            final PsiClass psiClass = chooser.getSelected();
            if (psiClass != null) {
                myEditor.setText(psiClass.getQualifiedName());
            }
        }
    });
    panel.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
            if (!e.isTemporary() && myEditor != null) {
                IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                    IdeFocusManager.getGlobalInstance().requestFocus(myEditor, true);
                });
            }
        }

        public void focusLost(FocusEvent e) {
        }
    });
    myEditor.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
        }

        public void focusLost(FocusEvent e) {
            if (!e.isTemporary()) {
                stopCellEditing();
            }
        }
    });
    return panel;
}
Also used : TreeClassChooser(com.intellij.ide.util.TreeClassChooser) PsiClass(com.intellij.psi.PsiClass) Document(com.intellij.openapi.editor.Document) EditorTextField(com.intellij.ui.EditorTextField) FixedSizeButton(com.intellij.openapi.ui.FixedSizeButton)

Aggregations

EditorTextField (com.intellij.ui.EditorTextField)47 Document (com.intellij.openapi.editor.Document)11 NotNull (org.jetbrains.annotations.NotNull)11 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)9 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)7 EditorEx (com.intellij.openapi.editor.ex.EditorEx)5 EditorComboBoxEditor (com.intellij.ui.EditorComboBoxEditor)5 EditorComboBoxRenderer (com.intellij.ui.EditorComboBoxRenderer)5 StringComboboxEditor (com.intellij.ui.StringComboboxEditor)5 JBLabel (com.intellij.ui.components.JBLabel)4 Editor (com.intellij.openapi.editor.Editor)3 DocumentListener (com.intellij.openapi.editor.event.DocumentListener)3 ExternalSystemUiAware (com.intellij.openapi.externalSystem.ExternalSystemUiAware)3 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)3 Project (com.intellij.openapi.project.Project)3 ComboBox (com.intellij.openapi.ui.ComboBox)3 FixedSizeButton (com.intellij.openapi.ui.FixedSizeButton)3 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)2 InlayParameterHintsProvider (com.intellij.codeInsight.hints.InlayParameterHintsProvider)2 Language (com.intellij.lang.Language)2