KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jdon > strutsutil > treeview > ViewNode


1 /**
2  * Copyright 2003-2006 the original author or authors.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6
7        http://www.apache.org/licenses/LICENSE-2.0
8
9   * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */

15
16 package com.jdon.strutsutil.treeview;
17
18 import java.io.Serializable JavaDoc;
19 import java.util.*;
20
21 /**
22  * 节点
23  *
24  * 包å?«çˆ¶èŠ‚点和å­?节点的上下三级。
25  *
26  * 父节点<-- 当å‰?节点 -->å­?节点
27  *
28  * 采å?–类似游标的形å¼?,整个树就是由这样的节点上下衔接在一起的。
29  *
30  *
31  * 一个节点包å?«ä¸‰ä¸ªéƒ¨åˆ†çš„ä¿¡æ?¯
32  * 1.节点的相关树信æ?¯
33  * 2.节点的相关显示信æ?¯
34  * 3.节点的属性信æ?¯
35  *
36  * 节点和TreeControl属于n:1çš„å…³è?”关系
37  *
38  * <p>Copyright: Jdon.com Copyright (c) 2003</p>
39  * <p></p>
40  * @author banq
41  * @version 1.0
42  */

43
44 public class ViewNode implements Serializable JavaDoc {
45
46   //是å?¦æ˜¯å…„弟å§?妹中最å?Žä¸€ä¸ª
47
private boolean last = false;
48   //是å?¦æ˜¯å?¶ï¼ˆæ— å­?节点)
49
private boolean leaf = false;
50
51   //本Node是å?¦è¢«é€‰æ‹©
52
private boolean selected = false;
53  //是å?¦å±•å¼€æ˜¾ç¤ºå…¶æ‰€æœ‰çš„å­?节点
54
private boolean expanded = false;
55
56   //该节点的父节点
57
private ViewNode parent = null;
58   //该节点的深度
59
private int depth = 0;
60
61   //树形结构对象
62
private TreeControl tree = null;
63   //该节点的所有å­?节点
64
private List children = new ArrayList();
65
66   //节点的关键字
67
protected String JavaDoc key = null;
68   //节点的label标识å??称
69
protected String JavaDoc label = null;
70
71   //å?Žå?°æ˜¯å?¦æ›´æ–°
72
protected boolean root = false;
73   //---------------------------------节点在树结构中的属性
74

75   public boolean isLast() {
76     return (this.last);
77   }
78   public void setLast(boolean last) {
79     this.last = last;
80   }
81
82   public boolean isLeaf() {
83     return (this.leaf);
84   }
85   public void setTree(TreeControl tree) {
86     this.tree = tree;
87   }
88   public void clearChildren() {
89     children.clear();
90   }
91
92   /**
93    * Return the set of child nodes for this node.
94    */

95   public ViewNode[] findChildren() {
96     synchronized (children) {
97       ViewNode results[] = new ViewNode[children.size()];
98       return ( (ViewNode[]) children.toArray(results));
99     }
100   }
101
102   /**
103    * 增加å­?节点
104    * @param child
105    * @throws java.lang.IllegalArgumentException
106    */

107   public void addChild(ViewNode child) throws IllegalArgumentException JavaDoc {
108     tree.addNode(child);
109     child.setParent(this);
110     this.leaf = false; //一旦增加å­?节点,该节点就ä¸?是å?¶äº†ã€‚
111
int n = children.size();
112     if (n > 0) {
113       ViewNode node = (ViewNode) children.get(n - 1);
114       node.setLast(false);
115     }
116     child.setLast(true);
117     children.add(child);
118   }
119
120   public ViewNode getParent() {
121     return (this.parent);
122   }
123
124   public void setParent(ViewNode parent) {
125     this.parent = parent;
126     if (parent == null)
127       depth = 1;
128     else
129       depth = parent.getDepth() + 1;
130   }
131
132   public int getDepth() {
133     return depth;
134   }
135
136   //--------------------------------- 节点在树结构中的属性 结æ?Ÿ
137

138   //--------------------------------- 与动æ€?显示相关
139

140   public boolean isSelected() {
141     return (this.selected);
142   }
143
144   public void setSelected(boolean selected) {
145     this.selected = selected;
146   }
147
148   public boolean isExpanded() {
149     return (this.expanded);
150   }
151
152   public void setExpanded(boolean expanded) {
153     this.expanded = expanded;
154   }
155
156   //--------------------------------- 与动æ€?显示相关 结æ?Ÿ
157

158   //--------------------------------- 节点的通用属性
159

160   public String JavaDoc getKey() {
161     return (this.key);
162   }
163
164   public String JavaDoc getLabel() {
165     return (this.label);
166   }
167   public boolean isRoot() {
168     return root;
169   }
170   public void setRoot(boolean root) {
171     this.root = root;
172   }
173
174   //--------------------------------- 节点的通用属性 结æ?Ÿ
175

176   public ViewNode(String JavaDoc key, String JavaDoc label, boolean leaf) {
177     super();
178     this.key = key;
179     this.label = label;
180     this.leaf = leaf;
181   }
182
183 }
184
Popular Tags