Search in sources :

Example 41 with DocumentAdapter

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

the class DartSdkUtil method initDartSdkAndDartiumControls.

public static void initDartSdkAndDartiumControls(@Nullable final Project project, @NotNull final ComboboxWithBrowseButton dartSdkPathComponent, @NotNull final JBLabel versionLabel, @NotNull final ComboboxWithBrowseButton dartiumPathComponent, @NotNull final Computable<ChromeSettings> currentDartiumSettingsRetriever, @NotNull final JButton dartiumSettingsButton, @NotNull final Computable<Boolean> isResettingControlsComputable) {
    dartSdkPathComponent.getComboBox().setEditable(true);
    addKnownPathsToCombo(dartSdkPathComponent.getComboBox(), DART_SDK_KNOWN_PATHS, DartSdkUtil::isDartSdkHome);
    if (SystemInfo.isMac && getItemFromCombo(dartSdkPathComponent.getComboBox()).isEmpty()) {
        // no need to check folder presence here; even if it doesn't exist - that's the best we can suggest
        dartSdkPathComponent.getComboBox().getEditor().setItem("/usr/local/opt/dart/libexec");
    }
    dartiumPathComponent.getComboBox().setEditable(true);
    addKnownPathsToCombo(dartiumPathComponent.getComboBox(), DARTIUM_KNOWN_PATHS, path -> !path.isEmpty() && new File(path).exists());
    if (SystemInfo.isMac && getItemFromCombo(dartiumPathComponent.getComboBox()).isEmpty()) {
        // Dartium path is optional, so set it only if valid
        if (new File("/usr/local/opt/dart/Chromium.app").isDirectory()) {
            dartiumPathComponent.getComboBox().getEditor().setItem("/usr/local/opt/dart/Chromium.app");
        }
    }
    final String sdkHomePath = getItemFromCombo(dartSdkPathComponent.getComboBox());
    versionLabel.setText(sdkHomePath.isEmpty() ? "" : getSdkVersion(sdkHomePath));
    final TextComponentAccessor<JComboBox> textComponentAccessor = new TextComponentAccessor<JComboBox>() {

        @Override
        public String getText(final JComboBox component) {
            return getItemFromCombo(component);
        }

        @Override
        public void setText(@NotNull final JComboBox component, @NotNull final String text) {
            if (!text.isEmpty() && !isDartSdkHome(text)) {
                final String probablySdkPath = text + "/dart-sdk";
                if (isDartSdkHome(probablySdkPath)) {
                    component.getEditor().setItem(FileUtilRt.toSystemDependentName(probablySdkPath));
                    return;
                }
            }
            component.getEditor().setItem(FileUtilRt.toSystemDependentName(text));
        }
    };
    final ComponentWithBrowseButton.BrowseFolderActionListener<JComboBox> browseFolderListener = new ComponentWithBrowseButton.BrowseFolderActionListener<>("Select Dart SDK path", null, dartSdkPathComponent, project, FileChooserDescriptorFactory.createSingleFolderDescriptor(), textComponentAccessor);
    dartSdkPathComponent.addActionListener(browseFolderListener);
    dartiumPathComponent.addBrowseFolderListener("Select Dartium browser path", null, project, FileChooserDescriptorFactory.createSingleFileOrExecutableAppDescriptor(), TextComponentAccessor.STRING_COMBOBOX_WHOLE_TEXT);
    final JTextComponent editorComponent = (JTextComponent) dartSdkPathComponent.getComboBox().getEditor().getEditorComponent();
    editorComponent.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(final DocumentEvent e) {
            final String sdkHomePath = getItemFromCombo(dartSdkPathComponent.getComboBox());
            versionLabel.setText(sdkHomePath.isEmpty() ? "" : getSdkVersion(sdkHomePath));
            if (!isResettingControlsComputable.compute() && isDartSdkHome(sdkHomePath)) {
                final String dartiumPath = DartiumUtil.getDartiumPathForSdk(sdkHomePath);
                if (dartiumPath != null) {
                    dartiumPathComponent.getComboBox().getEditor().setItem(FileUtilRt.toSystemDependentName(dartiumPath));
                }
            }
        }
    });
    dartiumSettingsButton.addActionListener(e -> ShowSettingsUtil.getInstance().editConfigurable(dartiumSettingsButton, currentDartiumSettingsRetriever.compute().createConfigurable()));
// we decided to save one line in settings and always use Dartium in checked mode
//checkedModeCheckBox.addActionListener(new ActionListener() {
//  public void actionPerformed(final ActionEvent e) {
//    DartiumUtil.setCheckedMode(currentDartiumSettingsRetriever.compute().getEnvironmentVariables(), checkedModeCheckBox.isSelected());
//  }
//});
}
Also used : DocumentAdapter(com.intellij.ui.DocumentAdapter) JTextComponent(javax.swing.text.JTextComponent) DocumentEvent(javax.swing.event.DocumentEvent) NotNull(org.jetbrains.annotations.NotNull) TextComponentAccessor(com.intellij.openapi.ui.TextComponentAccessor) ComponentWithBrowseButton(com.intellij.openapi.ui.ComponentWithBrowseButton) File(java.io.File)

Example 42 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, AbstractButton[] buttons) {
    field.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void textChanged(DocumentEvent event) {
            checkTagNameField(dialog, field, label);
        }
    });
    for (AbstractButton button : buttons) {
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                checkTagNameField(dialog, field, label);
            }
        });
    }
    checkTagNameField(dialog, field, label);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent)

Example 43 with DocumentAdapter

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

the class CopyFilesOrDirectoriesDialog method createNorthPanel.

@Override
protected JComponent createNorthPanel() {
    myInformationLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true);
    final FormBuilder formBuilder = FormBuilder.createFormBuilder().addComponent(myInformationLabel).addVerticalGap(UIUtil.LARGE_VGAP - UIUtil.DEFAULT_VGAP);
    DocumentListener documentListener = new DocumentAdapter() {

        @Override
        public void textChanged(DocumentEvent event) {
            validateOKButton();
        }
    };
    if (myShowNewNameField) {
        myNewNameField = new JBTextField();
        myNewNameField.getDocument().addDocumentListener(documentListener);
        formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.new.name.label"), myNewNameField);
    }
    if (myShowDirectoryField) {
        myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton();
        myTargetDirectoryField.setTextFieldPreferredWidth(MAX_PATH_LENGTH);
        final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS);
        if (recentEntries != null) {
            getTargetDirectoryComponent().setHistory(recentEntries);
        }
        final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
        myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"), RefactoringBundle.message("the.file.will.be.copied.to.this.directory"), myProject, descriptor, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);
        getTargetDirectoryComponent().addDocumentListener(new DocumentAdapter() {

            @Override
            protected void textChanged(DocumentEvent e) {
                validateOKButton();
            }
        });
        formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.to.directory.label"), myTargetDirectoryField);
        String shortcutText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION));
        formBuilder.addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText));
    }
    final JPanel wrapper = new JPanel(new BorderLayout());
    wrapper.add(myOpenFilesInEditor, BorderLayout.EAST);
    formBuilder.addComponent(wrapper);
    return formBuilder.getPanel();
}
Also used : FormBuilder(com.intellij.util.ui.FormBuilder) DocumentListener(javax.swing.event.DocumentListener) TextFieldWithHistoryWithBrowseButton(com.intellij.ui.TextFieldWithHistoryWithBrowseButton) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) DocumentAdapter(com.intellij.ui.DocumentAdapter) JBTextField(com.intellij.ui.components.JBTextField) DocumentEvent(javax.swing.event.DocumentEvent)

Example 44 with DocumentAdapter

use of com.intellij.ui.DocumentAdapter 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 45 with DocumentAdapter

use of com.intellij.ui.DocumentAdapter 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)

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