KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > treetable > FileNode


1 /*
2  * $Id: FileNode.java,v 1.1.1.1 2004/06/16 01:43:39 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.swing.treetable;
9
10 import java.io.File JavaDoc;
11 import java.util.List JavaDoc;
12 import java.util.Vector JavaDoc;
13
14 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
15
16 /**
17  * FileNode
18  *
19  * @author Ramesh Gupta
20  */

21 public class FileNode extends DefaultMutableTreeNode JavaDoc {
22     public FileNode(File JavaDoc file) {
23     this.file = file;
24     this.isDir = file.isDirectory();
25     }
26
27     /* @todo Add userObject support
28        public FileNode(Object userObject) {
29        ...
30        }
31
32        public FileNode(Object userObject, boolean allowsChildren) {
33        ...
34        }
35     */

36
37     public boolean getAllowsChildren() {
38     return isDir;
39     }
40
41     protected List JavaDoc getChildren() { // rg:changed return type
42
if (children == null) {
43         try {
44         final String JavaDoc[] files = file.list();
45         if (files != null) {
46             // Create an empty list of FileNodes (#elements = files.length)
47
children = new Vector JavaDoc(files.length);
48             final String JavaDoc path = file.getPath();
49             for (int i = 0; i < files.length; i++) {
50             final File JavaDoc childFile = new File JavaDoc(path, files[i]);
51             children.add(new FileNode(childFile));
52             }
53         }
54         }
55         catch (SecurityException JavaDoc se) {
56         }
57     }
58
59     return children;
60     }
61
62     public File JavaDoc getFile() {
63     return file;
64     }
65
66     public boolean isLeaf() {
67     return !isDir;
68     }
69
70     public String JavaDoc toString() {
71     return file.getName();
72     }
73
74     private final File JavaDoc file;
75     private final boolean isDir;
76 }
77
Popular Tags