Package org.apache.pivot.wtk.text

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


            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

    }

    @Override
    public void layout() {
        TextInput textInput = (TextInput)getComponent();
        TextNode textNode = textInput.getTextNode();

        glyphVector = null;

        if (textNode != null) {
            int n = textNode.getCharacterCount();

            if (n > 0) {
                CharacterIterator ci = null;
                if (textInput.isPassword()) {
                    StringBuilder buf = new StringBuilder(n);
                    for (int i = 0; i < n; i++) {
                        buf.append(BULLET);
                    }

                    ci = new StringCharacterIterator(buf.toString());
                } else {
                    ci= textNode.getCharacterIterator();
                }

                FontRenderContext fontRenderContext = Platform.getFontRenderContext();
                glyphVector = font.createGlyphVector(fontRenderContext, ci);
View Full Code Here

    @Override
    public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
        if (button == Mouse.Button.LEFT
            && count > 1) {
            TextInput textInput = (TextInput)getComponent();
            TextNode textNode = textInput.getTextNode();

            if (textNode != null) {
                textInput.setSelection(0, textNode.getCharacterCount());
            }
        }

        return super.mouseClick(component, button, x, y, count);
    }
View Full Code Here

        // character as well as meta key presses
        if (character > 0x1F
            && character != 0x7F
            && !Keyboard.isPressed(Keyboard.Modifier.META)) {
            TextInput textInput = (TextInput)getComponent();
            TextNode textNode = textInput.getTextNode();

            if (textNode != null) {
                if (textInput.getSelectionLength() == 0
                    && textNode.getCharacterCount() == textInput.getMaximumLength()) {
                    Toolkit.getDefaultToolkit().beep();
                } else {
                    Validator validator = textInput.getValidator();
                    boolean strictValidation = textInput.isStrictValidation();

                    if (validator != null
                        && strictValidation) {
                        StringBuilder buf = new StringBuilder(textNode.getText());
                        int selectionStart = textInput.getSelectionStart();
                        buf.insert(selectionStart, character);

                        if (validator.isValid(buf.toString())) {
                            textInput.insert(character);
View Full Code Here

    @Override
    public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
        boolean consumed = super.keyPressed(component, keyCode, keyLocation);

        TextInput textInput = (TextInput)getComponent();
        TextNode textNode = textInput.getTextNode();

        if (textNode != null) {
            Keyboard.Modifier commandModifier = Platform.getCommandModifier();
            if (keyCode == Keyboard.KeyCode.DELETE
                || keyCode == Keyboard.KeyCode.BACKSPACE) {
                boolean backspace = (keyCode == Keyboard.KeyCode.DELETE ? false : true);

                Validator validator = textInput.getValidator();
                boolean strictValidation = textInput.isStrictValidation();

                if (validator != null
                    && strictValidation) {
                    StringBuilder buf = new StringBuilder(textNode.getText());
                    int index = textInput.getSelectionStart();
                    int count = textInput.getSelectionLength();

                    if (count > 0) {
                        buf.delete(index, index + count);
                    } else {
                        if (backspace) {
                            index--;
                        }

                        if (index >= 0
                            && index < textNode.getCharacterCount()) {
                            buf.deleteCharAt(index);
                        }
                    }

                    if (validator.isValid(buf.toString())) {
                        textInput.delete(backspace);
                    } else {
                        Toolkit.getDefaultToolkit().beep();
                    }
                } else {
                    textInput.delete(backspace);
                }

                consumed = true;
            } else if (keyCode == Keyboard.KeyCode.LEFT) {
                int selectionStart = textInput.getSelectionStart();
                int selectionLength = textInput.getSelectionLength();

                if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
                    && Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
                    // Add all preceding text to the selection
                    selectionLength = selectionStart + selectionLength;
                    selectionStart = 0;
                    consumed = true;
                } else if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
                    // Add the previous character to the selection
                    if (selectionStart > 0) {
                        selectionStart--;
                        selectionLength++;
                    }

                    consumed = true;
                } else if (Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
                    // Clear the selection and move the caret to the beginning of
                    // the text
                    selectionStart = 0;
                    selectionLength = 0;
                    consumed = true;
                } else {
                    // Clear the selection and move the caret back by one
                    // character
                    if (selectionLength == 0
                        && selectionStart > 0) {
                        selectionStart--;
                        consumed = true;
                    }

                    selectionLength = 0;
                }

                textInput.setSelection(selectionStart, selectionLength);

                if (textNode.getCharacterCount() > 0) {
                    scrollCharacterToVisible(selectionStart);
                } else {
                    setScrollLeft(0);
                }
            } else if (keyCode == Keyboard.KeyCode.RIGHT) {
                int selectionStart = textInput.getSelectionStart();
                int selectionLength = textInput.getSelectionLength();

                if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
                    && Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
                    // Add all subsequent text to the selection
                    selectionLength = textNode.getCharacterCount() - selectionStart;
                    consumed = true;
                } else if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
                    // Add the next character to the selection
                    if (selectionStart + selectionLength < textNode.getCharacterCount()) {
                        selectionLength++;
                    }

                    consumed = true;
                } else if (Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
                    // Clear the selection and move the caret to the end of
                    // the text
                    selectionStart = textNode.getCharacterCount();
                    selectionLength = 0;
                    consumed = true;
                } else {
                    // Clear the selection and move the caret forward by one
                    // character
                    selectionStart += selectionLength;

                    if (selectionLength == 0
                        && selectionStart < textNode.getCharacterCount()) {
                        selectionStart++;
                        consumed = true;
                    }

                    selectionLength = 0;
                }

                textInput.setSelection(selectionStart, selectionLength);

                if (textNode.getCharacterCount() > 0) {
                    scrollCharacterToVisible(selectionStart + selectionLength - 1);
                } else {
                    scrollLeft = 0;
                    updateSelection();
                }
            } else if (keyCode == Keyboard.KeyCode.HOME) {
                // Move the caret to the beginning of the text
                if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
                    textInput.setSelection(0, textInput.getSelectionStart());
                } else {
                    textInput.setSelection(0, 0);
                }

                consumed = true;
            } else if (keyCode == Keyboard.KeyCode.END) {
                // Move the caret to the end of the text
                if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
                    int selectionStart = textInput.getSelectionStart();
                    textInput.setSelection(selectionStart, textNode.getCharacterCount()
                        - selectionStart);
                } else {
                    textInput.setSelection(textNode.getCharacterCount(), 0);
                }

                consumed = true;
            } else if (keyCode == Keyboard.KeyCode.A
                && Keyboard.isPressed(commandModifier)) {
                // Select all
                textInput.setSelection(0, textNode.getCharacterCount());
                consumed = true;
            } else if (keyCode == Keyboard.KeyCode.X
                && Keyboard.isPressed(commandModifier)) {
                if (textInput.isPassword()) {
                    Toolkit.getDefaultToolkit().beep();
View Full Code Here

                    textInput.selectAll();
                }
            }

            if (textInput.getSelectionLength() == 0) {
                TextNode textNode = textInput.getTextNode();
                int selectionStart = textInput.getSelectionStart();
                if (selectionStart < textNode.getCharacterCount()) {
                    scrollCharacterToVisible(selectionStart);
                }

                showCaret(true);
            } else {
View Full Code Here

        int height = getHeight();

        int selectionStart = textInput.getSelectionStart();
        int selectionLength = textInput.getSelectionLength();

        TextNode textNode = textInput.getTextNode();
        int n = (textNode == null) ? 0 : textNode.getCharacterCount();

        Bounds leadingSelectionBounds;
        if (selectionStart < n) {
            leadingSelectionBounds = getCharacterBounds(selectionStart);
        } else {
View Full Code Here

            int selectionLength = textInput.getSelectionLength();
            int selectionEnd = selectionStart + selectionLength - 1;

            switch (scrollDirection) {
                case FORWARD: {
                    TextNode textNode = textInput.getTextNode();
                    if (selectionEnd < textNode.getCharacterCount() - 1) {
                        selectionEnd++;
                        textInput.setSelection(selectionStart, selectionEnd - selectionStart + 1);
                        scrollCharacterToVisible(selectionEnd);
                    }
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

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.