Search in sources :

Example 31 with DocumentEvent

use of com.intellij.openapi.editor.event.DocumentEvent in project intellij-community by JetBrains.

the class JavaChangeSignatureDialog method createAdditionalPanels.

@NotNull
protected List<Pair<String, JPanel>> createAdditionalPanels() {
    // this method is invoked before constructor body
    myExceptionsModel = new ExceptionsTableModel(myMethod.getMethod().getThrowsList());
    myExceptionsModel.setTypeInfos(myMethod.getMethod());
    final JBTable table = new JBTable(myExceptionsModel);
    table.setStriped(true);
    table.setRowHeight(20);
    table.getColumnModel().getColumn(0).setCellRenderer(new CodeFragmentTableCellRenderer(myProject));
    final JavaCodeFragmentTableCellEditor cellEditor = new JavaCodeFragmentTableCellEditor(myProject);
    cellEditor.addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            final int row = table.getSelectedRow();
            final int col = table.getSelectedColumn();
            myExceptionsModel.setValueAt(cellEditor.getCellEditorValue(), row, col);
            updateSignature();
        }
    });
    table.getColumnModel().getColumn(0).setCellEditor(cellEditor);
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.getSelectionModel().setSelectionInterval(0, 0);
    table.setSurrendersFocusOnKeystroke(true);
    myPropExceptionsButton = new AnActionButton(RefactoringBundle.message("changeSignature.propagate.exceptions.title"), null, AllIcons.Hierarchy.Caller) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final Ref<JavaCallerChooser> chooser = new Ref<>();
            Consumer<Set<PsiMethod>> callback = psiMethods -> {
                myMethodsToPropagateExceptions = psiMethods;
                myExceptionPropagationTree = chooser.get().getTree();
            };
            chooser.set(new JavaCallerChooser(myMethod.getMethod(), myProject, RefactoringBundle.message("changeSignature.exception.caller.chooser"), myExceptionPropagationTree, callback));
            chooser.get().show();
        }
    };
    myPropExceptionsButton.setShortcut(CustomShortcutSet.fromString("alt X"));
    final JPanel panel = ToolbarDecorator.createDecorator(table).addExtraAction(myPropExceptionsButton).createPanel();
    panel.setBorder(IdeBorderFactory.createEmptyBorder());
    myExceptionsModel.addTableModelListener(mySignatureUpdater);
    final ArrayList<Pair<String, JPanel>> result = new ArrayList<>();
    final String message = RefactoringBundle.message("changeSignature.exceptions.panel.border.title");
    result.add(Pair.create(message, panel));
    return result;
}
Also used : JavaCallerChooser(com.intellij.refactoring.changeSignature.inCallers.JavaCallerChooser) ArrayList(java.util.ArrayList) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) JBTable(com.intellij.ui.table.JBTable) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) JavaCodeFragmentTableCellEditor(com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor) Ref(com.intellij.openapi.util.Ref) CodeFragmentTableCellRenderer(com.intellij.refactoring.ui.CodeFragmentTableCellRenderer) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with DocumentEvent

use of com.intellij.openapi.editor.event.DocumentEvent in project intellij-plugins by JetBrains.

the class FlashRunConfigurationForm method initMainClassRelatedControls.

private void initMainClassRelatedControls() {
    myOverrideMainClassCheckBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            if (myOverrideMainClassCheckBox.isSelected()) {
                updateOutputFileName(myOutputFileNameTextField, false);
            }
            updateControls();
            if (myMainClassComponent.isEnabled()) {
                IdeFocusManager.getInstance(myProject).requestFocus(myMainClassComponent.getChildComponent(), true);
            }
        }
    });
    myMainClassComponent.addDocumentListener(new DocumentListener() {

        @Override
        public void documentChanged(final DocumentEvent e) {
            final String shortName = StringUtil.getShortName(myMainClassComponent.getText().trim());
            if (!shortName.isEmpty()) {
                myOutputFileNameTextField.setText(shortName + ".swf");
            }
        }
    });
    myOutputFileNameTextField.getDocument().addDocumentListener(new com.intellij.ui.DocumentAdapter() {

        @Override
        protected void textChanged(final javax.swing.event.DocumentEvent e) {
            final FlexBuildConfiguration bc = myBCCombo.getBC();
            if (bc != null && bc.getTargetPlatform() == TargetPlatform.Web) {
                updateBCOutputLabel(bc);
            }
        }
    });
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) ActionEvent(java.awt.event.ActionEvent) FlexBuildConfiguration(com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) ActionListener(java.awt.event.ActionListener)

Example 33 with DocumentEvent

use of com.intellij.openapi.editor.event.DocumentEvent in project kotlin by JetBrains.

the class PluginStartupComponent method initComponent.

@Override
public void initComponent() {
    registerPathVariable();
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        ThreadTrackerPatcherForTeamCityTesting.INSTANCE.patchThreadTracker();
    }
    JarUserDataManager.INSTANCE.register(KotlinJavaScriptLibraryDetectionUtil.HasKotlinJSMetadataInJar.INSTANCE);
    DebuggerFiltersUtilKt.addKotlinStdlibDebugFilterIfNeeded();
    try {
        // API added in 15.0.2
        UpdateChecker.INSTANCE.getExcludedFromUpdateCheckPlugins().add("org.jetbrains.kotlin");
    } catch (Throwable throwable) {
        LOG.debug("Excluding Kotlin plugin updates using old API", throwable);
        UpdateChecker.getDisabledToUpdatePlugins().add("org.jetbrains.kotlin");
    }
    EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            VirtualFile virtualFile = FileDocumentManager.getInstance().getFile(e.getDocument());
            if (virtualFile != null && virtualFile.getFileType() == KotlinFileType.INSTANCE) {
                KotlinPluginUpdater.Companion.getInstance().kotlinFileEdited();
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 34 with DocumentEvent

use of com.intellij.openapi.editor.event.DocumentEvent in project intellij-community by JetBrains.

the class CheckRegExpForm method createUIComponents.

private void createUIComponents() {
    myProject = myRegexpFile.getProject();
    Document document = PsiDocumentManager.getInstance(myProject).getDocument(myRegexpFile);
    final Language language = myRegexpFile.getLanguage();
    final LanguageFileType fileType;
    if (language instanceof RegExpLanguage) {
        fileType = RegExpLanguage.INSTANCE.getAssociatedFileType();
    } else {
        // for correct syntax highlighting
        fileType = new RegExpFileType(language);
    }
    myRegExp = new EditorTextField(document, myProject, fileType);
    final String sampleText = PropertiesComponent.getInstance(myProject).getValue(LAST_EDITED_REGEXP, "Sample Text");
    mySampleText = new EditorTextField(sampleText, myProject, PlainTextFileType.INSTANCE) {

        @Override
        protected void updateBorder(@NotNull EditorEx editor) {
            setupBorder(editor);
        }
    };
    mySampleText.setOneLineMode(false);
    int preferredWidth = Math.max(JBUI.scale(250), myRegExp.getPreferredSize().width);
    myRegExp.setPreferredWidth(preferredWidth);
    mySampleText.setPreferredWidth(preferredWidth);
    myRootPanel = new JPanel(new BorderLayout()) {

        Disposable disposable;

        Alarm updater;

        @Override
        public void addNotify() {
            super.addNotify();
            disposable = Disposer.newDisposable();
            IdeFocusManager.getGlobalInstance().requestFocus(mySampleText, true);
            new AnAction() {

                @Override
                public void actionPerformed(AnActionEvent e) {
                    IdeFocusManager.findInstance().requestFocus(myRegExp.getFocusTarget(), true);
                }
            }.registerCustomShortcutSet(CustomShortcutSet.fromString("shift TAB"), mySampleText);
            updater = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, disposable);
            DocumentAdapter documentListener = new DocumentAdapter() {

                @Override
                public void documentChanged(DocumentEvent e) {
                    update();
                }
            };
            myRegExp.addDocumentListener(documentListener);
            mySampleText.addDocumentListener(documentListener);
            update();
            mySampleText.selectAll();
        }

        public void update() {
            final TransactionId transactionId = TransactionGuard.getInstance().getContextTransaction();
            updater.cancelAllRequests();
            if (!updater.isDisposed()) {
                updater.addRequest(() -> {
                    final RegExpMatchResult result = isMatchingText(myRegexpFile, mySampleText.getText());
                    TransactionGuard.getInstance().submitTransaction(myProject, transactionId, () -> setBalloonState(result));
                }, 200);
            }
        }

        @Override
        public void removeNotify() {
            super.removeNotify();
            Disposer.dispose(disposable);
            PropertiesComponent.getInstance(myProject).setValue(LAST_EDITED_REGEXP, mySampleText.getText());
        }
    };
    myRootPanel.setBorder(JBUI.Borders.empty(UIUtil.DEFAULT_VGAP, UIUtil.DEFAULT_HGAP));
}
Also used : Disposable(com.intellij.openapi.Disposable) EditorEx(com.intellij.openapi.editor.ex.EditorEx) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Document(com.intellij.openapi.editor.Document) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) TransactionId(com.intellij.openapi.application.TransactionId) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) EditorTextField(com.intellij.ui.EditorTextField) Alarm(com.intellij.util.Alarm)

Example 35 with DocumentEvent

use of com.intellij.openapi.editor.event.DocumentEvent in project android by JetBrains.

the class EditLogFilterDialog method createEditorFields.

private void createEditorFields() {
    myNameFieldLabel.setLabelFor(myFilterNameField);
    myLogMessageField = new RegexFilterComponent(LOG_FILTER_MESSAGE_HISTORY, FILTER_HISTORY_SIZE);
    myLogMessageFieldWrapper.add(myLogMessageField);
    myLogMessageLabel.setLabelFor(myLogMessageField);
    myTagField = new RegexFilterComponent(LOG_FILTER_TAG_HISTORY, FILTER_HISTORY_SIZE);
    myTagFieldWrapper.add(myTagField);
    myLogTagLabel.setLabelFor(myTagField);
    myPidField = new TextFieldWithAutoCompletion<>(myProject, new TextFieldWithAutoCompletion.StringsCompletionProvider(null, null) {

        @NotNull
        @Override
        public Collection<String> getItems(String prefix, boolean cached, CompletionParameters parameters) {
            parseExistingMessagesIfNecessary();
            setItems(myUsedPids);
            return super.getItems(prefix, cached, parameters);
        }

        @Override
        public int compare(String item1, String item2) {
            final int pid1 = Integer.parseInt(item1);
            final int pid2 = Integer.parseInt(item2);
            return Comparing.compare(pid1, pid2);
        }
    }, true, null);
    myPidFieldWrapper.add(myPidField);
    myPidLabel.setLabelFor(myPidField);
    myPackageNameField = new RegexFilterComponent(LOG_FILTER_PACKAGE_NAME_HISTORY, FILTER_HISTORY_SIZE);
    myPackageNameFieldWrapper.add(myPackageNameField);
    myPackageNameLabel.setLabelFor(myPackageNameField);
    myLogLevelCombo.setModel(new EnumComboBoxModel<>(Log.LogLevel.class));
    myLogLevelCombo.setRenderer(new ListCellRendererWrapper() {

        @Override
        public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            if (value != null) {
                setText(StringUtil.capitalize(((Log.LogLevel) value).getStringValue().toLowerCase()));
            }
        }
    });
    myLogLevelCombo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (myActiveFilter == null) {
                return;
            }
            Log.LogLevel selectedItem = (Log.LogLevel) myLogLevelCombo.getSelectedItem();
            myActiveFilter.setLogLevel(selectedItem.getStringValue());
        }
    });
    final Key<JComponent> componentKey = new Key<>("myComponent");
    myFilterNameField.getDocument().putUserData(componentKey, myFilterNameField);
    myPidField.getDocument().putUserData(componentKey, myPidField);
    DocumentListener l = new DocumentListener() {

        @Override
        public void documentChanged(DocumentEvent e) {
            if (myActiveFilter == null) {
                return;
            }
            String text = e.getDocument().getText().trim();
            JComponent src = e.getDocument().getUserData(componentKey);
            if (src == myPidField) {
                myActiveFilter.setPid(text);
            } else if (src == myFilterNameField) {
                int index = myFiltersList.getSelectedIndex();
                if (index != -1) {
                    myFiltersListModel.setElementAt(text, index);
                }
                myActiveFilter.setName(text);
            }
        }
    };
    myFilterNameField.getDocument().addDocumentListener(l);
    myPidField.getDocument().addDocumentListener(l);
    RegexFilterComponent.Listener rl = new RegexFilterComponent.Listener() {

        @Override
        public void filterChanged(RegexFilterComponent filter) {
            if (myActiveFilter == null) {
                return;
            }
            if (filter == myTagField) {
                myActiveFilter.setLogTagPattern(filter.getFilter());
                myActiveFilter.setLogTagIsRegex(filter.isRegex());
            } else if (filter == myLogMessageField) {
                myActiveFilter.setLogMessagePattern(filter.getFilter());
                myActiveFilter.setLogMessageIsRegex(filter.isRegex());
            } else if (filter == myPackageNameField) {
                myActiveFilter.setPackageNamePattern(filter.getFilter());
                myActiveFilter.setPackageNameIsRegex(filter.isRegex());
            }
        }
    };
    myTagField.addRegexListener(rl);
    myLogMessageField.addRegexListener(rl);
    myPackageNameField.addRegexListener(rl);
}
Also used : DocumentListener(com.intellij.openapi.editor.event.DocumentListener) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) ActionListener(java.awt.event.ActionListener) ListSelectionListener(javax.swing.event.ListSelectionListener) Log(com.android.ddmlib.Log) ActionEvent(java.awt.event.ActionEvent) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) CompletionParameters(com.intellij.codeInsight.completion.CompletionParameters) ActionListener(java.awt.event.ActionListener) Key(com.intellij.openapi.util.Key)

Aggregations

DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)54 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)40 Document (com.intellij.openapi.editor.Document)14 DocumentListener (com.intellij.openapi.editor.event.DocumentListener)12 EditorTextField (com.intellij.ui.EditorTextField)8 ActionEvent (java.awt.event.ActionEvent)8 ActionListener (java.awt.event.ActionListener)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Nullable (org.jetbrains.annotations.Nullable)5 Disposable (com.intellij.openapi.Disposable)4 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)4 Editor (com.intellij.openapi.editor.Editor)4 ReferenceEditorComboWithBrowseButton (com.intellij.ui.ReferenceEditorComboWithBrowseButton)4 NotNull (org.jetbrains.annotations.NotNull)4 Language (com.intellij.lang.Language)3 AnAction (com.intellij.openapi.actionSystem.AnAction)3 Module (com.intellij.openapi.module.Module)3 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)2 FrozenDocument (com.intellij.openapi.editor.impl.FrozenDocument)2 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)2