View Javadoc

1   /*
2    * $Id: SimpleCellRenderer.java,v 1.3 2006/03/27 22:43:21 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.preferences;
22  
23  import java.awt.Component;
24  
25  import javax.swing.JLabel;
26  import javax.swing.JTree;
27  import javax.swing.border.Border;
28  import javax.swing.border.EmptyBorder;
29  import javax.swing.tree.DefaultTreeCellRenderer;
30  
31  /***
32   * The cell renderer for a XmlElementNode.
33   *
34   * @version	$Revision: 1.3 $, $Date: 2006/03/27 22:43:21 $
35   * @author Edwin Dankert <edankert@gmail.com>
36   */
37  public class SimpleCellRenderer extends DefaultTreeCellRenderer {
38  	private static final long serialVersionUID = -1320645592895770122L;
39  
40      private static final Border BORDER = new EmptyBorder( 0, 2, 0, 0);
41  	
42  	/***
43  	  * Configures the renderer based on the passed in components.
44  	  * The value is set from messaging the tree with
45  	  * <code>convertValueToText</code>, which ultimately invokes
46  	  * <code>toString</code> on <code>value</code>.
47  	  * The foreground color is set based on the selection and the icon
48  	  * is set based on on leaf and expanded.
49  	  */
50  	public Component getTreeCellRendererComponent( JTree tree, Object value,
51  						  boolean selected, boolean expanded, boolean leaf, 
52  						  int row,  boolean focus) {
53  		JLabel label = (JLabel)super.getTreeCellRendererComponent( tree, value, selected, expanded, leaf, row, focus);
54  		
55  		label.setIcon( null);
56  		label.setBorder( BORDER);
57  //		label.setText( value.toString());
58  		
59  		return label;
60  	}
61  }