Package org.apache.pivot.wtk.text

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


    @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

    }

    @Override
    public void validate() {
        if (!isValid()) {
            TextNode textNode = (TextNode)getNode();
            FontRenderContext fontRenderContext = Platform.getFontRenderContext();

            int breakWidth = getBreakWidth();
            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 (textPaneSkin.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(textPaneSkin, textNode, end);
            } else {
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

        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

        }

        @Override
        public void validate() {
            if (!isValid()) {
                TextNode textNode = (TextNode)getNode();
                FontRenderContext fontRenderContext = Platform.getFontRenderContext();

                int breakWidth = getBreakWidth();
                CharacterIterator ci = textNode.getCharacterIterator(start);

                float lineWidth = 0;
                int lastWhitespaceIndex = -1;

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

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

                    c = ci.current();
                }

                int end;
                if (wrapText) {
                    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 = font.createGlyphVector(fontRenderContext,
                    textNode.getCharacterIterator(start, end));

                if (end < ci.getEndIndex()) {
                    length = end - start;
                    next = new TextNodeView(textNode, end);
                } else {
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

        textInput.getTextInputCharacterListeners().add(this);
        textInput.getTextInputSelectionListeners().add(this);

        textInput.setCursor(Cursor.TEXT);

        TextNode textNode = textInput.getTextNode();
        if (textNode != null) {
            updateSelection();
        }
    }
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.