Search in sources :

Example 1 with Node

use of javafx.scene.Node in project JFoenix by jfoenixadmin.

the class JFXTreeTableRowSkin method layoutChildren.

//	@Override protected void updateChildren() {
//		super.updateChildren();				
//		if(getSkinnable().getIndex() > -1){
//			if(oldSkin != this){
//				if( (!(expandedIndex == getSkinnable().getIndex() || expandTriggered) || rippler == null)
//						|| !getSkinnable().isSelected()){
//					rippler = new JFXRippler(new StackPane());
//				}else{
//					this.rippler = oldSkin.rippler;
//				}	
//			}else{
//				if(!expandTriggered){
//					rippler = new JFXRippler(new StackPane());
//				}else if(!getSkinnable().isSelected()){
//					rippler = new JFXRippler(new StackPane());
//				}
//			}
//			getChildren().add(0,rippler);
//		}
//	}
@Override
protected void layoutChildren(final double x, final double y, final double w, final double h) {
    // allow custom skin to grouped rows
    getSkinnable().getStyleClass().remove("tree-table-row-group");
    if (getSkinnable().getTreeItem() != null && getSkinnable().getTreeItem().getValue() instanceof RecursiveTreeObject && getSkinnable().getTreeItem().getValue().getClass() == RecursiveTreeObject.class)
        getSkinnable().getStyleClass().add("tree-table-row-group");
    if (getSkinnable().getIndex() > -1 && getSkinnable().getTreeTableView().getTreeItem(getSkinnable().getIndex()) != null) {
        super.layoutChildren(x, y, w, h);
        // disclosure row case
        if (getSkinnable().getTreeItem() != null && !getSkinnable().getTreeItem().isLeaf()) {
            //				Control c = getVirtualFlowOwner();
            //				final double defaultDisclosureWidth = disclosureWidthMap.containsKey(c) ? disclosureWidthMap.get(c) : 0;
            //				double disclosureWidth =  getDisclosureNode().prefWidth(h);
            //				if (disclosureWidth > defaultDisclosureWidth) {
            //					disclosureWidthMap.put(c, disclosureWidth);
            //					Parent p = getSkinnable();
            //					while (p != null) {
            //						if (p instanceof VirtualFlow)
            //							break;
            //						p = p.getParent();
            //					}
            //					if(p!=null){
            //						final VirtualFlow<?> flow = (VirtualFlow<?>) p;
            //						for (int i = flow.getFirstVisibleCell().getIndex() ; i <= flow.getLastVisibleCell().getIndex(); i++) {
            //							IndexedCell<?> cell = flow.getCell(i);							
            //							if (cell == null || cell.isEmpty() || cell.getIndex() >= getSkinnable().getIndex()) continue;
            //							cell.requestLayout();
            //							cell.layout();
            //						}
            //					}
            //				}
            Node arrow = ((Parent) getDisclosureNode()).getChildrenUnmodifiable().get(0);
            // relocating the disclosure node according to the grouping column
            if (((RecursiveTreeObject<?>) getSkinnable().getItem()).getGroupedColumn() != null) {
                Node col = getChildren().get((getSkinnable().getTreeTableView().getTreeItemLevel(getSkinnable().getTreeItem()) + 1));
                if (getSkinnable().getItem() instanceof RecursiveTreeObject) {
                    int index = getSkinnable().getTreeTableView().getColumns().indexOf(((RecursiveTreeObject<?>) getSkinnable().getItem()).getGroupedColumn());
                    //						getSkinnable().getTreeTableView().getColumns().get(index).getText();
                    // index + 2 , if the rippler was added
                    col = getChildren().get(index + 1);
                }
                arrow.getParent().setTranslateX(col.getBoundsInParent().getMinX());
                arrow.getParent().setLayoutX(0);
            } else {
                arrow.getParent().setTranslateX(0);
                arrow.getParent().setLayoutX(0);
            }
            // add disclosure node animation 	
            if (expandedAnimation == null || !expandedAnimation.getStatus().equals(Status.RUNNING)) {
                expandedAnimation = new Timeline(new KeyFrame(Duration.millis(160), new KeyValue(arrow.rotateProperty(), 90, Interpolator.EASE_BOTH)));
                expandedAnimation.setOnFinished((finish) -> arrow.setRotate(90));
            }
            if (collapsedAnimation == null || !collapsedAnimation.getStatus().equals(Status.RUNNING)) {
                collapsedAnimation = new Timeline(new KeyFrame(Duration.millis(160), new KeyValue(arrow.rotateProperty(), 0, Interpolator.EASE_BOTH)));
                collapsedAnimation.setOnFinished((finish) -> arrow.setRotate(0));
            }
            getSkinnable().getTreeItem().expandedProperty().removeListener(expandedListener);
            getSkinnable().getTreeItem().expandedProperty().addListener(expandedListener);
            if (expandTriggered) {
                if (getSkinnable().getTreeTableView().getTreeItem(getSkinnable().getIndex()).isExpanded()) {
                    arrow.setRotate(0);
                    expandedAnimation.play();
                } else {
                    arrow.setRotate(90);
                    collapsedAnimation.play();
                }
                expandTriggered = false;
            } else {
                if (getSkinnable().getTreeTableView().getTreeItem(getSkinnable().getIndex()).isExpanded()) {
                    if (!expandedAnimation.getStatus().equals(Status.RUNNING))
                        arrow.setRotate(90);
                } else {
                    if (!collapsedAnimation.getStatus().equals(Status.RUNNING))
                        arrow.setRotate(0);
                }
            }
        }
    }
}
Also used : Node(javafx.scene.Node) RecursiveTreeObject(com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject)

Example 2 with Node

use of javafx.scene.Node in project JFoenix by jfoenixadmin.

the class JFXNodesList method animateList.

/**
	 * animates the list to show/hide the nodes
	 */
public void animateList() {
    expanded = !expanded;
    if (animateTimeline.getStatus().equals(Status.RUNNING))
        animateTimeline.stop();
    animateTimeline.getKeyFrames().clear();
    double duration = 120 / (double) this.getChildren().size();
    // show child nodes 
    if (expanded)
        this.getChildren().forEach(child -> child.setVisible(true));
    // add child nodes animation
    for (int i = 1; i < this.getChildren().size(); i++) {
        Node child = this.getChildren().get(i);
        ArrayList<KeyValue> keyValues = animationsMap.get(child).call(expanded);
        animateTimeline.getKeyFrames().add(new KeyFrame(Duration.millis(i * duration), keyValues.toArray(new KeyValue[keyValues.size()])));
    }
    // add 1st element animation
    ArrayList<KeyValue> keyValues = animationsMap.get(this.getChildren().get(0)).call(expanded);
    animateTimeline.getKeyFrames().add(new KeyFrame(Duration.millis(160), keyValues.toArray(new KeyValue[keyValues.size()])));
    // hide child nodes to allow mouse events on the nodes behind them
    if (!expanded) {
        animateTimeline.setOnFinished((finish) -> {
            for (int i = 1; i < this.getChildren().size(); i++) this.getChildren().get(i).setVisible(false);
        });
    } else {
        animateTimeline.setOnFinished(null);
    }
    animateTimeline.play();
}
Also used : Button(javafx.scene.control.Button) KeyFrame(javafx.animation.KeyFrame) Status(javafx.animation.Animation.Status) Node(javafx.scene.Node) Timeline(javafx.animation.Timeline) StackPane(javafx.scene.layout.StackPane) HashMap(java.util.HashMap) VBox(javafx.scene.layout.VBox) ArrayList(java.util.ArrayList) Duration(javafx.util.Duration) Region(javafx.scene.layout.Region) Interpolator(javafx.animation.Interpolator) KeyValue(javafx.animation.KeyValue) Callback(javafx.util.Callback) KeyValue(javafx.animation.KeyValue) Node(javafx.scene.Node) KeyFrame(javafx.animation.KeyFrame)

Example 3 with Node

use of javafx.scene.Node in project JFoenix by jfoenixadmin.

the class JFXNodesList method addAnimatedNode.

/**
	 * add node to list with a specified callback that is triggered after the node animation is finished. 
	 * Note: this method must be called instead of getChildren().add().
	 * 
	 * @param node
	 */
public void addAnimatedNode(Region node, Callback<Boolean, ArrayList<KeyValue>> animationCallBack) {
    // create container for the node if it's a sub nodes list
    if (node instanceof JFXNodesList) {
        StackPane container = new StackPane(node);
        container.setPickOnBounds(false);
        addAnimatedNode(container, animationCallBack);
        return;
    }
    // init node property
    node.setVisible(false);
    node.minWidthProperty().bind(node.prefWidthProperty());
    node.minHeightProperty().bind(node.prefHeightProperty());
    if (this.getChildren().size() > 0)
        initNode(node);
    else {
        if (node instanceof Button)
            ((Button) node).setOnAction((action) -> this.animateList());
        else
            node.setOnMouseClicked((click) -> this.animateList());
        node.getStyleClass().add("trigger-node");
    }
    // init the list height and width
    if (this.getChildren().size() == 0) {
        node.setVisible(true);
        this.minHeightProperty().bind(node.prefHeightProperty());
        this.maxHeightProperty().bind(node.prefHeightProperty());
        this.minWidthProperty().bind(node.prefWidthProperty());
        this.maxWidthProperty().bind(node.prefWidthProperty());
    }
    // add the node and its listeners
    this.getChildren().add(node);
    this.rotateProperty().addListener((o, oldVal, newVal) -> node.setRotate(newVal.doubleValue() % 180 == 0 ? newVal.doubleValue() : -newVal.doubleValue()));
    if (animationCallBack == null && this.getChildren().size() != 1)
        animationCallBack = (expanded) -> {
            return initDefaultAnimation(node, expanded);
        };
    else if (animationCallBack == null && this.getChildren().size() == 1)
        animationCallBack = (expanded) -> {
            return new ArrayList<KeyValue>();
        };
    animationsMap.put(node, animationCallBack);
}
Also used : Button(javafx.scene.control.Button) KeyFrame(javafx.animation.KeyFrame) Status(javafx.animation.Animation.Status) Node(javafx.scene.Node) Timeline(javafx.animation.Timeline) StackPane(javafx.scene.layout.StackPane) HashMap(java.util.HashMap) VBox(javafx.scene.layout.VBox) ArrayList(java.util.ArrayList) Duration(javafx.util.Duration) Region(javafx.scene.layout.Region) Interpolator(javafx.animation.Interpolator) KeyValue(javafx.animation.KeyValue) Callback(javafx.util.Callback) Button(javafx.scene.control.Button) ArrayList(java.util.ArrayList) StackPane(javafx.scene.layout.StackPane)

Example 4 with Node

use of javafx.scene.Node in project JFoenix by jfoenixadmin.

the class JFXRippler method getMask.

// methods that can be changed by extending the rippler class
/**
	 * generate the clipping mask
	 * @return the mask node
	 */
protected Node getMask() {
    double borderWidth = ripplerPane.getBorder() != null ? ripplerPane.getBorder().getInsets().getTop() : 0;
    Bounds bounds = control.getBoundsInParent();
    double width = control.getLayoutBounds().getWidth();
    double height = control.getLayoutBounds().getHeight();
    double diffMinX = Math.abs(control.getBoundsInLocal().getMinX() - control.getLayoutBounds().getMinX());
    double diffMinY = Math.abs(control.getBoundsInLocal().getMinY() - control.getLayoutBounds().getMinY());
    double diffMaxX = Math.abs(control.getBoundsInLocal().getMaxX() - control.getLayoutBounds().getMaxX());
    double diffMaxY = Math.abs(control.getBoundsInLocal().getMaxY() - control.getLayoutBounds().getMaxY());
    Node mask;
    switch(getMaskType()) {
        case RECT:
            // -0.1 to prevent resizing the anchor pane
            mask = new Rectangle(bounds.getMinX() + diffMinX, bounds.getMinY() + diffMinY, width - 0.1 - 2 * borderWidth, height - 0.1 - 2 * borderWidth);
            break;
        case CIRCLE:
            double radius = Math.min((width / 2) - 0.1 - 2 * borderWidth, (height / 2) - 0.1 - 2 * borderWidth);
            mask = new Circle((bounds.getMinX() + diffMinX + bounds.getMaxX() - diffMaxX) / 2, (bounds.getMinY() + diffMinY + bounds.getMaxY() - diffMaxY) / 2, radius, Color.BLUE);
            break;
        default:
            // -0.1 to prevent resizing the anchor pane
            mask = new Rectangle(bounds.getMinX() + diffMinX, bounds.getMinY() + diffMinY, width - 0.1 - 2 * borderWidth, height - 0.1 - 2 * borderWidth);
            break;
    }
    if (control instanceof Shape || (control instanceof Region && ((Region) control).getShape() != null)) {
        mask = new StackPane();
        ((Region) mask).setShape((control instanceof Shape) ? (Shape) control : ((Region) control).getShape());
        ((Region) mask).setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
        mask.resize(width, height);
        mask.relocate(bounds.getMinX() + diffMinX, bounds.getMinY() + diffMinY);
    }
    return mask;
}
Also used : Circle(javafx.scene.shape.Circle) Shape(javafx.scene.shape.Shape) Bounds(javafx.geometry.Bounds) Node(javafx.scene.Node) Rectangle(javafx.scene.shape.Rectangle)

Example 5 with Node

use of javafx.scene.Node in project JFoenix by jfoenixadmin.

the class JFXTextAreaOldSkin method showError.

private void showError(ValidatorBase validator) {
    // set text in error label
    errorLabel.setText(validator.getMessage());
    // show error icon
    Node awsomeIcon = validator.getIcon();
    errorIcon.getChildren().clear();
    if (awsomeIcon != null) {
        errorIcon.getChildren().add(awsomeIcon);
        StackPane.setAlignment(awsomeIcon, Pos.TOP_RIGHT);
    }
    // init only once, to fix the text pane from resizing
    if (initYlayout == -1) {
        mainPane.setMaxHeight(mainPane.getHeight());
        initYlayout = mainPane.getBoundsInParent().getMinY();
        initHeight = getSkinnable().getHeight();
        currentFieldHeight = initHeight;
    }
    errorContainer.setVisible(true);
    errorShown = true;
}
Also used : Node(javafx.scene.Node)

Aggregations

Node (javafx.scene.Node)118 Label (javafx.scene.control.Label)18 Stage (javafx.stage.Stage)17 Parent (javafx.scene.Parent)16 Button (javafx.scene.control.Button)16 ArrayList (java.util.ArrayList)15 ObservableList (javafx.collections.ObservableList)14 FXML (javafx.fxml.FXML)14 List (java.util.List)12 BorderPane (javafx.scene.layout.BorderPane)12 HBox (javafx.scene.layout.HBox)11 IOException (java.io.IOException)10 Platform (javafx.application.Platform)10 Insets (javafx.geometry.Insets)10 Color (javafx.scene.paint.Color)10 FXCollections (javafx.collections.FXCollections)9 MouseEvent (javafx.scene.input.MouseEvent)9 VBox (javafx.scene.layout.VBox)9 FadeTransition (javafx.animation.FadeTransition)8 MenuItem (javafx.scene.control.MenuItem)8