Search in sources :

Example 11 with CachedTransition

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

the class JFXColorPickerUI method moveToColor.

public void moveToColor(Color color) {
    allowColorChange = false;
    double max = Math.max(color.getRed(), Math.max(color.getGreen(), color.getBlue())), min = Math.min(color.getRed(), Math.min(color.getGreen(), color.getBlue()));
    double hue = 0;
    double l = (max + min) / 2;
    double s = 0;
    if (max == min) {
        // achromatic
        hue = s = 0;
    } else {
        double d = max - min;
        s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
        if (max == color.getRed()) {
            hue = (color.getGreen() - color.getBlue()) / d + (color.getGreen() < color.getBlue() ? 6 : 0);
        } else if (max == color.getGreen()) {
            hue = (color.getBlue() - color.getRed()) / d + 2;
        } else if (max == color.getBlue()) {
            hue = (color.getRed() - color.getGreen()) / d + 4;
        }
        hue /= 6;
    }
    currentHue = map(hue, 0, 1, 0, 255);
    // Animate Hue
    double theta = map(currentHue, 0, 255, -Math.PI, Math.PI);
    double x = centerX + huesRadius * Math.cos(theta);
    double y = centerY + huesRadius * Math.sin(theta);
    colorsTransition = new CurveTransition(new Point2D(colorSelector.getTranslateX() + colorSelector.getPrefWidth() / 2, colorSelector.getTranslateY() + colorSelector.getPrefHeight() / 2), new Point2D(x, y));
    // Animate SL
    s = map(s, 0, 1, 0, 255);
    l = map(l, 0, 1, 0, 255);
    Point2D point = getPointFromSL((int) s, (int) l, slRadius);
    double pX = centerX - point.getX();
    double pY = centerY - point.getY();
    double endPointX;
    double endPointY;
    if (Math.pow(pX - centerX, 2) + Math.pow(pY - centerY, 2) < Math.pow(slRadius - 2, 2)) {
        endPointX = pX - selector.getPrefWidth() / 2;
        endPointY = pY - selector.getPrefHeight() / 2;
    } else {
        double dx = pX - centerX;
        double dy = pY - centerY;
        theta = Math.atan2(dy, dx);
        x = centerX + (slRadius - 2) * Math.cos(theta);
        y = centerY + (slRadius - 2) * Math.sin(theta);
        endPointX = x - selector.getPrefWidth() / 2;
        endPointY = y - selector.getPrefHeight() / 2;
    }
    selectorTransition = new CachedTransition(selector, new Timeline(new KeyFrame(Duration.millis(1000), new KeyValue(selector.translateXProperty(), endPointX, Interpolator.EASE_BOTH), new KeyValue(selector.translateYProperty(), endPointY, Interpolator.EASE_BOTH)))) {

        {
            setCycleDuration(Duration.millis(160));
            setDelay(Duration.seconds(0));
        }
    };
    if (pTrans != null)
        pTrans.stop();
    pTrans = new ParallelTransition(colorsTransition, selectorTransition);
    pTrans.setOnFinished((finish) -> {
        if (pTrans.getStatus().equals(Status.STOPPED))
            allowColorChange = true;
    });
    pTrans.play();
    refreshHSLCircle();
}
Also used : Point2D(javafx.geometry.Point2D) CachedTransition(com.jfoenix.transitions.CachedTransition)

Example 12 with CachedTransition

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

the class JFXComboBoxListViewSkin method createFloatingAnimation.

private void createFloatingAnimation() {
    // TODO: the 6.05 should be computed, for now its hard coded to keep the alignment with other controls
    promptTextUpTransition = new CachedTransition(customPane, new Timeline(new KeyFrame(Duration.millis(1300), new KeyValue(promptText.translateYProperty(), -customPane.getHeight() + 6.05, 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(customPane, new Timeline(new KeyFrame(Duration.millis(1300), new KeyValue(promptTextFill, ((JFXComboBox<?>) getSkinnable()).getFocusColor(), Interpolator.EASE_BOTH)))) {

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

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

        ;
    };
    promptTextDownTransition = new CachedTransition(customPane, 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);
    });
}
Also used : CachedTransition(com.jfoenix.transitions.CachedTransition)

Example 13 with CachedTransition

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

the class JFXPasswordFieldSkinAndroid method createFloatingLabel.

private void createFloatingLabel() {
    if (((JFXPasswordField) 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, ((JFXPasswordField) 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 : TextFieldSkin(com.sun.javafx.scene.control.skin.TextFieldSkin) JFXPasswordField(com.jfoenix.controls.JFXPasswordField) Text(javafx.scene.text.Text) JFXPasswordField(com.jfoenix.controls.JFXPasswordField) Field(java.lang.reflect.Field) CachedTransition(com.jfoenix.transitions.CachedTransition)

Example 14 with CachedTransition

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

the class JFXTextFieldSkin 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 : 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)

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