Search in sources :

Example 6 with CachedTransition

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

the class JFXPasswordFieldSkin 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 7 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 8 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 9 with CachedTransition

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

the class JFXMasonryPane method layoutChildren.

/***************************************************************************
	 *                                                                         *
	 * Override/Inherited methods                                              *
	 *                                                                         *
	 **************************************************************************/
/**
	 * {@inheritDoc}
	 */
@Override
protected void layoutChildren() {
    performingLayout = true;
    if (!valid) {
        int col, row;
        col = (int) Math.floor(this.getWidth() / (getCellWidth() + 2 * getHSpacing()));
        col = getLimitColumn() != -1 && col > getLimitColumn() ? getLimitColumn() : col;
        if (matrix != null && col == matrix[0].length) {
            performingLayout = false;
            return;
        }
        //(int) Math.floor(this.getHeight() / (cellH + 2*vSpacing));
        row = 100;
        row = getLimitRow() != -1 && row > getLimitRow() ? getLimitRow() : row;
        matrix = new int[row][col];
        double minWidth = -1;
        double minHeight = -1;
        List<BoundingBox> newBoxes;
        List<Region> childs = new ArrayList<>();
        for (int i = 0; i < getChildren().size(); i++) if (getChildren().get(i) instanceof Region)
            childs.add((Region) getChildren().get(i));
        newBoxes = layoutMode.get().fillGrid(matrix, childs, getCellWidth(), getCellHeight(), row, col, getHSpacing(), getVSpacing());
        if (newBoxes == null) {
            performingLayout = false;
            return;
        }
        for (int i = 0; i < getChildren().size() && i < newBoxes.size(); i++) {
            Region block = (Region) getChildren().get(i);
            if (!(block instanceof GridPane)) {
                double blockX, blockY, blockWidth, blockHeight;
                if (newBoxes.get(i) != null) {
                    blockX = newBoxes.get(i).getMinY() * getCellWidth() + ((newBoxes.get(i).getMinY() + 1) * 2 - 1) * getHSpacing();
                    blockY = newBoxes.get(i).getMinX() * getCellHeight() + ((newBoxes.get(i).getMinX() + 1) * 2 - 1) * getVSpacing();
                    blockWidth = newBoxes.get(i).getWidth() * getCellWidth() + (newBoxes.get(i).getWidth() - 1) * 2 * getHSpacing();
                    blockHeight = newBoxes.get(i).getHeight() * getCellHeight() + (newBoxes.get(i).getHeight() - 1) * 2 * getVSpacing();
                } else {
                    blockX = block.getLayoutX();
                    blockY = block.getLayoutY();
                    blockWidth = -1;
                    blockHeight = -1;
                }
                if (animationMap == null) {
                    // init static children
                    block.setLayoutX(blockX);
                    block.setLayoutY(blockY);
                    block.setPrefSize(blockWidth, blockHeight);
                    block.resizeRelocate(blockX, blockY, blockWidth, blockHeight);
                } else {
                    if (oldBoxes == null || i >= oldBoxes.size()) {
                        // handle new children
                        block.setOpacity(0);
                        block.setLayoutX(blockX);
                        block.setLayoutY(blockY);
                        block.setPrefSize(blockWidth, blockHeight);
                        block.resizeRelocate(blockX, blockY, blockWidth, blockHeight);
                    }
                    if (newBoxes.get(i) != null) {
                        // handle children repositioning
                        animationMap.put(block, new CachedTransition(block, new Timeline(new KeyFrame(Duration.millis(2000), new KeyValue(block.opacityProperty(), 1, Interpolator.LINEAR), new KeyValue(block.layoutXProperty(), blockX, Interpolator.LINEAR), new KeyValue(block.layoutYProperty(), blockY, Interpolator.LINEAR)))) {

                            {
                                setCycleDuration(Duration.seconds(0.320));
                                setDelay(Duration.seconds(0));
                                setOnFinished((finish) -> {
                                    block.setLayoutX(blockX);
                                    block.setLayoutY(blockY);
                                    block.setOpacity(1);
                                });
                            }
                        });
                    } else {
                        // handle children is being hidden ( cause it can't fit in the pane )
                        animationMap.put(block, new CachedTransition(block, new Timeline(new KeyFrame(Duration.millis(2000), new KeyValue(block.opacityProperty(), 0, Interpolator.LINEAR), new KeyValue(block.layoutXProperty(), blockX, Interpolator.LINEAR), new KeyValue(block.layoutYProperty(), blockY, Interpolator.LINEAR)))) {

                            {
                                setCycleDuration(Duration.seconds(0.320));
                                setDelay(Duration.seconds(0));
                                setOnFinished((finish) -> {
                                    block.setLayoutX(blockX);
                                    block.setLayoutY(blockY);
                                    block.setOpacity(0);
                                });
                            }
                        });
                    }
                }
                if (newBoxes.get(i) != null) {
                    if (blockX + blockWidth > minWidth)
                        minWidth = blockX + blockWidth;
                    if (blockY + blockHeight > minHeight)
                        minHeight = blockY + blockHeight;
                }
            }
        }
        this.setMinSize(minWidth, minHeight);
        if (animationMap == null)
            animationMap = new HashMap<>();
        trans.stop();
        ParallelTransition newTransition = new ParallelTransition();
        newTransition.getChildren().addAll(animationMap.values());
        newTransition.play();
        trans = newTransition;
        oldBoxes = newBoxes;
        // FOR DEGBBUGING
        //						root.getChildren().clear();		
        //						for(int y = 0; y < matrix.length; y++){
        //							for(int x = 0; x < matrix[0].length; x++){
        //			
        //								// Create a new TextField in each Iteration
        //								Label tf = new Label();
        //								tf.setStyle(matrix[y][x] == 0 ? colors[0] : colors[matrix[y][x]%4+1]);
        //								tf.setMinWidth(getCellWidth());
        //								tf.setMinHeight(getCellHeight());
        //								tf.setAlignment(Pos.CENTER);
        //								tf.setText(matrix[y][x] + "");
        //								// Iterate the Index using the loops
        //								root.setRowIndex(tf,y);
        //								root.setColumnIndex(tf,x);    
        //								root.setMargin(tf, new Insets(getVSpacing(),getHSpacing(),getVSpacing(),getHSpacing()));
        //								root.getChildren().add(tf);
        //							}
        //						}
        valid = true;
    }
    // FOR DEGBBUGING
    //				if(!getChildren().contains(root)) getChildren().add(root);
    //				root.resizeRelocate(0, 0, this.getWidth(), this.getHeight());
    performingLayout = false;
}
Also used : javafx.beans.property(javafx.beans.property) Change(javafx.collections.ListChangeListener.Change) BoundingBox(javafx.geometry.BoundingBox) Node(javafx.scene.Node) javafx.animation(javafx.animation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CachedTransition(com.jfoenix.transitions.CachedTransition) Duration(javafx.util.Duration) List(java.util.List) Region(javafx.scene.layout.Region) ChangeListener(javafx.beans.value.ChangeListener) GridPane(javafx.scene.layout.GridPane) Pane(javafx.scene.layout.Pane) GridPane(javafx.scene.layout.GridPane) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BoundingBox(javafx.geometry.BoundingBox) Region(javafx.scene.layout.Region) CachedTransition(com.jfoenix.transitions.CachedTransition)

Example 10 with CachedTransition

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

the class JFXPasswordFieldOldSkin 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();
                }
            }
            promptContainer.getChildren().add(promptText);
            if (triggerFloatLabel) {
                promptText.setTranslateY(-textPane.getHeight());
                promptText.setTranslateX(-(promptText.getLayoutBounds().getWidth() * 0.15) / 2);
                promptText.setLayoutY(0);
                promptText.setScaleX(0.85);
                promptText.setScaleY(0.85);
            }
        }
        promptTextUpTransition = new CachedTransition(textPane, new Timeline(new KeyFrame(Duration.millis(1300), new KeyValue(promptText.translateYProperty(), -textPane.getHeight(), 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(textPane, 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(textPane, new Timeline(new KeyFrame(Duration.millis(1300), new KeyValue(promptText.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) -> {
            promptText.setTranslateX(0);
            promptText.setTranslateY(0);
            promptText.setScaleX(1);
            promptText.setScaleY(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)

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