Search in sources :

Example 1 with JFXTextArea

use of com.jfoenix.controls.JFXTextArea in project JFoenix by jfoenixadmin.

the class JFXTextAreaOldSkin method createFloatingLabel.

private void createFloatingLabel() {
    if (((JFXTextArea) getSkinnable()).isLabelFloat()) {
        if (promptText == null) {
            // get the prompt text node or create it
            boolean triggerFloatLabel = false;
            if (((Region) scrollPane.getContent()).getChildrenUnmodifiable().get(0) instanceof Text)
                promptText = (Text) ((Region) scrollPane.getContent()).getChildrenUnmodifiable().get(0);
            else {
                Field field;
                try {
                    field = TextAreaSkin.class.getDeclaredField("promptNode");
                    field.setAccessible(true);
                    createPromptNode();
                    field.set(this, promptText);
                    // position the prompt node in its position
                    triggerFloatLabel = true;
                    oldPromptTextFill = promptTextFill.get();
                } catch (NoSuchFieldException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (SecurityException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            promptTextGroup = new Group(promptText);
            promptContainer.getChildren().add(promptTextGroup);
            StackPane.setAlignment(promptTextGroup, Pos.TOP_LEFT);
            // MUST KEEP: having transparent border fix the blurring effect on focus
            promptContainer.setStyle("-fx-border-color:TRANSPARENT");
            if (triggerFloatLabel) {
                promptContainer.setTranslateY(-promptText.getLayoutBounds().getHeight() - 5);
                promptText.setScaleX(0.85);
                promptText.setScaleY(0.85);
            }
        }
        // create prompt animations
        promptTextUpTransition = new CachedTransition(promptContainer, new Timeline(new KeyFrame(Duration.millis(1300), new KeyValue(promptContainer.translateYProperty(), -promptText.getLayoutBounds().getHeight() - 5, Interpolator.EASE_BOTH), //								new KeyValue(promptText.translateXProperty(), - promptText.getLayoutBounds().getWidth()*0.15/2, Interpolator.EASE_BOTH),
        new KeyValue(promptText.scaleXProperty(), 0.85, Interpolator.EASE_BOTH), new KeyValue(promptText.scaleYProperty(), 0.85, Interpolator.EASE_BOTH)))) {

            {
                setDelay(Duration.millis(0));
                setCycleDuration(Duration.millis(300));
            }
        };
        promptTextColorTransition = new CachedTransition(promptContainer, new Timeline(new KeyFrame(Duration.millis(1300), new KeyValue(promptTextFill, focusedLine.getStroke(), Interpolator.EASE_BOTH)))) {

            {
                setDelay(Duration.millis(0));
                setCycleDuration(Duration.millis(300));
            }

            protected void starting() {
                super.starting();
                oldPromptTextFill = promptTextFill.get();
            }

            ;
        };
        promptTextDownTransition = new CachedTransition(promptContainer, new Timeline(new KeyFrame(Duration.millis(1300), new KeyValue(promptContainer.translateYProperty(), 0, Interpolator.EASE_BOTH), //										new KeyValue(promptText.translateXProperty(), 0, Interpolator.EASE_BOTH),
        new KeyValue(promptText.scaleXProperty(), 1, Interpolator.EASE_BOTH), new KeyValue(promptText.scaleYProperty(), 1, Interpolator.EASE_BOTH)))) {

            {
                setDelay(Duration.millis(0));
                setCycleDuration(Duration.millis(300));
            }
        };
        promptTextDownTransition.setOnFinished((finish) -> {
            promptContainer.setTranslateY(0);
            promptText.setScaleX(1);
            promptText.setScaleY(1);
        });
        promptText.visibleProperty().unbind();
        promptText.visibleProperty().set(true);
    }
}
Also used : JFXTextArea(com.jfoenix.controls.JFXTextArea) Group(javafx.scene.Group) TextAreaSkin(com.sun.javafx.scene.control.skin.TextAreaSkin) Text(javafx.scene.text.Text) Field(java.lang.reflect.Field) CachedTransition(com.jfoenix.transitions.CachedTransition)

Example 2 with JFXTextArea

use of com.jfoenix.controls.JFXTextArea in project JFoenix by jfoenixadmin.

the class JFXTextAreaSkin method createFloatingLabel.

private void createFloatingLabel() {
    if (((JFXTextArea) getSkinnable()).isLabelFloat()) {
        if (promptText == null) {
            // get the prompt text node or create it
            boolean triggerFloatLabel = false;
            if (((Region) scrollPane.getContent()).getChildrenUnmodifiable().get(0) instanceof Text)
                promptText = (Text) ((Region) scrollPane.getContent()).getChildrenUnmodifiable().get(0);
            else {
                Field field;
                try {
                    field = TextAreaSkin.class.getDeclaredField("promptNode");
                    field.setAccessible(true);
                    createPromptNode();
                    field.set(this, promptText);
                    // position the prompt node in its position
                    triggerFloatLabel = true;
                    oldPromptTextFill = promptTextFill.get();
                } catch (NoSuchFieldException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (SecurityException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            // fixed issue text area is being resized when the content is excedeing its width
            promptText.wrappingWidthProperty().addListener((o, oldval, newVal) -> {
                if (newVal.doubleValue() > getSkinnable().getWidth())
                    promptText.setWrappingWidth(getSkinnable().getWidth());
            });
            promptText.getTransforms().add(promptTextScale);
            promptContainer.getChildren().add(promptText);
            if (triggerFloatLabel) {
                promptText.setTranslateY(-promptText.getBoundsInLocal().getHeight() - 2);
                promptTextScale.setX(0.85);
                promptTextScale.setY(0.85);
            }
        }
        // create prompt animations
        promptTextUpTransition = new CachedTransition(promptContainer, new Timeline(new KeyFrame(Duration.millis(1300), new KeyValue(promptText.translateYProperty(), -promptText.getLayoutBounds().getHeight() - 2, Interpolator.EASE_BOTH), new KeyValue(promptTextScale.xProperty(), 0.85, Interpolator.EASE_BOTH), new KeyValue(promptTextScale.yProperty(), 0.85, Interpolator.EASE_BOTH)))) {

            {
                setDelay(Duration.millis(0));
                setCycleDuration(Duration.millis(240));
            }
        };
        promptTextColorTransition = new CachedTransition(promptContainer, new Timeline(new KeyFrame(Duration.millis(1300), new KeyValue(promptTextFill, ((JFXTextArea) getSkinnable()).getFocusColor(), Interpolator.EASE_BOTH)))) {

            {
                setDelay(Duration.millis(0));
                setCycleDuration(Duration.millis(160));
            }

            protected void starting() {
                super.starting();
                oldPromptTextFill = promptTextFill.get();
            }

            ;
        };
        promptTextDownTransition = new CachedTransition(promptContainer, new Timeline(new KeyFrame(Duration.millis(1300), new KeyValue(promptText.translateYProperty(), 0, Interpolator.EASE_BOTH), new KeyValue(promptTextScale.xProperty(), 1, Interpolator.EASE_BOTH), new KeyValue(promptTextScale.yProperty(), 1, Interpolator.EASE_BOTH)))) {

            {
                setDelay(Duration.millis(0));
                setCycleDuration(Duration.millis(240));
            }
        };
        promptTextDownTransition.setOnFinished((finish) -> {
            promptText.setTranslateY(0);
            promptTextScale.setX(1);
            promptTextScale.setY(1);
        });
        promptText.visibleProperty().unbind();
        promptText.visibleProperty().set(true);
    }
}
Also used : JFXTextArea(com.jfoenix.controls.JFXTextArea) TextAreaSkin(com.sun.javafx.scene.control.skin.TextAreaSkin) Text(javafx.scene.text.Text) Field(java.lang.reflect.Field) CachedTransition(com.jfoenix.transitions.CachedTransition)

Example 3 with JFXTextArea

use of com.jfoenix.controls.JFXTextArea in project JFoenix by jfoenixadmin.

the class TextAreaDemo method start.

@Override
public void start(Stage stage) {
    VBox main = new VBox();
    main.setSpacing(50);
    TextArea javafxTextArea = new TextArea();
    javafxTextArea.setPromptText("JavaFX Text Area");
    main.getChildren().add(javafxTextArea);
    JFXTextArea jfxTextArea = new JFXTextArea();
    jfxTextArea.setPromptText("JFoenix Text Area :D");
    jfxTextArea.setLabelFloat(true);
    RequiredFieldValidator validator = new RequiredFieldValidator();
    // NOTE adding error class to text area is causing the cursor to disapper
    validator.setErrorStyleClass("");
    validator.setMessage("Please type something!");
    validator.setIcon(new Icon(AwesomeIcon.WARNING, "1em", ";", "error"));
    jfxTextArea.getValidators().add(validator);
    jfxTextArea.focusedProperty().addListener((o, oldVal, newVal) -> {
        if (!newVal)
            jfxTextArea.validate();
    });
    main.getChildren().add(jfxTextArea);
    StackPane pane = new StackPane();
    pane.getChildren().add(main);
    StackPane.setMargin(main, new Insets(100));
    pane.setStyle("-fx-background-color:WHITE");
    final Scene scene = new Scene(pane, 800, 600);
    scene.getStylesheets().add(ButtonDemo.class.getResource("/resources/css/jfoenix-components.css").toExternalForm());
    stage.setTitle("JFX Button Demo");
    stage.setScene(scene);
    stage.show();
}
Also used : JFXTextArea(com.jfoenix.controls.JFXTextArea) Insets(javafx.geometry.Insets) JFXTextArea(com.jfoenix.controls.JFXTextArea) TextArea(javafx.scene.control.TextArea) Icon(de.jensd.fx.fontawesome.Icon) AwesomeIcon(de.jensd.fx.fontawesome.AwesomeIcon) Scene(javafx.scene.Scene) VBox(javafx.scene.layout.VBox) RequiredFieldValidator(com.jfoenix.validation.RequiredFieldValidator) StackPane(javafx.scene.layout.StackPane)

Example 4 with JFXTextArea

use of com.jfoenix.controls.JFXTextArea in project JFoenix by jfoenixadmin.

the class JFXTextAreaSkinAndroid method createFloatingLabel.

private void createFloatingLabel() {
    if (((JFXTextArea) getSkinnable()).isLabelFloat()) {
        if (promptText == null) {
            // get the prompt text node or create it
            boolean triggerFloatLabel = false;
            if (((Region) scrollPane.getContent()).getChildrenUnmodifiable().get(0) instanceof Text)
                promptText = (Text) ((Region) scrollPane.getContent()).getChildrenUnmodifiable().get(0);
            else {
                Field field;
                try {
                    field = TextAreaSkin.class.getDeclaredField("promptNode");
                    field.setAccessible(true);
                    createPromptNode();
                    field.set(this, promptText);
                    // position the prompt node in its position
                    triggerFloatLabel = true;
                    oldPromptTextFill = promptTextFill.get();
                } catch (NoSuchFieldException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (SecurityException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            // fixed issue text area is being resized when the content is excedeing its width
            promptText.wrappingWidthProperty().addListener((o, oldval, newVal) -> {
                if (newVal.doubleValue() > getSkinnable().getWidth())
                    promptText.setWrappingWidth(getSkinnable().getWidth());
            });
            promptText.getTransforms().add(promptTextScale);
            promptContainer.getChildren().add(promptText);
            if (triggerFloatLabel) {
                promptText.setTranslateY(-promptText.getBoundsInLocal().getHeight() - 2);
                promptTextScale.setX(0.85);
                promptTextScale.setY(0.85);
            }
        }
        // create prompt animations
        promptTextUpTransition = new CachedTransition(promptContainer, new Timeline(new KeyFrame(Duration.millis(1300), new KeyValue(promptText.translateYProperty(), -promptText.getLayoutBounds().getHeight() - 2, Interpolator.EASE_BOTH), new KeyValue(promptTextScale.xProperty(), 0.85, Interpolator.EASE_BOTH), new KeyValue(promptTextScale.yProperty(), 0.85, Interpolator.EASE_BOTH)))) {

            {
                setDelay(Duration.millis(0));
                setCycleDuration(Duration.millis(240));
            }
        };
        promptTextColorTransition = new CachedTransition(promptContainer, new Timeline(new KeyFrame(Duration.millis(1300), new KeyValue(promptTextFill, ((JFXTextArea) getSkinnable()).getFocusColor(), Interpolator.EASE_BOTH)))) {

            {
                setDelay(Duration.millis(0));
                setCycleDuration(Duration.millis(160));
            }

            protected void starting() {
                super.starting();
                oldPromptTextFill = promptTextFill.get();
            }

            ;
        };
        promptTextDownTransition = new CachedTransition(promptContainer, new Timeline(new KeyFrame(Duration.millis(1300), new KeyValue(promptText.translateYProperty(), 0, Interpolator.EASE_BOTH), new KeyValue(promptTextScale.xProperty(), 1, Interpolator.EASE_BOTH), new KeyValue(promptTextScale.yProperty(), 1, Interpolator.EASE_BOTH)))) {

            {
                setDelay(Duration.millis(0));
                setCycleDuration(Duration.millis(240));
            }
        };
        promptTextDownTransition.setOnFinished((finish) -> {
            promptText.setTranslateY(0);
            promptTextScale.setX(1);
            promptTextScale.setY(1);
        });
        promptText.visibleProperty().unbind();
        promptText.visibleProperty().set(true);
    }
}
Also used : JFXTextArea(com.jfoenix.controls.JFXTextArea) TextAreaSkin(com.sun.javafx.scene.control.skin.TextAreaSkin) Text(javafx.scene.text.Text) Field(java.lang.reflect.Field) CachedTransition(com.jfoenix.transitions.CachedTransition)

Aggregations

JFXTextArea (com.jfoenix.controls.JFXTextArea)4 CachedTransition (com.jfoenix.transitions.CachedTransition)3 TextAreaSkin (com.sun.javafx.scene.control.skin.TextAreaSkin)3 Field (java.lang.reflect.Field)3 Text (javafx.scene.text.Text)3 RequiredFieldValidator (com.jfoenix.validation.RequiredFieldValidator)1 AwesomeIcon (de.jensd.fx.fontawesome.AwesomeIcon)1 Icon (de.jensd.fx.fontawesome.Icon)1 Insets (javafx.geometry.Insets)1 Group (javafx.scene.Group)1 Scene (javafx.scene.Scene)1 TextArea (javafx.scene.control.TextArea)1 StackPane (javafx.scene.layout.StackPane)1 VBox (javafx.scene.layout.VBox)1