001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.log4j.lf5.viewer.categoryexplorer; 018 019import javax.swing.tree.DefaultMutableTreeNode; 020import javax.swing.tree.TreeNode; 021import java.util.Enumeration; 022 023/** 024 * CategoryNode 025 * 026 * @author Michael J. Sikorsky 027 * @author Robert Shaw 028 */ 029 030// Contributed by ThoughtWorks Inc. 031 032public class CategoryNode extends DefaultMutableTreeNode { 033 private static final long serialVersionUID = 5958994817693177319L; 034 //-------------------------------------------------------------------------- 035 // Constants: 036 //-------------------------------------------------------------------------- 037 038 //-------------------------------------------------------------------------- 039 // Protected Variables: 040 //-------------------------------------------------------------------------- 041 protected boolean _selected = true; 042 protected int _numberOfContainedRecords = 0; 043 protected int _numberOfRecordsFromChildren = 0; 044 protected boolean _hasFatalChildren = false; 045 protected boolean _hasFatalRecords = false; 046 047 //-------------------------------------------------------------------------- 048 // Private Variables: 049 //-------------------------------------------------------------------------- 050 051 //-------------------------------------------------------------------------- 052 // Constructors: 053 //-------------------------------------------------------------------------- 054 055 /** 056 * 057 */ 058 public CategoryNode(String title) { 059 setUserObject(title); 060 } 061 062 //-------------------------------------------------------------------------- 063 // Public Methods: 064 //-------------------------------------------------------------------------- 065 public String getTitle() { 066 return (String) getUserObject(); 067 } 068 069 public void setSelected(boolean s) { 070 if (s != _selected) { 071 _selected = s; 072 } 073 } 074 075 public boolean isSelected() { 076 return _selected; 077 } 078 079 /** 080 * @deprecated 081 */ 082 public void setAllDescendantsSelected() { 083 Enumeration children = children(); 084 while (children.hasMoreElements()) { 085 CategoryNode node = (CategoryNode) children.nextElement(); 086 node.setSelected(true); 087 node.setAllDescendantsSelected(); 088 } 089 } 090 091 /** 092 * @deprecated 093 */ 094 public void setAllDescendantsDeSelected() { 095 Enumeration children = children(); 096 while (children.hasMoreElements()) { 097 CategoryNode node = (CategoryNode) children.nextElement(); 098 node.setSelected(false); 099 node.setAllDescendantsDeSelected(); 100 } 101 } 102 103 public String toString() { 104 return (getTitle()); 105 } 106 107 public boolean equals(Object obj) { 108 if (obj instanceof CategoryNode) { 109 CategoryNode node = (CategoryNode) obj; 110 String tit1 = getTitle().toLowerCase(); 111 String tit2 = node.getTitle().toLowerCase(); 112 113 if (tit1.equals(tit2)) { 114 return (true); 115 } 116 } 117 return (false); 118 } 119 120 public int hashCode() { 121 return (getTitle().hashCode()); 122 } 123 124 public void addRecord() { 125 _numberOfContainedRecords++; 126 addRecordToParent(); 127 } 128 129 public int getNumberOfContainedRecords() { 130 return _numberOfContainedRecords; 131 } 132 133 public void resetNumberOfContainedRecords() { 134 _numberOfContainedRecords = 0; 135 _numberOfRecordsFromChildren = 0; 136 _hasFatalRecords = false; 137 _hasFatalChildren = false; 138 } 139 140 public boolean hasFatalRecords() { 141 return _hasFatalRecords; 142 } 143 144 public boolean hasFatalChildren() { 145 return _hasFatalChildren; 146 } 147 148 public void setHasFatalRecords(boolean flag) { 149 _hasFatalRecords = flag; 150 } 151 152 public void setHasFatalChildren(boolean flag) { 153 _hasFatalChildren = flag; 154 } 155 156 //-------------------------------------------------------------------------- 157 // Protected Methods: 158 //-------------------------------------------------------------------------- 159 160 protected int getTotalNumberOfRecords() { 161 return getNumberOfRecordsFromChildren() + getNumberOfContainedRecords(); 162 } 163 164 /** 165 * Passes up the addition from child to parent 166 */ 167 protected void addRecordFromChild() { 168 _numberOfRecordsFromChildren++; 169 addRecordToParent(); 170 } 171 172 protected int getNumberOfRecordsFromChildren() { 173 return _numberOfRecordsFromChildren; 174 } 175 176 protected void addRecordToParent() { 177 TreeNode parent = getParent(); 178 if (parent == null) { 179 return; 180 } 181 ((CategoryNode) parent).addRecordFromChild(); 182 } 183 //-------------------------------------------------------------------------- 184 // Private Methods: 185 //-------------------------------------------------------------------------- 186 187 //-------------------------------------------------------------------------- 188 // Nested Top-Level Classes or Interfaces: 189 //-------------------------------------------------------------------------- 190 191} 192 193 194 195 196 197