Package org.apache.pivot.wtk.text

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


            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


        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

            // may be added as many TextPaneSkinTextNodeView's.

            // Break the views into multiple rows
            int breakWidth = getBreakWidth();

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

            Row row = new Row();
            for (Node node : paragraph) {
                TextPaneSkinNodeView nodeView = textPaneSkin.createNodeView(node);

                nodeView.setBreakWidth(Math.max(breakWidth - (row.width
                    + PARAGRAPH_TERMINATOR_WIDTH), 0));
                nodeView.validate();

                int nodeViewWidth = nodeView.getWidth();

                if (row.width + nodeViewWidth > breakWidth
                    && row.width > 0) {
                    // The view is too big to fit in the remaining space,
                    // and it is not the only view in this row
                    rows.add(row);
                    row = new Row();
                    row.width = 0;
                }

                // Add the view to the row
                row.nodeViews.add(nodeView);
                row.width += nodeViewWidth;

                // If the view was split into multiple views, add them to
                // their own rows
                nodeView = nodeView.getNext();
                while (nodeView != null) {
                    rows.add(row);
                    row = new Row();

                    nodeView.setBreakWidth(breakWidth);
                    nodeView.validate();

                    row.nodeViews.add(nodeView);
                    row.width = nodeView.getWidth();

                    nodeView = nodeView.getNext();
                }
            }

            // Add the last row
            if (row.nodeViews.getLength() > 0) {
                rows.add(row);
            }

            // Clear all existing views
            remove(0, getLength());

            // Add the row views to this view, lay out, and calculate height
            int x = 0;
            int width = 0;
            int height = 0;
            for (int i = 0, n = rows.getLength(); i < n; i++) {
                row = rows.get(i);
                row.y = height;

                width = Math.max(width, row.width);

                // Determine the row height
                for (TextPaneSkinNodeView nodeView : row.nodeViews) {
                    row.height = Math.max(row.height, nodeView.getHeight());
                }

                if (paragraph.getHorizontalAlignment() == HorizontalAlignment.LEFT) {
                    x = 0;
                } else if (paragraph.getHorizontalAlignment() == HorizontalAlignment.CENTER) {
                    x = (width - row.width) / 2;
                } else {
                    // right alignment
                    x = width - row.width;
                }
View Full Code Here

            // 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

        public void validate() {
            if (!isValid()) {
                // Break the views into multiple rows
                int breakWidth = getBreakWidth();

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

                Row row = new Row();
                for (Node node : paragraph) {
                    NodeView nodeView = createNodeView(node);
View Full Code Here

            } catch(IOException exception) {
                throw new RuntimeException(exception);
            }
        } else {
            document = new Document();
            document.add(new Paragraph(""));
        }

        setDocument(document);
    }
View Full Code Here

            // 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.