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: ToggleCellRenderer.java,v $
023   Revision 1.3  2004/05/12 18:52:46  markl
024   comment block updates
025
026   Revision 1.2  2004/03/20 05:15:18  markl
027   make renderer tolerant of invalid value types.
028
029   Revision 1.1  2004/03/16 06:05:56  markl
030   new class
031   ----------------------------------------------------------------------------
032*/
033
034package kiwi.ui;
035
036import java.awt.*;
037import javax.swing.*;
038
039import kiwi.util.*;
040
041/** A cell renderer that displays a boolean value using a ToggleIndicator.
042 *
043 * @author Mark Lindner
044 * @since Kiwi 2.0
045 */
046
047public class ToggleCellRenderer extends AbstractCellRenderer
048  {
049  private ToggleIndicator toggle;
050
051  /** Construct a new <code>ToggleTableCellRenderer</code>.
052   *
053   * @param icon The icon that represents the <b>true</b> value.
054   * @param altIcon The icon that represents the <b>false</b> value.
055   */
056  
057  public ToggleCellRenderer(Icon icon, Icon altIcon)
058    {
059    toggle = new ToggleIndicator(icon, altIcon);
060    }
061
062  /**
063   */
064  
065  protected JComponent getCellRenderer(JComponent component, Object value,
066                                       int row, int column)
067    {
068    boolean flag = false;
069    
070    if(value.getClass() == Boolean.class)
071      {
072      Boolean b = (Boolean)value;
073      flag = b.booleanValue();
074      }
075    else if(value.getClass() == BooleanHolder.class)
076      {
077      BooleanHolder b = (BooleanHolder)value;
078      flag = b.getValue();
079      }
080
081    toggle.setState(flag);
082
083    return(toggle);
084    }
085
086  }
087
088/* end of source file */