KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdnc > JNTree


1 /*
2  * $Id: JNTree.java,v 1.3 2004/09/01 05:00:33 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.jdnc;
9
10 import javax.swing.JScrollPane JavaDoc;
11 import javax.swing.tree.DefaultTreeModel JavaDoc;
12 import javax.swing.tree.TreeModel JavaDoc;
13
14 import org.jdesktop.swing.decorator.FilterPipeline;
15 import org.jdesktop.swing.decorator.HighlighterPipeline;
16 import org.jdesktop.swing.JXTree;
17
18 /**
19  * Encapsulates JXTree functionality inside a JNComponent.
20  *
21  * @author Ramesh Gupta
22  *
23  * @javabean.class
24  * displayName="Tree Component"
25  * name="JNTree"
26  * shortDesctiption="A tree control"
27  *
28  * @javabean.icons
29  * color16="/javax/swing/beaninfo/images/JTreeColor16.gif"
30  * color32="/javax/swing/beaninfo/images/JTreeColor32.gif"
31  */

32 public class JNTree extends JNComponent {
33     /**
34      * Default constructor
35      */

36     public JNTree() {
37         this(new DefaultTreeModel JavaDoc(null));
38     }
39
40     /**
41      * Creates a new JNTreeTable component that presents a JTree view for
42      * the specified model.
43      *
44      * @param model data model for the tree
45      * @exception throws IllegalArgumentException if model is null
46      */

47     public JNTree(TreeModel JavaDoc model) {
48         tree = new JXTree(model);
49         add(new JScrollPane JavaDoc(tree)); // defaults to BorderLayout.CENTER
50
}
51
52     /**
53      * Returns the tree for this component.
54      *
55      * @return the tree for this component
56      */

57     public JXTree getTree() {
58         return tree;
59     }
60
61     /**
62      * Returns the data model for the tree.
63      *
64      * @return the data model for the tree
65      */

66     public TreeModel JavaDoc getTreeModel() {
67         return getTree().getModel();
68     }
69
70     /**
71      * Sets the data model for the tree.
72      *
73      * @param model data model for the tree
74      * @exception throws IllegalArgumentException if model is null
75      *
76      * @javabean.property
77      * shortDescription="sets the tree model"
78      */

79     public void setTreeModel(TreeModel JavaDoc model) {
80         getTree().setModel(model);
81     }
82
83     /*
84         public Color getOddRowBackground() {
85             return treeTable.getOddRowBackground();
86         }
87         public void setOddRowBackground(Color color) {
88             treeTable.setOddRowBackground(color);
89         }
90         public Color getEvenRowBackground() {
91             return treeTable.getEvenRowBackground();
92         }
93         public void setEvenRowBackground(Color color) {
94          treeTable.setEvenRowBackground(color);
95         }
96      */

97     public int getRowHeight() {
98         return getTree().getRowHeight();
99     }
100
101     /**
102      * @javabean.property shortDescription="sets the row height"
103      */

104     public void setRowHeight(int value) {
105         getTree().setRowHeight(value);
106     }
107
108 /*
109     public int getRowMargin() {
110         return tree.getRowMargin();
111     }
112
113     public void setRowMargin(int value) {
114         tree.setRowMargin(value);
115     }
116 */

117     public int getSelectionMode() {
118         return getTree().getSelectionModel().getSelectionMode();
119     }
120
121     /**
122      * @javabean.property shortDescription="Sets the selection mode"
123      */

124     public void setSelectionMode(int mode) {
125         getTree().getSelectionModel().setSelectionMode(mode);
126     }
127
128 /*
129     public boolean getShowHorizontalLines() {
130         return tree.getShowHorizontalLines();
131     }
132
133     public void setShowHorizontalLines(boolean value) {
134         tree.setShowHorizontalLines(value);
135     }
136 */

137
138     public FilterPipeline getFilters() {
139         return getTree().getFilters();
140     }
141
142     public void setFilters(FilterPipeline pipeline) {
143         getTree().setFilters(pipeline);
144     }
145
146     public HighlighterPipeline getHighlighters() {
147         return getTree().getHighlighters();
148     }
149
150     /**
151      * @javabean.property shortDescription="Sets the highlighter pipeline"
152      */

153     public void setHighlighters(HighlighterPipeline pipeline) {
154         getTree().setHighlighters(pipeline);
155     }
156
157     /**
158      * Collapses specified row in the tree table.
159      */

160     public void collapseRow(int row) {
161         getTree().collapseRow(row);
162     }
163
164     /**
165      * Expands all nodes in the tree table.
166      */

167     public void expandRow(int row) {
168         getTree().expandRow(row);
169     }
170
171     /**
172      * Collapses all nodes in the tree table.
173      */

174     public void collapseAll() {
175         getTree().collapseAll();
176     }
177
178     /**
179      * Expands all nodes in the tree table.
180      */

181     public void expandAll() {
182         getTree().expandAll();
183     }
184
185     protected JXTree tree = null;
186 }
187
Popular Tags