1 package org.catacomb.druid.gui.edit;
2
3
4 import org.catacomb.druid.gui.base.DummyTree;
5 import org.catacomb.druid.swing.DBorderLayout;
6 import org.catacomb.druid.swing.DCheckboxTree;
7 import org.catacomb.druid.swing.DScrollPane;
8 import org.catacomb.interlish.structure.*;
9 import org.catacomb.report.E;
10
11
12 import java.util.ArrayList;
13
14
15 public class DruCheckboxTreePanel extends DruGCPanel implements SelectionActor, Consumer, Visible {
16
17 static final long serialVersionUID = 1001;
18
19 DCheckboxTree dTree;
20 DScrollPane scrollPane;
21
22 Tree tree;
23
24 String selectionType;
25
26
27 public DruCheckboxTreePanel() {
28 super();
29
30 dTree = new DCheckboxTree();
31 scrollPane = new DScrollPane(dTree);
32 setBorderLayout(2, 2);
33 addDComponent(scrollPane, DBorderLayout.CENTER);
34 scrollPane.setScrollSize(180, 240);
35 setTree(new DummyTree());
36 }
37
38
39 public void clear() {
40 tree = null;
41 dTree.clear();
42 }
43
44
45 public void setTree(Tree tr) {
46 if (tr != null) {
47 tree = tr;
48 dTree.setTree(tree);
49
50 dTree.setSelectionActor(this);
51
52 int ipol = tree.getRootPolicy();
53 if (ipol == Tree.HIDE_ROOT) {
54 dTree.setRootVisible(false);
55
56 } else if (ipol == Tree.SHOW_ROOT) {
57 dTree.setRootVisible(true);
58
59 } else {
60 dTree.setRootVisible(true);
61 }
62 }
63 }
64
65
66
67 public void selectionAction(Object osel, String sid) {
68 if (osel == null) {
69 return;
70 }
71
72 if (osel instanceof TreeNode) {
73 if (((TreeNode)osel).isLeaf()) {
74 selectionType = "leaf";
75 } else {
76 selectionType = "branch";
77 }
78 } else {
79 E.warning("non tree node in tree selection " + osel);
80 selectionType = SpecialStrings.NONE_STRING;
81 }
82
83
84 }
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99 public void showNewItem(Object[] pathToChild) {
100
101 dTree.setTree(tree);
102
103
104 dTree.dTreeExpandPath(pathToChild);
105
106 }
107
108
109
110
111
112
113
114
115
116
117
118
119 public void setMenu(DruMenu drum) {
120 dTree.setMenu(drum.getGUIPeer());
121
122
123 }
124
125
126
127 public String getSelectionType() {
128 return selectionType;
129 }
130
131
132 private Object[] pathTo(TreeNode tn) {
133 ArrayList<Object> al = new ArrayList<Object>();
134
135 al.add(tn);
136
137 Object obj = tn.getParent();
138 while (obj != null) {
139 al.add(0, obj);
140 if (obj instanceof TreeNode) {
141 obj = ((TreeNode)obj).getParent();
142 } else {
143 obj = null;
144 }
145 }
146 return al.toArray();
147 }
148
149
150 public String[] getMultiStringSelection() {
151 return dTree.getMultiStringSelection();
152 }
153
154
155 public String[] getExpandedMultiStringSelection() {
156 return dTree.getExpandedMultiStringSelection();
157 }
158
159
160
161 public void setSelected(String[] content) {
162 dTree.setSelected(content);
163 }
164
165
166 public void ensureVisible(TreeNode tn) {
167 if (tn != null) {
168 dTree.ensureVisible(pathTo(tn));
169 }
170 }
171
172
173
174 }