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: BooleanCellRenderer.java,v $
023   Revision 1.6  2004/05/12 19:13:43  markl
024   comment block updates
025
026   Revision 1.5  2004/01/23 00:17:17  markl
027   rewritten to extend AbstractCellRenderer
028
029   Revision 1.4  2003/01/19 09:50:52  markl
030   Javadoc & comment header updates.
031
032   Revision 1.3  2001/03/12 09:27:52  markl
033   Source code and Javadoc cleanup.
034
035   Revision 1.2  1999/07/06 09:17:59  markl
036   Fixed rendering so that we inherit the table's colors properly.
037
038   Revision 1.1  1999/04/23 07:26:28  markl
039   Initial revision
040   ----------------------------------------------------------------------------
041*/
042
043package kiwi.ui;
044
045import java.awt.*;
046import javax.swing.*;
047import javax.swing.border.*;
048import javax.swing.table.TableCellRenderer;
049
050import kiwi.util.*;
051
052/** A table cell renderer for displaying boolean values. Renders a value,
053 * which may be either a <code>Boolean</code> object or a
054 * <code>BooleanHolder</code> object, as a non-editable checkbox.
055 *
056 * @author Mark Lindner
057 *
058 * @see java.lang.Boolean
059 * @see kiwi.util.BooleanHolder
060 */
061
062public class BooleanCellRenderer extends AbstractCellRenderer
063  {
064  private JCheckBox renderer;
065
066  /** Construct a new <code>BooleanCellRenderer</code>
067   */
068  
069  public BooleanCellRenderer()
070    {
071    renderer = new JCheckBox();    
072    renderer.setHorizontalAlignment(SwingConstants.CENTER);
073    }
074
075  /** Get a reference to the renderer component.
076   */
077  
078  protected JComponent getCellRenderer(JComponent component, Object value,
079                                       int row, int column)
080    {
081    boolean flag;
082    if(value instanceof BooleanHolder)
083      flag = ((BooleanHolder)value).getValue();
084    else if(value instanceof Boolean)
085      flag = ((Boolean)value).booleanValue();
086    else
087      flag = false;
088
089    renderer.setSelected(flag);
090
091    return(renderer);
092    }
093  
094  }
095
096/* end of source file */