Search in sources :

Example 46 with EditorTextField

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

the class TextControl method createMainComponent.

@Override
protected TextPanel createMainComponent(TextPanel boundedComponent, final Project project) {
    if (boundedComponent == null) {
        boundedComponent = new TextPanel();
    }
    boundedComponent.removeAll();
    final Function<String, Document> factory = s -> PsiDocumentManager.getInstance(project).getDocument(PsiFileFactory.getInstance(project).createFileFromText("a.txt", PlainTextLanguage.INSTANCE, "", true, false));
    final TextPanel boundedComponent1 = boundedComponent;
    final EditorTextField editorTextField = new EditorTextField(factory.fun(""), project, FileTypes.PLAIN_TEXT) {

        @Override
        protected EditorEx createEditor() {
            final EditorEx editor = super.createEditor();
            return boundedComponent1 instanceof MultiLineTextPanel ? makeBigEditor(editor, ((MultiLineTextPanel) boundedComponent1).getRowCount()) : editor;
        }

        @Override
        protected boolean isOneLineMode() {
            return false;
        }
    };
    if (boundedComponent instanceof BigTextPanel) {
        final ReferenceEditorWithBrowseButton editor = new ReferenceEditorWithBrowseButton(null, editorTextField, factory);
        boundedComponent.add(editor);
        editor.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                EditorTextField textArea = new EditorTextField(editorTextField.getDocument(), project, FileTypes.PLAIN_TEXT) {

                    @Override
                    protected EditorEx createEditor() {
                        final EditorEx editor = super.createEditor();
                        editor.setEmbeddedIntoDialogWrapper(true);
                        return makeBigEditor(editor, 5);
                    }

                    @Override
                    protected boolean isOneLineMode() {
                        return false;
                    }
                };
                DialogBuilder builder = new DialogBuilder(project);
                builder.setDimensionServiceKey("TextControl");
                builder.setCenterPanel(textArea);
                builder.setPreferredFocusComponent(textArea);
                builder.setTitle(UIBundle.message("big.text.control.window.title"));
                builder.addCloseButton();
                builder.show();
            }
        });
        return boundedComponent;
    }
    boundedComponent.add(editorTextField);
    return boundedComponent;
}
Also used : EditorTextField(com.intellij.ui.EditorTextField) PsiFileFactory(com.intellij.psi.PsiFileFactory) ActionListener(java.awt.event.ActionListener) Document(com.intellij.openapi.editor.Document) ActionEvent(java.awt.event.ActionEvent) java.awt(java.awt) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) ReferenceEditorWithBrowseButton(com.intellij.ui.ReferenceEditorWithBrowseButton) Function(com.intellij.util.Function) FileTypes(com.intellij.openapi.fileTypes.FileTypes) Project(com.intellij.openapi.project.Project) EditorEx(com.intellij.openapi.editor.ex.EditorEx) UIBundle(com.intellij.ui.UIBundle) NotNull(org.jetbrains.annotations.NotNull) PlainTextLanguage(com.intellij.openapi.fileTypes.PlainTextLanguage) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) javax.swing(javax.swing) EditorEx(com.intellij.openapi.editor.ex.EditorEx) ActionEvent(java.awt.event.ActionEvent) Document(com.intellij.openapi.editor.Document) ActionListener(java.awt.event.ActionListener) EditorTextField(com.intellij.ui.EditorTextField) ReferenceEditorWithBrowseButton(com.intellij.ui.ReferenceEditorWithBrowseButton) DialogBuilder(com.intellij.openapi.ui.DialogBuilder)

Example 47 with EditorTextField

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

the class EditorTextFieldControl method doReset.

@Override
protected void doReset() {
    final EditorTextField textField = getEditorTextField(getComponent());
    textField.getDocument().removeDocumentListener(myListener);
    super.doReset();
    textField.getDocument().addDocumentListener(myListener);
}
Also used : EditorTextField(com.intellij.ui.EditorTextField)

Example 48 with EditorTextField

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

the class PyChangeSignatureDialog method getTableEditor.

@Override
protected JBTableRowEditor getTableEditor(final JTable t, final ParameterTableModelItemBase<PyParameterInfo> item) {
    return new JBTableRowEditor() {

        private EditorTextField myNameEditor;

        private EditorTextField myDefaultValueEditor;

        private JCheckBox myDefaultInSignature;

        @Override
        public void prepareEditor(JTable table, int row) {
            setLayout(new GridLayout(1, 3));
            final JPanel parameterPanel = createParameterPanel();
            add(parameterPanel);
            final JPanel defaultValuePanel = createDefaultValuePanel();
            add(defaultValuePanel);
            final JPanel defaultValueCheckBox = createDefaultValueCheckBox();
            add(defaultValueCheckBox);
            final String nameText = myNameEditor.getText();
            myDefaultValueEditor.setEnabled(!nameText.startsWith("*") && !PyNames.CANONICAL_SELF.equals(nameText));
            myDefaultInSignature.setEnabled(!nameText.startsWith("*") && !PyNames.CANONICAL_SELF.equals(nameText));
        }

        private JPanel createDefaultValueCheckBox() {
            final JPanel defaultValuePanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 4, 2, true, false));
            final JBLabel inSignatureLabel = new JBLabel(PyBundle.message("refactoring.change.signature.dialog.default.value.checkbox"), UIUtil.ComponentStyle.SMALL);
            IJSwingUtilities.adjustComponentsOnMac(inSignatureLabel, myDefaultInSignature);
            defaultValuePanel.add(inSignatureLabel, BorderLayout.WEST);
            myDefaultInSignature = new JCheckBox();
            myDefaultInSignature.setSelected(((PyParameterTableModelItem) item).isDefaultInSignature());
            myDefaultInSignature.addItemListener(new ItemListener() {

                @Override
                public void itemStateChanged(ItemEvent event) {
                    ((PyParameterTableModelItem) item).setDefaultInSignature(myDefaultInSignature.isSelected());
                }
            });
            myDefaultInSignature.addChangeListener(mySignatureUpdater);
            myDefaultInSignature.setEnabled(item.parameter.getOldIndex() == -1);
            defaultValuePanel.add(myDefaultInSignature, BorderLayout.EAST);
            return defaultValuePanel;
        }

        private JPanel createDefaultValuePanel() {
            final JPanel defaultValuePanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 4, 2, true, false));
            final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(item.defaultValueCodeFragment);
            myDefaultValueEditor = new EditorTextField(doc, getProject(), getFileType());
            final JBLabel defaultValueLabel = new JBLabel(PyBundle.message("refactoring.change.signature.dialog.default.value.label"), UIUtil.ComponentStyle.SMALL);
            IJSwingUtilities.adjustComponentsOnMac(defaultValueLabel, myDefaultValueEditor);
            defaultValuePanel.add(defaultValueLabel);
            defaultValuePanel.add(myDefaultValueEditor);
            myDefaultValueEditor.setPreferredWidth(t.getWidth() / 2);
            myDefaultValueEditor.addDocumentListener(mySignatureUpdater);
            return defaultValuePanel;
        }

        private JPanel createParameterPanel() {
            final JPanel namePanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 4, 2, true, false));
            myNameEditor = new EditorTextField(item.parameter.getName(), getProject(), getFileType());
            final JBLabel nameLabel = new JBLabel(PyBundle.message("refactoring.change.signature.dialog.name.label"), UIUtil.ComponentStyle.SMALL);
            IJSwingUtilities.adjustComponentsOnMac(nameLabel, myNameEditor);
            namePanel.add(nameLabel);
            namePanel.add(myNameEditor);
            myNameEditor.setPreferredWidth(t.getWidth() / 2);
            myNameEditor.addDocumentListener(new DocumentAdapter() {

                @Override
                public void documentChanged(DocumentEvent event) {
                    fireDocumentChanged(event, 0);
                    myDefaultValueEditor.setEnabled(!myNameEditor.getText().startsWith("*"));
                    myDefaultInSignature.setEnabled(!myNameEditor.getText().startsWith("*"));
                }
            });
            myNameEditor.addDocumentListener(mySignatureUpdater);
            return namePanel;
        }

        @Override
        public JBTableRow getValue() {
            return new JBTableRow() {

                @Override
                public Object getValueAt(int column) {
                    switch(column) {
                        case 0:
                            return myNameEditor.getText().trim();
                        case 1:
                            return new Pair<>(item.defaultValueCodeFragment, ((PyParameterTableModelItem) item).isDefaultInSignature());
                    }
                    return null;
                }
            };
        }

        @Override
        public JComponent getPreferredFocusedComponent() {
            return myNameEditor.getFocusTarget();
        }

        @Override
        public JComponent[] getFocusableComponents() {
            final List<JComponent> focusable = new ArrayList<>();
            focusable.add(myNameEditor.getFocusTarget());
            if (myDefaultValueEditor != null) {
                focusable.add(myDefaultValueEditor.getFocusTarget());
            }
            return focusable.toArray(new JComponent[focusable.size()]);
        }
    };
}
Also used : ItemEvent(java.awt.event.ItemEvent) ArrayList(java.util.ArrayList) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Document(com.intellij.openapi.editor.Document) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) JBTableRowEditor(com.intellij.util.ui.table.JBTableRowEditor) EditorTextField(com.intellij.ui.EditorTextField) JBLabel(com.intellij.ui.components.JBLabel) ItemListener(java.awt.event.ItemListener) JBTableRow(com.intellij.util.ui.table.JBTableRow) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) Pair(com.intellij.openapi.util.Pair)

Example 49 with EditorTextField

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

the class PyConsoleSpecificOptionsPanel method configureStartingScriptPanel.

private void configureStartingScriptPanel(final PyConsoleOptions.PyConsoleSettings optionsProvider) {
    myEditorTextField = new EditorTextField(createDocument(myProject, optionsProvider.myCustomStartScript), myProject, PythonFileType.INSTANCE) {

        @Override
        protected EditorEx createEditor() {
            final EditorEx editor = super.createEditor();
            editor.setVerticalScrollbarVisible(true);
            return editor;
        }

        @Override
        protected boolean isOneLineMode() {
            return false;
        }
    };
    myStartingScriptPanel.setLayout(new BorderLayout());
    myStartingScriptPanel.add(myEditorTextField, BorderLayout.CENTER);
    myConsoleSettings = optionsProvider;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) EditorTextField(com.intellij.ui.EditorTextField)

Example 50 with EditorTextField

use of com.intellij.ui.EditorTextField in project Perl5-IDEA by Camelcade.

the class PerlConfigurationEditorBase method getDebuggingComponent.

@Nullable
protected JComponent getDebuggingComponent() {
    JPanel panel = new JPanel();
    panel.setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 5, true, false));
    myScriptCharset = new JTextField();
    LabeledComponent<JTextField> scriptCharset = LabeledComponent.create(myScriptCharset, PerlBundle.message("perl.run.option.script.encoding"));
    scriptCharset.setLabelLocation(BorderLayout.WEST);
    panel.add(scriptCharset);
    myStartMode = new ComboBox(new MapComboBoxModel<>(PerlDebugOptionsSets.STARTUP_OPTIONS)) {

        @Override
        public void setRenderer(ListCellRenderer renderer) {
            super.setRenderer(new ColoredListCellRenderer<String>() {

                @Override
                protected void customizeCellRenderer(@NotNull JList list, String value, int index, boolean selected, boolean hasFocus) {
                    append(PerlDebugOptionsSets.STARTUP_OPTIONS.get(value));
                }
            });
        }
    };
    LabeledComponent<?> startMode = LabeledComponent.create(myStartMode, PerlBundle.message("perl.run.option.debugger.startup.mode"));
    startMode.setLabelLocation(BorderLayout.WEST);
    panel.add(startMode);
    myIsNonInteractiveModeEnabled = new JCheckBox(PerlBundle.message("perl.run.option.debugger.noninteractive.mode"));
    panel.add(myIsNonInteractiveModeEnabled);
    myIsCompileTimeBreakpointsEnabled = new JCheckBox(PerlBundle.message("perl.run.option.debugger.compile.time.breakpoints"));
    panel.add(myIsCompileTimeBreakpointsEnabled);
    PsiFile fileFromText = PsiFileFactory.getInstance(myProject).createFileFromText("file.dummy", PerlFileTypeScript.INSTANCE, "", 0, true);
    Document document = PsiDocumentManager.getInstance(myProject).getDocument(fileFromText);
    myInitCodeTextField = new EditorTextField(document, myProject, PerlFileTypeScript.INSTANCE);
    myInitCodeTextField.setOneLineMode(false);
    myInitCodeTextField.setPreferredSize(new Dimension(0, 100));
    LabeledComponent<EditorTextField> initCode = LabeledComponent.create(myInitCodeTextField, PerlBundle.message("perl.run.option.debugger.init.code"));
    initCode.setLabelLocation(BorderLayout.NORTH);
    panel.add(initCode);
    return panel;
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) Document(com.intellij.openapi.editor.Document) MapComboBoxModel(org.jdesktop.swingx.combobox.MapComboBoxModel) NotNull(org.jetbrains.annotations.NotNull) EditorTextField(com.intellij.ui.EditorTextField) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) PsiFile(com.intellij.psi.PsiFile) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) Nullable(org.jetbrains.annotations.Nullable)

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