001/* ---------------------------------------------------------------------------- 002 The Kiwi Toolkit - A Java Class Library 003 Copyright (C) 1998-2004 Mark A. Lindner 004 005 This library is free software; you can redistribute it and/or 006 modify it under the terms of the GNU General Public License as 007 published by the Free Software Foundation; either version 2 of the 008 License, or (at your option) any later version. 009 010 This library is distributed in the hope that it will be useful, 011 but WITHOUT ANY WARRANTY; without even the implied warranty of 012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 General Public License for more details. 014 015 You should have received a copy of the GNU General Public License 016 along with this library; if not, write to the Free Software 017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 018 02111-1307, USA. 019 020 The author may be contacted at: mark_a_lindner@yahoo.com 021 ---------------------------------------------------------------------------- 022 $Log: ColoredCellRenderer.java,v $ 023 Revision 1.5 2004/05/12 19:15:36 markl 024 comment block updates 025 026 Revision 1.4 2003/01/19 09:50:53 markl 027 Javadoc & comment header updates. 028 029 Revision 1.3 2001/03/12 09:27:53 markl 030 Source code and Javadoc cleanup. 031 032 Revision 1.2 1999/01/10 01:00:58 markl 033 added GPL header & RCS tag 034 ---------------------------------------------------------------------------- 035*/ 036 037package kiwi.ui; 038 039import java.awt.*; 040import javax.swing.*; 041 042import kiwi.ui.ColoredString; 043 044/** A cell renderer for <code>ColoredString</code>s; for use with 045 * <code>JList</code>s. 046 * 047 * @see kiwi.ui.ColoredString 048 * @see javax.swing.JList 049 * 050 * @author Mark Lindner 051 */ 052 053public class ColoredCellRenderer extends JLabel implements ListCellRenderer 054 { 055 private Color gray = new Color(100, 100, 100); 056 057 /** Construct a new <code>ColeredCellRenderer</code>. */ 058 059 public ColoredCellRenderer() 060 { 061 setOpaque(true); 062 } 063 064 /** Return the component (in this case a <code>JLabel</code> that is used 065 * as a "rubber stamp" for drawing items in the <code>JList</code>. The 066 * background of the cell is black, and the foreground will be the color of 067 * the colored string. 068 * 069 * @param list The associated <code>JList</code> instance. 070 * @param value The <code>ColoredString</code> to draw. 071 * @param index The offset of the item in the list. 072 * @param isSelected <code>true</code> if this item is currently selected 073 * in the list. 074 * @param cellHasFocus <code>true</code> if this item currently has focus 075 * in the list. 076 */ 077 078 public Component getListCellRendererComponent(JList list, 079 Object value, int index, 080 boolean isSelected, 081 boolean cellHasFocus) 082 { 083 ColoredString s = (ColoredString)value; 084 085 setText(s.getString()); 086 setBackground(isSelected ? gray : Color.black); 087 setForeground(s.getColor()); 088 return(this); 089 } 090 091 } 092 093/* end of source file */