Search in sources :

Example 1 with Block

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

the class TextPaneSkinBlockView method detach.

@Override
protected void detach() {
    super.detach();
    Block block = (Block) getNode();
    block.getBlockListeners().remove(this);
}
Also used : Block(org.apache.pivot.wtk.text.Block)

Example 2 with Block

use of org.apache.pivot.wtk.text.Block 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 3 with Block

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

the class TextPane method insertImage.

public void insertImage(Image image) {
    Utils.checkNull(image, "image");
    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 ImageNode(image));
    } 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 ImageNode(image), 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) ImageNode(org.apache.pivot.wtk.text.ImageNode)

Example 4 with Block

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

the class TextPaneSkinBlockView method attach.

@Override
protected void attach() {
    super.attach();
    Block block = (Block) getNode();
    block.getBlockListeners().add(this);
}
Also used : Block(org.apache.pivot.wtk.text.Block)

Aggregations

Block (org.apache.pivot.wtk.text.Block)4 ComponentNode (org.apache.pivot.wtk.text.ComponentNode)2 Element (org.apache.pivot.wtk.text.Element)2 ImageNode (org.apache.pivot.wtk.text.ImageNode)2 Node (org.apache.pivot.wtk.text.Node)2 TextNode (org.apache.pivot.wtk.text.TextNode)2