/*
*
* Perforce/JBuilder Opentool
* Copyright (C) 2002
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.dafreels.vcs.util;
import javax.swing.*;
import java.awt.*;
/**
* Title: Perforce Open Tool
* Description: This class allow the creation of Icons that paint a specific region
* within a larger region. Allows the programmer to load a single larger
* image strip of icons with the same with and height and walk overthem
* create a new icon for every sub-image
* Copyright: Copyright (c) 2002
* Company:
* @author Shannon J. Newbold
* @version 1.0
*/
public class CompositeIconFactory {
private Image m_image;
private int m_imageWidth;
private int m_imageHeight;
/**
* Constructs a new factory object for iterating over a group of icons.
* @img the composite image to iterate over.
* @width the width of all icons in the image
* @height the height of all icons in the image
*/
public CompositeIconFactory(Image img, int width, int height) {
m_image = img;
m_imageWidth = width;
m_imageHeight = height;
}
/**
* Returns a new icon that is x'th position in the list of icons
*/
public javax.swing.Icon getIcon(int xpos) {
return getIcon(xpos, 0);
}
/**
* Returns a new icon that is at the x'th and y'th position
* which has the width and height specified in the constructor of this object.
*/
public Icon getIcon(int xpos, int ypos) {
return new c(m_image, xpos*m_imageWidth, ypos*m_imageHeight,
m_imageWidth,m_imageHeight);
}
/**
* This is an inner class which draws the specific icon in the image.
*/
class c implements javax.swing.Icon {
private Image m_image;
private int m_startX;
private int m_startY;
private int m_imageWidth;
private int m_imageHeight;
public c(Image img, int startX, int startY, int width, int height) {
m_image = img;
m_startX = startX;
m_startY = startY;
m_imageWidth = width;
m_imageHeight = height;
}
/**
* Paint method with paints the image.
*/
public void paintIcon(Component comp, Graphics g, int x, int y) {
g.drawImage(m_image,x,y,x+m_imageWidth,y+m_imageHeight,
m_startX,m_startY,m_startX+m_imageWidth,m_startY+m_imageHeight,
null);
}
/**
* Returns the width of the Icon
*/
public int getIconWidth() {
return m_imageWidth;
}
/**
* Returns the height of the Icon
*/
public int getIconHeight() {
return m_imageHeight;
}
}
}