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;
});
}
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);
}
}
}
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;
}
Aggregations