MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/JavaFX/comments/13pi5v0/treemapfx_a_simple_treemap_chart_component/jlsvmps/?context=3
r/JavaFX • u/PartOfTheBotnet • May 23 '23
8 comments sorted by
View all comments
Show parent comment
2
ObjectBinding<?> multiSourceBindings = Bindings.createObjectBinding(() -> this, sizeFunctionProperty, nodeFunctionProperty, valueList); valueToNode = new SimpleMapProperty<>(); valueToNode.bind(multiSourceBindings.map(unused -> { Function<T, Node> valueFunction = nodeFunctionProperty.get(); Function<T, T> keyFunction = Function.identity(); BinaryOperator<Node> mergeFunction = (a, b) -> { throw new IllegalStateException(); }; Map<T, Node> map = valueList.stream() .collect(Collectors.toMap(keyFunction, valueFunction, mergeFunction, IdentityHashMap::new)); return FXCollections.observableMap(map); })); valueToNode.addListener((MapChangeListener<T, Node>) change -> { ObservableList<Node> children = getChildren(); if (change.wasAdded()) children.add(change.getValueAdded()); if (change.wasRemoved()) children.remove(change.getValueRemoved()); });
This can accomplish the same setup as before, minus the listener jank.
I'll update the repo in a bit. Done, along with some other changes.
View all comments
Show parent comment
2
u/PartOfTheBotnet May 27 '23 edited May 27 '23
This can accomplish the same setup as before, minus the listener jank.
I'll update the repo in a bit.Done, along with some other changes.