Package org.apache.pivot.wtk.text

Examples of org.apache.pivot.wtk.text.Node


        }
    }

    private Color getStyledBackgroundColor() {
        Color backgroundColor = null;
        Node node = getNode();
        // run up the tree until we find a Element's style to apply
        while (node != null) {
            if (node instanceof Element) {
                backgroundColor = ((Element) node).getBackgroundColor();
                if (backgroundColor != null) {
                    break;
                }
            }
            node = node.getParent();
        }
        return backgroundColor;
    }
View Full Code Here


            // the document is currently empty
            Paragraph paragraph = new Paragraph();
            paragraph.add(text);
            document.insert(paragraph, 0);
        } else {
            Node descendant = document.getDescendantAt(selectionStart);
            int offset = selectionStart - descendant.getDocumentOffset();

            if (descendant instanceof TextNode) {
                // The caret is positioned within an existing text node
                TextNode textNode = (TextNode)descendant;
                textNode.insertText(text, offset);
            } else if (descendant instanceof Paragraph) {
                // The caret is positioned on the paragraph terminator
                Paragraph paragraph = (Paragraph)descendant;

                int n = paragraph.getLength();
                if (n > 0) {
                    Node node = paragraph.get(n - 1);
                    if (node instanceof TextNode) {
                        // Insert the text into the existing node
                        TextNode textNode = (TextNode)node;
                        textNode.insertText(text, offset - textNode.getOffset());
                    } else {
View Full Code Here

        if (selectionLength > 0) {
            document.removeRange(selectionStart, selectionLength);
        }

        // Walk up the tree until we find a paragraph
        Node descendant = document.getDescendantAt(selectionStart);
        while (!(descendant instanceof Paragraph)) {
            descendant = descendant.getParent();
        }

        // Split the paragraph at the insertion point
        Paragraph leadingSegment = (Paragraph)descendant;
        int offset = selectionStart - leadingSegment.getDocumentOffset();
View Full Code Here

            characterCount = 1;
        }

        if (offset >= 0
            && offset < document.getCharacterCount()) {
            Node descendant = document.getDescendantAt(offset);

            if (selectionLength == 0
                && descendant instanceof Paragraph) {
                // We are deleting a paragraph terminator
                Paragraph paragraph = (Paragraph)descendant;
View Full Code Here

        }
    }

    private Color getStyledBackgroundColor() {
        Color backgroundColor = null;
        Node node = getNode();
        // run up the tree until we find a Element's style to apply
        while (node != null) {
            if (node instanceof Element) {
                backgroundColor = ((Element) node).getBackgroundColor();
                if (backgroundColor != null) {
                    break;
                }
            }
            node = node.getParent();
        }
        return backgroundColor;
    }
View Full Code Here

    private interface StyleApplicator {
        void apply(TextSpan span);
    }

    private void applyAlignmentStyle(HorizontalAlignment horizontalAlignment) {
        Node node = textPane.getDocument().getDescendantAt(textPane.getSelectionStart());
        while (node != null && !(node instanceof Paragraph)) {
            node = node.getParent();
        }
        if (node != null) {
            Paragraph paragraph = (Paragraph) node;
            paragraph.setHorizontalAlignment(horizontalAlignment);
        }
View Full Code Here

            // if the selection covers the first part of the span-node, split
            // off the first part of the span-node, and apply the style to it
            int intersectionLength = selectionSpan.end - textSpan.start;
            TextSpan node1 = spanNode.getRange(0, intersectionLength);
            styleApplicator.apply(node1);
            Node node2 = spanNode.getRange(intersectionLength, characterCount - intersectionLength);
            Element parent = spanNode.getParent();
            int index = parent.remove(spanNode);
            parent.insert(node1, index);
            parent.insert(node2, index + 1);
        } else if (selectionSpan.end >= textSpan.end) {
View Full Code Here

            // the document is currently empty
            Paragraph paragraph = new Paragraph();
            paragraph.add(text);
            document.insert(paragraph, 0);
        } else {
            Node descendant = document.getDescendantAt(selectionStart);
            int offset = selectionStart - descendant.getDocumentOffset();

            if (descendant instanceof TextNode) {
                // The caret is positioned within an existing text node
                TextNode textNode = (TextNode)descendant;
                textNode.insertText(text, offset);
            } else if (descendant instanceof Paragraph) {
                // The caret is positioned on the paragraph terminator
                Paragraph paragraph = (Paragraph)descendant;

                int n = paragraph.getLength();
                if (n > 0) {
                    Node node = paragraph.get(n - 1);
                    if (node instanceof TextNode) {
                        // Insert the text into the existing node
                        TextNode textNode = (TextNode)node;
                        textNode.insertText(text, offset - textNode.getOffset());
                    } else {
View Full Code Here

        if (selectionLength > 0) {
            document.removeRange(selectionStart, selectionLength);
        }

        // Walk up the tree until we find a paragraph
        Node descendant = document.getDescendantAt(selectionStart);
        while (!(descendant instanceof Paragraph)) {
            descendant = descendant.getParent();
        }

        // Split the paragraph at the insertion point
        Paragraph leadingSegment = (Paragraph)descendant;
        int offset = selectionStart - leadingSegment.getDocumentOffset();
View Full Code Here

            characterCount = 1;
        }

        if (offset >= 0
            && offset < document.getCharacterCount()) {
            Node descendant = document.getDescendantAt(offset);

            if (selectionLength == 0
                && descendant instanceof Paragraph) {
                // We are deleting a paragraph terminator
                Paragraph paragraph = (Paragraph)descendant;
View Full Code Here

TOP

Related Classes of org.apache.pivot.wtk.text.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.