Package pivot.wtk.text

Examples of pivot.wtk.text.TextNode


            return next;
        }

        @Override
        public int getCharacterAt(int x, int y) {
            TextNode textNode = (TextNode)getNode();

            // TODO This isn't terribly efficient - either use a character
            // iterator or cache the generated string in TextNode#getText()
            String text = textNode.getText();

            // TODO Can we use a glyph vector for this? We could create the
            // vector when the view is created so we don't need to rebuild it
            // every time
            int offset;
View Full Code Here


            return offset + start;
        }

        @Override
        public Bounds getCharacterBounds(int offset) {
            TextNode textNode = (TextNode)getNode();

            // TODO This isn't terribly efficient - either use a character
            // iterator or cache the generated string in TextNode#getText()
            String text = textNode.getText();
            GlyphVector glyphVector = font.createGlyphVector(fontRenderContext, text);

            Shape glyphVisualBounds = glyphVector.getGlyphVisualBounds(offset);
            Rectangle glyphBounds = glyphVisualBounds.getBounds();
            Bounds bounds = new Bounds(glyphBounds.x, 0, glyphBounds.width, 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

    @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();
            textInput.setSelection(0, textNode.getCharacterCount());
        }

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

        // Ignore characters in the control range and the ASCII delete
        // character
        if (character > 0x1F
            && character != 0x7F) {
            TextInput textInput = (TextInput)getComponent();
            TextNode textNode = textInput.getTextNode();

            if (textNode.getCharacterCount() < textInput.getMaximumLength()) {
                int index = textInput.getSelectionStart();
                Validator validator = textInput.getValidator();

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

                    if (validator.isValid(buf.toString())) {
                        textInput.insertText(character, index);
                    } else {
View Full Code Here

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

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

        if (keyCode == Keyboard.KeyCode.DELETE
            || keyCode == Keyboard.KeyCode.BACKSPACE) {
            Direction direction = (keyCode == Keyboard.KeyCode.DELETE ?
                Direction.FORWARD : Direction.BACKWARD);

            Validator validator = textInput.getValidator();

            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 (direction == Direction.BACKWARD) {
                        index--;
                    }

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

                if (validator.isValid(buf.toString())) {
                    textInput.delete(direction);
                } else {
                    ApplicationContext.beep();
                }
            } else {
                textInput.delete(direction);
            }
        } 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;
            } else if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
                // Add the previous character to the selection
                if (selectionStart > 0) {
                    selectionStart--;
                    selectionLength++;
                }
            } else if (Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
                // Clear the selection and move the caret to the beginning of
                // the text
                selectionStart = 0;
                selectionLength = 0;
            } else {
                // Clear the selection and move the caret back by one
                // character
                if (selectionLength == 0
                    && selectionStart > 0) {
                    selectionStart--;
                }

                selectionLength = 0;
            }

            textInput.setSelection(selectionStart, selectionLength);
        } 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;
            } else if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
                // Add the next character to the selection
                if (selectionStart + selectionLength < textNode.getCharacterCount()) {
                    selectionLength++;
                }
            } 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;
            } else {
                // Clear the selection and move the caret forward by one
                // character
                selectionStart += selectionLength;

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

                selectionLength = 0;
            }

            textInput.setSelection(selectionStart, selectionLength);
        } else if (keyCode == Keyboard.KeyCode.A
            && Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
            // Select all
            textInput.setSelection(0, textNode.getCharacterCount());
        } else if (keyCode == Keyboard.KeyCode.X
            && Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
            if (textInput.isPassword()) {
                ApplicationContext.beep();
            } else {
View Full Code Here

    @Override
    public void focusedChanged(Component component, boolean temporary) {
        super.focusedChanged(component, temporary);

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

        if (component.isFocused()) {
            showCaret(textInput.getSelectionLength() == 0);

            if (!temporary
                && Mouse.getCapturer() != component) {
                textInput.setSelection(0, textNode.getCharacterCount());
            }
        } else {
            if (!temporary) {
                textInput.setSelection(textInput.getSelectionStart()
                    + textInput.getSelectionLength(), 0);
View Full Code Here

    private class ScrollSelectionCallback implements Runnable {
        private int x = 0;

        public void run() {
            TextInput textInput = (TextInput)getComponent();
            TextNode textNode = textInput.getTextNode();

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

            if (x < 0) {
                // Add the previous character to the selection
                if (selectionStart > 0) {
                    selectionStart--;
                    selectionLength++;
                }
            } else {
                // Add the next character to the selection
                if (selectionStart + selectionLength < textNode.getCharacterCount()) {
                    selectionLength++;
                }
            }

            textInput.setSelection(selectionStart, selectionLength);
View Full Code Here

TOP

Related Classes of 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.