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: ColorSwatchCellRenderer.java,v $
023   Revision 1.5  2004/05/12 19:12:18  markl
024   comment block updates
025
026   Revision 1.4  2004/01/22 23:47:13  markl
027   rewritten to use AbstractCellRenderer.
028
029   Revision 1.3  2003/01/19 09:50:53  markl
030   Javadoc & comment header updates.
031
032   Revision 1.2  2001/03/12 09:27:52  markl
033   Source code and Javadoc cleanup.
034
035   Revision 1.1  2000/10/15 09:31:46  markl
036   New class.
037   ----------------------------------------------------------------------------
038*/
039
040package kiwi.ui;
041
042import java.awt.*;
043import javax.swing.*;
044import javax.swing.border.*;
045import javax.swing.table.*;
046
047import kiwi.text.ColorFormatter;
048
049/** A cell renderer for color swatches.
050 *
051 * @author Mark Lindner
052 */
053
054public class ColorSwatchCellRenderer extends AbstractCellRenderer
055  implements ListCellRenderer, TableCellRenderer
056  {
057  private static ColorSwatch swatch = new ColorSwatch();
058  private JLabel renderer;
059
060  /** Construct a new <code>ColorSwatchCellRenderer</code>.
061   */
062  
063  public ColorSwatchCellRenderer()
064    {
065    renderer = new JLabel();
066    renderer.setIcon(swatch);
067    }
068
069  /**
070   */
071
072  protected JComponent getCellRenderer(JComponent component, Object value,
073                                       int row, int column)
074    {
075    Color c = (Color)value;
076
077    renderer.setFont(component.getFont());
078    
079    swatch.setColor(c);
080    renderer.setText(ColorFormatter.nameForColor(c));
081
082    return(renderer);
083    }
084
085  }
086
087/* end of source file */