📄 dynamictreenode.java
字号:
/* * File: DynamicTreeNode.java * Project: MPI Linguistic Application * Date: 02 May 2007 * * Copyright (C) 2001-2007 Max Planck Institute for Psycholinguistics * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */package mpi.eudico.server.corpora.clom;import java.util.Iterator;import java.util.Vector;import javax.swing.tree.DefaultMutableTreeNode;/** * A Node to be used in a JTree that loads its contents dynamicaly. This has * the advantage that the nodes only will be added to the JTree when they are * needed. If the EUDICO data tree would be loaded staticaly we would have to * add all the Transcriptions from all the (Sub)Corpora to the Tree before * showing it to the user. * * @author Hennie Brugman * @author Albert Russel * @version 06-Mai-1998 * @version Aug 2005 Identity removed */public class DynamicTreeNode extends DefaultMutableTreeNode { /** The Object that is the content of this TreeNode. */ private TreeViewable nodeObject; /** * A flag that indicates whether this nodes child nodes are loaded. Since * this is a DynamicTreeNode the default value is false. */ private boolean childrenLoaded; /** * Creates a DynamicTreeNode with theNodeObject as its content and * depending on Identity zero or more available child nodes. When a user * has for example no acces to Transcription X in a certain Corpus Y that * Transcription X will not be returned if that user askes for the child * nodes that belong to Corpus Y. * * @param theNodeObject The Object that becomes the content of this node. * Not Nullable. * * @throws RuntimeException DOCUMENT ME! */ public DynamicTreeNode(TreeViewable theNodeObject) { super(theNodeObject); if (theNodeObject == null) { throw new RuntimeException( "DynamicTreeNode: given NodeObject is null"); } nodeObject = theNodeObject; childrenLoaded = false; } /** * Returns the String with which the node Object is visible in the JTree. * * @return DOCUMENT ME! */ public String toString() { return nodeObject.getNodeName(); } /** * Returns false if this node has children, otherwise true. * * @return DOCUMENT ME! */ public boolean isTreeViewableLeaf() { return nodeObject.isTreeViewableLeaf(); } /** * Is called when the tree wants to know how many children a node has. * therefore this is the moment to load a nodes children if they where not * already loaded. * * @return DOCUMENT ME! */ public int getChildCount() { if (!childrenLoaded) { loadChildren(); } return super.getChildCount(); } /** * Loads all the child nodes from this DynamicTreeNode that are available * for identity and inserts them into the JTree. * <pre> * Precondition: none of the children of the node is NULL * (Errorcase) for each child of the node that is NULL: skip and log. * </pre> */ private void loadChildren() { int i = 0; DynamicTreeNode newNode; Vector children = nodeObject.getChildren(); Iterator iter = children.iterator(); while (iter.hasNext()) { TreeViewable node = (TreeViewable) iter.next(); if (node == null) { System.err.println( "DynamicTreeNode: skipping a NULL Node child."); } else { newNode = new DynamicTreeNode(node); insert(newNode, i++); } } childrenLoaded = true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -