01: package org.acm.seguin.pmd.swingui;
02:
03: import javax.swing.tree.DefaultMutableTreeNode;
04: import java.io.File;
05:
06: /**
07: *
08: * @author Donald A. Leckie
09: * @since August 17, 2002
10: * @version $Revision: 1.1 $, $Date: 2003/07/29 20:51:59 $
11: */
12: class DirectoryTreeNode extends DefaultMutableTreeNode {
13:
14: /**
15: ******************************************************************************
16: */
17: private DirectoryTreeNode(String name) {
18: super (name);
19: }
20:
21: /**
22: ******************************************************************************
23: *
24: * @param directory
25: */
26: protected DirectoryTreeNode(File directory) {
27: super (directory);
28: }
29:
30: /**
31: ******************************************************************************
32: *
33: * @return The directory or file name.
34: */
35: public String toString() {
36: Object userObject = getUserObject();
37:
38: if (userObject instanceof String) {
39: return (String) userObject;
40: }
41:
42: File file = ((File) userObject);
43: String name = file.getName();
44:
45: if ((name != null) && (name.length() > 0)) {
46: return name;
47: }
48:
49: return file.getPath();
50: }
51:
52: /**
53: ******************************************************************************
54: *
55: * @return A new root node.
56: */
57: protected static DirectoryTreeNode createRootNode(String rootName) {
58: return new DirectoryTreeNode(rootName);
59: }
60: }
|