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: ImagePanel.java,v $
023   Revision 1.5  2004/05/12 18:52:18  markl
024   comment block updates
025
026   Revision 1.4  2003/01/19 09:50:53  markl
027   Javadoc & comment header updates.
028
029   Revision 1.3  2001/12/25 10:13:15  markl
030   Added getImage() & setImage()
031
032   Revision 1.2  2001/03/12 09:27:55  markl
033   Source code and Javadoc cleanup.
034
035   Revision 1.1  1999/04/23 07:25:23  markl
036   Initial revision
037   ----------------------------------------------------------------------------
038*/
039 
040package kiwi.ui;
041
042import java.awt.*;
043import javax.swing.*;
044
045/** A component for displaying an icon image. The component's preferred and
046 * minimum sizes are equal to the size of the image.
047 *
048 * @author Mark Lindner
049 */
050
051public class ImagePanel extends JComponent
052  {
053  private Icon image;
054  private Dimension size;
055
056  /** Construct a new <code>ImagePanel</code> with the specified icon image.
057   *
058   * @param image The icon to paint in the panel.
059   */
060       
061  public ImagePanel(Icon image)
062    {
063    _setImage(image);
064    }
065
066  /** Get the icon image currently displayed by this <code>ImagePanel</code>.
067   *
068   * @since Kiwi 1.3.2
069   *
070   * @return The icon.
071   */
072
073  public Icon getImage()
074    {
075    return(image);
076    }
077
078  private void _setImage(Icon image)
079    {
080    this.image = image;
081    size = new Dimension(image.getIconWidth(), image.getIconHeight());
082    }
083
084  /** Set an icon image for the <code>ImagePanel</code>
085   *
086   * @since Kiwi 1.3.3
087   *
088   * @param image The icon to paint in the panel.
089   */
090   
091  public void setImage(Icon image)
092    {
093    _setImage(image);
094    repaint();
095    }
096  
097  /** Paint the component.
098   */
099   
100  public void paintComponent(Graphics gc)
101    {
102    image.paintIcon(this, gc, 0, 0);
103    }
104
105  /** Get the preferred size of the component.
106   *
107   * @return The size of the image.
108   */
109   
110  public Dimension getPreferredSize()
111    {
112    return(size);
113    }
114
115  /** Get the minimum size of the component.
116   *
117   * @return The size of the image.
118   */
119   
120  public Dimension getMinimumSize()
121    {
122    return(size);
123    }
124
125  }
126
127/* end of source file */