KickJava   Java API By Example, From Geeks To Geeks.

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


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.tree.DefaultMutableTreeNode JavaDoc;
19 import javax.swing.tree.TreeNode JavaDoc;
20 import java.util.Enumeration JavaDoc;
21
22 /**
23  * CategoryNode
24  *
25  * @author Michael J. Sikorsky
26  * @author Robert Shaw
27  */

28
29 // Contributed by ThoughtWorks Inc.
30

31 public class CategoryNode extends DefaultMutableTreeNode JavaDoc {
32   //--------------------------------------------------------------------------
33
// Constants:
34
//--------------------------------------------------------------------------
35

36   //--------------------------------------------------------------------------
37
// Protected Variables:
38
//--------------------------------------------------------------------------
39
protected boolean _selected = true;
40   protected int _numberOfContainedRecords = 0;
41   protected int _numberOfRecordsFromChildren = 0;
42   protected boolean _hasFatalChildren = false;
43   protected boolean _hasFatalRecords = false;
44
45   //--------------------------------------------------------------------------
46
// Private Variables:
47
//--------------------------------------------------------------------------
48

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

53   /**
54    *
55    */

56   public CategoryNode(String JavaDoc title) {
57     setUserObject(title);
58   }
59
60   //--------------------------------------------------------------------------
61
// Public Methods:
62
//--------------------------------------------------------------------------
63
public String JavaDoc getTitle() {
64     return (String JavaDoc) getUserObject();
65   }
66
67   public void setSelected(boolean s) {
68     if (s != _selected) {
69       _selected = s;
70     }
71   }
72
73   public boolean isSelected() {
74     return _selected;
75   }
76
77   /**
78    * @deprecated
79    */

80   public void setAllDescendantsSelected() {
81     Enumeration JavaDoc children = children();
82     while (children.hasMoreElements()) {
83       CategoryNode node = (CategoryNode) children.nextElement();
84       node.setSelected(true);
85       node.setAllDescendantsSelected();
86     }
87   }
88
89   /**
90    * @deprecated
91    */

92   public void setAllDescendantsDeSelected() {
93     Enumeration JavaDoc children = children();
94     while (children.hasMoreElements()) {
95       CategoryNode node = (CategoryNode) children.nextElement();
96       node.setSelected(false);
97       node.setAllDescendantsDeSelected();
98     }
99   }
100
101   public String JavaDoc toString() {
102     return (getTitle());
103   }
104
105   public boolean equals(Object JavaDoc obj) {
106     if (obj instanceof CategoryNode) {
107       CategoryNode node = (CategoryNode) obj;
108       String JavaDoc tit1 = getTitle().toLowerCase();
109       String JavaDoc tit2 = node.getTitle().toLowerCase();
110
111       if (tit1.equals(tit2)) {
112         return (true);
113       }
114     }
115     return (false);
116   }
117
118   public int hashCode() {
119     return (getTitle().hashCode());
120   }
121
122   public void addRecord() {
123     _numberOfContainedRecords++;
124     addRecordToParent();
125   }
126
127   public int getNumberOfContainedRecords() {
128     return _numberOfContainedRecords;
129   }
130
131   public void resetNumberOfContainedRecords() {
132     _numberOfContainedRecords = 0;
133     _numberOfRecordsFromChildren = 0;
134     _hasFatalRecords = false;
135     _hasFatalChildren = false;
136   }
137
138   public boolean hasFatalRecords() {
139     return _hasFatalRecords;
140   }
141
142   public boolean hasFatalChildren() {
143     return _hasFatalChildren;
144   }
145
146   public void setHasFatalRecords(boolean flag) {
147     _hasFatalRecords = flag;
148   }
149
150   public void setHasFatalChildren(boolean flag) {
151     _hasFatalChildren = flag;
152   }
153
154   //--------------------------------------------------------------------------
155
// Protected Methods:
156
//--------------------------------------------------------------------------
157

158   protected int getTotalNumberOfRecords() {
159     return getNumberOfRecordsFromChildren() + getNumberOfContainedRecords();
160   }
161
162   /**
163    * Passes up the addition from child to parent
164    */

165   protected void addRecordFromChild() {
166     _numberOfRecordsFromChildren++;
167     addRecordToParent();
168   }
169
170   protected int getNumberOfRecordsFromChildren() {
171     return _numberOfRecordsFromChildren;
172   }
173
174   protected void addRecordToParent() {
175     TreeNode JavaDoc parent = getParent();
176     if (parent == null) {
177       return;
178     }
179     ((CategoryNode) parent).addRecordFromChild();
180   }
181   //--------------------------------------------------------------------------
182
// Private Methods:
183
//--------------------------------------------------------------------------
184

185   //--------------------------------------------------------------------------
186
// Nested Top-Level Classes or Interfaces:
187
//--------------------------------------------------------------------------
188

189 }
190
191
192
193
194
195
196
Popular Tags