1 | import javax.swing.tree.*; |
2 | |
3 | static <A, B extends Cl<A>> JTree jDynamicTree(A root, IF1<A, B> makeChildren, O... _) { |
4 | ret jDynamicTree(root, toF1(makeChildren), _); |
5 | } |
6 | |
7 | static <A, B extends Cl<A>> JTree jDynamicTree(final A root, final F1<A, B> makeChildren, fO... _) { |
8 | // optional wrapping/unwrapping of nodes for nicer printing |
9 | optPar IF1 wrapNode; |
10 | optPar IF1 unwrapNode; |
11 | |
12 | ret swing(func -> JTree { |
13 | DefaultMutableTreeNode rootNode = new(callFOrKeep(wrapNode, root)); |
14 | rootNode.add(new DefaultMutableTreeNode(jDynamicTree_dummy())); |
15 | final JTree tree = new JTree(rootNode); |
16 | tree.setShowsRootHandles(true); |
17 | tree.collapseRow(0); |
18 | final bool keepChildrenOnCollapse = optParam(_, 'keepChildrenOnCollapse, false); |
19 | bool makeChildrenIsFast = boolParam makeChildrenIsFast(_) || makeChildren == null; |
20 | bool debug = boolPar debug(_); |
21 | |
22 | class jDynamicTree_Listener implements TreeWillExpandListener { |
23 | public void treeWillCollapse(TreeExpansionEvent e) {} |
24 | public void treeWillExpand(TreeExpansionEvent e) { pcall { |
25 | if (debug) print("treeWillExpand"); |
26 | DefaultMutableTreeNode node = cast e.getPath().getLastPathComponent(); |
27 | if (!keepChildrenOnCollapse || jDynamicTree_isInDummyState(node)) { |
28 | L<A> l = asList(callF(makeChildren, callFOrKeep(unwrapNode, (A) node.getUserObject()))); |
29 | if (makeChildrenIsFast |
30 | ? replaceTreeNodeChildren_withDummyChild2(node, l, jDynamicTree_dummy(), makeChildren) |
31 | : replaceTreeNodeChildren_withDummyChild(node, l, jDynamicTree_dummy())) |
32 | ((DefaultTreeModel) tree.getModel()).nodeStructureChanged(node); |
33 | } |
34 | }} |
35 | } |
36 | tree.addTreeWillExpandListener(new jDynamicTree_Listener); |
37 | |
38 | ret tree; |
39 | }); |
40 | } |
Began life as a copy of #1016044
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1025669 |
Snippet name: | jDynamicTree with node wrapping [dev.] |
Eternal ID of this version: | #1025669/1 |
Text MD5: | 172bcaf8488c4379414a12414e20bea8 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-10-12 21:56:54 |
Source code size: | 1808 bytes / 40 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 169 / 203 |
Referenced in: | [show references] |