View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.gui.tree;
21  
22  import javax.swing.tree.DefaultMutableTreeNode;
23  import javax.swing.tree.TreeNode;
24  
25  /***
26   * Node used by the {@link xnap.gui.SearchResultTreePanel}.
27   */
28  public class SearchPathNode extends DefaultMutableTreeNode
29  {
30  
31      // --- Data Field(s) ---
32  
33      protected int resultCount = 0;
34  
35      // --- Constructor(s) ---
36  
37      public SearchPathNode(String name)
38      {
39  	super(name);
40      }
41  
42      // --- Method(s) ---
43  
44      public String getName()
45      {
46  	return getUserObject().toString();
47      }
48  
49      public String[] getSearchPath()
50      {
51  	TreeNode[] pathToRoot = getPath();
52  
53  	if (pathToRoot.length > 1) {
54  	    String[] path = new String[pathToRoot.length - 1];
55  	    for (int i = 0; i < pathToRoot.length - 1; i++) {
56  		path[i] = ((SearchPathNode)pathToRoot[i + 1]).getName();
57  	    }
58  	    return path;
59  	}
60  	else {
61  	    return null;
62  	}
63      }
64  
65      public void incResultCount()
66      {
67  	resultCount++;
68      }
69  
70      public String toString()
71      {
72  	StringBuffer sb = new StringBuffer();
73  	sb.append(getUserObject().toString());
74  	if (resultCount > 0) {
75  	    sb.append(" (");
76  	    sb.append(resultCount);
77  	    sb.append(")");
78  	}
79  	return sb.toString();
80      }
81  
82  }