-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathTreeNode.java
More file actions
executable file
·87 lines (69 loc) · 1.63 KB
/
Copy pathTreeNode.java
File metadata and controls
executable file
·87 lines (69 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package javaforce.webui;
import java.util.*;
/** TreeNode
*
* @author pquiring
*/
public class TreeNode {
private Object data;
private TreeNode parent;
private ArrayList<TreeNode> children = new ArrayList<TreeNode>();
public TreeModel model;
public boolean leaf;
public boolean opened;
public TreeNode() {
leaf = false;
opened = true;
}
public void setData(Object data) {
this.data = data;
}
public Object getData() {
return data;
}
public Object getUserObject() {
return null;
}
public String toString() {
if (data == null) return "null";
return data.toString();
}
public void addNode(TreeNode node) {
if (node == this) return;
model.changed = true;
node.model = model;
children.add(node);
}
public void removeNode(int idx) {
removeNode(children.get(idx));
}
public void removeNode(TreeNode node) {
model.changed = true;
node.model = null;
children.remove(node);
}
public boolean hasChildren() {
return children.size() > 0;
}
public int getChildCount() {
return children.size();
}
public TreeNode getChildAt(int idx) {
return children.get(idx);
}
public TreeNode[] getChildren() {
return children.toArray(new TreeNode[getChildCount()]);
}
public void setParent(TreeNode newParent) {
if (newParent == parent) return;
if (parent != null) {
parent.removeNode(this);
}
parent = newParent;
parent.addNode(this);
model.changed = true;
}
public TreeNode getParent() {
return parent;
}
}