KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > gui > ListRenderer


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/gui/ListRenderer.java#1 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2002-2007 Julian Hyde and others
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10 package mondrian.gui;
11
12 import javax.swing.*;
13 import java.awt.*;
14
15 /**
16  * <code>ListRenderer</code> ...
17  *
18  * @version $Id: //open/mondrian/src/main/mondrian/gui/ListRenderer.java#1 $
19  */

20 class ListRenderer implements ListCellRenderer {
21     // The original ListCellRenderer we want to override
22
ListCellRenderer std;
23
24     public ListRenderer(ListCellRenderer override) {
25         if (override == null) {
26             throw new NullPointerException JavaDoc(
27                     "ListRenderer constructor: default renderer is null");
28         }
29         std = override;
30     }
31
32     // Override of getListCellRendererComponent.
33
// This is called by the AWT event thread to paint components.
34
public Component getListCellRendererComponent(JList list,
35             Object JavaDoc value,
36             int index,
37             boolean isSelected,
38             boolean cellHasFocus) {
39         // Ask the standard renderer for what it thinks is right
40
Component c = std.getListCellRendererComponent(list,
41                 value,
42                 index,
43                 isSelected,
44                 cellHasFocus);
45         if (!isSelected) {
46             // Set the background of the returned component to Aqua
47
// striped background, but only for unselected cells;
48
// The standard renderer functions as desired for
49
// highlighted cells.
50
c.setBackground((Color)UIManager.get("ComboBox.background"));
51         }
52         return c;
53     }
54 }
55
56 // End ListRenderer.java
57
Popular Tags