View Javadoc

1   /*
2    * $Id: ResultCellRenderer.java,v 1.3 2006/03/27 22:43:59 edankert Exp $
3    *
4    * The contents of this file are subject to the Mozilla Public License 
5    * Version 1.1 (the "License"); you may not use this file except in 
6    * compliance with the License. You may obtain a copy of the License at 
7    * http://www.mozilla.org/MPL/ 
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis, 
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
11   * for the specific language governing rights and limitations under the License.
12   *
13   * The Original Code is XML Hammer code. (org.xmlhammer.*)
14   *
15   * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
16   * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
17   * All Rights Reserved.
18   *
19   * Contributor(s): Edwin Dankert <edankert@gmail.com>
20   */
21  package org.xmlhammer.gui.output;
22  
23  import java.awt.Component;
24  
25  import javax.swing.JLabel;
26  import javax.swing.JTree;
27  import javax.swing.tree.DefaultTreeCellRenderer;
28  
29  /***
30   * The cell renderer for the result nodes.
31   *
32   * @version	$Revision: 1.3 $, $Date: 2006/03/27 22:43:59 $
33   * @author Edwin Dankert <edankert@gmail.com>
34   */
35  public class ResultCellRenderer extends DefaultTreeCellRenderer {
36  	private static final long serialVersionUID = 5916506993949258784L;
37  
38  	private ResultNode result = null;
39  	
40  	/***
41  	  * Configures the renderer based on the passed in components.
42  	  * The value is set from messaging the tree with
43  	  * <code>convertValueToText</code>, which ultimately invokes
44  	  * <code>toString</code> on <code>value</code>.
45  	  * The foreground color is set based on the selection and the icon
46  	  * is set based on on leaf and expanded.
47  	  */
48  	public Component getTreeCellRendererComponent( JTree tree, Object value,
49  						  boolean selected, boolean expanded, boolean leaf, 
50  						  int row,  boolean focus) {
51  		JLabel label = (JLabel)super.getTreeCellRendererComponent( tree, value, selected, expanded, leaf, row, focus);
52  		
53  		if ( value instanceof ResultNode) {
54  			result = (ResultNode)value;
55  			
56  			label.setText( result.getValue());
57  			label.setToolTipText( result.getDescription());
58  			label.setIcon( result.getIcon());
59  		}  else {
60  			label.setText( "Root");
61  		}
62  
63  //		if ( selected) {
64  //		    setForeground( UIManager.getColor("Tree.selectionForeground"));
65  //		    setBackground( UIManager.getColor("Tree.selectionBackground"));
66  //		} else  {
67  //		    setForeground( tree.getForeground());
68  //		    setBackground( tree.getBackground());
69  //		}
70  //
71  //	    setComponentOrientation( tree.getComponentOrientation());
72  //		setEnabled( tree.isEnabled());
73  //		setFont( tree.getFont());
74  
75  		return label;
76  	}
77  	
78  //	public Icon getIcon() {
79  //		return result != null ? result.getIcon() : null;
80  //	}
81  //	
82  //	public String getName() {
83  //		return result != null ? result.getName() : null;
84  //	}
85  //
86  //	public String getValue() {
87  //		return result != null ? result.getValue() : null;
88  //	}
89  //
90  //	public boolean isSelected() {
91  //		return selected;
92  //	}
93  }