View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  package org.apache.log4j.lf5.viewer.categoryexplorer;
    18
    19  import javax.swing.tree.DefaultMutableTreeNode;
    20  import javax.swing.tree.TreeNode;
    21  import java.util.Enumeration;
    22
    23  /**
    24   * CategoryNode
    25   *
    26   * @author Michael J. Sikorsky
    27   * @author Robert Shaw
    28   */
    29
    30  // Contributed by ThoughtWorks Inc.
    31
    32  public class CategoryNode extends DefaultMutableTreeNode {
    33    private static final long serialVersionUID = 5958994817693177319L;
    34    //--------------------------------------------------------------------------
    35    //   Constants:
    36    //--------------------------------------------------------------------------
    37
    38    //--------------------------------------------------------------------------
    39    //   Protected Variables:
    40    //--------------------------------------------------------------------------
    41    protected boolean _selected = true;
    42    protected int _numberOfContainedRecords = 0;
    43    protected int _numberOfRecordsFromChildren = 0;
    44    protected boolean _hasFatalChildren = false;
    45    protected boolean _hasFatalRecords = false;
    46
    47    //--------------------------------------------------------------------------
    48    //   Private Variables:
    49    //--------------------------------------------------------------------------
    50
    51    //--------------------------------------------------------------------------
    52    //   Constructors:
    53    //--------------------------------------------------------------------------
    54
    55    /**
    56     *
    57     */
    58    public CategoryNode(String title) {
    59      setUserObject(title);
    60    }
    61
    62    //--------------------------------------------------------------------------
    63    //   Public Methods:
    64    //--------------------------------------------------------------------------
    65    public String getTitle() {
    66      return (String) getUserObject();
    67    }
    68
    69    public void setSelected(boolean s) {
    70      if (s != _selected) {
    71        _selected = s;
    72      }
    73    }
    74
    75    public boolean isSelected() {
    76      return _selected;
    77    }
    78
    79    /**
    80     * @deprecated
    81     */
    82    public void setAllDescendantsSelected() {
    83      Enumeration children = children();
    84      while (children.hasMoreElements()) {
    85        CategoryNode node = (CategoryNode) children.nextElement();
    86        node.setSelected(true);
    87        node.setAllDescendantsSelected();
    88      }
    89    }
    90
    91    /**
    92     * @deprecated
    93     */
    94    public void setAllDescendantsDeSelected() {
    95      Enumeration children = children();
    96      while (children.hasMoreElements()) {
    97        CategoryNode node = (CategoryNode) children.nextElement();
    98        node.setSelected(false);
    99        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