1 16 package org.apache.log4j.lf5.viewer.categoryexplorer; 17 18 import javax.swing.tree.DefaultMutableTreeNode ; 19 import javax.swing.tree.TreeNode ; 20 import java.util.Enumeration ; 21 22 28 29 31 public class CategoryNode extends DefaultMutableTreeNode { 32 36 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 49 53 56 public CategoryNode(String title) { 57 setUserObject(title); 58 } 59 60 public String getTitle() { 64 return (String ) 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 80 public void setAllDescendantsSelected() { 81 Enumeration children = children(); 82 while (children.hasMoreElements()) { 83 CategoryNode node = (CategoryNode) children.nextElement(); 84 node.setSelected(true); 85 node.setAllDescendantsSelected(); 86 } 87 } 88 89 92 public void setAllDescendantsDeSelected() { 93 Enumeration 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 toString() { 102 return (getTitle()); 103 } 104 105 public boolean equals(Object obj) { 106 if (obj instanceof CategoryNode) { 107 CategoryNode node = (CategoryNode) obj; 108 String tit1 = getTitle().toLowerCase(); 109 String 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 158 protected int getTotalNumberOfRecords() { 159 return getNumberOfRecordsFromChildren() + getNumberOfContainedRecords(); 160 } 161 162 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 parent = getParent(); 176 if (parent == null) { 177 return; 178 } 179 ((CategoryNode) parent).addRecordFromChild(); 180 } 181 185 189 } 190 191 192 193 194 195 196 | Popular Tags |