Search in sources :

Example 61 with DocumentAdapter

use of com.intellij.ui.DocumentAdapter in project android by JetBrains.

the class TraceViewPanel method createSearchField.

private SearchTextField createSearchField() {
    SearchTextField stf = new SearchTextField(true);
    stf.setOpaque(false);
    stf.setEnabled(true);
    Utils.setSmallerFont(stf);
    stf.addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            searchTextChanged(getText(e));
        }

        private String getText(DocumentEvent e) {
            try {
                return e.getDocument().getText(0, e.getDocument().getLength());
            } catch (BadLocationException e1) {
                return "";
            }
        }
    });
    JTextField editorTextField = stf.getTextEditor();
    editorTextField.setMinimumSize(new Dimension(JBUI.scale(200), -1));
    editorTextField.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            closeSearchComponent();
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
    return stf;
}
Also used : SearchTextField(com.intellij.ui.SearchTextField) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) BadLocationException(javax.swing.text.BadLocationException)

Example 62 with DocumentAdapter

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

the class DartGeneratorPeer method enableIntellijLiveValidation.

private void enableIntellijLiveValidation() {
    final JTextComponent editorComponent = (JTextComponent) mySdkPathComboWithBrowse.getComboBox().getEditor().getEditorComponent();
    editorComponent.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(final DocumentEvent e) {
            validateInIntelliJ();
        }
    });
    myCreateSampleProjectCheckBox.addActionListener(e -> validateInIntelliJ());
    myTemplatesList.addListSelectionListener(e -> validateInIntelliJ());
}
Also used : DocumentAdapter(com.intellij.ui.DocumentAdapter) JTextComponent(javax.swing.text.JTextComponent) DocumentEvent(javax.swing.event.DocumentEvent)

Example 63 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 64 with DocumentAdapter

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

the class SelectDirWithFlashBuilderProjectsStep method setupInitialPathComponent.

private void setupInitialPathComponent() {
    myInitialPathComponent.getComponent().getTextField().getDocument().addDocumentListener(new DocumentAdapter() {

        protected void textChanged(final DocumentEvent e) {
            onInitialPathChanged();
        }
    });
    final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, true, true, false, false) {

        public boolean isFileVisible(final VirtualFile file, final boolean showHiddenFiles) {
            return (super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || FlashBuilderProjectFinder.isFlashBuilderProject(file)) || FlashBuilderProjectFinder.hasArchiveExtension(file.getPath()));
        }

        public Icon getIcon(final VirtualFile file) {
            // do not use Flash Builder specific icon for zip
            return !file.isDirectory() && (FlashBuilderProjectFinder.hasFxpExtension(file.getPath()) || FlashBuilderProjectFinder.isFlashBuilderProject(file)) ? dressIcon(file, getBuilder().getIcon()) : super.getIcon(file);
        }
    };
    myInitialPathComponent.getComponent().addBrowseFolderListener(FlexBundle.message("select.flash.builder.workspace.or.project"), null, getWizardContext().getProject(), descriptor);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent)

Aggregations

DocumentAdapter (com.intellij.ui.DocumentAdapter)64 DocumentEvent (javax.swing.event.DocumentEvent)64 ActionEvent (java.awt.event.ActionEvent)15 ActionListener (java.awt.event.ActionListener)15 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)10 ItemEvent (java.awt.event.ItemEvent)7 ItemListener (java.awt.event.ItemListener)7 Document (javax.swing.text.Document)7 JTextComponent (javax.swing.text.JTextComponent)5 NotNull (org.jetbrains.annotations.NotNull)5 Project (com.intellij.openapi.project.Project)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 FieldPanel (com.intellij.ui.FieldPanel)4 JBTextField (com.intellij.ui.components.JBTextField)4 ChangeEvent (javax.swing.event.ChangeEvent)4 List (java.util.List)3 Nullable (org.jetbrains.annotations.Nullable)3 VariantsCompletionAction (com.intellij.find.editorHeaderActions.VariantsCompletionAction)2 MemberChooser (com.intellij.ide.util.MemberChooser)2 TreeClassChooser (com.intellij.ide.util.TreeClassChooser)2