⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 genericmenuloader.java

📁 一个实用工具类
💻 JAVA
字号:
/* * Copyright (C) butor.com. All rights reserved. * * This software is published under the terms of the GNU Library General * Public License (GNU LGPL), a copy of which has been included with this * distribution in the LICENSE.txt file.  */package org.butor.web.menu;import java.util.ArrayList;import java.util.Collection;import org.butor.log.Log;/** * This class is used to build any item hierarchy such as an menu hierarchy.  * * @author Nguyen The Hung */public abstract class GenericMenuLoader {	/** 	 * Top node (dummy node, i.e. placeholder for all children nodes).	 */	private Branch f_topNode;	/**	 * List of nodes as read from the config file.	 */	private ArrayList f_listOfNodes;			/**	 * Constructor for GenericMenuLoader.	 */	public GenericMenuLoader() {				super();		f_topNode = new Branch("", "");		f_listOfNodes = new ArrayList();	}		/**	 * Clear the list of nodes.	 */	protected void clear() {				Log.logStr(Log.LOG_LEVEL_LOW, this, Log.LOG_TYPE_INFO, "clear()", "");				f_listOfNodes.clear();	}		/**	 * Add a node to the list.	 * @param node org.butor.wak.menu.Branch	 */	protected void add(Branch node) {				if (node == null) {			Log.logStr(this, Log.LOG_TYPE_ERROR, "add()", "Cannot add node [null].");			return;		}				Log.logStr(Log.LOG_LEVEL_LOW, this, Log.LOG_TYPE_INFO, "add()", "Branch = [" + node.toString() + "].");				f_listOfNodes.add(node);	}		/**	 * Remove a node.	 * @param node org.butor.wak.menu.Branch	 * @return boolean 	 */	protected boolean remove(Branch node) {		if (node == null) {			Log.logStr(this, Log.LOG_TYPE_ERROR, "remove()", "Cannot remove node [null].");			return false;		}				return remove(node.getName());	}		/**	 * Remove a node.	 * @param name java.lang.String	 * @return boolean	 */	protected boolean remove(String name) {				if (name == null) {			Log.logStr(this, Log.LOG_TYPE_ERROR, "remove()", "Cannot remove node. Name = [null].");			return false;		}				Log.logStr(Log.LOG_LEVEL_LOW, this, Log.LOG_TYPE_INFO, "remove()", name);				for (int i = 0; i < f_listOfNodes.size(); i++) {			if (name.equals(((Branch) f_listOfNodes.get(i)).getName())) {				f_listOfNodes.remove(i);				return true;			}		}				Log.logStr(Log.LOG_LEVEL_LOW, this, Log.LOG_TYPE_INFO, "remove()", name + " not found.");				return false;	}		/**	 * It is up to the sub-class implementation to decide whether the node	 * should be displayed.	 */	protected abstract boolean shouldDisplayNode(IBranch node);	/**	 * Recursively build the node hierarchy expanding downward.	 * @param topNode org.butor.wak.menu.Branch	 * @param list java.util.ArrayList	 */	private void buildHierarchy(Branch topNode, ArrayList list) {				Log.logStr(Log.LOG_LEVEL_LOW, this, Log.LOG_TYPE_INFO, "buildHierarchy()", "");				// Find all the nodes that contain the parent name = top node name		String topNodeName = topNode.getName();		for (int i = 0; i < list.size(); i++) {			Branch node = (Branch) list.get(i);			String nodeName = node.getName();						// if node without name then bypass			if (nodeName != null && !nodeName.equals("")) {				String parentName = node.getParentName();								if (parentName == null) {					parentName = ""; // default to top-level				}				if (parentName.equals(topNodeName)) {					// Note: if the node is not displayed then all the children will not					// be displayed as well.					if (shouldDisplayNode(node)) {						topNode.addBranch(node);						buildHierarchy(node, list);					}				}			}		}	}		/**	 * Build the hierarchy	 */	protected void build() {				f_topNode.removeAllChildren();		buildHierarchy(f_topNode, f_listOfNodes);	}		/**	 * Return the list of hierarchy nodes.	 * @return java.util.Collection	 */	public Collection getHierarchy() {		return f_topNode.getChildren();	}	/**	 * Return the list of nodes.	 * @return java.util.Collection	 */	public Collection getList() {		return f_listOfNodes;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -