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: HeaderCellRenderer.java,v $
023   Revision 1.4  2004/05/31 07:28:05  markl
024   Added an outer border so text doesn't bump up against bevels.
025
026   Revision 1.3  2003/01/19 09:50:53  markl
027   Javadoc & comment header updates.
028
029   Revision 1.2  2001/03/12 09:27:55  markl
030   Source code and Javadoc cleanup.
031
032   Revision 1.1  1999/04/23 07:26:21  markl
033   Initial revision
034   ----------------------------------------------------------------------------
035*/
036
037package kiwi.ui;
038
039import java.awt.*;
040import javax.swing.*;
041import javax.swing.border.*;
042import javax.swing.table.*;
043
044/** A customized header table cell renderer that left-justifies the header
045 * text and may optionally render an icon.
046 *
047 * @author Mark Lindner
048 */
049
050public class HeaderCellRenderer extends JPanel implements TableCellRenderer
051  {
052  private Icon sortIcon;
053  private static final Border headerBorder
054    = new CompoundBorder(new BevelBorder(BevelBorder.RAISED),
055                         new EmptyBorder(0, 3, 0, 3));
056  private JLabel l_text, l_icon;
057   
058  /** Construct a new <code>HeaderCellRenderer</code>.
059   */
060   
061  public HeaderCellRenderer()
062    {
063    setOpaque(false);
064    setBorder(headerBorder);
065    setLayout(new BorderLayout(0, 0));
066
067    l_text = new KLabel();
068    l_text.setVerticalTextPosition(SwingConstants.CENTER);
069    l_text.setHorizontalTextPosition(SwingConstants.LEFT);
070    add("Center", l_text);
071
072    l_icon = new KLabel();
073    add("East", l_icon);
074    }
075
076  /** Set the icon for the renderer. The icon is rendered against the right
077   * edge of the renderer.
078   *
079   * @param icon The icon.
080   */
081
082  public void setIcon(Icon icon)
083    {
084    l_icon.setIcon(icon);
085    }
086  
087  /** Get the cell renderer component.
088   */
089   
090  public Component getTableCellRendererComponent(JTable table, Object value,
091                                                 boolean isSelected,
092                                                 boolean hasFocus, int row,
093                                                 int column)
094    {
095    l_text.setText(value.toString());
096    
097    return(this);
098    }
099
100  }
101
102/* end of source file */