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.table;
21  
22  import java.util.Iterator;
23  
24  import javax.swing.table.DefaultTableCellRenderer;
25  
26  import org.apache.log4j.Logger;
27  import org.xnap.gui.util.GUIHelper;
28  import org.xnap.search.SearchResult;
29  import org.xnap.util.StringHelper;
30  
31  public class SearchResultCellRenderer extends DefaultTableCellRenderer
32  {
33  	//--- Constant(s) ---
34  	
35  	//--- Data field(s) ---
36  	
37      private static Logger logger = Logger.getLogger(SearchResultCellRenderer.class);
38  	
39  	//--- Constructor(s) ---
40  	
41      public SearchResultCellRenderer()
42  	{
43  		
44  	}
45  
46      //--- Method(s) ---
47  	
48  	public void setValue(Object value)
49  	{
50  		if (value instanceof SearchResult) {
51  			SearchResult sr = (SearchResult)value;
52  			Iterator it = sr.keys();
53  			if (it != null) {
54  				StringBuffer sb = new StringBuffer("<html><table>");
55  				while (it.hasNext()) {
56  					String key = (String)it.next();
57  					sb.append(GUIHelper.tableRow(key, sr.get(key) + ""));
58  				}
59  				sb.append("</table></html>");
60  				setToolTipText(sb.toString());
61  				String[] path = sr.getPath();
62  				super.setValue((path != null) ? StringHelper.toString(path, "/")
63  							   : null);
64  			}
65  		}
66  	}
67  }