|
What this is
Other links
The source code/* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software * License version 1.1, a copy of which has been included with this * distribution in the LICENSE.txt file. */ package org.apache.log4j.lf5.viewer.categoryexplorer; import org.apache.log4j.lf5.LogRecord; import javax.swing.*; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Enumeration; /** * CategoryExplorerModel * * @author Michael J. Sikorsky * @author Robert Shaw * @author Brent Sprecher * @author Richard Hurst */ // Contributed by ThoughtWorks Inc. public class CategoryExplorerModel extends DefaultTreeModel { //-------------------------------------------------------------------------- // Constants: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Protected Variables: //-------------------------------------------------------------------------- protected boolean _renderFatal = true; protected ActionListener _listener = null; protected ActionEvent _event = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Nodes Selection changed"); //-------------------------------------------------------------------------- // Private Variables: //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // Constructors: //-------------------------------------------------------------------------- public CategoryExplorerModel(CategoryNode node) { super(node); } //-------------------------------------------------------------------------- // Public Methods: //-------------------------------------------------------------------------- public void addLogRecord(LogRecord lr) { CategoryPath path = new CategoryPath(lr.getCategory()); addCategory(path); // create category path if it is new CategoryNode node = getCategoryNode(path); node.addRecord(); // update category node if (_renderFatal && lr.isFatal()) { TreeNode[] nodes = getPathToRoot(node); int len = nodes.length; CategoryNode parent; // i = 0 gives root node // skip node and root, loop through "parents" in between for (int i = 1; i < len - 1; i++) { parent = (CategoryNode) nodes[i]; parent.setHasFatalChildren(true); nodeChanged(parent); } node.setHasFatalRecords(true); nodeChanged(node); } } public CategoryNode getRootCategoryNode() { return (CategoryNode) getRoot(); } public CategoryNode getCategoryNode(String category) { CategoryPath path = new CategoryPath(category); return (getCategoryNode(path)); } /** * returns null if no CategoryNode exists. */ public CategoryNode getCategoryNode(CategoryPath path) { CategoryNode root = (CategoryNode) getRoot(); CategoryNode parent = root; // Start condition. for (int i = 0; i < path.size(); i++) { CategoryElement element = path.categoryElementAt(i); // If the two nodes have matching titles they are considered equal. Enumeration children = parent.children(); boolean categoryAlreadyExists = false; while (children.hasMoreElements()) { CategoryNode node = (CategoryNode) children.nextElement(); String title = node.getTitle().toLowerCase(); String pathLC = element.getTitle().toLowerCase(); if (title.equals(pathLC)) { categoryAlreadyExists = true; // This is now the new parent node. parent = node; break; // out of the while, and back to the for(). } } if (categoryAlreadyExists == false) { return null; // Didn't find the Node. } } return (parent); } /** * @return true if all the nodes in the specified CategoryPath are * selected. */ public boolean isCategoryPathActive(CategoryPath path) { CategoryNode root = (CategoryNode) getRoot(); CategoryNode parent = root; // Start condition. boolean active = false; for (int i = 0; i < path.size(); i++) { CategoryElement element = path.categoryElementAt(i); // If the two nodes have matching titles they are considered equal. Enumeration children = parent.children(); boolean categoryAlreadyExists = false; active = false; while (children.hasMoreElements()) { CategoryNode node = (CategoryNode) children.nextElement(); String title = node.getTitle().toLowerCase(); String pathLC = element.getTitle().toLowerCase(); if (title.equals(pathLC)) { categoryAlreadyExists = true; // This is now the new parent node. parent = node; if (parent.isSelected()) { active = true; } break; // out of the while, and back to the for(). } } if (active == false || categoryAlreadyExists == false) { return false; } } return (active); } /** * |
... this post is sponsored by my books ... | |
![]() #1 New Release! |
![]() FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.