Search in sources :

Example 6 with DocumentAdapter

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

the class AddNamespaceDialog method addUpdateListener.

private void addUpdateListener(ComboBox comboBox) {
    final ComboBoxEditor boxEditor = comboBox.getEditor();
    if (boxEditor != null) {
        final Component component = boxEditor.getEditorComponent();
        if (component instanceof JTextField) {
            ((JTextField) component).getDocument().addDocumentListener(new DocumentAdapter() {

                protected void textChanged(DocumentEvent e) {
                    updateOkAction();
                }
            });
        }
    }
    comboBox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            updateOkAction();
        }
    });
}
Also used : ItemEvent(java.awt.event.ItemEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) ItemListener(java.awt.event.ItemListener) DocumentEvent(javax.swing.event.DocumentEvent)

Example 7 with DocumentAdapter

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

the class SetBackgroundImageDialog method setupComponents.

private void setupComponents() {
    myAdjusting = true;
    myPreviewPanel.setLayout(new CardLayout());
    myPreviewPanel.add(myEditorPreview.getPanel(), "editor");
    myPreviewPanel.add(myIdePreview, "ide");
    ((CardLayout) myPreviewPanel.getLayout()).show(myPreviewPanel, "editor");
    myPathField.getComboBox().setEditable(true);
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, true, false).withFileFilter(file -> ImageFileTypeManager.getInstance().isImage(file));
    myPathField.addBrowseFolderListener(null, null, null, descriptor, TextComponentAccessor.STRING_COMBOBOX_WHOLE_TEXT);
    JTextComponent textComponent = getComboEditor();
    textComponent.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            if (myAdjusting)
                return;
            imagePathChanged();
        }
    });
    for (Enumeration<AbstractButton> e = getTargetRbGroup().getElements(); e.hasMoreElements(); ) {
        AbstractButton button = e.nextElement();
        button.setActionCommand(button.getText());
        button.addItemListener(this::targetChanged);
    }
    for (Enumeration<AbstractButton> e = getFillRbGroup().getElements(); e.hasMoreElements(); ) {
        AbstractButton button = e.nextElement();
        button.setActionCommand(button.getText());
        button.addItemListener(this::fillOrPlaceChanged);
    }
    for (Enumeration<AbstractButton> e = getPlaceRbGroup().getElements(); e.hasMoreElements(); ) {
        AbstractButton button = e.nextElement();
        button.setActionCommand(button.getText());
        button.addItemListener(this::fillOrPlaceChanged);
    }
    ChangeListener opacitySync = new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (myAdjusting)
                return;
            myAdjusting = true;
            boolean b = e.getSource() == myOpacitySpinner;
            if (b) {
                int value = (Integer) myOpacitySpinner.getValue();
                myOpacitySpinner.setValue(Math.min(Math.max(0, value), 100));
                myOpacitySlider.setValue(value);
            } else {
                myOpacitySpinner.setValue(myOpacitySlider.getValue());
            }
            myAdjusting = false;
            opacityChanged();
        }
    };
    myOpacitySpinner.addChangeListener(opacitySync);
    myOpacitySlider.addChangeListener(opacitySync);
    myOpacitySlider.setValue(15);
    myOpacitySpinner.setValue(15);
    myScaleRb.setSelected(true);
    myCenterRb.setSelected(true);
    myEditorRb.setSelected(true);
    boolean perProject = !Comparing.equal(getBackgroundSpec(myProject, getSystemProp(true)), getBackgroundSpec(null, getSystemProp(true)));
    myThisProjectOnlyCb.setSelected(perProject);
    myAdjusting = false;
}
Also used : FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) DocumentAdapter(com.intellij.ui.DocumentAdapter) JTextComponent(javax.swing.text.JTextComponent) DocumentEvent(javax.swing.event.DocumentEvent) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener)

Example 8 with DocumentAdapter

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

the class GenerateVisitorByHierarchyAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    final Ref<String> visitorNameRef = Ref.create("MyVisitor");
    final Ref<PsiClass> parentClassRef = Ref.create(null);
    final Project project = e.getData(CommonDataKeys.PROJECT);
    assert project != null;
    final PsiNameHelper helper = PsiNameHelper.getInstance(project);
    final PackageChooserDialog dialog = new PackageChooserDialog("Choose Target Package and Hierarchy Root Class", project) {

        @Override
        protected ValidationInfo doValidate() {
            PsiDocumentManager.getInstance(project).commitAllDocuments();
            if (!helper.isQualifiedName(visitorNameRef.get())) {
                return new ValidationInfo("Visitor class name is not valid");
            } else if (parentClassRef.isNull()) {
                return new ValidationInfo("Hierarchy root class should be specified");
            } else if (parentClassRef.get().isAnnotationType() || parentClassRef.get().isEnum()) {
                return new ValidationInfo("Hierarchy root class should be an interface or a class");
            }
            return super.doValidate();
        }

        protected JComponent createCenterPanel() {
            final JPanel panel = new JPanel(new BorderLayout());
            panel.add(super.createCenterPanel(), BorderLayout.CENTER);
            panel.add(createNamePanel(), BorderLayout.NORTH);
            panel.add(createBaseClassPanel(), BorderLayout.SOUTH);
            return panel;
        }

        private JComponent createNamePanel() {
            LabeledComponent<JTextField> labeledComponent = new LabeledComponent<>();
            labeledComponent.setText("Visitor class");
            final JTextField nameField = new JTextField(visitorNameRef.get());
            labeledComponent.setComponent(nameField);
            nameField.getDocument().addDocumentListener(new DocumentAdapter() {

                protected void textChanged(final DocumentEvent e) {
                    visitorNameRef.set(nameField.getText());
                }
            });
            return labeledComponent;
        }

        private JComponent createBaseClassPanel() {
            LabeledComponent<EditorTextField> labeledComponent = new LabeledComponent<>();
            labeledComponent.setText("Hierarchy root class");
            final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(project);
            final PsiTypeCodeFragment codeFragment = factory.createTypeCodeFragment("", null, true, JavaCodeFragmentFactory.ALLOW_VOID);
            final Document document = PsiDocumentManager.getInstance(project).getDocument(codeFragment);
            final EditorTextField editorTextField = new EditorTextField(document, project, StdFileTypes.JAVA);
            labeledComponent.setComponent(editorTextField);
            editorTextField.addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {

                public void documentChanged(final com.intellij.openapi.editor.event.DocumentEvent e) {
                    parentClassRef.set(null);
                    try {
                        final PsiType psiType = codeFragment.getType();
                        final PsiClass psiClass = psiType instanceof PsiClassType ? ((PsiClassType) psiType).resolve() : null;
                        parentClassRef.set(psiClass);
                    } catch (PsiTypeCodeFragment.IncorrectTypeException e1) {
                    // ok
                    }
                }
            });
            return labeledComponent;
        }
    };
    final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(e.getDataContext());
    if (element instanceof PsiPackage) {
        dialog.selectPackage(((PsiPackage) element).getQualifiedName());
    } else if (element instanceof PsiDirectory) {
        final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory) element);
        if (aPackage != null) {
            dialog.selectPackage(aPackage.getQualifiedName());
        }
    }
    dialog.show();
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE || dialog.getSelectedPackage() == null || dialog.getSelectedPackage().getQualifiedName().length() == 0 || parentClassRef.isNull()) {
        return;
    }
    final String visitorQName = generateEverything(dialog.getSelectedPackage(), parentClassRef.get(), visitorNameRef.get());
    final IdeView ideView = LangDataKeys.IDE_VIEW.getData(e.getDataContext());
    final PsiClass visitorClass = JavaPsiFacade.getInstance(project).findClass(visitorQName, GlobalSearchScope.projectScope(project));
    if (ideView != null && visitorClass != null) {
        ideView.selectElement(visitorClass);
    }
}
Also used : Document(com.intellij.openapi.editor.Document) IdeView(com.intellij.ide.IdeView) EditorTextField(com.intellij.ui.EditorTextField) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) LabeledComponent(com.intellij.openapi.ui.LabeledComponent) Project(com.intellij.openapi.project.Project) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) PackageChooserDialog(com.intellij.ide.util.PackageChooserDialog)

Example 9 with DocumentAdapter

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

the class MakeParameterizedStaticDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    GridBagConstraints gbConstraints = new GridBagConstraints();
    JPanel panel = new JPanel(new GridBagLayout());
    gbConstraints.insets = JBUI.insets(4, 8);
    gbConstraints.weighty = 0;
    gbConstraints.weightx = 0;
    gbConstraints.gridx = 0;
    gbConstraints.gridy = GridBagConstraints.RELATIVE;
    gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gbConstraints.fill = GridBagConstraints.NONE;
    gbConstraints.anchor = GridBagConstraints.WEST;
    panel.add(createDescriptionLabel(), gbConstraints);
    gbConstraints.weighty = 0;
    gbConstraints.weightx = 0;
    gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
    gbConstraints.fill = GridBagConstraints.NONE;
    gbConstraints.anchor = GridBagConstraints.WEST;
    String text = myMember instanceof PsiMethod ? RefactoringBundle.message("add.object.as.a.parameter.with.name") : RefactoringBundle.message("add.object.as.a.parameter.to.constructors.with.name");
    myMakeClassParameter.setText(text);
    panel.add(myMakeClassParameter, gbConstraints);
    myMakeClassParameter.setSelected(myAnyNonFieldMembersUsed);
    gbConstraints.insets = JBUI.insets(0, 8, 4, 8);
    gbConstraints.weighty = 0;
    gbConstraints.weightx = 1;
    gbConstraints.gridwidth = 2;
    gbConstraints.fill = GridBagConstraints.HORIZONTAL;
    gbConstraints.anchor = GridBagConstraints.NORTHWEST;
    if (myNameSuggestions.length > 1) {
        myClassParameterNameInputField = createComboBoxForName();
    } else {
        JTextField textField = new JTextField();
        textField.setText(myNameSuggestions[0]);
        textField.getDocument().addDocumentListener(new DocumentAdapter() {

            public void textChanged(DocumentEvent event) {
                updateControls();
            }
        });
        myClassParameterNameInputField = textField;
    }
    panel.add(myClassParameterNameInputField, gbConstraints);
    gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
    if (myVariableData.length > 0) {
        gbConstraints.insets = JBUI.insets(4, 8);
        gbConstraints.weighty = 0;
        gbConstraints.weightx = 0;
        gbConstraints.gridheight = 1;
        gbConstraints.fill = GridBagConstraints.NONE;
        gbConstraints.anchor = GridBagConstraints.WEST;
        text = myMember instanceof PsiMethod ? RefactoringBundle.message("add.parameters.for.fields") : RefactoringBundle.message("add.parameters.for.fields.to.constructors");
        myMakeFieldParameters.setText(text);
        panel.add(myMakeFieldParameters, gbConstraints);
        myMakeFieldParameters.setSelected(!myAnyNonFieldMembersUsed);
        myParameterPanel = new ParameterTablePanel(myProject, myVariableData, myMember) {

            protected void updateSignature() {
            }

            protected void doEnterAction() {
                clickDefaultButton();
            }

            protected void doCancelAction() {
            }
        };
        gbConstraints.insets = JBUI.insets(0, 8, 4, 8);
        gbConstraints.gridwidth = 2;
        gbConstraints.fill = GridBagConstraints.BOTH;
        gbConstraints.weighty = 1;
        panel.add(myParameterPanel, gbConstraints);
    }
    ActionListener inputFieldValidator = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            updateControls();
        }
    };
    myMakeClassParameter.addActionListener(inputFieldValidator);
    myMakeFieldParameters.addActionListener(inputFieldValidator);
    if (myMember instanceof PsiMethod) {
        myGenerateDelegateCb = new JCheckBox(RefactoringBundle.message("delegation.panel.delegate.via.overloading.method"));
        panel.add(myGenerateDelegateCb, gbConstraints);
    }
    updateControls();
    return panel;
}
Also used : DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) ParameterTablePanel(com.intellij.refactoring.util.ParameterTablePanel)

Example 10 with DocumentAdapter

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

the class CvsFieldValidator method installOn.

public static void installOn(final TagNameFieldOwner dialog, final JTextField field, final JLabel label) {
    installOn(dialog, field, label, new AbstractButton[0]);
    field.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void textChanged(DocumentEvent event) {
            checkTagNameField(dialog, field, label);
        }
    });
    checkTagNameField(dialog, field, label);
}
Also used : DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent)

Aggregations

DocumentAdapter (com.intellij.ui.DocumentAdapter)81 DocumentEvent (javax.swing.event.DocumentEvent)81 ActionEvent (java.awt.event.ActionEvent)15 ActionListener (java.awt.event.ActionListener)15 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)11 Document (javax.swing.text.Document)8 JTextComponent (javax.swing.text.JTextComponent)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 ItemEvent (java.awt.event.ItemEvent)6 ItemListener (java.awt.event.ItemListener)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)6 JBTextField (com.intellij.ui.components.JBTextField)5 ChangeEvent (javax.swing.event.ChangeEvent)5 Project (com.intellij.openapi.project.Project)4 FieldPanel (com.intellij.ui.FieldPanel)4 ChangeListener (javax.swing.event.ChangeListener)4 List (java.util.List)3 DocumentListener (javax.swing.event.DocumentListener)3 ProjectSelector (com.google.cloud.tools.intellij.project.ProjectSelector)2