Search in sources :

Example 86 with DocumentEvent

use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.

the class ChangesTrackingTableView method addChangeListener.

private static void addChangeListener(final Component component, final ChangeListener listener, Disposable parentDisposable) {
    if (component instanceof CellEditorComponentWithBrowseButton) {
        addChangeListener(((CellEditorComponentWithBrowseButton) component).getChildComponent(), listener, parentDisposable);
    } else if (component instanceof JTextField) {
        final DocumentAdapter documentListener = new DocumentAdapter() {

            @Override
            protected void textChanged(DocumentEvent e) {
                listener.stateChanged(new ChangeEvent(component));
            }
        };
        final Document document = ((JTextField) component).getDocument();
        document.addDocumentListener(documentListener);
        Disposer.register(parentDisposable, new Disposable() {

            @Override
            public void dispose() {
                document.removeDocumentListener(documentListener);
            }
        });
    } else if (component instanceof JComboBox) {
        final ActionListener comboListener = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                listener.stateChanged(new ChangeEvent(component));
            }
        };
        ((JComboBox) component).addActionListener(comboListener);
        Disposer.register(parentDisposable, new Disposable() {

            @Override
            public void dispose() {
                ((JComboBox) component).removeActionListener(comboListener);
            }
        });
    } else if (component instanceof JCheckBox) {
        final ActionListener checkBoxListener = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                listener.stateChanged(new ChangeEvent(component));
            }
        };
        ((JCheckBox) component).addActionListener(checkBoxListener);
        Disposer.register(parentDisposable, new Disposable() {

            @Override
            public void dispose() {
                ((JCheckBox) component).removeActionListener(checkBoxListener);
            }
        });
    } else {
        throw new UnsupportedOperationException("editor control of type " + component.getClass().getName() + " is not supported");
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) Document(javax.swing.text.Document) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener)

Example 87 with DocumentEvent

use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.

the class ReplaceConstructorWithBuilderDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    final Splitter splitter = new Splitter(true);
    splitter.setFirstComponent(createTablePanel());
    splitter.setSecondComponent(myWholePanel);
    final ActionListener enableDisableListener = new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            setEnabled(myCreateBuilderClassRadioButton.isSelected());
            IdeFocusManager.getInstance(myProject).requestFocus(myCreateBuilderClassRadioButton.isSelected() ? myNewClassName : myExistentClassTF.getChildComponent(), true);
            validateButtons();
        }
    };
    myCreateBuilderClassRadioButton.addActionListener(enableDisableListener);
    myExistingBuilderClassRadioButton.addActionListener(enableDisableListener);
    myCreateBuilderClassRadioButton.setSelected(true);
    setEnabled(true);
    final DocumentAdapter validateButtonsListener = new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            validateButtons();
        }
    };
    myNewClassName.getDocument().addDocumentListener(validateButtonsListener);
    final PsiClass psiClass = myConstructors[0].getContainingClass();
    LOG.assertTrue(psiClass != null);
    myNewClassName.setText(psiClass.getName() + "Builder");
    return splitter;
}
Also used : Splitter(com.intellij.openapi.ui.Splitter) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) DocumentEvent(javax.swing.event.DocumentEvent)

Example 88 with DocumentEvent

use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.

the class SearchReplaceComponent method updateReplaceComponent.

private void updateReplaceComponent(@NotNull String textToSet) {
    if (!updateTextComponent(false)) {
        String existingText = myReplaceTextComponent.getText();
        if (!existingText.equals(textToSet)) {
            myReplaceTextComponent.setText(textToSet);
            if (existingText.length() == 0)
                myReplaceTextComponent.selectAll();
        }
        return;
    }
    myReplaceTextComponent.setText(textToSet);
    myReplaceTextComponent.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            ApplicationManager.getApplication().invokeLater(() -> replaceFieldDocumentChanged());
        }
    });
    if (!isMultiline()) {
        installReplaceOnEnterAction(myReplaceTextComponent);
    }
    new VariantsCompletionAction(myReplaceTextComponent);
    myReplaceFieldWrapper.revalidate();
    myReplaceFieldWrapper.repaint();
}
Also used : VariantsCompletionAction(com.intellij.find.editorHeaderActions.VariantsCompletionAction) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent)

Example 89 with DocumentEvent

use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.

the class SearchReplaceComponent method updateSearchComponent.

private void updateSearchComponent(@NotNull String textToSet) {
    if (!updateTextComponent(true)) {
        String existingText = mySearchTextComponent.getText();
        if (!existingText.equals(textToSet)) {
            mySearchTextComponent.setText(textToSet);
            // textToSet should be selected even if we have no selection before (if we have the selection then setText will remain it)
            if (existingText.length() == 0)
                mySearchTextComponent.selectAll();
        }
        return;
    }
    mySearchTextComponent.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            ApplicationManager.getApplication().invokeLater(() -> searchFieldDocumentChanged());
        }
    });
    mySearchTextComponent.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            if (StringUtil.isEmpty(mySearchTextComponent.getText())) {
                close();
            } else {
                IdeFocusManager.getInstance(myProject).requestFocus(myTargetComponent, true);
                addTextToRecent(mySearchTextComponent);
            }
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, SystemInfo.isMac ? META_DOWN_MASK : CTRL_DOWN_MASK), JComponent.WHEN_FOCUSED);
    // It registers a shortcut set automatically on construction
    new VariantsCompletionAction(mySearchTextComponent);
}
Also used : VariantsCompletionAction(com.intellij.find.editorHeaderActions.VariantsCompletionAction) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent)

Example 90 with DocumentEvent

use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.

the class GenerateJavadocAction method getAdditionalActionSettings.

@Override
protected JComponent getAdditionalActionSettings(Project project, final BaseAnalysisActionDialog dialog) {
    myConfigurable = new JavadocConfigurable(JavadocGenerationManager.getInstance(project).getConfiguration(), project);
    final JComponent component = myConfigurable.createComponent();
    myConfigurable.reset();
    myConfigurable.getOutputDirField().getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            updateAvailability(dialog);
        }
    });
    updateAvailability(dialog);
    return component;
}
Also used : JavadocConfigurable(com.intellij.javadoc.JavadocConfigurable) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent)

Aggregations

DocumentEvent (javax.swing.event.DocumentEvent)139 DocumentListener (javax.swing.event.DocumentListener)70 DocumentAdapter (com.intellij.ui.DocumentAdapter)64 ActionEvent (java.awt.event.ActionEvent)36 ActionListener (java.awt.event.ActionListener)34 JTextField (javax.swing.JTextField)22 JLabel (javax.swing.JLabel)18 JPanel (javax.swing.JPanel)18 Dimension (java.awt.Dimension)16 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)13 ItemEvent (java.awt.event.ItemEvent)13 ItemListener (java.awt.event.ItemListener)13 ChangeEvent (javax.swing.event.ChangeEvent)13 JButton (javax.swing.JButton)12 JCheckBox (javax.swing.JCheckBox)12 ChangeListener (javax.swing.event.ChangeListener)11 Document (javax.swing.text.Document)10 GridBagLayout (java.awt.GridBagLayout)9 NotNull (org.jetbrains.annotations.NotNull)9 GridBagConstraints (java.awt.GridBagConstraints)8