Search in sources :

Example 96 with Document

use of javax.swing.text.Document in project intellij-community by JetBrains.

the class HtmlUnknownTagInspection method createOptionsPanel.

@NotNull
protected static JComponent createOptionsPanel(@NotNull final HtmlUnknownElementInspection inspection) {
    final JPanel result = new JPanel(new BorderLayout());
    final JPanel internalPanel = new JPanel(new BorderLayout());
    result.add(internalPanel, BorderLayout.NORTH);
    final Ref<FieldPanel> panelRef = new Ref<>();
    final FieldPanel additionalAttributesPanel = new FieldPanel(null, null, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            Messages.showTextAreaDialog(panelRef.get().getTextField(), StringUtil.wordsToBeginFromUpperCase(inspection.getPanelTitle()), inspection.getClass().getSimpleName(), s -> reparseProperties(s), strings -> StringUtil.join(strings, ","));
        }
    }, null);
    ((JButton) additionalAttributesPanel.getComponent(1)).setIcon(PlatformIcons.OPEN_EDIT_DIALOG_ICON);
    panelRef.set(additionalAttributesPanel);
    additionalAttributesPanel.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            final Document document = e.getDocument();
            try {
                final String text = document.getText(0, document.getLength());
                if (text != null) {
                    inspection.updateAdditionalEntries(text.trim());
                }
            } catch (BadLocationException e1) {
                inspection.getLogger().error(e1);
            }
        }
    });
    final JCheckBox checkBox = new JCheckBox(inspection.getCheckboxTitle());
    checkBox.setSelected(inspection.isCustomValuesEnabled());
    checkBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final boolean b = checkBox.isSelected();
            if (b != inspection.isCustomValuesEnabled()) {
                inspection.enableCustomValues(b);
                additionalAttributesPanel.setEnabled(inspection.isCustomValuesEnabled());
            }
        }
    });
    internalPanel.add(checkBox, BorderLayout.NORTH);
    internalPanel.add(additionalAttributesPanel, BorderLayout.CENTER);
    additionalAttributesPanel.setPreferredSize(new Dimension(150, additionalAttributesPanel.getPreferredSize().height));
    additionalAttributesPanel.setEnabled(inspection.isCustomValuesEnabled());
    additionalAttributesPanel.setText(inspection.getAdditionalEntries());
    return result;
}
Also used : ActionListener(java.awt.event.ActionListener) TemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider) NonNls(org.jetbrains.annotations.NonNls) ConfigurableTemplateLanguageFileViewProvider(com.intellij.psi.templateLanguages.ConfigurableTemplateLanguageFileViewProvider) TemplateLanguageUtil(com.intellij.psi.templateLanguages.TemplateLanguageUtil) Nls(org.jetbrains.annotations.Nls) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Messages(com.intellij.openapi.ui.Messages) DocumentEvent(javax.swing.event.DocumentEvent) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PlatformIcons(com.intellij.util.PlatformIcons) StringUtil(com.intellij.openapi.util.text.StringUtil) FileViewProvider(com.intellij.psi.FileViewProvider) FieldPanel(com.intellij.ui.FieldPanel) BadLocationException(javax.swing.text.BadLocationException) LocalQuickFixOnPsiElement(com.intellij.codeInspection.LocalQuickFixOnPsiElement) ActionEvent(java.awt.event.ActionEvent) java.awt(java.awt) ChangeTemplateDataLanguageAction(com.intellij.psi.templateLanguages.ChangeTemplateDataLanguageAction) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Function(com.intellij.util.Function) Document(javax.swing.text.Document) NotNull(org.jetbrains.annotations.NotNull) LangBundle(com.intellij.lang.LangBundle) Ref(com.intellij.openapi.util.Ref) DocumentAdapter(com.intellij.ui.DocumentAdapter) javax.swing(javax.swing) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.ui.DocumentAdapter) DocumentEvent(javax.swing.event.DocumentEvent) Document(javax.swing.text.Document) Ref(com.intellij.openapi.util.Ref) ActionListener(java.awt.event.ActionListener) FieldPanel(com.intellij.ui.FieldPanel) BadLocationException(javax.swing.text.BadLocationException) NotNull(org.jetbrains.annotations.NotNull)

Example 97 with Document

use of javax.swing.text.Document in project jdk8u_jdk by JetBrains.

the class TextComponentPrintable method releaseReadLock.

/**
     * Tries to release document's readlock
     *
     * Note: Not to be called on the EDT.
     */
private void releaseReadLock() {
    assert !SwingUtilities.isEventDispatchThread();
    Document document = textComponentToPrint.getDocument();
    if (document instanceof AbstractDocument) {
        try {
            ((AbstractDocument) document).readUnlock();
            needReadLock = true;
        } catch (Error ignore) {
        // readUnlock() might throw StateInvariantError
        }
    }
}
Also used : AbstractDocument(javax.swing.text.AbstractDocument) AbstractDocument(javax.swing.text.AbstractDocument) HTMLDocument(javax.swing.text.html.HTMLDocument) Document(javax.swing.text.Document)

Example 98 with Document

use of javax.swing.text.Document in project jdk8u_jdk by JetBrains.

the class TextComponentPrintable method acquireReadLock.

/**
     * Tries to acquire document's readLock if it was released
     * in releaseReadLock() method.
     *
     * Note: Not to be called on the EDT.
     */
private void acquireReadLock() {
    assert !SwingUtilities.isEventDispatchThread();
    if (needReadLock) {
        try {
            /*
                 * wait until all the EDT events are processed
                 * some of the document changes are asynchronous
                 * we need to make sure we get the lock after those changes
                 */
            SwingUtilities.invokeAndWait(new Runnable() {

                public void run() {
                }
            });
        } catch (InterruptedException ignore) {
        } catch (java.lang.reflect.InvocationTargetException ignore) {
        }
        Document document = textComponentToPrint.getDocument();
        ((AbstractDocument) document).readLock();
        needReadLock = false;
    }
}
Also used : AbstractDocument(javax.swing.text.AbstractDocument) AbstractDocument(javax.swing.text.AbstractDocument) HTMLDocument(javax.swing.text.html.HTMLDocument) Document(javax.swing.text.Document)

Example 99 with Document

use of javax.swing.text.Document in project jdk8u_jdk by JetBrains.

the class ElementTreePanel method setEditor.

/**
     * Resets the JTextComponent to <code>editor</code>. This will update
     * the tree accordingly.
     */
public void setEditor(JTextComponent editor) {
    if (this.editor == editor) {
        return;
    }
    if (this.editor != null) {
        Document oldDoc = this.editor.getDocument();
        oldDoc.removeDocumentListener(this);
        this.editor.removePropertyChangeListener(this);
        this.editor.removeCaretListener(this);
    }
    this.editor = editor;
    if (editor == null) {
        treeModel = null;
        tree.setModel(null);
    } else {
        Document newDoc = editor.getDocument();
        newDoc.addDocumentListener(this);
        editor.addPropertyChangeListener(this);
        editor.addCaretListener(this);
        treeModel = new ElementTreeModel(newDoc);
        tree.setModel(treeModel);
    }
}
Also used : Document(javax.swing.text.Document)

Example 100 with Document

use of javax.swing.text.Document in project suite by stupidsing.

the class EditorPane method replaceLines.

private void replaceLines(Fun<Segment, String> fun) throws BadLocationException {
    Document document = getDocument();
    int length = document.getLength();
    int ss = getSelectionStart();
    int se = max(ss, getSelectionEnd() - 1);
    while (0 < ss && document.getText(ss, 1).charAt(0) != 10) ss--;
    while (se < length && document.getText(se, 1).charAt(0) != 10) se++;
    // do not include first and last LFs
    int start = document.getText(ss, 1).charAt(0) == 10 ? ss + 1 : ss;
    int end = se;
    replace(document, start, end, fun);
}
Also used : Document(javax.swing.text.Document)

Aggregations

Document (javax.swing.text.Document)170 BadLocationException (javax.swing.text.BadLocationException)85 DocumentEvent (javax.swing.event.DocumentEvent)15 DefaultStyledDocument (javax.swing.text.DefaultStyledDocument)15 HTMLDocument (javax.swing.text.html.HTMLDocument)15 Element (javax.swing.text.Element)14 AbstractDocument (javax.swing.text.AbstractDocument)11 StringReader (java.io.StringReader)10 PlainDocument (javax.swing.text.PlainDocument)10 DocumentAdapter (com.intellij.ui.DocumentAdapter)8 Matcher (java.util.regex.Matcher)8 JTextComponent (javax.swing.text.JTextComponent)8 ActionEvent (java.awt.event.ActionEvent)7 DocumentListener (javax.swing.event.DocumentListener)7 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)7 IOException (java.io.IOException)6 PatternSyntaxException (java.util.regex.PatternSyntaxException)6 Highlighter (javax.swing.text.Highlighter)5 FieldDefinition (com.revolsys.record.schema.FieldDefinition)4 Point (java.awt.Point)4