Search in sources :

Example 1 with ComponentNode

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');
        }
    }
}
Also used : ImageNode(org.apache.pivot.wtk.text.ImageNode) ComponentNode(org.apache.pivot.wtk.text.ComponentNode) Node(org.apache.pivot.wtk.text.Node) TextNode(org.apache.pivot.wtk.text.TextNode) Element(org.apache.pivot.wtk.text.Element) TextNode(org.apache.pivot.wtk.text.TextNode) CharSpan(org.apache.pivot.text.CharSpan) TextSpan(org.apache.pivot.wtk.text.TextSpan) ComponentNode(org.apache.pivot.wtk.text.ComponentNode) Paragraph(org.apache.pivot.wtk.text.Paragraph)

Example 2 with ComponentNode

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);
}
Also used : ComponentNode(org.apache.pivot.wtk.text.ComponentNode)

Example 3 with ComponentNode

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;
}
Also used : Component(org.apache.pivot.wtk.Component) ComponentNode(org.apache.pivot.wtk.text.ComponentNode)

Example 4 with ComponentNode

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);
    }
}
Also used : Component(org.apache.pivot.wtk.Component) ComponentNode(org.apache.pivot.wtk.text.ComponentNode)

Example 5 with ComponentNode

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);
}
Also used : Frame(org.apache.pivot.wtk.Frame) HyperlinkButton(org.apache.pivot.wtk.HyperlinkButton) TextPane(org.apache.pivot.wtk.TextPane) TextNode(org.apache.pivot.wtk.text.TextNode) ImageNode(org.apache.pivot.wtk.text.ImageNode) Document(org.apache.pivot.wtk.text.Document) ComponentNode(org.apache.pivot.wtk.text.ComponentNode) Paragraph(org.apache.pivot.wtk.text.Paragraph)

Aggregations

ComponentNode (org.apache.pivot.wtk.text.ComponentNode)9 Component (org.apache.pivot.wtk.Component)5 ImageNode (org.apache.pivot.wtk.text.ImageNode)3 TextNode (org.apache.pivot.wtk.text.TextNode)3 Element (org.apache.pivot.wtk.text.Element)2 Node (org.apache.pivot.wtk.text.Node)2 Paragraph (org.apache.pivot.wtk.text.Paragraph)2 CharSpan (org.apache.pivot.text.CharSpan)1 Dimensions (org.apache.pivot.wtk.Dimensions)1 Frame (org.apache.pivot.wtk.Frame)1 HyperlinkButton (org.apache.pivot.wtk.HyperlinkButton)1 TextPane (org.apache.pivot.wtk.TextPane)1 Block (org.apache.pivot.wtk.text.Block)1 Document (org.apache.pivot.wtk.text.Document)1 TextSpan (org.apache.pivot.wtk.text.TextSpan)1