Package org.apache.pivot.wtk.text

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


    @Override
    protected void childLayout(int breakWidth) {
        // Break the views into multiple rows

        Paragraph paragraph = (Paragraph)getNode();
        rows = new ArrayList<Row>();
        int offset = 0;

        ParagraphChildLayouter layouter = new ParagraphChildLayouter();
        Row row = new Row();
View Full Code Here


    @Override
    public Dimensions getPreferredSize(int breakWidth) {
        // Break the views into multiple rows

        Paragraph paragraph = (Paragraph)getNode();
        ArrayList<Row> rowsLocal = new ArrayList<Row>();
        int offset = 0;

        ParagraphChildLayouter layouter = new ParagraphChildLayouter();
        Row row = new Row();
View Full Code Here

            delete(false);
        }

        if (document.getCharacterCount() == 0) {
            // 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 {
                        // Append a new text node
                        paragraph.add(new TextNode(text));
                    }
                } else {
                    // The paragraph is currently empty
                    paragraph.add(new TextNode(text));
                }
            } else {
                // The caret is positioned on a non-text character node; insert
                // the text into the descendant's parent
                Element parent = descendant.getParent();
View Full Code Here

        while (!(descendant instanceof Paragraph)) {
            descendant = descendant.getParent();
        }

        // Split the paragraph at the insertion point
        Paragraph leadingSegment = (Paragraph)descendant;
        int offset = selectionStart - leadingSegment.getDocumentOffset();
        int characterCount = leadingSegment.getCharacterCount() - offset;

        Paragraph trailingSegment = (Paragraph)leadingSegment.removeRange(offset, characterCount);

        Element parent = leadingSegment.getParent();
        int index = parent.indexOf(leadingSegment);
        parent.insert(trailingSegment, index + 1);
View Full Code Here

            Node descendant = document.getDescendantAt(offset);

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

                Element parent = paragraph.getParent();
                int index = parent.indexOf(paragraph);

                // Attempt to merge any successive content into the paragraph
                if (index < parent.getLength() - 1) {
                    // TODO This won't always be a paragraph - we'll need to
                    // find the next paragraph by walking the tree, then
                    // remove any empty nodes
                    Sequence<Node> removed = parent.remove(index + 1, 1);
                    Paragraph nextParagraph = (Paragraph)removed.get(0);
                    paragraph.insertRange(nextParagraph, paragraph.getCharacterCount() - 1);
                }
            } else {
                document.removeRange(offset, characterCount);
            }
        }

        // Ensure that the document remains editable
        if (document.getCharacterCount() == 0) {
            document.add(new Paragraph(""));
        }

        // Move the caret to the merge point
        if (offset >= 0) {
            setSelection(offset, 0);
View Full Code Here

    @Override
    protected void childLayout(int breakWidth) {
        // Break the views into multiple rows

        Paragraph paragraph = (Paragraph)getNode();
        rows = new ArrayList<Row>();
        int offset = 0;

        ParagraphChildLayouter layouter = new ParagraphChildLayouter();
        Row row = new Row();
View Full Code Here

    @Override
    public Dimensions getPreferredSize(int breakWidth) {
        // Break the views into multiple rows

        Paragraph paragraph = (Paragraph)getNode();
        ArrayList<Row> rows = new ArrayList<Row>();
        int offset = 0;

        ParagraphChildLayouter layouter = new ParagraphChildLayouter();
        Row row = new Row();
View Full Code Here

        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

            delete(false);
        }

        if (document.getCharacterCount() == 0) {
            // 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 {
                        // Append a new text node
                        paragraph.add(new TextNode(text));
                    }
                } else {
                    // The paragraph is currently empty
                    paragraph.add(new TextNode(text));
                }
            } else {
                // The caret is positioned on a non-text character node; insert
                // the text into the descendant's parent
                Element parent = descendant.getParent();
View Full Code Here

        while (!(descendant instanceof Paragraph)) {
            descendant = descendant.getParent();
        }

        // Split the paragraph at the insertion point
        Paragraph leadingSegment = (Paragraph)descendant;
        int offset = selectionStart - leadingSegment.getDocumentOffset();
        int characterCount = leadingSegment.getCharacterCount() - offset;

        Paragraph trailingSegment = (Paragraph)leadingSegment.removeRange(offset, characterCount);

        Element parent = leadingSegment.getParent();
        int index = parent.indexOf(leadingSegment);
        parent.insert(trailingSegment, index + 1);
View Full Code Here

TOP

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

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.