KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > treetable > DefaultMutableTreeTableNode


1 package org.netbeans.modules.tasklist.usertasks.treetable;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.Collections JavaDoc;
5 import java.util.Comparator JavaDoc;
6 import java.util.List JavaDoc;
7
8 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
9 import javax.swing.tree.TreeNode JavaDoc;
10
11 /**
12  * Default mutable TT node
13  */

14 public class DefaultMutableTreeTableNode extends DefaultMutableTreeNode JavaDoc
15         implements TreeTableNode {
16     private List JavaDoc<Object JavaDoc> values;
17     
18     /**
19      * Creates a tree node that has no parent and no children, but which
20      * allows children.
21      */

22     public DefaultMutableTreeTableNode() {
23     super(null);
24     }
25
26     /**
27      * Creates a tree node with no parent, no children, but which allows
28      * children, and initializes it with the specified user object.
29      *
30      * @param userObject an Object provided by the user that constitutes
31      * the node's data
32      */

33     public DefaultMutableTreeTableNode(Object JavaDoc userObject) {
34     super(userObject, true);
35     }
36
37     /**
38      * Creates a tree node with no parent, no children, initialized with
39      * the specified user object, and that allows children only if
40      * specified.
41      *
42      * @param userObject an Object provided by the user that constitutes
43      * the node's data
44      * @param allowsChildren if true, the node is allowed to have child
45      * nodes -- otherwise, it is always a leaf node
46      */

47     public DefaultMutableTreeTableNode(Object JavaDoc userObject, boolean allowsChildren) {
48     super(userObject, allowsChildren);
49     }
50     
51     public void setValueAt(Object JavaDoc aValue, int column) {
52         if (values == null)
53             values = new ArrayList JavaDoc<Object JavaDoc>();
54         
55         while (values.size() <= column) {
56             values.add(null);
57         }
58         values.set(column, aValue);
59     }
60
61     public Object JavaDoc getValueAt(int column) {
62         if (values == null)
63             return null;
64         if (values.size() > column)
65             return values.get(column);
66         else
67             return null;
68     }
69
70     public boolean isCellEditable(int column) {
71         return false;
72     }
73     
74     /**
75      * Sorts children nodes
76      *
77      * @param c a comparator for nodes comparing
78      */

79     @SuppressWarnings JavaDoc("unchecked")
80     public void sort(final Comparator JavaDoc<TreeNode JavaDoc> c) {
81         if (children == null)
82             return;
83         
84         // children is defined as Vector. This results in an "unchecked call"
85
// warning
86
Collections.sort(children, c);
87         
88         for (int i = 0; i < getChildCount(); i++) {
89             TreeNode JavaDoc tn = getChildAt(i);
90             ((DefaultMutableTreeTableNode) tn).sort(c);
91         }
92     }
93 }
94
Popular Tags