use of javax.swing.text.Element in project Botnak by Gocnak.
the class ListenerURL method mouseReleased.
@Override
public void mouseReleased(MouseEvent e) {
JTextPane editor = (JTextPane) e.getSource();
Point pt = new Point(e.getX(), e.getY());
int pos = editor.viewToModel(pt);
if (pos >= 0) {
Document doc = editor.getDocument();
if (doc instanceof DefaultStyledDocument) {
DefaultStyledDocument hdoc = (DefaultStyledDocument) doc;
Element el = hdoc.getCharacterElement(pos);
AttributeSet a = el.getAttributes();
String href = (String) a.getAttribute(HTML.Attribute.HREF);
if (href != null) {
Utils.openWebPage(href);
}
}
}
}
use of javax.swing.text.Element in project adempiere by adempiere.
the class HTMLRenderer method get.
/**
* Get View from HTML String
* @param html html string
* @return renderer view
*/
public static HTMLRenderer get(String html) {
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
try {
doc.remove(0, doc.getLength());
Reader r = new StringReader(html);
kit.read(r, doc, 0);
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
}
// Create Renderer
Element element = doc.getDefaultRootElement();
ViewFactory factory = kit.getViewFactory();
// Y_AXIS is main
View view = factory.create(element);
HTMLRenderer renderer = new HTMLRenderer(factory, view);
renderer.preferenceChanged(null, true, true);
return renderer;
}
use of javax.swing.text.Element in project jdk8u_jdk by JetBrains.
the class CAccessibleText method getLineNumberForIndex.
static int getLineNumberForIndex(final Accessible a, int index) {
final Accessible sa = CAccessible.getSwingAccessible(a);
if (!(sa instanceof JTextComponent))
return -1;
final JTextComponent jc = (JTextComponent) sa;
final Element root = jc.getDocument().getDefaultRootElement();
// treat -1 special, returns the current caret position
if (index == -1)
index = jc.getCaretPosition();
// Determine line number (can be -1)
return root.getElementIndex(index);
}
use of javax.swing.text.Element in project jdk8u_jdk by JetBrains.
the class CAccessibleText method getRangeForLine.
static int[] getRangeForLine(final Accessible a, final int lineIndex) {
Accessible sa = CAccessible.getSwingAccessible(a);
if (!(sa instanceof JTextComponent))
return null;
final JTextComponent jc = (JTextComponent) sa;
final Element root = jc.getDocument().getDefaultRootElement();
final Element line = root.getElement(lineIndex);
if (line == null)
return null;
return new int[] { line.getStartOffset(), line.getEndOffset() };
}
use of javax.swing.text.Element 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);
}
}
}
Aggregations