KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sshtools > ui > swing > BooleanIconRenderer


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
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
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20
21 package com.sshtools.ui.swing;
22
23 import java.awt.Component JavaDoc;
24 import javax.swing.Icon JavaDoc;
25 import javax.swing.JLabel JavaDoc;
26 import javax.swing.JTable JavaDoc;
27 import javax.swing.table.DefaultTableCellRenderer JavaDoc;
28
29 /**
30  * Extension of Swing {@link DefaultTableCellRenderer}that renders <code>Boolean</code>
31  * values as one of two icons.
32  *
33  * @author $Author: james $
34  */

35
36 public class BooleanIconRenderer
37     extends DefaultTableCellRenderer JavaDoc {
38
39   // Private instance variables
40

41   private Icon JavaDoc trueIcon;
42
43   private Icon JavaDoc falseIcon;
44
45   /**
46    * Construct a new BooleanIconRenderer.
47    *
48    * @param trueIcon icon for <code>Boolean.TRUE</code> values
49    * @param falseIcon icons for <code>Boolean.FALSE</code> vlaues
50    */

51
52   public BooleanIconRenderer(Icon JavaDoc trueIcon, Icon JavaDoc falseIcon) {
53
54     this.trueIcon = trueIcon;
55
56     this.falseIcon = falseIcon;
57
58     setHorizontalAlignment(JLabel.CENTER);
59
60   }
61
62   /*
63    * (non-Javadoc)
64    *
65    * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
66    * java.lang.Object, boolean, boolean, int, int)
67    */

68
69   public Component JavaDoc getTableCellRendererComponent(JTable JavaDoc table, Object JavaDoc value,
70
71                                                  boolean isSelected,
72                                                  boolean hasFocus, int row,
73                                                  int column) {
74
75     super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
76
77                                         row, column);
78
79     setText(null);
80
81     setIcon( ( (Boolean JavaDoc) value).booleanValue() ? trueIcon : falseIcon);
82
83     return this;
84
85   }
86
87   public String JavaDoc getText() {
88
89     return null;
90
91   }
92
93 }
94
Popular Tags