contenttreenode.java

来自「用Swing实现的CHM制作工具」· Java 代码 · 共 65 行

JAVA
65
字号
package g2w.app.gchm.gui;

import javax.swing.tree.DefaultMutableTreeNode;

import org.jdom.Document;

/**
 * A customized tree node used in tree component ContentTree.
 * The node uses an instance of ContentElement as its user object,
 * the user object also decides which icons of the node.
 * 
 * @author GreatGhoul
 * @version 017 2009-3-20 14:53:56
 */
public class ContentTreeNode extends DefaultMutableTreeNode {
	
	/**
	 * Construct a tree node with a xml element.
	 * 
	 * @param element The element.
	 */
	public ContentTreeNode(ContentElement element)  {
		super(element);
	}
	
	/**
	 * Return the user object.
	 * 
	 * @return The bound ContentElement.
	 */
	public ContentElement getUserObject() {
		return (ContentElement) super.getUserObject();
	}
	
	/**
	 * Remove self from the parent node. 
	 * It dose the same thing in the xml document.
	 */
	public void removeFromparent() {
		getUserObject().removeFromParent();
		super.removeFromParent();
	}

	/**
	 * Create a new tree node with the name "新标题";
	 * 
	 * @return A new topic node.
	 */
	public static ContentTreeNode createNewTopicNode() {
		return new ContentTreeNode(ContentElement.createNewTopic());
	}

	/**
	 * Create a root node using the given document.
	 * 
	 * @param document The given project document.
	 * @return The root node.
	 */
	public static ContentTreeNode createRoot(Document document) {
		return new ContentTreeNode(ContentElement.createRoot(document));
	}
}


⌨️ 快捷键说明

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