1 /** 2 * The chess framework library. 3 * More information is available at http://www.jinchess.com/. 4 * Copyright (C) 2002 Alexander Maryanovsky. 5 * All rights reserved. 6 * 7 * The chess framework library is free software; you can redistribute 8 * it and/or modify it under the terms of the GNU Lesser General Public License 9 * as published by the Free Software Foundation; either version 2 of the 10 * License, or (at your option) any later version. 11 * 12 * The chess framework library is distributed in the hope that it will 13 * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 15 * General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public License 18 * along with the chess framework library; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21 22 package free.chess; 23 24 import javax.swing.Icon; 25 import java.awt.Graphics; 26 import java.awt.Component; 27 import java.awt.Rectangle; 28 29 public class PieceIcon implements Icon{ 30 31 32 /** 33 * The Piece. 34 */ 35 36 private final Piece piece; 37 38 39 40 /** 41 * The PiecePainter. 42 */ 43 44 private final PiecePainter piecePainter; 45 46 47 48 /** 49 * The width of the icon. 50 */ 51 52 private final int width; 53 54 55 56 /** 57 * The height of the icon. 58 */ 59 60 private final int height; 61 62 63 64 65 /** 66 * Creates a new PieceIcon with the given Piece, PiecePainter, width and height. 67 */ 68 PieceIcon(Piece piece, PiecePainter piecePainter, int width, int height)69 public PieceIcon(Piece piece, PiecePainter piecePainter, int width, int height){ 70 this.piece = piece; 71 this.piecePainter = piecePainter; 72 this.width = width; 73 this.height = height; 74 } 75 76 77 78 79 /** 80 * Returns the width of the icon. 81 */ 82 getIconWidth()83 public int getIconWidth(){ 84 return width; 85 } 86 87 88 89 /** 90 * Returns the height of the icon. 91 */ 92 getIconHeight()93 public int getIconHeight(){ 94 return height; 95 } 96 97 98 99 /** 100 * Paints the icon on the given Graphics, at the given location. 101 */ 102 paintIcon(Component component, Graphics g, int x, int y)103 public void paintIcon(Component component, Graphics g, int x, int y){ 104 piecePainter.paintPiece(piece, g, component, new Rectangle(x, y, width, height), false); 105 } 106 107 } 108