KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > component > tree > IceUserObject


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.faces.component.tree;
35
36 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
37
38
39 /**
40  * IceUserObject - the Object that constitutes a DefaultMutableTreeNode's
41  * user-specified data.
42  * <p/>
43  * The TreeModel must contain a tree of DefaultMutableTreeNode instances. Each
44  * DefaultMutableTreeNode instance encapsultes an IceUserObject. The
45  * IceUserObject is the extension point for the application developer.</p>
46  * <p/>
47  * By default all nodes are folders unless the leaf attribute is set true. </p>
48  * <p/>
49  * If the IceUserObject does not provide sufficient state for representation of
50  * the tree's nodes, then the application developer should extend the
51  * IceUserObject and add state as required to their extension. When creating an
52  * IceUserObject, the DefaultMutableTreeNode wrapper must be provided to the
53  * constructor. Then the node's state can be set to the attributes on the
54  * IceUserObject. </p>
55  */

56 public class IceUserObject {
57
58     protected DefaultMutableTreeNode JavaDoc wrapper;
59     protected String JavaDoc text;
60     protected boolean expanded;
61     protected String JavaDoc tooltip;
62     protected String JavaDoc action;
63     protected TreeNode treeNode;
64
65     // icon fields
66
protected String JavaDoc leafIcon;
67     protected String JavaDoc branchExpandedIcon;
68     protected String JavaDoc branchContractedIcon;
69     protected String JavaDoc icon;
70
71     // leaf field
72
protected boolean leaf;
73
74     // rowIndex to support new TreeDataModel
75
private int rowIndex;
76
77     /**
78      * @return rowIndex
79      */

80     public int getRowIndex() {
81         return rowIndex;
82     }
83
84     /**
85      * @param rowIndex
86      */

87     public void setRowIndex(int rowIndex) {
88         this.rowIndex = rowIndex;
89     }
90
91     //constructors
92

93     /**
94      * <p>Class constructor specifying the DefaultMutableTreeNode wrapper object
95      * that will hold a reference to this IceUserObject.</p>
96      *
97      * @param wrapper
98      */

99     public IceUserObject(DefaultMutableTreeNode JavaDoc wrapper) {
100         this.wrapper = wrapper;
101     }
102
103     /**
104      * <p>Set the value of the boolean leaf attribute. Setting the leaf
105      * attribute to true will force a tree node to be rendered as a leaf. By
106      * default the leaf attribute is false therefore all tree nodes will default
107      * to folders.</p>
108      *
109      * @param leaf
110      */

111     public void setLeaf(boolean leaf) {
112         this.leaf = leaf;
113     }
114
115     /**
116      * <p>Return false if the tree node is a folder.By default all tree nodes
117      * are folders.</p>
118      *
119      * @return the boolean value of the leaf attribute.
120      */

121     public boolean isLeaf() {
122         return this.leaf;
123     }
124
125     /**
126      * <p>Return the value of the <code>action</code> property.</p>
127      *
128      * @return action
129      */

130     public String JavaDoc action() {
131         return action;
132     }
133
134     // getters/setters
135

136     /**
137      * @param treeNode
138      */

139     public void setTreeNode(TreeNode treeNode) {
140         this.treeNode = treeNode;
141     }
142
143     /**
144      * @return treeNode
145      */

146     public TreeNode getTreeNode() {
147         return this.treeNode;
148     }
149
150     /**
151      * <p>Return the value of the <code>text</code> property.</p>
152      *
153      * @return text
154      */

155     public String JavaDoc getText() {
156         return text;
157     }
158
159     /**
160      * <p>Set the value of the <code>text</code> property.</p>
161      *
162      * @param text
163      */

164     public void setText(String JavaDoc text) {
165         this.text = text;
166     }
167
168     /**
169      * @return null
170      */

171     public String JavaDoc getFamily() {
172         return null;
173     }
174
175     /**
176      * <p>Return the value of the <code>expanded</code> property.</p>
177      *
178      * @return expanded
179      */

180     public boolean isExpanded() {
181         return expanded;
182     }
183
184     /**
185      * <p>Set the value of the <code>expanded</code> property.</p>
186      *
187      * @param isExpanded
188      */

189     public void setExpanded(boolean isExpanded) {
190         this.expanded = isExpanded;
191     }
192
193     /**
194      * <p>Return the value of the <code>tooltip</code> property.</p>
195      *
196      * @return tootip
197      */

198     public String JavaDoc getTooltip() {
199         return tooltip;
200     }
201
202     /**
203      * <p>Set the value of the <code>tooltip</code> property.</p>
204      *
205      * @param tooltipString
206      */

207     public void setTooltip(String JavaDoc tooltipString) {
208         this.tooltip = tooltipString;
209     }
210
211     /* (non-Javadoc)
212     * @see java.lang.Object#toString()
213     */

214     public String JavaDoc toString() {
215         return text;
216     }
217
218     /**
219      * <p>Return the value of the <code>leafIcon</code> property.</p>
220      *
221      * @return leafIcon
222      */

223     public String JavaDoc getLeafIcon() {
224         return leafIcon;
225     }
226
227     /**
228      * <p>Set the value of the <code>leafIcon</code> property.</p>
229      *
230      * @param leafIcon
231      */

232     public void setLeafIcon(String JavaDoc leafIcon) {
233         this.leafIcon = leafIcon;
234     }
235
236     /**
237      * <p>Return the value of the <code>branchContractedIcon</code>
238      * property.</p>
239      *
240      * @return branchContractedIcon
241      */

242     public String JavaDoc getBranchContractedIcon() {
243         return branchContractedIcon;
244     }
245
246     /**
247      * <p>Set the value of the <code>branchContractedIcon</code> property.</p>
248      *
249      * @param branchContractedIcon
250      */

251     public void setBranchContractedIcon(String JavaDoc branchContractedIcon) {
252         this.branchContractedIcon = branchContractedIcon;
253     }
254
255     /**
256      * <p>Return the value of the <code>branchExpandedIcon</code> property.</p>
257      *
258      * @return branchExpandedIcon
259      */

260     public String JavaDoc getBranchExpandedIcon() {
261         return branchExpandedIcon;
262     }
263
264     /**
265      * <p>Set the value of the <code>branchExpandedIcon</code> property.</p>
266      *
267      * @param branchExpandedIcon
268      */

269     public void setBranchExpandedIcon(String JavaDoc branchExpandedIcon) {
270         this.branchExpandedIcon = branchExpandedIcon;
271     }
272
273     /**
274      * <p>Return the appropriate icon based on this node's leaf attribute or
275      * expanded/collapsed state.</p> <p>By default the leaf attribute is
276      * false.</p>
277      *
278      * @return String application-relative path to the image file
279      */

280     public String JavaDoc getIcon() {
281         // leaf icon is rendered based on leaf attribute
282
if (this.isLeaf()) {
283             if (leafIcon != null) {
284                 return leafIcon;
285             }
286         } else if (isExpanded()) {
287             if (branchExpandedIcon != null) {
288                 return branchExpandedIcon;
289             }
290         } else {
291             if (branchContractedIcon != null) {
292                 return branchContractedIcon;
293             }
294         }
295         return icon;
296     }
297
298     /**
299      * <p>Return the value of the <code>wrapper</code> property.</p>
300      *
301      * @return wrapper
302      */

303     public DefaultMutableTreeNode JavaDoc getWrapper() {
304         return wrapper;
305     }
306
307     /**
308      * Set the DefaultMutableTreeNode instance that wraps this instance
309      *
310      * @param wrapper
311      */

312     public void setWrapper(DefaultMutableTreeNode JavaDoc wrapper) {
313         this.wrapper = wrapper;
314     }
315
316     /**
317      * <p>Return the value of the <code>action</code> property.</p>
318      *
319      * @return action
320      */

321     public String JavaDoc getAction() {
322         return action;
323     }
324
325     /**
326      * <p>Set the value of the <code>action</code> property.</p>
327      *
328      * @param action
329      */

330     public void setAction(String JavaDoc action) {
331         this.action = action;
332     }
333 }
Popular Tags