001/*
002// This software is subject to the terms of the Eclipse Public License v1.0
003// Agreement, available at the following URL:
004// http://www.eclipse.org/legal/epl-v10.html.
005// You must accept the terms of that agreement to use this software.
006//
007// Copyright (C) 2002-2005 Julian Hyde
008// Copyright (C) 2005-2011 Pentaho and others
009// All Rights Reserved.
010*/
011package mondrian.gui;
012
013import java.awt.*;
014import javax.swing.*;
015
016/**
017 * <code>ListRenderer</code> ...
018 */
019class ListRenderer implements ListCellRenderer {
020    // The original ListCellRenderer we want to override
021    ListCellRenderer std;
022
023    public ListRenderer(ListCellRenderer override) {
024        if (override == null) {
025            throw new NullPointerException(
026                "ListRenderer constructor: default renderer is null");
027        }
028        std = override;
029    }
030
031    // Override of getListCellRendererComponent.
032    // This is called by the AWT event thread to paint components.
033    public Component getListCellRendererComponent(
034        JList list,
035        Object value,
036        int index,
037        boolean isSelected,
038        boolean cellHasFocus)
039    {
040        // Ask the standard renderer for what it thinks is right
041        Component c =
042            std.getListCellRendererComponent(
043                list,
044                value,
045                index,
046                isSelected,
047                cellHasFocus);
048        if (!isSelected) {
049            // Set the background of the returned component to Aqua
050            // striped background, but only for unselected cells;
051            // The standard renderer functions as desired for
052            // highlighted cells.
053            c.setBackground((Color)UIManager.get("ComboBox.background"));
054        }
055        return c;
056    }
057}
058
059// End ListRenderer.java