Package org.apache.pivot.wtk.text

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


        if (selectionSpan.contains(textSpan)) {
            // if the text-node is contained wholly inside the selection, remove
            // the text-node, replace it with a Span, and apply the style
            Element parent = textNode.getParent();
            TextSpan newSpanNode = new TextSpan();
            newSpanNode.add(new TextNode(textNode.getText()));
            styleApplicator.apply(newSpanNode);
            int index = parent.remove(textNode);
            parent.insert(newSpanNode, index);
        } else if (selectionSpan.start <= textSpan.start) {
            // if the selection covers the first part of the text-node, split
            // off the first part of the text-node, and apply the style to it
            int intersectionLength = selectionSpan.end - textSpan.start;
            String part1 = textNode.getSubstring(0, intersectionLength);
            String part2 = textNode.getSubstring(intersectionLength, characterCount);

            TextSpan newSpanNode = new TextSpan();
            newSpanNode.add(new TextNode(part1));
            styleApplicator.apply(newSpanNode);

            Element parent = textNode.getParent();
            int index = parent.remove(textNode);
            parent.insert(newSpanNode, index);
            parent.insert(new TextNode(part2), index + 1);
        } else if (selectionSpan.end >= textSpan.end) {
            // if the selection covers the last part of the text-node, split off
            // the last part of the text-node, and apply the style to
            // it
            int intersectionStart = selectionSpan.start - textSpan.start;
            String part1 = textNode.getSubstring(0, intersectionStart);
            String part2 = textNode.getSubstring(intersectionStart, characterCount);

            TextSpan newSpanNode = new TextSpan();
            newSpanNode.add(new TextNode(part2));
            styleApplicator.apply(newSpanNode);

            Element parent = textNode.getParent();
            int index = parent.remove(textNode);
            parent.insert(new TextNode(part1), index);
            parent.insert(newSpanNode, index + 1);
        } else {
            // if the selection covers an internal part of the text-node, split
            // the
            // text-node into 3 parts, and apply the style to the second part
            int part2Start = selectionSpan.start - textSpan.start;
            int part2End = selectionSpan.end - textSpan.start + 1;
            String part1 = textNode.getSubstring(0, part2Start);
            String part2 = textNode.getSubstring(part2Start, part2End);
            String part3 = textNode.getSubstring(part2End, characterCount);

            TextSpan newSpanNode = new TextSpan();
            newSpanNode.add(new TextNode(part2));
            styleApplicator.apply(newSpanNode);

            Element parent = textNode.getParent();
            int index = parent.remove(textNode);
            parent.insert(new TextNode(part1), index);
            parent.insert(newSpanNode, index + 1);
            parent.insert(new TextNode(part3), index + 2);
        }
    }
View Full Code Here


            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();
                int index = parent.indexOf(descendant);
                parent.insert(new TextNode(text), index);
            }
        }

        // Set the selection start to the character following the insertion
        setSelection(selectionStart + text.length(), 0);
View Full Code Here

    @Override
    protected void attach() {
        super.attach();

        TextNode textNode = (TextNode)getNode();
        textNode.getTextNodeListeners().add(this);
    }
View Full Code Here

    @Override
    protected void detach() {
        super.detach();

        TextNode textNode = (TextNode)getNode();
        textNode.getTextNodeListeners().remove(this);
    }
View Full Code Here

        super.invalidate();
    }

    @Override
    protected void childLayout(int breakWidth) {
        TextNode textNode = (TextNode)getNode();
        FontRenderContext fontRenderContext = Platform.getFontRenderContext();

        CharSequenceCharacterIterator ci = new CharSequenceCharacterIterator(textNode.getCharacters(), start);

        float lineWidth = 0;
        int lastWhitespaceIndex = -1;

        Font effectiveFont = getEffectiveFont();
        char c = ci.first();
        while (c != CharacterIterator.DONE
            && lineWidth < breakWidth) {
            if (Character.isWhitespace(c)) {
                lastWhitespaceIndex = ci.getIndex();
            }

            int i = ci.getIndex();
            Rectangle2D characterBounds = effectiveFont.getStringBounds(ci, i, i + 1, fontRenderContext);
            lineWidth += characterBounds.getWidth();

            c = ci.current();
        }

        int end;
        if (getTextPaneSkin().getWrapText()) {
            if (textNode.getCharacterCount() == 0) {
                end = start;
            } else {
                if (lineWidth < breakWidth) {
                    end = ci.getEndIndex();
                } else {
                    if (lastWhitespaceIndex == -1) {
                        end = ci.getIndex() - 1;
                        if (end <= start) {
                            end = start + 1;
                        }
                    } else {
                        end = lastWhitespaceIndex + 1;
                    }
                }
            }
        } else {
            end = ci.getEndIndex();
        }

        glyphVector = getEffectiveFont().createGlyphVector(fontRenderContext,
            new CharSequenceCharacterIterator(textNode.getCharacters(), start, end));

        if (end < ci.getEndIndex()) {
            length = end - start;
            next = new TextPaneSkinTextNodeView(textNode, end);
            next.setParent(getParent());
View Full Code Here

            (int)Math.ceil(textBounds.getHeight()));
    }

    @Override
    public Dimensions getPreferredSize(int breakWidth) {
        TextNode textNode = (TextNode)getNode();
        FontRenderContext fontRenderContext = Platform.getFontRenderContext();

        CharSequenceCharacterIterator ci = new CharSequenceCharacterIterator(textNode.getCharacters(), start);

        float lineWidth = 0;
        int lastWhitespaceIndex = -1;

        Font effectiveFont = getEffectiveFont();
        char c = ci.first();
        while (c != CharacterIterator.DONE
            && lineWidth < breakWidth) {
            if (Character.isWhitespace(c)) {
                lastWhitespaceIndex = ci.getIndex();
            }

            int i = ci.getIndex();
            Rectangle2D characterBounds = effectiveFont.getStringBounds(ci, i, i + 1, fontRenderContext);
            lineWidth += characterBounds.getWidth();

            c = ci.current();
        }

        int end;
        if (getTextPaneSkin().getWrapText()) {
            if (textNode.getCharacterCount() == 0) {
                end = start;
            } else {
                if (lineWidth < breakWidth) {
                    end = ci.getEndIndex();
                } else {
                    if (lastWhitespaceIndex == -1) {
                        end = ci.getIndex() - 1;
                        if (end <= start) {
                            end = start + 1;
                        }
                    } else {
                        end = lastWhitespaceIndex + 1;
                    }
                }
            }
        } else {
            end = ci.getEndIndex();
        }

        GlyphVector glyphVector = getEffectiveFont().createGlyphVector(fontRenderContext,
            new CharSequenceCharacterIterator(textNode.getCharacters(), start, end));

        Rectangle2D textBounds = glyphVector.getLogicalBounds();
        return new Dimensions((int)Math.ceil(textBounds.getWidth()),
            (int)Math.ceil(textBounds.getHeight()));
    }
View Full Code Here

        invalidate();
    }

    @Override
    public String toString() {
        TextNode textNode = (TextNode)getNode();
        String text = textNode.getText();
        return "[" + text.substring(start, start + length) + "]";
    }
View Full Code Here

        for (int i = 0; i < indent; i++) {
            printStream.append("  ");
        }
        printStream.append("<" + node.getClass().getSimpleName() + ">");
        if (node instanceof TextNode) {
            TextNode textNode = (TextNode)node;
            String text = textNode.getText();
            printStream.append(text);
            printStream.append("</" + node.getClass().getSimpleName() + ">");
            printStream.println();
        } else {
            printStream.println();
View Full Code Here

        if (selectionSpan.contains(textSpan)) {
            // if the text-node is contained wholly inside the selection, remove
            // the text-node, replace it with a Span, and apply the style
            Element parent = textNode.getParent();
            org.apache.pivot.wtk.text.Span newSpanNode = new org.apache.pivot.wtk.text.Span();
            newSpanNode.add(new TextNode(textNode.getText()));
            styleApplicator.apply(newSpanNode);
            int index = parent.remove(textNode);
            parent.insert(newSpanNode, index);
        } else if (selectionSpan.start <= textSpan.start) {
            // if the selection covers the first part of the text-node, split
            // off the first part of the text-node, and apply the style to it
            int intersectionLength = selectionSpan.end - textSpan.start;
            String part1 = textNode.getSubstring(0, intersectionLength);
            String part2 = textNode.getSubstring(intersectionLength, characterCount);

            org.apache.pivot.wtk.text.Span newSpanNode = new org.apache.pivot.wtk.text.Span();
            newSpanNode.add(new TextNode(part1));
            styleApplicator.apply(newSpanNode);

            Element parent = textNode.getParent();
            int index = parent.remove(textNode);
            parent.insert(newSpanNode, index);
            parent.insert(new TextNode(part2), index + 1);
        } else if (selectionSpan.end >= textSpan.end) {
            // if the selection covers the last part of the text-node, split off
            // the last part of the text-node, and apply the style to
            // it
            int intersectionStart = selectionSpan.start - textSpan.start;
            String part1 = textNode.getSubstring(0, intersectionStart);
            String part2 = textNode.getSubstring(intersectionStart, characterCount);

            org.apache.pivot.wtk.text.Span newSpanNode = new org.apache.pivot.wtk.text.Span();
            newSpanNode.add(new TextNode(part2));
            styleApplicator.apply(newSpanNode);

            Element parent = textNode.getParent();
            int index = parent.remove(textNode);
            parent.insert(new TextNode(part1), index);
            parent.insert(newSpanNode, index + 1);
        } else {
            // if the selection covers an internal part of the text-node, split
            // the
            // text-node into 3 parts, and apply the style to the second part
            int part2Start = selectionSpan.start - textSpan.start;
            int part2End = selectionSpan.end - textSpan.start + 1;
            String part1 = textNode.getSubstring(0, part2Start);
            String part2 = textNode.getSubstring(part2Start, part2End);
            String part3 = textNode.getSubstring(part2End, characterCount);

            org.apache.pivot.wtk.text.Span newSpanNode = new org.apache.pivot.wtk.text.Span();
            newSpanNode.add(new TextNode(part2));
            styleApplicator.apply(newSpanNode);

            Element parent = textNode.getParent();
            int index = parent.remove(textNode);
            parent.insert(new TextNode(part1), index);
            parent.insert(newSpanNode, index + 1);
            parent.insert(new TextNode(part3), index + 2);
        }
    }
View Full Code Here

    private TextPaneSkinTextNodeView indexTextNodeView;

    public TextPaneSkinListItemView(TextPaneSkin textPaneSkin, org.apache.pivot.wtk.text.List.Item listItem) {
        super(textPaneSkin, listItem);

        this.indexTextNode = new TextNode("");
    }
View Full Code Here

TOP

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

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.