use of org.apache.pivot.wtk.text.ComponentNode in project pivot by apache.
the class TextPane method addToText.
/**
* Add the text from the given element (and its children) to the given buffer,
* respecting the range of characters to be included.
*
* @param text The buffer we're building.
* @param element The current element in the document.
* @param includeSpan The range of text to be included (in document-relative
* coordinates).
*/
private void addToText(StringBuilder text, Element element, Span includeSpan) {
Span elementSpan = element.getDocumentSpan();
Span elementIntersection = elementSpan.intersect(includeSpan);
if (elementIntersection != null) {
for (Node node : element) {
if (node instanceof Element) {
addToText(text, (Element) node, includeSpan);
} else {
Span nodeSpan = node.getDocumentSpan();
Span nodeIntersection = nodeSpan.intersect(includeSpan);
if (nodeIntersection != null) {
Span currentSpan = nodeIntersection.offset(-nodeSpan.start);
if (node instanceof TextNode) {
text.append(((TextNode) node).getCharacters(currentSpan));
} else if (node instanceof ComponentNode) {
text.append(((ComponentNode) node).getCharacters(currentSpan));
}
// TODO: anything more that could/should be handled?
// lists for instance???
}
}
}
if (element instanceof Paragraph && elementIntersection.end == elementSpan.end) {
// TODO: unclear if this is included in the character count for a paragraph or not
// or what that means for the intersection range above
text.append('\n');
}
}
}
use of org.apache.pivot.wtk.text.ComponentNode in project pivot by apache.
the class TextPaneSkinComponentNodeView method detach.
@Override
protected void detach() {
super.detach();
ComponentNode componentNode = (ComponentNode) getNode();
componentNode.getComponentNodeListeners().remove(this);
}
use of org.apache.pivot.wtk.text.ComponentNode in project pivot by apache.
the class TextPaneSkinComponentNodeView method getBaseline.
@Override
public int getBaseline() {
ComponentNode componentNode = (ComponentNode) getNode();
Component component = componentNode.getComponent();
int baseline = -1;
if (component != null) {
baseline = component.getBaseline();
}
return baseline;
}
use of org.apache.pivot.wtk.text.ComponentNode in project pivot by apache.
the class TextPaneSkinComponentNodeView method attach.
@Override
protected void attach() {
super.attach();
ComponentNode componentNode = (ComponentNode) getNode();
componentNode.getComponentNodeListeners().add(this);
Component component = componentNode.getComponent();
if (component != null) {
component.getComponentListeners().add(myComponentListener);
}
}
use of org.apache.pivot.wtk.text.ComponentNode in project pivot by apache.
the class HyperlinkButtonTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
frame = new Frame();
frame.setTitle("Hyperlink Button Test");
frame.setPreferredSize(480, 360);
HyperlinkButton button1 = new HyperlinkButton("http://pivot.apache.org");
HyperlinkButton button2 = new HyperlinkButton("Apache website", "http://apache.org");
TextPane textPane = new TextPane();
Document document = new Document();
TextNode text1 = new TextNode("Link to the Apache Pivot site: ");
TextNode text2 = new TextNode("Main Apache Software Foundation website: ");
ComponentNode compNode1 = new ComponentNode(button1);
ComponentNode compNode2 = new ComponentNode(button2);
Paragraph para1 = new Paragraph();
para1.add(text1);
document.add(para1);
document.add(compNode1);
Paragraph para2 = new Paragraph();
para2.add(text2);
document.add(para2);
document.add(compNode2);
ImageNode image1 = new ImageNode("/org/apache/pivot/tests/house.png");
document.add(image1);
textPane.setDocument(document);
frame.setContent(textPane);
frame.open(display);
}
Aggregations