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 java.awt.Graphics;
25 import java.awt.Color;
26 import java.awt.Component;
27 
28 
29 /**
30  * An implementation of BoardPainter which fills the squares with a solid color.
31  */
32 
33 public final class PlainBoardPainter extends AbstractColoredBoardPainter{
34 
35 
36 
37   /**
38    * Creates a new <code>PlainBoardPainter</code> which paints squares with the
39    * given light square color and dark square color.
40    */
41 
PlainBoardPainter(Color lightColor, Color darkColor)42   public PlainBoardPainter(Color lightColor, Color darkColor){
43     super(lightColor, darkColor);
44   }
45 
46 
47 
48   /**
49    * Creates a new <code>PlainBoardPainter</code> with some default colors for
50    * light and dark squares.
51    */
52 
PlainBoardPainter()53   public PlainBoardPainter(){
54     this(new Color(255,207,144),new Color(143,96,79));
55   }
56 
57 
58 
59   /**
60    * Returns a new <code>PlainBoardPainter</code>.
61    */
62 
freshInstance()63   public BoardPainter freshInstance(){
64     return new PlainBoardPainter();
65   }
66 
67 
68 
69   /**
70    * Paints the board at the given location on the given Graphics scaled to
71    * the given size.
72    */
73 
paintBoard(Graphics g, Component component, int x, int y, int width, int height)74   public void paintBoard(Graphics g, Component component, int x, int y, int width, int height){
75     int squareWidth = width/8;
76     int squareHeight = height/8;
77     Color lightColor = getLightColor();
78     Color darkColor = getDarkColor();
79 
80     for (int i=0;i<8;i++)
81       for (int j=0;j<8;j++){
82         if ((i+j)%2==0)
83           g.setColor(lightColor);
84         else
85           g.setColor(darkColor);
86 
87         g.fillRect(x+i*squareWidth, y+j*squareHeight, squareWidth, squareHeight);
88       }
89   }
90 
91 
92 }
93