Search in sources :

Example 6 with PseudoClass

use of javafx.css.PseudoClass in project tokentool by RPTools.

the class TokenTool_Controller method addPseudoClassToLeafs.

private void addPseudoClassToLeafs(TreeView<Path> tree) {
    PseudoClass leaf = PseudoClass.getPseudoClass("leaf");
    tree.setCellFactory(tv -> {
        TreeCell<Path> cell = new TreeCell<>();
        cell.itemProperty().addListener((obs, oldValue, newValue) -> {
            if (newValue == null) {
                cell.setText("");
                cell.setGraphic(null);
            } else {
                cell.setText(newValue.toFile().getName());
                cell.setGraphic(cell.getTreeItem().getGraphic());
            }
        });
        cell.treeItemProperty().addListener((obs, oldTreeItem, newTreeItem) -> cell.pseudoClassStateChanged(leaf, newTreeItem != null && newTreeItem.isLeaf()));
        return cell;
    });
}
Also used : PseudoClass(javafx.css.PseudoClass) Path(java.nio.file.Path) TreeCell(javafx.scene.control.TreeCell)

Example 7 with PseudoClass

use of javafx.css.PseudoClass in project JFoenix by jfoenixadmin.

the class JFXResponsiveHandler method scanAllNodes.

/**
 * scans all nodes in the scene and apply the css pseduoClass to them.
 *
 * @param parent      stage parent node
 * @param pseudoClass css class for certain device
 */
private void scanAllNodes(Parent parent, PseudoClass pseudoClass) {
    parent.getChildrenUnmodifiable().addListener(new ListChangeListener<Node>() {

        @Override
        public void onChanged(javafx.collections.ListChangeListener.Change<? extends Node> c) {
            while (c.next()) {
                if (!c.wasPermutated() && !c.wasUpdated()) {
                    for (Node addedNode : c.getAddedSubList()) {
                        if (addedNode instanceof Parent) {
                            scanAllNodes((Parent) addedNode, pseudoClass);
                        }
                    }
                }
            }
        }
    });
    for (Node component : parent.getChildrenUnmodifiable()) {
        if (component instanceof Pane) {
            ((Pane) component).getChildren().addListener(new ListChangeListener<Node>() {

                @Override
                public void onChanged(javafx.collections.ListChangeListener.Change<? extends Node> c) {
                    while (c.next()) {
                        if (!c.wasPermutated() && !c.wasUpdated()) {
                            for (Node addedNode : c.getAddedSubList()) {
                                if (addedNode instanceof Parent) {
                                    scanAllNodes((Parent) addedNode, pseudoClass);
                                }
                            }
                        }
                    }
                }
            });
            // if the component is a container, scan its children
            scanAllNodes((Pane) component, pseudoClass);
        } else if (component instanceof ScrollPane) {
            ((ScrollPane) component).contentProperty().addListener((o, oldVal, newVal) -> {
                scanAllNodes((Parent) newVal, pseudoClass);
            });
            // if the component is a container, scan its children
            if (((ScrollPane) component).getContent() instanceof Parent) {
                scanAllNodes((Parent) ((ScrollPane) component).getContent(), pseudoClass);
            }
        } else if (component instanceof Control) {
            // if the component is an instance of IInputControl, add to list
            component.pseudoClassStateChanged(PSEUDO_CLASS_EX_SMALL, pseudoClass == PSEUDO_CLASS_EX_SMALL);
            component.pseudoClassStateChanged(PSEUDO_CLASS_SMALL, pseudoClass == PSEUDO_CLASS_SMALL);
            component.pseudoClassStateChanged(PSEUDO_CLASS_MEDIUM, pseudoClass == PSEUDO_CLASS_MEDIUM);
            component.pseudoClassStateChanged(PSEUDO_CLASS_LARGE, pseudoClass == PSEUDO_CLASS_LARGE);
        }
    }
}
Also used : Parent(javafx.scene.Parent) ScrollPane(javafx.scene.control.ScrollPane) ListChangeListener(javafx.collections.ListChangeListener) Stage(javafx.stage.Stage) PseudoClass(javafx.css.PseudoClass) Node(javafx.scene.Node) Control(javafx.scene.control.Control) Pane(javafx.scene.layout.Pane) Control(javafx.scene.control.Control) Parent(javafx.scene.Parent) ScrollPane(javafx.scene.control.ScrollPane) Node(javafx.scene.Node) ScrollPane(javafx.scene.control.ScrollPane) Pane(javafx.scene.layout.Pane) ListChangeListener(javafx.collections.ListChangeListener)

Example 8 with PseudoClass

use of javafx.css.PseudoClass in project ariADDna by StnetixDevTeam.

the class TreeViewFactory method get.

/**
 * temporary method
 *
 * @return
 */
public TreeView get() {
    TreeView<String> tree = new TreeView<>();
    tree.setShowRoot(false);
    TreeItem<String> root = new TreeItem<>("");
    tree.setRoot(root);
    ChangeListener<Boolean> expandedListener = (obs, wasExpanded, isNowExpanded) -> {
        if (isNowExpanded) {
            System.out.println("expand");
            ReadOnlyProperty<?> expandedProperty = (ReadOnlyProperty<?>) obs;
            Object itemThatWasJustExpanded = expandedProperty.getBean();
            for (TreeItem<String> item : tree.getRoot().getChildren()) {
                if (item != itemThatWasJustExpanded) {
                    item.setExpanded(false);
                }
            }
        }
    };
    for (int i = 1; i <= 4; i++) {
        TreeItem<String> item = new TreeItem<>("Top level " + i);
        item.expandedProperty().addListener(expandedListener);
        root.getChildren().add(item);
        for (int j = 1; j <= 4; j++) {
            TreeItem<String> subItem = new TreeItem<>("Sub item " + i + ":" + j);
            item.getChildren().add(subItem);
        }
    }
    PseudoClass subElementPseudoClass = PseudoClass.getPseudoClass("sub-tree-item");
    tree.setCellFactory((TreeView<String> tv) -> {
        TreeCell<String> cell = new TreeCell<String>() {

            @Override
            public void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                setDisclosureNode(null);
                if (empty) {
                    setText("");
                    setGraphic(null);
                } else {
                    // appropriate text for item
                    setText(item);
                }
            }
        };
        cell.treeItemProperty().addListener((obs, oldTreeItem, newTreeItem) -> {
            cell.pseudoClassStateChanged(subElementPseudoClass, newTreeItem != null && newTreeItem.getParent() != cell.getTreeView().getRoot());
        });
        return cell;
    });
    return tree;
}
Also used : Component(org.springframework.stereotype.Component) PseudoClass(javafx.css.PseudoClass) TreeItem(javafx.scene.control.TreeItem) TreeCell(javafx.scene.control.TreeCell) ReadOnlyProperty(javafx.beans.property.ReadOnlyProperty) ChangeListener(javafx.beans.value.ChangeListener) TreeView(javafx.scene.control.TreeView) PseudoClass(javafx.css.PseudoClass) ReadOnlyProperty(javafx.beans.property.ReadOnlyProperty) TreeItem(javafx.scene.control.TreeItem) TreeCell(javafx.scene.control.TreeCell) TreeView(javafx.scene.control.TreeView)

Aggregations

PseudoClass (javafx.css.PseudoClass)8 File (java.io.File)3 ObservableList (javafx.collections.ObservableList)3 Node (javafx.scene.Node)3 Stage (javafx.stage.Stage)3 Method (java.lang.reflect.Method)2 URI (java.net.URI)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Platform (javafx.application.Platform)2 FXML (javafx.fxml.FXML)2 Parent (javafx.scene.Parent)2 Control (javafx.scene.control.Control)2 TreeCell (javafx.scene.control.TreeCell)2 TreeItem (javafx.scene.control.TreeItem)2 FileChooser (javafx.stage.FileChooser)2 Window (javafx.stage.Window)2 ColumnConstraintsWithPercentage (org.phoenicis.javafx.views.common.ColumnConstraintsWithPercentage)2 ShortcutCreationDTO (org.phoenicis.library.dto.ShortcutCreationDTO)2