Search in sources :

Example 66 with Node

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

the class JFXListCell method updateItem.

/**
	 * {@inheritDoc}
	 */
@Override
public void updateItem(T item, boolean empty) {
    super.updateItem(item, empty);
    if (empty) {
        setText(null);
        setGraphic(null);
        // remove empty (Trailing cells)
        setMouseTransparent(true);
        setStyle("-fx-background-color:TRANSPARENT;");
    } else {
        if (item != null) {
            // if cell is not a trailing cell then show it
            setStyle(null);
            setMouseTransparent(false);
            Node currentNode = getGraphic();
            Node newNode;
            if ((item instanceof Region || item instanceof Control))
                newNode = (Node) item;
            else
                newNode = new Label(item.toString());
            boolean isJFXListView = getListView() instanceof JFXListView;
            // show cell tooltip if its toggled in JFXListView
            if (isJFXListView && ((JFXListView<?>) getListView()).isShowTooltip() && newNode instanceof Label) {
                setTooltip(new Tooltip(((Label) newNode).getText()));
            }
            if (currentNode == null || !currentNode.equals(newNode)) {
                // clear nodes
                cellContent = newNode;
                cellRippler.rippler.cacheRippleClip(false);
                // RIPPLER ITEM : in case if the list item has its own rippler bind the list rippler and item rippler properties
                if (newNode instanceof JFXRippler) {
                    // build cell container from exisiting rippler
                    cellRippler.ripplerFillProperty().bind(((JFXRippler) newNode).ripplerFillProperty());
                    cellRippler.maskTypeProperty().bind(((JFXRippler) newNode).maskTypeProperty());
                    cellRippler.positionProperty().bind(((JFXRippler) newNode).positionProperty());
                    cellContent = ((JFXRippler) newNode).getControl();
                } else // SUBLIST ITEM : build the Cell node as sublist the sublist
                if (newNode instanceof JFXListView<?>) {
                    // add the sublist to the parent and style the cell as sublist item
                    ((JFXListView<?>) getListView()).addSublist((JFXListView<?>) newNode, this.getIndex());
                    this.getStyleClass().add("sublist-item");
                    if (this.getPadding() != null)
                        this.setPadding(new Insets(this.getPadding().getTop(), 0, this.getPadding().getBottom(), 0));
                    // First build the group item used to expand / hide the sublist
                    StackPane groupNode = new StackPane();
                    groupNode.getStyleClass().add("sublist-header");
                    SVGGlyph dropIcon = new SVGGlyph(0, "ANGLE_RIGHT", "M340 548.571q0 7.429-5.714 13.143l-266.286 266.286q-5.714 5.714-13.143 5.714t-13.143-5.714l-28.571-28.571q-5.714-5.714-5.714-13.143t5.714-13.143l224.571-224.571-224.571-224.571q-5.714-5.714-5.714-13.143t5.714-13.143l28.571-28.571q5.714-5.714 13.143-5.714t13.143 5.714l266.286 266.286q5.714 5.714 5.714 13.143z", Color.BLACK);
                    dropIcon.setStyle("-fx-min-width:0.4em;-fx-max-width:0.4em;-fx-min-height:0.6em;-fx-max-height:0.6em;");
                    dropIcon.getStyleClass().add("drop-icon");
                    /*
						 *  alignment of the group node can be changed using the following css selector
						 *  .jfx-list-view .sublist-header{ }
						 */
                    groupNode.getChildren().setAll(((JFXListView<?>) newNode).getGroupnode(), dropIcon);
                    // the margin is needed when rotating the angle
                    StackPane.setMargin(dropIcon, new Insets(0, 19, 0, 0));
                    StackPane.setAlignment(dropIcon, Pos.CENTER_RIGHT);
                    // Second build the sublist container
                    StackPane sublistContainer = new StackPane();
                    sublistContainer.setMinHeight(0);
                    sublistContainer.setMaxHeight(0);
                    sublistContainer.getChildren().setAll(newNode);
                    sublistContainer.setTranslateY(this.snappedBottomInset());
                    sublistContainer.setOpacity(0);
                    StackPane.setMargin(newNode, new Insets(-1, -1, 0, -1));
                    //						sublistContainer.heightProperty().addListener((o,oldVal,newVal)->{
                    //							// store the hieght of the sublist and resize it to 0 to make it hidden
                    //							if(subListHeight == -1){
                    //								subListHeight = newVal.doubleValue() + this.snappedBottomInset()/2;
                    //								//								totalSubListsHeight += subListHeight;
                    //								// set the parent list 
                    //								Platform.runLater(()->{
                    //									sublistContainer.setMinHeight(0);
                    //									sublistContainer.setPrefHeight(0);
                    //									sublistContainer.setMaxHeight(0);
                    //									//									double currentHeight = ((JFXListView<T>)getListView()).getHeight();
                    //									// FIXME : THIS SHOULD ONLY CALLED ONCE ( NOW ITS BEING CALLED FOR EVERY SUBLIST)
                    //									//									updateListViewHeight(currentHeight - totalSubListsHeight);
                    //								});	
                    //							}
                    //						});
                    // Third, create container of group title and the sublist
                    VBox contentHolder = new VBox();
                    contentHolder.getChildren().setAll(groupNode, sublistContainer);
                    contentHolder.getStyleClass().add("sublist-container");
                    VBox.setVgrow(groupNode, Priority.ALWAYS);
                    cellContent = contentHolder;
                    cellRippler.ripplerPane.addEventHandler(MouseEvent.ANY, (e) -> e.consume());
                    contentHolder.addEventHandler(MouseEvent.ANY, (e) -> {
                        if (!e.isConsumed()) {
                            cellRippler.ripplerPane.fireEvent(e);
                            e.consume();
                        }
                    });
                    cellRippler.ripplerPane.addEventHandler(MouseEvent.MOUSE_CLICKED, (e) -> {
                        if (!e.isConsumed()) {
                            e.consume();
                            contentHolder.fireEvent(e);
                        }
                    });
                    // cache rippler clip in subnodes						
                    cellRippler.rippler.cacheRippleClip(true);
                    this.setOnMouseClicked((e) -> e.consume());
                    // Finally, add sublist animation						
                    contentHolder.setOnMouseClicked((click) -> {
                        click.consume();
                        // stop the animation or change the list height 
                        if (expandAnimation != null && expandAnimation.getStatus().equals(Status.RUNNING))
                            expandAnimation.stop();
                        // invert the expand property 
                        expandedProperty.set(!expandedProperty.get());
                        double newAnimatedHeight = ((Region) newNode).prefHeight(-1) * (expandedProperty.get() ? 1 : -1);
                        double newHeight = expandedProperty.get() ? this.getHeight() + newAnimatedHeight : this.prefHeight(-1);
                        // animate showing/hiding the sublist
                        double contentHeight = expandedProperty.get() ? newAnimatedHeight : 0;
                        if (expandedProperty.get()) {
                            updateClipHeight(newHeight);
                            getListView().setPrefHeight(getListView().getHeight() + newAnimatedHeight + animatedHeight);
                        }
                        // update the animated height
                        animatedHeight = newAnimatedHeight;
                        int opacity = expandedProperty.get() ? 1 : 0;
                        expandAnimation = new Timeline(new KeyFrame(Duration.millis(320), new KeyValue(sublistContainer.minHeightProperty(), contentHeight, Interpolator.EASE_BOTH), new KeyValue(sublistContainer.maxHeightProperty(), contentHeight, Interpolator.EASE_BOTH), new KeyValue(sublistContainer.opacityProperty(), opacity, Interpolator.EASE_BOTH)));
                        if (!expandedProperty.get()) {
                            expandAnimation.setOnFinished((finish) -> {
                                updateClipHeight(newHeight);
                                getListView().setPrefHeight(getListView().getHeight() + newAnimatedHeight);
                                animatedHeight = 0;
                            });
                        }
                        expandAnimation.play();
                    });
                    // animate arrow
                    expandedProperty.addListener((o, oldVal, newVal) -> {
                        if (newVal)
                            new Timeline(new KeyFrame(Duration.millis(160), new KeyValue(dropIcon.rotateProperty(), 90, Interpolator.EASE_BOTH))).play();
                        else
                            new Timeline(new KeyFrame(Duration.millis(160), new KeyValue(dropIcon.rotateProperty(), 0, Interpolator.EASE_BOTH))).play();
                    });
                }
                ((Region) cellContent).setMaxHeight(((Region) cellContent).prefHeight(-1));
                setGraphic(cellContent);
                setText(null);
            }
        }
    }
}
Also used : Pos(javafx.geometry.Pos) ListCell(javafx.scene.control.ListCell) Control(javafx.scene.control.Control) MouseEvent(javafx.scene.input.MouseEvent) StackPane(javafx.scene.layout.StackPane) VBox(javafx.scene.layout.VBox) Insets(javafx.geometry.Insets) KeyValue(javafx.animation.KeyValue) Tooltip(javafx.scene.control.Tooltip) Color(javafx.scene.paint.Color) KeyFrame(javafx.animation.KeyFrame) Label(javafx.scene.control.Label) Status(javafx.animation.Animation.Status) Node(javafx.scene.Node) Timeline(javafx.animation.Timeline) Rectangle(javafx.scene.shape.Rectangle) SVGGlyph(com.jfoenix.svg.SVGGlyph) Platform(javafx.application.Platform) Priority(javafx.scene.layout.Priority) BooleanProperty(javafx.beans.property.BooleanProperty) Duration(javafx.util.Duration) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Region(javafx.scene.layout.Region) Interpolator(javafx.animation.Interpolator) Shape(javafx.scene.shape.Shape) Insets(javafx.geometry.Insets) KeyValue(javafx.animation.KeyValue) Node(javafx.scene.Node) Tooltip(javafx.scene.control.Tooltip) Label(javafx.scene.control.Label) Control(javafx.scene.control.Control) Timeline(javafx.animation.Timeline) SVGGlyph(com.jfoenix.svg.SVGGlyph) Region(javafx.scene.layout.Region) KeyFrame(javafx.animation.KeyFrame) VBox(javafx.scene.layout.VBox) StackPane(javafx.scene.layout.StackPane)

Example 67 with Node

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

the class JFXTreeCell method updateDisplay.

void updateDisplay(T item, boolean empty) {
    if (item == null || empty) {
        hbox = null;
        setText(null);
        setGraphic(null);
    } else {
        TreeItem<T> treeItem = getTreeItem();
        if (treeItem != null && treeItem.getGraphic() != null) {
            if (item instanceof Node) {
                setText(null);
                if (hbox == null) {
                    hbox = new HBox(3);
                }
                hbox.getChildren().setAll(treeItem.getGraphic(), (Node) item);
                setGraphic(hbox);
            } else {
                hbox = null;
                setText(item.toString());
                setGraphic(treeItem.getGraphic());
            }
        } else {
            hbox = null;
            if (item instanceof Node) {
                setText(null);
                setGraphic((Node) item);
            } else {
                setText(item.toString());
                setGraphic(null);
            }
        }
    }
}
Also used : HBox(javafx.scene.layout.HBox) Node(javafx.scene.Node)

Example 68 with Node

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

the class JFXTreeTableColumn method init.

private void init() {
    this.setCellFactory(new Callback<TreeTableColumn<S, T>, TreeTableCell<S, T>>() {

        @Override
        public TreeTableCell<S, T> call(TreeTableColumn<S, T> param) {
            return new JFXTreeTableCell<S, T>() {

                @Override
                protected void updateItem(T item, boolean empty) {
                    if (item == getItem())
                        return;
                    super.updateItem(item, empty);
                    if (item == null) {
                        super.setText(null);
                        super.setGraphic(null);
                    } else if (item instanceof Node) {
                        super.setText(null);
                        super.setGraphic((Node) item);
                    } else {
                        super.setText(item.toString());
                        super.setGraphic(null);
                    }
                }
            };
        }
    });
    Platform.runLater(() -> {
        final ContextMenu contextMenu = new ContextMenu();
        //			contextMenu.setOnShowing((showing)->{
        //				System.out.println("showing");
        //			});
        //			contextMenu.setOnShown((shown)->{
        //				System.out.println("shown");
        //			});
        MenuItem item1 = new MenuItem("Group");
        item1.setOnAction((action) -> {
            ((JFXTreeTableView) getTreeTableView()).group(this);
        });
        MenuItem item2 = new MenuItem("UnGroup");
        item2.setOnAction((action) -> {
            ((JFXTreeTableView) getTreeTableView()).unGroup(this);
        });
        contextMenu.getItems().addAll(item1, item2);
        setContextMenu(contextMenu);
    });
}
Also used : TreeTableCell(javafx.scene.control.TreeTableCell) JFXTreeTableCell(com.jfoenix.controls.cells.editors.base.JFXTreeTableCell) Node(javafx.scene.Node) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) TreeTableColumn(javafx.scene.control.TreeTableColumn)

Example 69 with Node

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

the class JFXPasswordFieldOldSkin 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) {
        textPane.setMaxHeight(textPane.getHeight());
        initYlayout = textPane.getBoundsInParent().getMinY();
        initHeight = getSkinnable().getHeight();
        currentFieldHeight = initHeight;
    }
    errorContainer.setVisible(true);
    errorShowen = true;
}
Also used : Node(javafx.scene.Node)

Example 70 with Node

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

the class JFXPasswordFieldSkin 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) {
        textPane.setMaxHeight(textPane.getHeight());
        initYLayout = textPane.getBoundsInParent().getMinY();
        initHeight = getSkinnable().getHeight();
        currentFieldHeight = initHeight;
    }
    errorContainer.setVisible(true);
    errorShown = true;
}
Also used : Node(javafx.scene.Node)

Aggregations

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