Search in sources :

Example 41 with AttributeSet

use of javax.swing.text.AttributeSet in project binnavi by google.

the class SyntaxDocument method highlightLinesAfter.

/*
   * Highlight lines to start or end delimiter
   */
private void highlightLinesAfter(final String content, final int line) {
    final int offset = rootElement.getElement(line).getEndOffset();
    // Start/End delimiter not found, nothing to do
    int startDelimiter = indexOf(content, getStartDelimiter(), offset);
    int endDelimiter = indexOf(content, getEndDelimiter(), offset);
    if (startDelimiter < 0) {
        startDelimiter = content.length();
    }
    if (endDelimiter < 0) {
        endDelimiter = content.length();
    }
    final int delimiter = Math.min(startDelimiter, endDelimiter);
    if (delimiter < offset) {
        return;
    }
    // Start/End delimiter found, reapply highlighting
    final int endLine = rootElement.getElementIndex(delimiter);
    for (int i = line + 1; i < endLine; i++) {
        final Element branch = rootElement.getElement(i);
        final Element leaf = doc.getCharacterElement(branch.getStartOffset());
        final AttributeSet as = leaf.getAttributes();
        if (as.isEqual(comment)) {
            applyHighlighting(content, i);
        }
    }
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) AttributeSet(javax.swing.text.AttributeSet) MutableAttributeSet(javax.swing.text.MutableAttributeSet) Element(javax.swing.text.Element)

Example 42 with AttributeSet

use of javax.swing.text.AttributeSet in project android-classyshark by google.

the class BatchDocument method appendBatchLineFeed.

public void appendBatchLineFeed(AttributeSet a) {
    batch.add(new ElementSpec(a, ElementSpec.ContentType, EOL_ARRAY, 0, 1));
    Element paragraph = getParagraphElement(0);
    AttributeSet pattern = paragraph.getAttributes();
    batch.add(new ElementSpec(null, ElementSpec.EndTagType));
    batch.add(new ElementSpec(pattern, ElementSpec.StartTagType));
}
Also used : AttributeSet(javax.swing.text.AttributeSet) Element(javax.swing.text.Element)

Example 43 with AttributeSet

use of javax.swing.text.AttributeSet in project java-swing-tips by aterai.

the class TooltipEditorKit method getSpanTitleAttribute.

private Optional<String> getSpanTitleAttribute(HTMLDocument doc, int pos) {
    // HTMLDocument doc = (HTMLDocument) editor.getDocument();
    Element elem = doc.getCharacterElement(pos);
    // if (!doesElementContainLocation(editor, elem, pos, e.getX(), e.getY())) {
    // elem = null;
    // }
    // if (elem != null) {
    AttributeSet a = elem.getAttributes();
    AttributeSet span = (AttributeSet) a.getAttribute(HTML.Tag.SPAN);
    return Optional.ofNullable(span).map(s -> Objects.toString(s.getAttribute(HTML.Attribute.TITLE)));
}
Also used : AttributeSet(javax.swing.text.AttributeSet) Element(javax.swing.text.Element)

Example 44 with AttributeSet

use of javax.swing.text.AttributeSet in project java-swing-tips by aterai.

the class MainPanel method checkId.

public void checkId(Element element) {
    AttributeSet attrs = element.getAttributes();
    Object elementName = attrs.getAttribute(AbstractDocument.ElementNameAttribute);
    Object name = Objects.isNull(elementName) ? attrs.getAttribute(StyleConstants.NameAttribute) : null;
    HTML.Tag tag;
    if (name instanceof HTML.Tag) {
        tag = (HTML.Tag) name;
    } else {
        return;
    }
    textArea.append(String.format("%s%n", tag));
    if (tag.isBlock()) {
        // block
        blockHighlight(element, attrs);
    } else {
        // inline
        inlineHighlight(element, attrs);
    }
}
Also used : MutableAttributeSet(javax.swing.text.MutableAttributeSet) AttributeSet(javax.swing.text.AttributeSet) HTML(javax.swing.text.html.HTML)

Aggregations

AttributeSet (javax.swing.text.AttributeSet)44 Element (javax.swing.text.Element)15 MutableAttributeSet (javax.swing.text.MutableAttributeSet)10 BadLocationException (javax.swing.text.BadLocationException)9 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)9 HTMLDocument (javax.swing.text.html.HTMLDocument)7 AbstractDocument (javax.swing.text.AbstractDocument)6 Document (javax.swing.text.Document)5 DocumentFilter (javax.swing.text.DocumentFilter)5 Font (java.awt.Font)3 Point (java.awt.Point)3 URL (java.net.URL)3 HTML (javax.swing.text.html.HTML)3 java.awt (java.awt)2 Color (java.awt.Color)2 Dimension (java.awt.Dimension)2 FontMetrics (java.awt.FontMetrics)2 Rectangle (java.awt.Rectangle)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2