extendedtreemodel.java
来自「JavaExplorer是一个独立于平台的浏览器」· Java 代码 · 共 92 行
JAVA
92 行
/** * File and FTP Explorer * Copyright 2002 * BOESCH Vincent * * 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 javaexplorer.gui.treenode;import javax.swing.tree.*;import javax.swing.tree.DefaultTreeModel;public class ExtendedTreeModel extends DefaultTreeModel { /** * Constructor for the FileTreeModel object * *@param root Description of Parameter */ public ExtendedTreeModel(TreeNode root) { this(root, false); } /** * Creates a tree specifying whether any * node can have children, or whether * only certain nodes can have children. * *@param root a TreeNode * object that is the root of the * tree *@param asksAllowsChildren Description * of Parameter *@see #asksAllowsChildren */ public ExtendedTreeModel(TreeNode root, boolean asksAllowsChildren) { super(root, asksAllowsChildren); } /** * Gets the PathToRoot attribute of the * FileTreeModel object * *@param aNode Description of Parameter *@param depth Description of Parameter *@return The PathToRoot value */ protected TreeNode[] getPathToRoot(TreeNode aNode, int depth) { TreeNode[] retNodes; // This method recurses, traversing towards the root in order // size the array. On the way back, it fills in the nodes, // starting from the root and working back to the original node. /* Check for null, in case someone passed in a null node, or they passed in an element that isn't rooted at root. */ if (aNode == null) { return null; } else { depth++; if (aNode.equals(root)) { retNodes = new TreeNode[depth]; } else { retNodes = getPathToRoot(aNode.getParent(), depth); } if (retNodes == null) { return null; } retNodes[retNodes.length - depth] = aNode; } return retNodes; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?