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.*;
    20  import javax.swing.tree.DefaultTreeCellRenderer;
    21  import java.awt.*;
    22  import java.net.URL;
    23
    24  /***
    25   * CategoryNodeRenderer
    26   *
    27   * @author Michael J. Sikorsky
    28   * @author Robert Shaw
    29   */
    30
    31  // Contributed by ThoughtWorks Inc.
    32
    33  public class CategoryNodeRenderer extends DefaultTreeCellRenderer {
    34    private static final long serialVersionUID = -6046702673278595048L;
    35
    36    //--------------------------------------------------------------------------
    37    //   Constants:
    38    //--------------------------------------------------------------------------
    39
    40    public static final Color FATAL_CHILDREN = new Color(189, 113, 0);
    41
    42    //--------------------------------------------------------------------------
    43    //   Protected Variables:
    44    //--------------------------------------------------------------------------
    45    protected JCheckBox _checkBox = new JCheckBox();
    46    protected JPanel _panel = new JPanel();
    47    protected static ImageIcon _sat = null;
    48  //   protected JLabel              _label  = new JLabel();
    49
    50    //--------------------------------------------------------------------------
    51    //   Private Variables:
    52    //--------------------------------------------------------------------------
    53
    54    //--------------------------------------------------------------------------
    55    //   Constructors:
    56    //--------------------------------------------------------------------------
    57    public CategoryNodeRenderer() {
    58      _panel.setBackground(UIManager.getColor("Tree.textBackground"));
    59
    60      if (_sat == null) {
    61        // Load the satellite image.
    62        String resource =
    63            "/org/apache/log4j/lf5/viewer/images/channelexplorer_satellite.gif";
    64        URL satURL = getClass().getResource(resource);
    65
    66        _sat = new ImageIcon(satURL);
    67      }
    68
    69      setOpaque(false);
    70      _checkBox.setOpaque(false);
    71      _panel.setOpaque(false);
    72
    73      // The flowlayout set to LEFT is very important so that the editor
    74      // doesn't jump around.
    75      _panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
    76      _panel.add(_checkBox);
    77      _panel.add(this);
    78
    79      setOpenIcon(_sat);
    80      setClosedIcon(_sat);
    81      setLeafIcon(_sat);
    82    }
    83
    84    //--------------------------------------------------------------------------
    85    //   Public Methods:
    86    //--------------------------------------------------------------------------
    87    public Component getTreeCellRendererComponent(
    88        JTree tree, Object value,
    89        boolean selected, boolean expanded,
    90        boolean leaf, int row,
    91        boolean hasFocus) {
    92
    93      CategoryNode node = (CategoryNode) value;
    94      //FileNode node = (FileNode)value;
    95      //String s = tree.convertValueToText(value, selected,
    96      //						   expanded, leaf, row, hasFocus);
    97
    98      super.getTreeCellRendererComponent(
    99          tree, value, selected, expanded,
    100         leaf, row, hasFocus);
    101
    102     if (row == 0) {
    103       // Root row -- no check box
    104       _checkBox.setVisible(false);
    105     } else {
    106       _checkBox.setVisible(true);
    107       _checkBox.setSelected(node.isSelected());
    108     }
    109     String toolTip = buildToolTip(node);
    110     _panel.setToolTipText(toolTip);
    111     if (node.hasFatalChildren()) {
    112       this.setForeground(FATAL_CHILDREN);
    113     }
    114     if (node.hasFatalRecords()) {
    115       this.setForeground(Color.red);
    116     }
    117
    118     return _panel;
    119   }
    120
    121   public Dimension getCheckBoxOffset() {
    122     return new Dimension(0, 0);
    123   }
    124
    125   //--------------------------------------------------------------------------
    126   //   Protected Methods:
    127   //--------------------------------------------------------------------------
    128
    129   protected String buildToolTip(CategoryNode node) {
    130     StringBuffer result = new StringBuffer();
    131     result.append(node.getTitle()).append(" contains a total of ");
    132     result.append(node.getTotalNumberOfRecords());
    133     result.append(" LogRecords.");
    134     result.append(" Right-click for more info.");
    135     return result.toString();
    136   }
    137   //--------------------------------------------------------------------------
    138   //   Private Methods:
    139   //--------------------------------------------------------------------------
    140
    141   //--------------------------------------------------------------------------
    142   //   Nested Top-Level Classes or Interfaces:
    143   //--------------------------------------------------------------------------
    144
    145 }
    146
    147
    148
    149
    150
    151