Package pivot.wtk

Examples of pivot.wtk.TextInput$TextInputTextListenerList


        ListButton typeListButton = new ListButton(new EnumList<ExpenseType>(ExpenseType.class));
        typeListButton.setSelectedItemKey("type");
        tableViewRowEditor.getCellEditors().put("type", typeListButton);

        // Amount uses a TextInput with strict currency validation
        TextInput amountTextInput = new TextInput();
        amountTextInput.setValidator(new CurrencyValidator());
        amountTextInput.getStyles().put("strictValidation", true);
        amountTextInput.setTextKey("amount");
        tableViewRowEditor.getCellEditors().put("amount", amountTextInput);

        window.open(display);
    }
View Full Code Here


        ListButton protocolListButton = (ListButton)serializer.getObjectByID("request.protocol");
        ListItem protocolListItem = (ListItem)protocolListButton.getSelectedItem();
        Protocol protocol = Protocol.decode(protocolListItem.getText());
        boolean secure = protocol.isSecure();

        TextInput hostTextInput = (TextInput)serializer.getObjectByID("request.host");
        String host = hostTextInput.getText();

        TextInput portTextInput = (TextInput)serializer.getObjectByID("request.port");
        String portText = portTextInput.getText();
        int port;
        try {
            port = Integer.parseInt(portText);
        } catch (Exception ex) {
            port = secure ? 443 : 80;
        }

        TextInput pathTextInput = (TextInput)serializer.getObjectByID("request.path");
        String path = pathTextInput.getText();

        ListButton methodListButton = (ListButton)serializer.getObjectByID("request.method");
        ListItem methodListItem = (ListItem)methodListButton.getSelectedItem();

        // Construct the HTTP request
View Full Code Here

                        sheet.close(false);
                    }
                });

                if (credentials != null) {
                    TextInput usernameTextInput = (TextInput)sheetSerializer.getObjectByID("username");
                    TextInput passwordTextInput = (TextInput)sheetSerializer.getObjectByID("password");
                    usernameTextInput.setText(credentials.getUsername());
                    passwordTextInput.setText(credentials.getPassword());
                }

                sheet.getSheetStateListeners().add(new SheetStateListener() {
                    public Vote previewSheetClose(Sheet sheet, boolean result) {
                        return Vote.APPROVE;
                    }

                    public void sheetCloseVetoed(Sheet sheet, Vote reaso) {
                        // No-op
                    }

                    public void sheetClosed(Sheet sheet) {
                        if (sheet.getResult()) {
                            TextInput usernameTextInput = (TextInput)
                                sheetSerializer.getObjectByID("username");
                            TextInput passwordTextInput = (TextInput)
                                sheetSerializer.getObjectByID("password");

                            String username = usernameTextInput.getText();
                            String password = passwordTextInput.getText();

                            if (username.length() == 0 && password.length() == 0) {
                                credentials = null;
                            } else {
                                credentials = new Credentials(username, password);
                            }
                        }
                    }
                });

                sheet.open(window);
            }
        };

        new Action("toggleHostnameVerificationAction") {
            public String getDescription() {
                return "Toggles lenient hostname verification";
            }

            public void perform() {
                lenientHostnameVerification = !lenientHostnameVerification;
            }
        };

        new Action("setKeystoreAction") {
            private String keystorePath = null;
            private String keystorePassword = null;

            public String getDescription() {
                return "Sets a trusted keystore";
            }

            public void perform() {
                final WTKXSerializer sheetSerializer = new WTKXSerializer();
                final Sheet sheet;

                try {
                    sheet = (Sheet)sheetSerializer.readObject("pivot/tools/net/setKeystore.wtkx");
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }

                Button okButton = (Button)sheetSerializer.getObjectByID("okButton");
                okButton.getButtonPressListeners().add(new ButtonPressListener() {
                    public void buttonPressed(Button button) {
                        sheet.close(true);
                    }
                });

                Button cancelButton = (Button)sheetSerializer.getObjectByID("cancelButton");
                cancelButton.getButtonPressListeners().add(new ButtonPressListener() {
                    public void buttonPressed(Button button) {
                        sheet.close(false);
                    }
                });

                if (keystorePath != null) {
                    TextInput pathTextInput = (TextInput)sheetSerializer.getObjectByID("path");
                    pathTextInput.setText(keystorePath);
                }

                if (keystorePassword != null) {
                    TextInput passwdTextInput = (TextInput)sheetSerializer.getObjectByID("passwd");
                    passwdTextInput.setText(keystorePassword);
                }

                sheet.getSheetStateListeners().add(new SheetStateListener() {
                    public Vote previewSheetClose(Sheet sheet, boolean result) {
                        Vote vote = Vote.APPROVE;

                        if (result) {
                            TextInput pathTextInput = (TextInput)sheetSerializer.getObjectByID("path");
                            TextInput passwdTextInput = (TextInput)sheetSerializer.getObjectByID("passwd");

                            keystorePath = pathTextInput.getText();
                            keystorePassword = passwdTextInput.getText();

                            File file = new File(keystorePath);
                            if (!file.exists()
                                || !file.isFile()) {
                                vote = Vote.DENY;
View Full Code Here

        throws Exception {
        WTKXSerializer wtkxSerializer = new WTKXSerializer();
        Component content =
            (Component)wtkxSerializer.readObject("pivot/tutorials/text/text.wtkx");

        TextInput stateTextInput =
            (TextInput)wtkxSerializer.getObjectByName("stateTextInput");

        stateTextInput.getTextInputCharacterListeners().add(new TextInputCharacterListener() {
            public void charactersInserted(TextInput textInput, int index, int count) {
                String text = textInput.getText();

                int i = Sequence.Search.binarySearch(states, text,
                    states.getComparator());
View Full Code Here

    @Override
    public void install(Component component) {
        super.install(component);

        TextInput textInput = (TextInput)component;
        textInput.getTextInputListeners().add(this);
        textInput.getTextInputCharacterListeners().add(this);
        textInput.getTextInputSelectionListeners().add(this);

        textInput.setCursor(Cursor.TEXT);

        selectionChanged(textInput, 0, 0);
    }
View Full Code Here

        selectionChanged(textInput, 0, 0);
    }

    @Override
    public void uninstall() {
        TextInput textInput = (TextInput)getComponent();
        textInput.getTextInputListeners().remove(this);
        textInput.getTextInputCharacterListeners().remove(this);
        textInput.getTextInputSelectionListeners().remove(this);

        textInput.setCursor(Cursor.DEFAULT);

        super.uninstall();
    }
View Full Code Here

        super.uninstall();
    }

    public int getPreferredWidth(int height) {
        TextInput textInput = (TextInput)getComponent();
        int textSize = textInput.getTextSize();

        // TODO Localize?
        // TODO Recalculate only when font changes
        String testString = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
View Full Code Here

    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);
        graphics.drawLine(1, 1, width - 2, 1);

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

        // 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

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.