explorertreemodel.java
来自「JavaExplorer是一个独立于平台的浏览器」· Java 代码 · 共 124 行
JAVA
124 行
/** * 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 ExplorerTreeModel extends DefaultTreeModel { /** * Constructor for the FileTreeModel object * *@param root Description of Parameter */ public ExplorerTreeModel(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 ExplorerTreeModel(TreeNode root, boolean asksAllowsChildren) { super(root, asksAllowsChildren); } /** * Gets the PathToRelativeRoot attribute * of the ExplorerTreeModel object * *@param aNode Description of Parameter *@param depth Description of Parameter *@param aRoot Description of Parameter *@return The PathToRelativeRoot * value */ protected TreeNode[] getPathToRelativeRoot(TreeNode aNode, int depth, TreeNode aRoot) { //Cette fois ci, on regarde toutes les racines des arbres //sauf l'explorer 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. if (aNode == null) { return null; } else { depth++; if (aNode.equals(aRoot)) { retNodes = new TreeNode[depth]; } else { retNodes = getPathToRelativeRoot(aNode.getParent(), depth, aRoot); } if (retNodes == null) { return null; } retNodes[retNodes.length - depth] = aNode; } return retNodes; } /** * Gets the pathToRoot attribute of the * ExplorerTreeModel object * *@param aNode Description of the Parameter *@param depth Description of the Parameter *@return The pathToRoot value */ protected TreeNode[] getPathToRoot(TreeNode aNode, int depth) { //Cette fois ci, on regarde toutes les racines des arbres //sauf l'explorer java.util.Enumeration enum = root.children(); TreeNode[] retNodes = null; TreeNode[] tmpNodes = null; while (enum.hasMoreElements() && (tmpNodes == null)) { tmpNodes = getPathToRelativeRoot(aNode, depth, (TreeNode) enum.nextElement()); } if (tmpNodes != null) { retNodes = new TreeNode[tmpNodes.length + 1]; retNodes[0] = root; for (int i = 0; i < tmpNodes.length; i++) { retNodes[i + 1] = tmpNodes[i]; } } return retNodes; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?