com.crashlytics.tools.android_2.1.0

n(CategoryNode node, boolean selected)
  {
    TreeNode[] nodes = getPathToRoot(node);
    int len = nodes.length;
    for (int i = 1; i < len; i++)
    {
      CategoryNode parent = (CategoryNode)nodes[i];
      if (parent.isSelected() != selected)
      {
        parent.setSelected(selected);
        nodeChanged(parent);
      }
    }
    notifyActionListeners();
  }
  
  public synchronized void addActionListener(ActionListener l)
  {
    _listener = AWTEventMulticaster.add(_listener, l);
  }
  
  public synchronized void removeActionListener(ActionListener l)
  {
    _listener = AWTEventMulticaster.remove(_listener, l);
  }
  
  public void resetAllNodeCounts()
  {
    Enumeration nodes = getRootCategoryNode().depthFirstEnumeration();
    while (nodes.hasMoreElements())
    {
      CategoryNode current = (CategoryNode)nodes.nextElement();
      current.resetNumberOfContainedRecords();
      nodeChanged(current);
    }
  }
  
  public TreePath getTreePathToRoot(CategoryNode node)
  {
    if (node == null) {
      return null;
    }
    return new TreePath(getPathToRoot(node));
  }
  
  protected void notifyActionListeners()
  {
    if (_listener != null) {
      _listener.actionPerformed(_event);
    }
  }
  
  protected void refresh(final CategoryNode node)
  {
    SwingUtilities.invokeLater(new Runnable()
    {
      public void run()
      {
        nodeChanged(node);
      }
    });
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryExplorerModel
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import javax.swing.event.TreeModelEvent;

class CategoryExplorerTree$1
  extends TreeModelAdapter
{
  private final CategoryExplorerTree this$0;
  
  CategoryExplorerTree$1(CategoryExplorerTree paramCategoryExplorerTree) {}
  
  public void treeNodesInserted(TreeModelEvent e)
  {
    this$0.expandRootNode();
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryExplorerTree.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import java.awt.event.MouseEvent;
import javax.swing.JTree;
import javax.swing.event.TreeModelEvent;
import javax.swing.tree.TreePath;

public class CategoryExplorerTree
  extends JTree
{
  private static final long serialVersionUID = 8066257446951323576L;
  protected CategoryExplorerModel _model;
  protected boolean _rootAlreadyExpanded = false;
  
  public CategoryExplorerTree(CategoryExplorerModel model)
  {
    super(model);
    
    _model = model;
    init();
  }
  
  public CategoryExplorerTree()
  {
    CategoryNode rootNode = new CategoryNode("Categories");
    
    _model = new CategoryExplorerModel(rootNode);
    
    setModel(_model);
    
    init();
  }
  
  public CategoryExplorerModel getExplorerModel()
  {
    return _model;
  }
  
  public String getToolTipText(MouseEvent e)
  {
    try
    {
      return super.getToolTipText(e);
    }
    catch (Exception ex) {}
    return "";
  }
  
  protected void init()
  {
    putClientProperty("JTree.lineStyle", "Angled");
    
    CategoryNodeRenderer renderer = new CategoryNodeRenderer();
    setEditable(true);
    setCellRenderer(renderer);
    
    CategoryNodeEditor editor = new CategoryNodeEditor(_model);
    
    setCellEditor(new CategoryImmediateEditor(this, new CategoryNodeRenderer(), editor));
    
    setShowsRootHandles(true);
    
    setToolTipText("");
    
    ensureRootExpansion();
  }
  
  protected void expandRootNode()
  {
    if (_rootAlreadyExpanded) {
      return;
    }
    _rootAlreadyExpanded = true;
    TreePath path = new TreePath(_model.getRootCategoryNode().getPath());
    expandPath(path);
  }
  
  protected void ensureRootExpansion()
  {
    _model.addTreeModelListener(new TreeModelAdapter()
    {
      public void treeNodesInserted(TreeModelEvent e)
      {
        expandRootNode();
      }
    });
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryExplorerTree
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.util.EventObject;
import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellEditor;
import javax.swing.tree.TreePath;

public class CategoryImmediateEditor
  extends DefaultTreeCellEditor
{
  private CategoryNodeRenderer renderer;
  protected Icon editingIcon = null;
  
  public CategoryImmediateEditor(JTree tree, CategoryNodeRenderer renderer, CategoryNodeEditor editor)
  {
    super(tree, renderer, editor);
    this.renderer = renderer;
    renderer.setIcon(null);
    renderer.setLeafIcon(null);
    renderer.setOpenIcon(null);
    renderer.setClosedIcon(null);
    
    editingIcon = null;
  }
  
  public boolean shouldSelectCell(EventObject e)
  {
    boolean rv = false;
    if ((e instanceof MouseEvent))
    {
      MouseEvent me = (MouseEvent)e;
      TreePath path = tree.getPathForLocation(me.getX(), me.getY());
      
      CategoryNode node = (CategoryNode)path.getLastPathComponent();
      
      rv = node.isLeaf();
    }
    return rv;
  }
  
  public boolean inCheckBoxHitRegion(MouseEvent e)
  {
    TreePath path = tree.getPathForLocation(e.getX(), e.getY());
    if (path == null) {
      return false;
    }
    CategoryNode node = (CategoryNode)path.getLastPathComponent();
    boolean rv = false;
    
    Rectangle bounds = tree.getRowBounds(lastRow);
    Dimension checkBoxOffset = renderer.getCheckBoxOffset();
    
    bounds.translate(offset + width, height);
    
    rv = bounds.contains(e.getPoint());
    
    return true;
  }
  
  protected boolean canEditImmediately(EventObject e)
  {
    boolean rv = false;
    if ((e instanceof MouseEvent))
    {
      MouseEvent me = (MouseEvent)e;
      rv = inCheckBoxHitRegion(me);
    }
    return rv;
  }
  
  protected void determineOffset(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)
  {
    offset = 0;
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryImmediateEditor
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import java.util.Enumeration;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;

public class CategoryNode
  extends DefaultMutableTreeNode
{
  private static final long serialVersionUID = 5958994817693177319L;
  protected boolean _selected = true;
  protected int _numberOfContainedRecords = 0;
  protected int _numberOfRecordsFromChildren = 0;
  protected boolean _hasFatalChildren = false;
  protected boolean _hasFatalRecords = false;
  
  public CategoryNode(String title)
  {
    setUserObject(title);
  }
  
  public String getTitle()
  {
    return (String)getUserObject();
  }
  
  public void setSelected(boolean s)
  {
    if (s != _selected) {
      _selected = s;
    }
  }
  
  public boolean isSelected()
  {
    return _selected;
  }
  
  /**
   * @deprecated
   */
  public void setAllDescendantsSelected()
  {
    Enumeration children = children();
    while (children.hasMoreElements())
    {
      CategoryNode node = (CategoryNode)children.nextElement();
      node.setSelected(true);
      node.setAllDescendantsSelected();
    }
  }
  
  /**
   * @deprecated
   */
  public void setAllDescendantsDeSelected()
  {
    Enumeration children = children();
    while (children.hasMoreElements())
    {
      CategoryNode node = (CategoryNode)children.nextElement();
      node.setSelected(false);
      node.setAllDescendantsDeSelected();
    }
  }
  
  public String toString()
  {
    return getTitle();
  }
  
  public boolean equals(Object obj)
  {
    if ((obj instanceof CategoryNode))
    {
      CategoryNode node = (CategoryNode)obj;
      String tit1 = getTitle().toLowerCase();
      String tit2 = node.getTitle().toLowerCase();
      if (tit1.equals(tit2)) {
        return true;
      }
    }
    return false;
  }
  
  public int hashCode()
  {
    return getTitle().hashCode();
  }
  
  public void addRecord()
  {
    _numberOfContainedRecords += 1;
    addRecordToParent();
  }
  
  public int getNumberOfContainedRecords()
  {
    return _numberOfContainedRecords;
  }
  
  public void resetNumberOfContainedRecords()
  {
    _numberOfContainedRecords = 0;
    _numberOfRecordsFromChildren = 0;
    _hasFatalRecords = false;
    _hasFatalChildren = false;
  }
  
  public boolean hasFatalRecords()
  {
    return _hasFatalRecords;
  }
  
  public boolean hasFatalChildren()
  {
    return _hasFatalChildren;
  }
  
  public void setHasFatalRecords(boolean flag)
  {
    _hasFatalRecords = flag;
  }
  
  public void setHasFatalChildren(boolean flag)
  {
    _hasFatalChildren = flag;
  }
  
  protected int getTotalNumberOfRecords()
  {
    return getNumberOfRecordsFromChildren() + getNumberOfContainedRecords();
  }
  
  protected void addRecordFromChild()
  {
    _numberOfRecordsFromChildren += 1;
    addRecordToParent();
  }
  
  protected int getNumberOfRecordsFromChildren()
  {
    return _numberOfRecordsFromChildren;
  }
  
  protected void addRecordToParent()
  {
    TreeNode parent = getParent();
    if (parent == null) {
      return;
    }
    ((CategoryNode)parent).addRecordFromChild();
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryNode
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBox;

class CategoryNodeEditor$1
  implements ActionListener
{
  private final CategoryNodeEditor this$0;
  
  CategoryNodeEditor$1(CategoryNodeEditor paramCategoryNodeEditor) {}
  
  public void actionPerformed(ActionEvent e)
  {
    this$0._categoryModel.update(this$0._lastEditedNode, this$0._checkBox.isSelected());
    this$0.stopCellEditing();
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryNodeEditor.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

class CategoryNodeEditor$2
  extends MouseAdapter
{
  private final CategoryNodeEditor this$0;
  
  CategoryNodeEditor$2(CategoryNodeEditor paramCategoryNodeEditor) {}
  
  public void mousePressed(MouseEvent e)
  {
    if ((e.getModifiers() & 0x4) != 0) {
      this$0.showPopup(this$0._lastEditedNode, e.getX(), e.getY());
    }
    this$0.stopCellEditing();
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryNodeEditor.2
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class CategoryNodeEditor$3
  implements ActionListener
{
  private final CategoryNodeEditor this$0;
  
  CategoryNodeEditor$3(CategoryNodeEditor paramCategoryNodeEditor, CategoryNode paramCategoryNode) {}
  
  public void actionPerformed(ActionEvent e)
  {
    this$0.showPropertiesDialog(val$node);
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryNodeEditor.3
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class CategoryNodeEditor$4
  implements ActionListener
{
  private final CategoryNodeEditor this$0;
  
  CategoryNodeEditor$4(CategoryNodeEditor paramCategoryNodeEditor, CategoryNode paramCategoryNode) {}
  
  public void actionPerformed(ActionEvent e)
  {
    this$0._categoryModel.setDescendantSelection(val$node, true);
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryNodeEditor.4
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class CategoryNodeEditor$5
  implements ActionListener
{
  private final CategoryNodeEditor this$0;
  
  CategoryNodeEditor$5(CategoryNodeEditor paramCategoryNodeEditor, CategoryNode paramCategoryNode) {}
  
  public void actionPerformed(ActionEvent e)
  {
    this$0._categoryModel.setDescendantSelection(val$node, false);
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryNodeEditor.5
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class CategoryNodeEditor$6
  implements ActionListener
{
  private final CategoryNodeEditor this$0;
  
  CategoryNodeEditor$6(CategoryNodeEditor paramCategoryNodeEditor, CategoryNode paramCategoryNode) {}
  
  public void actionPerformed(ActionEvent e)
  {
    this$0.expandDescendants(val$node);
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryNodeEditor.6
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class CategoryNodeEditor$7
  implements ActionListener
{
  private final CategoryNodeEditor this$0;
  
  CategoryNodeEditor$7(CategoryNodeEditor paramCategoryNodeEditor, CategoryNode paramCategoryNode) {}
  
  public void actionPerformed(ActionEvent e)
  {
    this$0.collapseDescendants(val$node);
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryNodeEditor.7
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class CategoryNodeEditor$8
  implements ActionListener
{
  private final CategoryNodeEditor this$0;
  
  CategoryNodeEditor$8(CategoryNodeEditor paramCategoryNodeEditor) {}
  
  public void actionPerformed(ActionEvent e)
  {
    while (this$0.removeUnusedNodes() > 0) {}
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryNodeEditor.8
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Enumeration;
import javax.swing.JCheckBox;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTree;
import javax.swing.tree.TreePath;

public class CategoryNodeEditor
  extends CategoryAbstractCellEditor
{
  protected CategoryNodeEditorRenderer _renderer;
  protected CategoryNode _lastEditedNode;
  protected JCheckBox _checkBox;
  protected CategoryExplorerModel _categoryModel;
  protected JTree _tree;
  
  public CategoryNodeEditor(CategoryExplorerModel model)
  {
    _renderer = new CategoryNodeEditorRenderer();
    _checkBox = _renderer.getCheckBox();
    _categoryModel = model;
    
    _checkBox.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        _categoryModel.update(_lastEditedNode, _checkBox.isSelected());
        stopCellEditing();
      }
    });
    _renderer.addMouseListener(new MouseAdapter()
    {
      public void mousePressed(MouseEvent e)
      {
        if ((e.getModifiers() & 0x4) != 0) {
          showPopup(_lastEditedNode, e.getX(), e.getY());
        }
        stopCellEditing();
      }
    });
  }
  
  public Component getTreeCellEditorComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row)
  {
    _lastEditedNode = ((CategoryNode)value);
    _tree = tree;
    
    return _renderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, true);
  }
  
  public Object getCellEditorValue()
  {
    return _lastEditedNode.getUserObject();
  }
  
  protected JMenuItem createPropertiesMenuItem(final CategoryNode node)
  {
    JMenuItem result = new JMenuItem("Properties");
    result.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        showPropertiesDialog(node);
      }
    });
    return result;
  }
  
  protected void showPropertiesDialog(CategoryNode node)
  {
    JOptionPane.showMessageDialog(_tree, getDisplayedProperties(node), "Category Properties: " + node.getTitle(), -1);
  }
  
  protected Object getDisplayedProperties(CategoryNode node)
  {
    ArrayList result = new ArrayList();
    result.add("Category: " + node.getTitle());
    if (node.hasFatalRecords()) {
      result.add("Contains at least one fatal LogRecord.");
    }
    if (node.hasFatalChildren()) {
      result.add("Contains descendants with a fatal LogRecord.");
    }
    result.add("LogRecords in this category alone: " + node.getNumberOfContainedRecords());
    
    result.add("LogRecords in descendant categories: " + node.getNumberOfRecordsFromChildren());
    
    result.add("LogRecords in this category including descendants: " + node.getTotalNumberOfRecords());
    
    return result.toArray();
  }
  
  protected void showPopup(CategoryNode node, int x, int y)
  {
    JPopupMenu popup = new JPopupMenu();
    popup.setSize(150, 400);
    if (node.getParent() == null)
    {
      popup.add(createRemoveMenuItem());
      popup.addSeparator();
    }
    popup.add(createSelectDescendantsMenuItem(node));
    popup.add(createUnselectDescendantsMenuItem(node));
    popup.addSeparator();
    popup.add(createExpandMenuItem(node));
    popup.add(createCollapseMenuItem(node));
    popup.addSeparator();
    popup.add(createPropertiesMenuItem(node));
    popup.show(_renderer, x, y);
  }
  
  protected JMenuItem createSelectDescendantsMenuItem(final CategoryNode node)
  {
    JMenuItem selectDescendants = new JMenuItem("Select All Descendant Categories");
    
    selectDescendants.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        _categoryModel.setDescendantSelection(node, true);
      }
    });
    return selectDescendants;
  }
  
  protected JMenuItem createUnselectDescendantsMenuItem(final CategoryNode node)
  {
    JMenuItem unselectDescendants = new JMenuItem("Deselect All Descendant Categories");
    
    unselectDescendants.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        _categoryModel.setDescendantSelection(node, false);
      }
    });
    return unselectDescendants;
  }
  
  protected JMenuItem createExpandMenuItem(final CategoryNode node)
  {
    JMenuItem result = new JMenuItem("Expand All Descendant Categories");
    result.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        expandDescendants(node);
      }
    });
    return result;
  }
  
  protected JMenuItem createCollapseMenuItem(final CategoryNode node)
  {
    JMenuItem result = new JMenuItem("Collapse All Descendant Categories");
    result.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        collapseDescendants(node);
      }
    });
    return result;
  }
  
  protected JMenuItem createRemoveMenuItem()
  {
    JMenuItem result = new JMenuItem("Remove All Empty Categories");
    result.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        while (removeUnusedNodes() > 0) {}
      }
    });
    return result;
  }
  
  protected void expandDescendants(CategoryNode node)
  {
    Enumeration descendants = node.depthFirstEnumeration();
    while (descendants.hasMoreElements())
    {
      CategoryNode current = (CategoryNode)descendants.nextElement();
      expand(current);
    }
  }
  
  protected void collapseDescendants(CategoryNode node)
  {
    Enumeration descendants = node.depthFirstEnumeration();
    while (descendants.hasMoreElements())
    {
      CategoryNode current = (CategoryNode)descendants.nextElement();
      collapse(current);
    }
  }
  
  protected int removeUnusedNodes()
  {
    int count = 0;
    CategoryNode root = _categoryModel.getRootCategoryNode();
    Enumeration enumeration = root.depthFirstEnumeration();
    while (enumeration.hasMoreElements())
    {
      CategoryNode node = (CategoryNode)enumeration.nextElement();
      if ((node.isLeaf()) && (node.getNumberOfContainedRecords() == 0) && (node.getParent() != null))
      {
        _categoryModel.removeNodeFromParent(node);
        count++;
      }
    }
    return count;
  }
  
  protected void expand(CategoryNode node)
  {
    _tree.expandPath(getTreePath(node));
  }
  
  protected TreePath getTreePath(CategoryNode node)
  {
    return new TreePath(node.getPath());
  }
  
  protected void collapse(CategoryNode node)
  {
    _tree.collapsePath(getTreePath(node));
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryNodeEditor
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import java.awt.Component;
import javax.swing.JCheckBox;
import javax.swing.JTree;

public class CategoryNodeEditorRenderer
  extends CategoryNodeRenderer
{
  private static final long serialVersionUID = -6094804684259929574L;
  
  public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
  {
    Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    
    return c;
  }
  
  public JCheckBox getCheckBox()
  {
    return _checkBox;
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryNodeEditorRenderer
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.tree.DefaultTreeCellRenderer;

public class CategoryNodeRenderer
  extends DefaultTreeCellRenderer
{
  private static final long serialVersionUID = -6046702673278595048L;
  public static final Color FATAL_CHILDREN = new Color(189, 113, 0);
  protected JCheckBox _checkBox = new JCheckBox();
  protected JPanel _panel = new JPanel();
  protected static ImageIcon _sat = null;
  
  public CategoryNodeRenderer()
  {
    _panel.setBackground(UIManager.getColor("Tree.textBackground"));
    if (_sat == null)
    {
      String resource = "/org/apache/log4j/lf5/viewer/images/channelexplorer_satellite.gif";
      
      URL satURL = getClass().getResource(resource);
      
      _sat = new ImageIcon(satURL);
    }
    setOpaque(false);
    _checkBox.setOpaque(false);
    _panel.setOpaque(false);
    
    _panel.setLayout(new FlowLayout(0, 0, 0));
    _panel.add(_checkBox);
    _panel.add(this);
    
    setOpenIcon(_sat);
    setClosedIcon(_sat);
    setLeafIcon(_sat);
  }
  
  public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
  {
    CategoryNode node = (CategoryNode)value;
    
    super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    if (row == 0)
    {
      _checkBox.setVisible(false);
    }
    else
    {
      _checkBox.setVisible(true);
      _checkBox.setSelected(node.isSelected());
    }
    String toolTip = buildToolTip(node);
    _panel.setToolTipText(toolTip);
    if (node.hasFatalChildren()) {
      setForeground(FATAL_CHILDREN);
    }
    if (node.hasFatalRecords()) {
      setForeground(Color.red);
    }
    return _panel;
  }
  
  public Dimension getCheckBoxOffset()
  {
    return new Dimension(0, 0);
  }
  
  protected String buildToolTip(CategoryNode node)
  {
    StringBuffer result = new StringBuffer();
    result.append(node.getTitle()).append(" contains a total of ");
    result.append(node.getTotalNumberOfRecords());
    result.append(" LogRecords.");
    result.append(" Right-click for more info.");
    return result.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryNodeRenderer
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import java.util.LinkedList;
import java.util.StringTokenizer;

public class CategoryPath
{
  protected LinkedList _categoryElements = new LinkedList();
  
  public CategoryPath() {}
  
  public CategoryPath(String category)
  {
    String processedCategory = category;
    if (processedCategory == null) {
      processedCategory = "Debug";
    }
    processedCategory = processedCategory.replace('/', '.');
    processedCategory = processedCategory.replace('\\', '.');
    
    StringTokenizer st = new StringTokenizer(processedCategory, ".");
    while (st.hasMoreTokens())
    {
      String element = st.nextToken();
      addCategoryElement(new CategoryElement(element));
    }
  }
  
  public int size()
  {
    int count = _categoryElements.size();
    
    return count;
  }
  
  public boolean isEmpty()
  {
    boolean empty = false;
    if (_categoryElements.size() == 0) {
      empty = true;
    }
    return empty;
  }
  
  public void removeAllCategoryElements()
  {
    _categoryElements.clear();
  }
  
  public void addCategoryElement(CategoryElement categoryElement)
  {
    _categoryElements.addLast(categoryElement);
  }
  
  public CategoryElement categoryElementAt(int index)
  {
    return (CategoryElement)_categoryElements.get(index);
  }
  
  public String toString()
  {
    StringBuffer out = new StringBuffer(100);
    
    out.append("\n");
    out.append("===========================\n");
    out.append("CategoryPath:                   \n");
    out.append("---------------------------\n");
    
    out.append("\nCategoryPath:\n\t");
    if (size() > 0) {
      for (int i = 0; i < size(); i++)
      {
        out.append(categoryElementAt(i).toString());
        out.append("\n\t");
      }
    } else {
      out.append("<<NONE>>");
    }
    out.append("\n");
    out.append("===========================\n");
    
    return out.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.CategoryPath
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.categoryexplorer;

import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;

public class TreeModelAdapter
  implements TreeModelListener
{
  public void treeNodesChanged(TreeModelEvent e) {}
  
  public void treeNodesInserted(TreeModelEvent e) {}
  
  public void treeNodesRemoved(TreeModelEvent e) {}
  
  public void treeStructureChanged(TreeModelEvent e) {}
}

/* Location:
 * Qualified Name:     org.apache.log4j.lf5.viewer.categoryexplorer.TreeModelAdapter
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.log4j.lf5.viewer.configure;

import java.awt.Color;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.tree.TreePath;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.log4j.lf5.LogLevel;
import org.apache.log4j.lf5.LogLevelFormatException;
import org.apache.log4j.lf5.viewer.LogBrokerMonitor;
import org.apache.log4j.lf5.viewer.LogTable;
import org.apache.log4j.lf5.viewer.LogTableColumn;
import org.apache.log4j.lf5.viewer.LogTableColumnFormatException;
import org.apache.log4j.lf5.viewer.categoryexplorer.CategoryExplorerModel;
import org.apache.log4j.lf5.viewer.categoryexplorer.CategoryExplorerTree;
import org.apache.log4j.lf5.viewer.categoryexplorer.CategoryNode;
import org.apache.log4j.lf5.viewer.categoryexplorer.CategoryPath;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class ConfigurationManager
{
  private static final String CONFIG_FILE_NAME = "lf5_configuration.xml";
  private static final String NAME = "name";
  private static final String PATH = "path";
  private static final String SELECTED = "selected";
  private static final String EXPANDED = "expanded";
  private static final String CATEGORY = "category";
  private static final String FIRST_CATEGORY_NAME = "Categories";
  private static final String LEVEL = "level";
  private static final String COLORLEVEL = "colorlevel";
  private static final String RED = "red";
  private static final String GREEN = "green";
  private static final String BLUE = "blue";
  private static final String COLUMN = "column";
  private static final String NDCTEXTFILTER = "searchtext";
  private LogBrokerMonitor _monitor = null;
  private LogTable _table = null;
  
  public ConfigurationManager(LogBrokerMonitor monitor, LogTable table)
  {
    _monitor = monitor;
    _table = table;
    load();
  }
  
  public void save()
  {
    CategoryExplorerModel model = _monitor.getCategoryExplorerTree().getExplorerModel();
    CategoryNode root = model.getRootCategoryNode();
    
    StringBuffer xml = new StringBuffer(2048);
    openXMLDocument(xml);
    openConfigurationXML(xml);
    processLogRecordFilter(_monitor.getNDCTextFilter(), xml);
    processLogLevels(_monitor.getLogLevelMenuItems(), xml);
    processLogLevelColors(_monitor.getLogLevelMenuItems(), LogLevel.getLogLevelColorMap(), xml);
    
    processLogTableColumns(LogTableColumn.getLogTableColumns(), xml);
    processConfigurationNode(root, xml);
    closeConfigurationXML(xml);
    store(xml.toString());
  }
  
  public void reset()
  {
    deleteConfigurationFile();
    collapseTree();
    selectAllNodes();
  }
  
  public static String treePathToString(TreePath path)
  {
    StringBuffer sb = new StringBuffer();
    CategoryNode n = null;
    Object[] objects = path.getPath();
    for (int i = 1; i < objects.length; i++)
    {
      n = (CategoryNode)objects[i];
      if (i > 1) {
        sb.append(".");
      }
      sb.append(n.getTitle());
    }
    return sb.toString();
  }
  
  protected void load()
  {
    File file = new File(getFilename());
    if (file.exists()) {
      try
      {
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
        Document doc = docBuilder.parse(file);
        processRecordFilter(doc);
        processCategories(doc);
        processLogLevels(doc);
        processLogLevelColors(doc);
        processLogTableColumns(doc);
      }
      catch (Exception e)
      {
        System.err.println("Unable process configuration file at " + getFilename() + ". Error Message=" + e.getMessage());
      }
    }
  }
  
  protected void processRecordFilter(Document doc)
  {
    NodeList nodeList = doc.getElementsByTagName("searchtext");
    
    Node n = nodeList.item(0);
    if (n == null) {
      return;
    }
    NamedNodeMap map = n.getAttributes();
    String text = getValue(map, "name");
    if ((text == null) || (text.equals(""))) {
      return;
    }
    _monitor.setNDCLogRecordFilter(text);
  }
  
  protected void processCategories(Document doc)
  {
    CategoryExplorerTree tree = _monitor.getCategoryExplorerTree();
    CategoryExplorerModel model = tree.getExplorerModel();
    NodeList nodeList = doc.getElementsByTagName("category");
    
    NamedNodeMap map = nodeList.item(0).getAttributes();
    int j = getValue(map, "name").equalsIgnoreCase("Categories") ? 1 : 0;
    for (int i = nodeList.getLength() - 1; i >= j; i--)
    {
      Node n = nodeList.item(i);
      map = n.getAttributes();
      CategoryNode chnode = model.addCategory(new CategoryPath(getValue(map, "path")));
      chnode.setSelected(getValue(map, "selected").equalsIgnoreCase("true"));
      if (getValue(map, "expanded").equalsIgnoreCase("true")) {}
      tree.expandPath(model.getTreePathToRoot(chnode));
    }
  }
  
  protected void processLogLevels(Document doc)
  {
    NodeList nodeList = doc.getElementsByTagName("level");
    Map menuItems = _monitor.getLogLevelMenuItems();
    for (int i = 0; i < nodeList.getLength(); i++)
    {
      Node n = nodeList.item(i);
      NamedNodeMap map = n.getAttributes();
      String name = getValue(map, "name");
      try
      {
        JCheckBoxMenuItem item = (JCheckBoxMenuItem)menuItems.get(LogLevel.valueOf(name));
        
        item.setSelected(getValue(map, "selected").equalsIgnoreCase("true"));
      }
      catch (LogLevelFormatException e) {}
    }
  }
  
  protected void processLogLevelColors(Document doc)
  {
    NodeList nodeList = doc.getElementsByTagName("colorlevel");
    LogLevel.getLogLevelColorMap();
    for (int i = 0; i < nodeList.getLength(); i++)
    {
      Node n = nodeList.item(i);
      if (n == null) {
        return;
      }
      NamedNodeMap map = n.getAttributes();
      String name = getValue(map, "name");
      try
      {
        LogLevel level = LogLevel.valueOf(name);
        int red = Integer.parseInt(getValue(map, "red"));
        int green = Integer.parseInt(getValue(map, "green"));
        int blue = Integer.parseInt(getValue(map, "blue"));
        Color c = new Color(red, green, blue);
        if (level != null) {
          level.setLogLevelColorMap(level, c);
        }
      }
      catch (LogLevelFormatException e) {}
    }
  }
  
  protected void processLogTableColumns(Document doc)
  {
    NodeList nodeList = doc.getElementsByTagName("column");
    Map menuItems = _monitor.getLogTableColumnMenuItems();
    List selectedColumns = new ArrayList();
    for (int i = 0; i < nodeList.getLength(); i++)
    {
      Node n = nodeList.item(i);
      if (n == null) {
        return;
      }
      NamedNodeMap map = n.getAttributes();
      String name = getValue(map, "name");
      try
      {
        LogTableColumn column = LogTableColumn.valueOf(name);
        JCheckBoxMenuItem item = (JCheckBoxMenuItem)menuItems.get(column);
        
        item.setSelected(getValue(map, "selected").equalsIgnoreCase("true"));
        if (item.isSelected()) {
          selectedColumns.add(column);
        }
      }
      catch (LogTableColumnFormatException e) {}
      if (selectedColumns.isEmpty()) {
        _table.setDetailedView();
      } else {
        _table.setView(selectedColumns);
      }
    }
  }
  
  protected String getValue(NamedNodeMap map, String attr)
  {
    Node n = map.getNamedItem(attr);
    return n.getNodeValue();
  }
  
  protected void collapseTree()
  {
    CategoryExplorerTree tree = _monitor.getCategoryExplorerTree();
    for (int i = tree.getRowCount() - 1; i > 0; i--) {
      tree.collapseRow(i);
    }
  }
  
  protected void selectAllNodes()
  {
    CategoryExplorerModel model = _monitor.getCategoryExplorerTree().getExplorerModel();
    CategoryNode root = model.getRootCategoryNode();
    Enumeration all = root.breadthFirstEnumeration();
    CategoryNode n = null;
    while (all.hasMoreElements())
    {
      n = (CategoryNode)all.nextElement();
      n.setSelected(true);
    }
  }
  
  protected void store(String s)
  {
    try
    {
      PrintWriter writer = new PrintWriter(new FileWriter(getFilename()));
      writer.print(s);
      writer.close();
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
  }
  
  protected void deleteConfigurationFile()
  {
    try
    {
      File f = new File(getFilename());
      if (f.exists()) {
        f.delete();
      }
    }
    catch (SecurityException e)
    {
      System.err.println("Cannot delete " + getFilename() + " because a security violation occured.");
    }
  }
  
  protected String getFilename()
  {
    String home = System.getProperty("user.home");
    String sep = System.getProperty("file.separator");
    
    return home + sep + "lf5" + sep + "lf5_configuration.xml";
  }
  
  private void processConfigurationNode(CategoryNode node, StringBuffer xml)
  {
    CategoryExplorerModel model = _monitor.getCategoryExplorerTree().getExplorerModel();
    
    Enumeration all = node.breadthFirstEnumeration();
    CategoryNode n = null;
    while (all.hasMoreElements())
    {
      n = (CategoryNode)all.nextElement();
      exportXMLElement(n, model.getTreePathToRoot(n), xml);
    }
  }
  
  private void processLogLevels(Map logLevelMenuItems, StringBuffer xml)
  {
    xml.append("\t<loglevels>\r\n");
    Iterator it = logLevelMenuItems.keySet().iterator();
    while (it.hasNext())
    {
      LogLevel level = (LogLevel)it.next();
      JCheckBoxMenuItem item = (JCheckBoxMenuItem)logLevelMenuItems.get(level);
      exportLogLevelXMLElement(level.getLabel(), item.isSelected(), xml);
    }
    xml.append("\t</loglevels>\r\n");
  }
  
  private void processLogLevelColors(Map logLevelMenuItems, Map logLevelColors, StringBuffer xml)
  {
    xml.append("\t<loglevelcolors>\r\n");
    
    Iterator it = logLevelMenuItems.keySet().iterator();
    while (it.hasNext())
    {
      LogLevel level = (LogLevel)it.next();
      
      Color color = (Color)logLevelColors.get(level);
      exportLogLevelColorXMLElement(level.getLabel(), color, xml);
    }
    xml.append("\t</loglevelcolors>\r\n");
  }
  
  private void processLogTableColumns(List logTableColumnMenuItems, StringBuffer xml)
  {
    xml.append("\t<logtablecolumns>\r\n");
    Iterator it = logTableColumnMenuItems.iterator();
    while (it.hasNext())
    {
      LogTableColumn column = (LogTableColumn)it.next();
      JCheckBoxMenuItem item = _monitor.getTableColumnMenuItem(column);
      exportLogTableColumnXMLElement(column.getLabel(), item.isSelected(), xml);
    }
    xml.append("\t</logtablecolumns>\r\n");
  }
  
  private void processLogRecordFilter(String text, StringBuffer xml)
  {
    xml.append("\t<").append("searchtext").append(" ");
    xml.append("name").append("=\"").append(text).append("\"");
    xml.append("/>\r\n");
  }
  
  private void openXMLDocument(StringBuffer xml)
  {
    xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n");
  }
  
  private void openConfigurationXML(StringBuffer xml)
  {
    xml.append("<configuration>\r\n");
  }
  
  private void closeConfigurationXML(StringBuffer xml)
  {
    xml.append("</configuration>\r\n");
  }
  
  private void exportXMLElement(CategoryNode node, TreePath path, StringBuffer xml)
  {
    CategoryExplorerTree tree = _monitor.getCategoryExplorerTree();
    
    xml.append("\t<").append("category").append(" ");
    xml.append("name").append("=\"").append(node.getTitle()).append("\" ");
    xml.append("path").append("=\"").append(treePathToString(path)).append("\" ");
    xml.append("expanded").append("=\"").append(tree.isExpanded(path)).append("\" ");
    xml.append("selected").append("=\"").append(node.isSelected()).append("\"/>\r\n");
  }
  
  private void exportLogLevelXMLElement(String label, boolean selected, StringBuffer xml)
  {
    xml.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd