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);
}
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("]");
}
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));
}
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)));
}
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);
}
Aggregations