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: SubImageIcon.java,v $
023   Revision 1.2  2004/05/12 18:23:08  markl
024   comment block update
025
026   Revision 1.1  2004/01/22 23:57:10  markl
027   new class
028   ----------------------------------------------------------------------------
029*/
030
031package kiwi.ui;
032
033import java.awt.*;
034import javax.swing.*;
035
036/** An icon that is drawn as a portion of a larger image.
037 *
038 * @author Mark Lindner
039 * @since Kiwi 2.0
040 */
041
042public class SubImageIcon implements Icon
043  {
044  private Image image;
045  private int x0, y0, w, h;
046
047  /** Construct a new <code>SubImageIcon</code>.
048   *
049   * @param image The parent image.
050   * @param x The x-offset of the icon within the image.
051   * @param y The y-offset of the icon within the image.
052   * @param w The width of the icon.
053   * @param h The height of the icon.
054   */
055  
056  public SubImageIcon(Image image, int x, int y, int w, int h)
057    {
058    this.image = image;
059    this.x0 = x;
060    this.y0 = y;
061    this.w = w;
062    this.h = h;
063    }
064
065  /**
066   */
067
068  public int getIconHeight()
069    {
070    return(h);
071    }
072
073  /**
074   */
075
076  public int getIconWidth()
077    {
078    return(w);
079    }
080
081  /**
082   */
083
084  public void paintIcon(Component c, Graphics gc, int x, int y)
085    {
086    gc.drawImage(image, x, y, x + w, y + h, x0, y0, x0 + w, y0 + h, c);
087    }
088  
089  }
090
091/* end of source file */