Search in sources :

Example 16 with DocumentAdapter

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

the class LiveTemplateSettingsEditor method createComponents.

private void createComponents(boolean allowNoContexts) {
    JPanel panel = new JPanel(new GridBagLayout());
    GridBag gb = new GridBag().setDefaultInsets(4, 4, 4, 4).setDefaultWeightY(1).setDefaultFill(GridBagConstraints.BOTH);
    JPanel editorPanel = new JPanel(new BorderLayout(4, 4));
    editorPanel.setPreferredSize(JBUI.size(250, 100));
    editorPanel.setMinimumSize(editorPanel.getPreferredSize());
    editorPanel.add(myTemplateEditor.getComponent(), BorderLayout.CENTER);
    JLabel templateTextLabel = new JLabel(CodeInsightBundle.message("dialog.edit.template.template.text.title"));
    templateTextLabel.setLabelFor(myTemplateEditor.getContentComponent());
    editorPanel.add(templateTextLabel, BorderLayout.NORTH);
    editorPanel.setFocusable(false);
    panel.add(editorPanel, gb.nextLine().next().weighty(1).weightx(1).coverColumn(2));
    myEditVariablesButton = new JButton(CodeInsightBundle.message("dialog.edit.template.button.edit.variables"));
    myEditVariablesButton.setDefaultCapable(false);
    myEditVariablesButton.setMaximumSize(myEditVariablesButton.getPreferredSize());
    panel.add(myEditVariablesButton, gb.next().weighty(0));
    myTemplateOptionsPanel = new JPanel(new BorderLayout());
    myTemplateOptionsPanel.add(createTemplateOptionsPanel());
    panel.add(myTemplateOptionsPanel, gb.nextLine().next().next().coverColumn(2).weighty(1));
    panel.add(createShortContextPanel(allowNoContexts), gb.nextLine().next().weighty(0).fillCellNone().anchor(GridBagConstraints.WEST));
    myTemplateEditor.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            validateEditVariablesButton();
            myTemplate.setString(myTemplateEditor.getDocument().getText());
            applyVariables(updateVariablesByTemplateText());
            myNodeChanged.run();
        }
    });
    myEditVariablesButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            editVariables();
        }
    });
    add(createNorthPanel(), BorderLayout.NORTH);
    add(panel, BorderLayout.CENTER);
}
Also used : DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) GridBag(com.intellij.util.ui.GridBag) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent)

Example 17 with DocumentAdapter

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

the class LookupImpl method addListeners.

private void addListeners() {
    myEditor.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            if (!myChangeGuard && !myFinishing) {
                hideLookup(false);
            }
        }
    }, this);
    final CaretListener caretListener = new CaretAdapter() {

        @Override
        public void caretPositionChanged(CaretEvent e) {
            if (!myChangeGuard && !myFinishing) {
                hideLookup(false);
            }
        }
    };
    final SelectionListener selectionListener = new SelectionListener() {

        @Override
        public void selectionChanged(final SelectionEvent e) {
            if (!myChangeGuard && !myFinishing) {
                hideLookup(false);
            }
        }
    };
    final EditorMouseListener mouseListener = new EditorMouseAdapter() {

        @Override
        public void mouseClicked(EditorMouseEvent e) {
            e.consume();
            hideLookup(false);
        }
    };
    myEditor.getCaretModel().addCaretListener(caretListener);
    myEditor.getSelectionModel().addSelectionListener(selectionListener);
    myEditor.addEditorMouseListener(mouseListener);
    Disposer.register(this, new Disposable() {

        @Override
        public void dispose() {
            myEditor.getCaretModel().removeCaretListener(caretListener);
            myEditor.getSelectionModel().removeSelectionListener(selectionListener);
            myEditor.removeEditorMouseListener(mouseListener);
        }
    });
    JComponent editorComponent = myEditor.getContentComponent();
    if (editorComponent.isShowing()) {
        Disposer.register(this, new UiNotifyConnector(editorComponent, new Activatable() {

            @Override
            public void showNotify() {
            }

            @Override
            public void hideNotify() {
                hideLookup(false);
            }
        }));
    }
    myList.addListSelectionListener(new ListSelectionListener() {

        private LookupElement oldItem = null;

        @Override
        public void valueChanged(@NotNull ListSelectionEvent e) {
            if (!myUpdating) {
                final LookupElement item = getCurrentItem();
                fireCurrentItemChanged(oldItem, item);
                oldItem = item;
            }
        }
    });
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            setFocusDegree(FocusDegree.FOCUSED);
            markSelectionTouched();
            if (clickCount == 2) {
                CommandProcessor.getInstance().executeCommand(myProject, () -> finishLookup(NORMAL_SELECT_CHAR), "", null);
            }
            return true;
        }
    }.installOn(myList);
}
Also used : Disposable(com.intellij.openapi.Disposable) MouseEvent(java.awt.event.MouseEvent) Activatable(com.intellij.util.ui.update.Activatable) ListSelectionEvent(javax.swing.event.ListSelectionEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) UiNotifyConnector(com.intellij.util.ui.update.UiNotifyConnector) RelativePoint(com.intellij.ui.awt.RelativePoint) ListSelectionListener(javax.swing.event.ListSelectionListener) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 18 with DocumentAdapter

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

the class FindDialog method initCombobox.

private void initCombobox(@NotNull final ComboBox comboBox) {
    comboBox.setEditable(true);
    comboBox.setMaximumRowCount(8);
    comboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            validateFindButton();
        }
    });
    final Component editorComponent = comboBox.getEditor().getEditorComponent();
    if (editorComponent instanceof EditorTextField) {
        final EditorTextField etf = (EditorTextField) editorComponent;
        DocumentAdapter listener = new DocumentAdapter() {

            @Override
            public void documentChanged(final DocumentEvent e) {
                handleComboBoxValueChanged(comboBox);
            }
        };
        etf.addDocumentListener(listener);
        myComboBoxListeners.put(etf, listener);
    } else {
        if (editorComponent instanceof JTextComponent) {
            final javax.swing.text.Document document = ((JTextComponent) editorComponent).getDocument();
            final com.intellij.ui.DocumentAdapter documentAdapter = new com.intellij.ui.DocumentAdapter() {

                @Override
                protected void textChanged(javax.swing.event.DocumentEvent e) {
                    handleAnyComboBoxValueChanged(comboBox);
                }
            };
            document.addDocumentListener(documentAdapter);
            Disposer.register(myDisposable, new Disposable() {

                @Override
                public void dispose() {
                    document.removeDocumentListener(documentAdapter);
                }
            });
        } else {
            assert false;
        }
    }
    if (!myHelper.getModel().isReplaceState()) {
        makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "choosePrevious", () -> {
            int row = myResultsPreviewTable.getSelectedRow();
            if (row > 0)
                myResultsPreviewTable.setRowSelectionInterval(row - 1, row - 1);
            TableUtil.scrollSelectionToVisible(myResultsPreviewTable);
        });
        makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "chooseNext", () -> {
            int row = myResultsPreviewTable.getSelectedRow();
            if (row >= -1 && row + 1 < myResultsPreviewTable.getRowCount()) {
                myResultsPreviewTable.setRowSelectionInterval(row + 1, row + 1);
                TableUtil.scrollSelectionToVisible(myResultsPreviewTable);
            }
        });
        makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "scrollUp", () -> {
            ScrollingUtil.movePageUp(myResultsPreviewTable);
        });
        makeResultsPreviewActionOverride(comboBox, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "scrollDown", () -> {
            ScrollingUtil.movePageDown(myResultsPreviewTable);
        });
        AnAction action = new AnAction() {

            @Override
            public void actionPerformed(AnActionEvent e) {
                if (isResultsPreviewTabActive()) {
                    navigateToSelectedUsage(myResultsPreviewTable);
                }
            }
        };
        action.registerCustomShortcutSet(CommonShortcuts.getEditSource(), comboBox, myDisposable);
        new AnAction() {

            @Override
            public void actionPerformed(AnActionEvent e) {
                if (!isResultsPreviewTabActive() || myResultsPreviewTable.getSelectedRowCount() == 0)
                    doOKAction();
                else
                    action.actionPerformed(e);
            }
        }.registerCustomShortcutSet(CommonShortcuts.ENTER, comboBox, myDisposable);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) JTextComponent(javax.swing.text.JTextComponent) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) javax.swing(javax.swing) com.intellij.ui(com.intellij.ui) com.intellij.openapi.ui(com.intellij.openapi.ui) JTextComponent(javax.swing.text.JTextComponent)

Example 19 with DocumentAdapter

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

the class FileTemplateConfigurable method createEditor.

private Editor createEditor() {
    EditorFactory editorFactory = EditorFactory.getInstance();
    Document doc = myFile == null ? editorFactory.createDocument(myTemplate == null ? "" : myTemplate.getText()) : PsiDocumentManager.getInstance(myFile.getProject()).getDocument(myFile);
    assert doc != null;
    Editor editor = editorFactory.createEditor(doc, myProject);
    EditorSettings editorSettings = editor.getSettings();
    editorSettings.setVirtualSpace(false);
    editorSettings.setLineMarkerAreaShown(false);
    editorSettings.setIndentGuidesShown(false);
    editorSettings.setLineNumbersShown(false);
    editorSettings.setFoldingOutlineShown(false);
    editorSettings.setAdditionalColumnsCount(3);
    editorSettings.setAdditionalLinesCount(3);
    editorSettings.setCaretRowShown(false);
    editor.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            onTextChanged();
        }
    });
    ((EditorEx) editor).setHighlighter(createHighlighter());
    JPanel topPanel = new JPanel(new BorderLayout());
    JPanel southPanel = new JPanel(new HorizontalLayout(40));
    southPanel.add(myAdjustBox);
    southPanel.add(myLiveTemplateBox);
    topPanel.add(southPanel, BorderLayout.SOUTH);
    topPanel.add(editor.getComponent(), BorderLayout.CENTER);
    mySplitter.setFirstComponent(topPanel);
    return editor;
}
Also used : EditorFactory(com.intellij.openapi.editor.EditorFactory) EditorSettings(com.intellij.openapi.editor.EditorSettings) EditorEx(com.intellij.openapi.editor.ex.EditorEx) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) Document(com.intellij.openapi.editor.Document) Editor(com.intellij.openapi.editor.Editor) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) HorizontalLayout(com.intellij.ui.components.panels.HorizontalLayout)

Example 20 with DocumentAdapter

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

the class ChangeSignatureDialogBase method createParametersPanel.

protected JPanel createParametersPanel(boolean hasTabsInDialog) {
    myParametersTable = new TableView<ParameterTableModelItem>(myParametersTableModel) {

        @Override
        public void removeEditor() {
            clearEditorListeners();
            super.removeEditor();
        }

        @Override
        public void editingStopped(ChangeEvent e) {
            super.editingStopped(e);
            // to update disabled cells background
            repaint();
        }

        private void clearEditorListeners() {
            final TableCellEditor editor = getCellEditor();
            if (editor instanceof StringTableCellEditor) {
                final StringTableCellEditor ed = (StringTableCellEditor) editor;
                ed.clearListeners();
            } else if (editor instanceof CodeFragmentTableCellEditorBase) {
                ((CodeFragmentTableCellEditorBase) editor).clearListeners();
            }
        }

        @Override
        public Component prepareEditor(final TableCellEditor editor, final int row, final int column) {
            final DocumentAdapter listener = new DocumentAdapter() {

                @Override
                public void documentChanged(DocumentEvent e) {
                    final TableCellEditor ed = myParametersTable.getCellEditor();
                    if (ed != null) {
                        Object editorValue = ed.getCellEditorValue();
                        myParametersTableModel.setValueAtWithoutUpdate(editorValue, row, column);
                        updateSignature();
                    }
                }
            };
            if (editor instanceof StringTableCellEditor) {
                final StringTableCellEditor ed = (StringTableCellEditor) editor;
                ed.addDocumentListener(listener);
            } else if (editor instanceof CodeFragmentTableCellEditorBase) {
                ((CodeFragmentTableCellEditorBase) editor).addDocumentListener(listener);
            }
            return super.prepareEditor(editor, row, column);
        }

        @Override
        public void editingCanceled(ChangeEvent e) {
            super.editingCanceled(e);
        }
    };
    myParametersTable.setCellSelectionEnabled(true);
    myParametersTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myParametersTable.getSelectionModel().setSelectionInterval(0, 0);
    myParametersTable.setSurrendersFocusOnKeystroke(true);
    myPropagateParamChangesButton.setShortcut(CustomShortcutSet.fromString("alt G"));
    if (isListTableViewSupported()) {
        myParametersList = createParametersListTable();
        final JPanel buttonsPanel = ToolbarDecorator.createDecorator(myParametersList.getTable()).addExtraAction(myPropagateParamChangesButton).createPanel();
        myParametersList.getTable().getModel().addTableModelListener(mySignatureUpdater);
        return buttonsPanel;
    } else {
        final JPanel buttonsPanel = ToolbarDecorator.createDecorator(getTableComponent()).addExtraAction(myPropagateParamChangesButton).createPanel();
        myPropagateParamChangesButton.setEnabled(false);
        myPropagateParamChangesButton.setVisible(false);
        myParametersTable.setStriped(true);
        myParametersTableModel.addTableModelListener(mySignatureUpdater);
        customizeParametersTable(myParametersTable);
        return buttonsPanel;
    }
}
Also used : DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) ChangeEvent(javax.swing.event.ChangeEvent) TableCellEditor(javax.swing.table.TableCellEditor)

Aggregations

DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)41 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)40 Document (com.intellij.openapi.editor.Document)10 EditorTextField (com.intellij.ui.EditorTextField)6 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)6 Disposable (com.intellij.openapi.Disposable)4 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ReferenceEditorComboWithBrowseButton (com.intellij.ui.ReferenceEditorComboWithBrowseButton)4 NotNull (org.jetbrains.annotations.NotNull)4 AnAction (com.intellij.openapi.actionSystem.AnAction)3 Editor (com.intellij.openapi.editor.Editor)3 Module (com.intellij.openapi.module.Module)3 Pair (com.intellij.openapi.util.Pair)3 Ref (com.intellij.openapi.util.Ref)3 Nullable (org.jetbrains.annotations.Nullable)3 TemplateState (com.intellij.codeInsight.template.impl.TemplateState)2 Language (com.intellij.lang.Language)2 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)2