Search in sources :

Example 86 with Element

use of javax.swing.text.Element in project chatty by chatty.

the class MyDocument method refresh.

public void refresh(int offset, int len) {
    DefaultDocumentEvent changes = new AbstractDocument.DefaultDocumentEvent(offset, len, DocumentEvent.EventType.CHANGE);
    Element root = getDefaultRootElement();
    Element[] removed = new Element[0];
    Element[] added = new Element[0];
    changes.addEdit(new ElementEdit(root, 0, removed, added));
    changes.end();
    fireChangedUpdate(changes);
}
Also used : Element(javax.swing.text.Element)

Example 87 with Element

use of javax.swing.text.Element in project chatty by chatty.

the class GuiUtil method debugLineContents.

/**
 * Output the text of the subelements of the given element.
 *
 * @param line
 */
public static void debugLineContents(Element line) {
    Document doc = line.getDocument();
    System.out.print("[");
    for (int i = 0; i < line.getElementCount(); i++) {
        Element l = line.getElement(i);
        // System.out.println(l);
        try {
            System.out.print("'" + doc.getText(l.getStartOffset(), l.getEndOffset() - l.getStartOffset()) + "'");
        } catch (BadLocationException ex) {
            System.out.println("Bad location");
        }
    }
    System.out.println("]");
}
Also used : Element(javax.swing.text.Element) Document(javax.swing.text.Document) Point(java.awt.Point) BadLocationException(javax.swing.text.BadLocationException)

Example 88 with Element

use of javax.swing.text.Element 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 89 with Element

use of javax.swing.text.Element 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 90 with Element

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

the class NoWrapEditorKit method applyHighlighting.

private void applyHighlighting(String content, int line) {
    Element root = getDefaultRootElement();
    int startOffset = root.getElement(line).getStartOffset();
    int endOffset = root.getElement(line).getEndOffset() - 1;
    int lineLength = endOffset - startOffset;
    int contentLength = content.length();
    endOffset = endOffset >= contentLength ? contentLength - 1 : endOffset;
    setCharacterAttributes(startOffset, lineLength, getStyle(StyleContext.DEFAULT_STYLE), true);
    checkForTokens(content, startOffset, endOffset);
}
Also used : Element(javax.swing.text.Element)

Aggregations

Element (javax.swing.text.Element)100 BadLocationException (javax.swing.text.BadLocationException)35 Point (java.awt.Point)19 AttributeSet (javax.swing.text.AttributeSet)15 Document (javax.swing.text.Document)15 HTMLDocument (javax.swing.text.html.HTMLDocument)11 FontMetrics (java.awt.FontMetrics)6 Dimension (java.awt.Dimension)5 Rectangle (java.awt.Rectangle)5 View (javax.swing.text.View)5 Font (java.awt.Font)4 Insets (java.awt.Insets)4 IOException (java.io.IOException)4 AbstractDocument (javax.swing.text.AbstractDocument)4 StyledDocument (javax.swing.text.StyledDocument)4 java.awt (java.awt)3 Objects (java.util.Objects)3 javax.swing (javax.swing)3 AbstractElement (javax.swing.text.AbstractDocument.AbstractElement)3 HTML (javax.swing.text.html.HTML)3