KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > lf5 > viewer > categoryexplorer > CategoryExplorerTree


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

16 package org.apache.log4j.lf5.viewer.categoryexplorer;
17
18 import javax.swing.*;
19 import javax.swing.event.TreeModelEvent JavaDoc;
20 import javax.swing.tree.TreePath JavaDoc;
21 import java.awt.event.MouseEvent JavaDoc;
22
23 /**
24  * CategoryExplorerTree
25  *
26  * @author Michael J. Sikorsky
27  * @author Robert Shaw
28  * @author Brent Sprecher
29  * @author Brad Marlborough
30  */

31
32 // Contributed by ThoughtWorks Inc.
33

34 public class CategoryExplorerTree extends JTree {
35   //--------------------------------------------------------------------------
36
// Constants:
37
//--------------------------------------------------------------------------
38

39   //--------------------------------------------------------------------------
40
// Protected Variables:
41
//--------------------------------------------------------------------------
42
protected CategoryExplorerModel _model;
43   protected boolean _rootAlreadyExpanded = false;
44
45   //--------------------------------------------------------------------------
46
// Private Variables:
47
//--------------------------------------------------------------------------
48

49   //--------------------------------------------------------------------------
50
// Constructors:
51
//--------------------------------------------------------------------------
52

53   /**
54    * Construct a CategoryExplorerTree with a specific model.
55    */

56   public CategoryExplorerTree(CategoryExplorerModel model) {
57     super(model);
58
59     _model = model;
60     init();
61   }
62
63   /**
64    * Construct a CategoryExplorerTree and create a default CategoryExplorerModel.
65    */

66   public CategoryExplorerTree() {
67     super();
68
69     CategoryNode rootNode = new CategoryNode("Categories");
70
71     _model = new CategoryExplorerModel(rootNode);
72
73     setModel(_model);
74
75     init();
76   }
77
78   //--------------------------------------------------------------------------
79
// Public Methods:
80
//--------------------------------------------------------------------------
81

82   public CategoryExplorerModel getExplorerModel() {
83     return (_model);
84   }
85
86   public String JavaDoc getToolTipText(MouseEvent JavaDoc e) {
87
88     try {
89       return super.getToolTipText(e);
90     } catch (Exception JavaDoc ex) {
91       return "";
92     }
93
94   }
95
96   //--------------------------------------------------------------------------
97
// Protected Methods:
98
//--------------------------------------------------------------------------
99

100   protected void init() {
101     // Put visible lines on the JTree.
102
putClientProperty("JTree.lineStyle", "Angled");
103
104     // Configure the Tree with the appropriate Renderers and Editors.
105

106     CategoryNodeRenderer renderer = new CategoryNodeRenderer();
107     setEditable(true);
108     setCellRenderer(renderer);
109
110     CategoryNodeEditor editor = new CategoryNodeEditor(_model);
111
112     setCellEditor(new CategoryImmediateEditor(this,
113         new CategoryNodeRenderer(),
114         editor));
115     setShowsRootHandles(true);
116
117     setToolTipText("");
118
119     ensureRootExpansion();
120
121   }
122
123   protected void expandRootNode() {
124     if (_rootAlreadyExpanded) {
125       return;
126     }
127     _rootAlreadyExpanded = true;
128     TreePath JavaDoc path = new TreePath JavaDoc(_model.getRootCategoryNode().getPath());
129     expandPath(path);
130   }
131
132   protected void ensureRootExpansion() {
133     _model.addTreeModelListener(new TreeModelAdapter() {
134       public void treeNodesInserted(TreeModelEvent JavaDoc e) {
135         expandRootNode();
136       }
137     });
138   }
139
140   //--------------------------------------------------------------------------
141
// Private Methods:
142
//--------------------------------------------------------------------------
143

144   //--------------------------------------------------------------------------
145
// Nested Top-Level Classes or Interfaces:
146
//--------------------------------------------------------------------------
147

148 }
149
150
151
152
153
154
155
Popular Tags