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: KListModelListCellRenderer.java,v $
023   Revision 1.2  2004/05/31 07:48:22  markl
024   javadoc updates
025
026   Revision 1.1  2004/05/13 21:41:27  markl
027   new class
028
029   Revision 1.6  2003/01/19 09:50:53  markl
030   Javadoc & comment header updates.
031
032   Revision 1.5  2001/03/12 09:27:58  markl
033   Source code and Javadoc cleanup.
034
035   Revision 1.4  1999/06/08 08:56:44  markl
036   Fixed to inherit font from JList.
037
038   Revision 1.3  1999/02/27 08:19:08  markl
039   Made constructors public.
040
041   Revision 1.2  1999/01/10 02:53:23  markl
042   added GPL header & RCS tag
043   ----------------------------------------------------------------------------
044*/
045
046package kiwi.ui;
047
048import java.awt.*;
049import javax.swing.*;
050import javax.swing.border.*;
051
052import kiwi.ui.model.*;
053
054/** An implementation of <code>ListCellRenderer</code> for use with
055  * <code>JList</code>s that are connected to a <code>ITreeModel</code> via
056  * a <code>TreeModelListAdapter</code>. This cell renderer consults the tree
057  * model for a cell's rendering information, such as its label and icon.
058  *
059  * @see javax.swing.JList
060  * @see kiwi.ui.model.KListModel
061  * @see kiwi.ui.model.KListModelAdapter
062  *
063  * @author Mark Lindner
064  */
065
066public class KListModelListCellRenderer extends AbstractCellRenderer
067  {
068  private EmptyBorder emptyBorder = new EmptyBorder(0, 0, 0, 0);
069  private KListModel model = null;
070  private JLabel label;
071
072  /** Construct a new <code>ModelListCellRenderer</code>.
073   */
074
075  public KListModelListCellRenderer()
076    {
077    label = new JLabel();
078    }
079
080  /** Construct a new <code>ModelListCellRenderer</code>.
081    *
082    * @param model The list model that will be used with this renderer.
083    */
084  
085  public KListModelListCellRenderer(KListModel model)
086    {
087    this();
088    setModel(model);
089    }
090
091  /** Set the data model for this renderer.
092   *
093   * @param model The model.
094   */
095
096  public void setModel(KListModel model)
097    {
098    this.model = model;
099    }
100
101  /*
102   */
103
104  public JComponent getCellRenderer(JComponent component, Object value,
105                                    int row, int column)
106    {
107    if((model == null) || (value == null))
108      {
109      label.setIcon(null);
110      label.setText((value == null) ? null : value.toString());
111      }
112    else
113      {
114      label.setIcon(model.getIcon(value));
115      label.setText(model.getLabel(value));
116      }
117
118    return(label);
119    }
120
121  }
122
123/* end of source file */