KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > client > manager > ManagerCellRenderer


1 package hero.client.manager;
2
3 /*
4 *
5 * ManagerCellRenderer.java -
6 * Copyright (C) 2002 Ecoo Team
7 * valdes@loria.fr
8 *
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */

24
25
26 import java.awt.Color JavaDoc;
27 import java.awt.Component JavaDoc;
28
29 import javax.swing.BorderFactory JavaDoc;
30 import javax.swing.JLabel JavaDoc;
31 import javax.swing.JList JavaDoc;
32 import javax.swing.ListCellRenderer JavaDoc;
33
34 class ManagerCellRenderer extends JLabel JavaDoc implements ListCellRenderer JavaDoc {
35     
36     public ManagerCellRenderer () {
37     // Don't paint behind the component
38
setOpaque(true);
39     }
40     
41     // Set the attributes of the
42
//class and return a reference
43
public Component JavaDoc getListCellRendererComponent(JList JavaDoc list,
44                           Object JavaDoc value, // value to display
45
int index, // cell index
46
boolean iss, // is selected
47
boolean chf) // cell has focus?
48
{
49         // Set the text and color
50
//background for rendering
51
setText(((ListItem)value).getValue());
52         setBackground(((ListItem)value).getColor());
53         
54         // Set a border if the list
55
//item is selected
56
if (iss) {
57                 setBorder(
58               BorderFactory.createLineBorder(Color.blue, 2));
59             } else {
60                 setBorder(
61               BorderFactory.createLineBorder(list.getBackground(), 2));
62             }
63         return this;
64         }
65 }
66
Popular Tags