Search in sources :

Example 1 with CachedTransition

use of com.jfoenix.transitions.CachedTransition 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)

Example 2 with CachedTransition

use of com.jfoenix.transitions.CachedTransition in project JFoenix by jfoenixadmin.

the class JFXTextFieldSkinAndroid method createFloatingLabel.

private void createFloatingLabel() {
    if (((JFXTextField) getSkinnable()).isLabelFloat()) {
        if (promptText == null) {
            // get the prompt text node or create it
            boolean triggerFloatLabel = false;
            if (textPane.getChildren().get(0) instanceof Text)
                promptText = (Text) textPane.getChildren().get(0);
            else {
                Field field;
                try {
                    field = TextFieldSkin.class.getDeclaredField("promptNode");
                    field.setAccessible(true);
                    createPromptNode();
                    field.set(this, promptText);
                    // position the prompt node in its position
                    triggerFloatLabel = true;
                } 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();
                }
            }
            promptText.getTransforms().add(promptTextScale);
            promptContainer.getChildren().add(promptText);
            if (triggerFloatLabel) {
                promptText.setTranslateY(-textPane.getHeight());
                promptTextScale.setX(0.85);
                promptTextScale.setY(0.85);
            }
        }
        promptTextUpTransition = new CachedTransition(textPane, new Timeline(new KeyFrame(Duration.millis(1300), new KeyValue(promptText.translateYProperty(), -textPane.getHeight(), 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(textPane, new Timeline(new KeyFrame(Duration.millis(1300), new KeyValue(promptTextFill, ((JFXTextField) getSkinnable()).getFocusColor(), Interpolator.EASE_BOTH)))) {

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

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

            ;
        };
        promptTextDownTransition = new CachedTransition(textPane, 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 : JFXTextFieldSkin(com.jfoenix.skins.JFXTextFieldSkin) TextFieldSkin(com.sun.javafx.scene.control.skin.TextFieldSkin) JFXTextField(com.jfoenix.controls.JFXTextField) Text(javafx.scene.text.Text) Field(java.lang.reflect.Field) JFXTextField(com.jfoenix.controls.JFXTextField) CachedTransition(com.jfoenix.transitions.CachedTransition)

Example 3 with CachedTransition

use of com.jfoenix.transitions.CachedTransition in project JFoenix by jfoenixadmin.

the class JFXTabPaneSkin method layoutChildren.

@Override
protected void layoutChildren(final double x, final double y, final double w, final double h) {
    double headerHeight = snapSize(headerContainer.prefHeight(-1));
    headerContainer.resize(w, headerHeight);
    headerContainer.relocate(x, y);
    headerContainerClip.setX(0);
    headerContainerClip.setY(0);
    headerContainerClip.setWidth(w);
    // 10 is the height of the shadow effect
    headerContainerClip.setHeight(headerHeight + 10);
    // position the tab content for the selected tab only
    double contentStartX = 0;
    double contentStartY = 0;
    contentStartX = x;
    contentStartY = y + headerHeight;
    double contentWidth = w - (0);
    double contentHeight = h - (headerHeight);
    Rectangle clip = new Rectangle(contentWidth, contentHeight);
    tabsContainerHolder.setClip(clip);
    tabsContainerHolder.resize(contentWidth, contentHeight);
    tabsContainerHolder.relocate(contentStartX, contentStartY);
    tabsContainer.resize(contentWidth * tabContentHolders.size(), contentHeight);
    for (int i = 0, max = tabContentHolders.size(); i < max; i++) {
        TabContentHolder tabContentHolder = tabContentHolders.get(i);
        tabContentHolder.setVisible(true);
        tabContentHolder.setTranslateX(contentWidth * i);
        if (tabContentHolder.getClip() != null) {
            ((Rectangle) tabContentHolder.getClip()).setWidth(contentWidth);
            ((Rectangle) tabContentHolder.getClip()).setHeight(contentHeight);
        }
        if (tabContentHolder.tab == selectedTab) {
            int index = getSkinnable().getTabs().indexOf(selectedTab);
            if (index != i) {
                tabsContainer.setTranslateX(-contentWidth * i);
                diffTabsIndices = i - index;
            } else {
                // fix X translation after changing the tabs
                if (diffTabsIndices != 0) {
                    tabsContainer.setTranslateX(tabsContainer.getTranslateX() + contentWidth * diffTabsIndices);
                    diffTabsIndices = 0;
                }
                // animate upon tab selection only otherwise just translate the selected tab 
                if (isSelectingTab) {
                    new CachedTransition(tabsContainer, new Timeline(new KeyFrame(Duration.millis(1000), new KeyValue(tabsContainer.translateXProperty(), -contentWidth * index, Interpolator.EASE_BOTH)))) {

                        {
                            setCycleDuration(Duration.seconds(0.320));
                            setDelay(Duration.seconds(0));
                        }
                    }.play();
                } else
                    tabsContainer.setTranslateX(-contentWidth * index);
            }
        }
        tabContentHolder.resize(contentWidth, contentHeight);
    }
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) Rectangle(javafx.scene.shape.Rectangle) KeyFrame(javafx.animation.KeyFrame) CachedTransition(com.jfoenix.transitions.CachedTransition)

Example 4 with CachedTransition

use of com.jfoenix.transitions.CachedTransition 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 5 with CachedTransition

use of com.jfoenix.transitions.CachedTransition 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)

Aggregations

CachedTransition (com.jfoenix.transitions.CachedTransition)14 Field (java.lang.reflect.Field)9 Text (javafx.scene.text.Text)9 TextFieldSkin (com.sun.javafx.scene.control.skin.TextFieldSkin)6 JFXPasswordField (com.jfoenix.controls.JFXPasswordField)3 JFXTextArea (com.jfoenix.controls.JFXTextArea)3 JFXTextField (com.jfoenix.controls.JFXTextField)3 TextAreaSkin (com.sun.javafx.scene.control.skin.TextAreaSkin)3 KeyFrame (javafx.animation.KeyFrame)2 KeyValue (javafx.animation.KeyValue)2 Timeline (javafx.animation.Timeline)2 JFXTextFieldSkin (com.jfoenix.skins.JFXTextFieldSkin)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 javafx.animation (javafx.animation)1 javafx.beans.property (javafx.beans.property)1 ChangeListener (javafx.beans.value.ChangeListener)1 Change (javafx.collections.ListChangeListener.Change)1 BoundingBox (javafx.geometry.BoundingBox)1