Package pivot.wtk

Examples of pivot.wtk.TextInput$TextInputTextListenerList


    public void layout() {
        // No-op
    }

    public void paint(Graphics2D graphics) {
        TextInput textInput = (TextInput)getComponent();

        int width = getWidth();
        int height = getHeight();

        Color backgroundColor;
        Color borderColor;
        Color bevelColor;

        if (textInput.isEnabled()) {
            if (textInput.isTextValid()) {
                backgroundColor = this.backgroundColor;
                bevelColor = this.bevelColor;
            } else {
                backgroundColor = invalidBackgroundColor;
                bevelColor = invalidBevelColor;
            }

            borderColor = this.borderColor;
        } else {
            backgroundColor = disabledBackgroundColor;
            borderColor = disabledBorderColor;
            bevelColor = disabledBevelColor;
        }

        graphics.setStroke(new BasicStroke());

        // Paint the background
        graphics.setPaint(backgroundColor);
        graphics.fillRect(0, 0, width, height);

        // Paint the bevel
        graphics.setPaint(bevelColor);
        GraphicsUtilities.drawLine(graphics, 1, 1, width - 2, Orientation.HORIZONTAL);

        // Paint the border
        graphics.setPaint(borderColor);
        GraphicsUtilities.drawRect(graphics, 0, 0, width, height);

        // Paint the content
        String text = getText();

        boolean prompt = false;
        if (text.length() == 0
            && !textInput.isFocused()) {
            text = textInput.getPrompt();

            if (text == null) {
                text = "";
            } else {
                prompt = true;
            }
        }

        boolean textValid = textInput.isTextValid();

        LineMetrics lm = font.getLineMetrics("", fontRenderContext);
        int ascent = Math.round(lm.getAscent());

        graphics.translate(padding.left - scrollLeft + 1, padding.top + ascent + 1);

        if (text.length() > 0) {
            // Paint the text
            if (fontRenderContext.isAntiAliased()) {
                graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                    Platform.getTextAntialiasingHint());
            }

            if (fontRenderContext.usesFractionalMetrics()) {
                graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                    RenderingHints.VALUE_FRACTIONALMETRICS_ON);
            }

            Color color;
            if (textInput.isEnabled()) {
                if (prompt) {
                    color = promptColor;
                } else if (!textValid) {
                    color = invalidColor;
                } else {
                    color = this.color;
                }
            } else {
               color = disabledColor;
            }

            graphics.setFont(font);
            graphics.setPaint(color);
            graphics.drawString(text, 0, 0);

            if (textInput.getSelectionLength() > 0) {
                // Paint the selection
                Graphics2D selectionGraphics = (Graphics2D)graphics.create();
                selectionGraphics.clip(logicalHighlightShape.getBounds());

                Color selectionColor;
                Color selectionBackgroundColor;

                if (textInput.isFocused()) {
                    selectionColor = this.selectionColor;
                    selectionBackgroundColor = this.selectionBackgroundColor;
                } else {
                    selectionColor = inactiveSelectionColor;
                    selectionBackgroundColor = inactiveSelectionBackgroundColor;
                }

                selectionGraphics.setPaint(selectionBackgroundColor);
                selectionGraphics.fill(logicalHighlightShape);

                selectionGraphics.setPaint(selectionColor);
                selectionGraphics.drawString(text, 0, 0);

                selectionGraphics.dispose();
            }
        }

        if (textInput.getSelectionLength() == 0
            && textInput.isFocused()
            && caretOn) {
            Color color;
            if (!textValid) {
                color = invalidColor;
            } else {
View Full Code Here


            graphics.draw(caretShapes[0]);
        }
    }

    protected String getText() {
        TextInput textInput = (TextInput)getComponent();

        // TODO Use the internal character iterator instead of getting a copy
        // of the string
        String text = textInput.getText();

        if (textInput.isPassword()) {
            int n = text.length();
            StringBuilder passwordTextBuilder = new StringBuilder(n);
            for (int i = 0; i < n; i++) {
                passwordTextBuilder.append("*");
            }
View Full Code Here

        if (Mouse.getCapturer() == component) {
            String text = getText();

            if (text.length() > 0) {
                TextInput textInput = (TextInput)getComponent();

                if (x >= 0
                    && x < textInput.getWidth()) {
                    // Stop the scroll selection timer
                    if (scheduledScrollSelectionCallback != null) {
                        scheduledScrollSelectionCallback.cancel();
                        scheduledScrollSelectionCallback = null;
                    }

                    // Get the current selection
                    int selectionStart = textInput.getSelectionStart();
                    int selectionLength = textInput.getSelectionLength();

                    // Get the insertion index
                    int index = getInsertionIndex(text, x);

                    if (index < selectionStart) {
                        selectionLength += (selectionStart - index);
                        selectionStart = index;
                    } else {
                        if (index > selectionStart + selectionLength) {
                            selectionLength = index - selectionStart;
                        }
                    }

                    textInput.setSelection(selectionStart, selectionLength);
                } else {
                    scrollSelectionCallback.x = x;

                    if (scheduledScrollSelectionCallback == null) {
                        scheduledScrollSelectionCallback =
View Full Code Here

    @Override
    public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
        if (button == Mouse.Button.LEFT) {
            // Move the caret to the insertion point
            TextInput textInput = (TextInput)getComponent();
            String text = getText();

            if (text.length() > 0) {
                int index = getInsertionIndex(text, x);
                textInput.setSelection(index, 0);
            }

            // Set focus to the text input
            textInput.requestFocus();
        }

        return super.mouseDown(component, button, x, y);
    }
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 {
                        ApplicationContext.beep();
                    }
                } else {
                    textInput.insertText(character, index);
                }
            } else {
                ApplicationContext.beep();
            }
        }
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 {
                textInput.cut();
            }
        } else if (keyCode == Keyboard.KeyCode.C
            && Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
            if (textInput.isPassword()) {
                ApplicationContext.beep();
            } else {
                textInput.copy();
            }
        } else if (keyCode == Keyboard.KeyCode.V
            && Keyboard.isPressed(Keyboard.Modifier.CTRL)) {
            textInput.paste();
        } else {
            consumed = super.keyPressed(component, keyCode, keyLocation);
        }

        return consumed;
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);
            }

            showCaret(false);
        }
View Full Code Here

        // TODO Report this issue to Sun?
        if (text.length() == 0) {
            text = " ";
        }

        TextInput textInput = (TextInput)getComponent();

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

        TextLayout textLayout = new TextLayout(text, font, fontRenderContext);

        caretShapes = textLayout.getCaretShapes(selectionStart);
        logicalHighlightShape = textLayout.getLogicalHighlightShape(selectionStart,
            selectionStart + selectionLength);

        int width = getWidth();

        if (width <= padding.left + padding.right + 2) {
            scrollLeft = 0;
        } else {
            if (textInput.getSelectionLength() == 0) {
                Rectangle2D caretBounds = caretShapes[0].getBounds();
                int caretLeft = (int)caretBounds.getX();

                if (caretLeft - scrollLeft < 0) {
                    // Ensure that the left edge of caret is visible
                    scrollLeft = caretLeft;
                } else {
                    // Ensure that the right edge of the caret is visible
                    int caretRight = (int)caretBounds.getMaxX();

                    if (caretRight - scrollLeft + padding.left + 1 > width - padding.right - 1) {
                        scrollLeft = Math.max(caretRight
                            - (width - (padding.left + padding.right + 2)), 0);
                    }
                }
            } else {
                Rectangle2D logicalHighlightBounds = logicalHighlightShape.getBounds();
                int logicalHighlightLeft = (int)logicalHighlightBounds.getX();

                if (logicalHighlightLeft - scrollLeft < 0) {
                    // Ensure that the left edge of the highlight is visible
                    scrollLeft = logicalHighlightLeft;
                } else {
                    // Ensure that the right edge of the highlight is visible
                    int logicalHighlightRight = (int)logicalHighlightBounds.getMaxX();

                    if (logicalHighlightRight - scrollLeft + padding.left + 1 > width - padding.right - 1) {
                        scrollLeft = Math.max(logicalHighlightRight
                            - (width - (padding.left + padding.right + 2)), 0);
                    }
                }
            }
        }

        showCaret(textInput.isFocused()
            && textInput.getSelectionLength() == 0);

        repaintComponent();
    }
View Full Code Here

            if (caretBounds.width == 0) {
                caretBounds.width++;
            }

            TextInput textInput = (TextInput)getComponent();
            textInput.repaint(caretBounds.x, caretBounds.y,
                caretBounds.width, caretBounds.height, true);
        }
View Full Code Here

TOP

Related Classes of pivot.wtk.TextInput$TextInputTextListenerList

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.