Search in sources :

Example 6 with ComponentNode

use of org.apache.pivot.wtk.text.ComponentNode in project pivot by apache.

the class TextPane method insertComponent.

public void insertComponent(Component component) {
    Utils.checkNull(component, "component");
    checkDocumentExists();
    if (selectionLength > 0) {
        removeDocumentRange(selectionStart, selectionLength);
    }
    // If the insertion is at the end of the document, then just add
    if (selectionStart >= document.getCharacterCount() - 1) {
        document.add(new ComponentNode(component));
    } else {
        // Walk up the tree until we find a block
        Node descendant = document.getDescendantAt(selectionStart);
        while (!(descendant instanceof Block)) {
            descendant = descendant.getParent();
        }
        Element parent = descendant.getParent();
        if (parent != null) {
            int index = parent.indexOf(descendant);
            parent.insert(new ComponentNode(component), index + 1);
        }
    }
    // Set the selection start to the character following the insertion
    setSelection(selectionStart + 1, selectionLength);
}
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) Block(org.apache.pivot.wtk.text.Block) ComponentNode(org.apache.pivot.wtk.text.ComponentNode)

Example 7 with ComponentNode

use of org.apache.pivot.wtk.text.ComponentNode in project pivot by apache.

the class TextPaneSkinComponentNodeView method setSkinLocation.

@Override
protected void setSkinLocation(int skinX, int skinY) {
    ComponentNode componentNode = (ComponentNode) getNode();
    Component component = componentNode.getComponent();
    if (component != null) {
        // I have to un-translate the x and y coordinates because the
        // component is painted by the Container object, and it's
        // co-ordinates
        // are relative to the Container object, not to the document node
        // hierarchy.
        component.setLocation(skinX, skinY);
    }
}
Also used : Component(org.apache.pivot.wtk.Component) ComponentNode(org.apache.pivot.wtk.text.ComponentNode)

Example 8 with ComponentNode

use of org.apache.pivot.wtk.text.ComponentNode in project pivot by apache.

the class TextPaneSkinComponentNodeView method childLayout.

@Override
protected void childLayout(int breakWidth) {
    ComponentNode componentNode = (ComponentNode) getNode();
    Component component = componentNode.getComponent();
    if (component == null) {
        setSize(0, 0);
    } else {
        component.validate();
        component.setSize(component.getPreferredWidth(), component.getPreferredHeight());
        setSize(component.getWidth(), component.getHeight());
    }
}
Also used : Component(org.apache.pivot.wtk.Component) ComponentNode(org.apache.pivot.wtk.text.ComponentNode)

Example 9 with ComponentNode

use of org.apache.pivot.wtk.text.ComponentNode in project pivot by apache.

the class TextPaneSkinComponentNodeView method getPreferredSize.

@Override
public Dimensions getPreferredSize(int breakWidth) {
    ComponentNode componentNode = (ComponentNode) getNode();
    Component component = componentNode.getComponent();
    if (component == null) {
        return new Dimensions(0, 0);
    }
    return new Dimensions(component.getPreferredWidth(), component.getPreferredHeight());
}
Also used : Dimensions(org.apache.pivot.wtk.Dimensions) Component(org.apache.pivot.wtk.Component) ComponentNode(org.apache.pivot.wtk.text.ComponentNode)

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