1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.tree;
21
22 import javax.swing.JTree;
23 import javax.swing.event.TreeModelEvent;
24 import javax.swing.event.TreeModelListener;
25
26 /***
27 * Do not use this class, it will break your JTree. This class causes
28 * funny ghost rows with JTreeTable objects.
29 */
30 public class AutoTreeExpander implements TreeModelListener
31 {
32
33
34
35 private JTree jt;
36 private boolean expandRootOnly;
37
38
39
40 /***
41 *
42 */
43 public AutoTreeExpander(JTree jt, boolean expandRootOnly)
44 {
45 this.jt = jt;
46 this.expandRootOnly = expandRootOnly;
47
48 jt.getModel().addTreeModelListener(this);
49 }
50
51 public AutoTreeExpander(JTree jt)
52 {
53 this(jt, false);
54 }
55
56
57
58 public static AutoTreeExpander install(JTree jt, boolean expandRootOnly)
59 {
60 return new AutoTreeExpander(jt, expandRootOnly);
61 }
62
63 public static AutoTreeExpander install(JTree jt)
64 {
65 return new AutoTreeExpander(jt);
66 }
67
68 public void treeNodesChanged(TreeModelEvent e)
69 {
70 }
71
72 public void treeNodesInserted(TreeModelEvent e)
73 {
74 if (expandRootOnly) {
75 jt.expandPath(e.getTreePath());
76 jt.getModel().removeTreeModelListener(this);
77 }
78 else {
79 jt.expandPath(e.getTreePath().getParentPath());
80 }
81 }
82
83 public void treeNodesRemoved(TreeModelEvent e)
84 {
85 }
86
87 public void treeStructureChanged(TreeModelEvent e)
88 {
89 }
90
91 }