KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > fonts > CheckboxCellRenderer


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * CheckboxCellRenderer.java
28  *
29  * Created on October 5, 2006, 10:03 AM
30  *
31  */

32
33 package it.businesslogic.ireport.gui.fonts;
34
35 import java.awt.Color JavaDoc;
36 import java.awt.Component JavaDoc;
37 import javax.swing.DefaultListCellRenderer JavaDoc;
38 import javax.swing.JCheckBox JavaDoc;
39 import javax.swing.JList JavaDoc;
40 import javax.swing.UIManager JavaDoc;
41 import javax.swing.border.*;
42
43 /**
44  *
45  * @author gtoffoli
46  */

47 public class CheckboxCellRenderer extends DefaultListCellRenderer JavaDoc
48 {
49       protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
50             
51       public Component JavaDoc getListCellRendererComponent(
52                     JList JavaDoc list, Object JavaDoc value, int index,
53                     boolean isSelected, boolean cellHasFocus)
54       {
55          if (value instanceof CheckBoxListEntry)
56          {
57              CheckBoxListEntry checkbox = (CheckBoxListEntry) value;
58              checkbox.setBackground(isSelected ?
59                      list.getSelectionBackground() : list.getBackground());
60              if (checkbox.isRed())
61              {
62                  checkbox.setForeground( Color.red );
63              }
64              else
65              {
66              checkbox.setForeground(isSelected ?
67                      list.getSelectionForeground() : list.getForeground());
68              }
69              checkbox.setEnabled(isEnabled());
70              checkbox.setFont(getFont());
71              checkbox.setFocusPainted(false);
72              checkbox.setBorderPainted(true);
73              checkbox.setBorder(isSelected ?
74               UIManager.getBorder(
75                "List.focusCellHighlightBorder") : noFocusBorder);
76              
77              return checkbox;
78          }
79          else
80          {
81             return super.getListCellRendererComponent(list, value.getClass().getName(), index, isSelected, cellHasFocus);
82          }
83    }
84 }
85
Popular Tags