View Javadoc

1   /*
2    *  XNap Commons
3    *
4    *  Copyright (C) 2005  Felix Berger
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License, or (at your option) any later version.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package org.xnap.commons.gui.tree;
21  
22  import java.io.File;
23  
24  public class FileNode extends File 
25  {
26  
27      boolean fullPath;
28      String label;
29  
30      public FileNode(File f, boolean fullPath, String label)
31      {
32  		super(f, "");
33  		this.fullPath = fullPath;
34  		this.label = (label == null) ? "" : label;
35      }
36  
37      public FileNode(File f, boolean fullPath)
38      {
39  		this(f, fullPath, "");
40      }
41  
42      public FileNode(File f)
43      {
44  		this(f, false, "");
45      }
46  
47      @Override
48      public boolean equals(Object obj)
49      {
50  		if (obj instanceof FileNode) {
51  			FileNode f = (FileNode)obj;
52  			return super.equals(obj) && label.equals(f.label);
53  		}
54  		else {
55  			return super.equals(obj);
56  		}
57      }
58      
59      @Override
60      public int hashCode()
61      {
62      	return label.hashCode() + 31 * super.hashCode();
63      }
64      
65      public String getLabel()
66      {
67  		return label;
68      }
69      
70      public String toString()
71      {
72  		if (fullPath) {
73  			return getPath() + label;
74  		}
75  		else {
76  			return getName() + label;
77  		}
78      }
79  }