import org.hedgecode.chess.position.Square;
/**
- *
+ * Storage class for chess board images.
*
* @author Dmitry Samoshin aka gotty
*/
public class Board {
+ private BufferedImage board;
private SquarePair<BufferedImage> squares;
+
private int squareSize;
- Board(SquarePair<BufferedImage> squares) {
+ private Board(SquarePair<BufferedImage> squares) {
this.squares = squares;
int width = Math.max(squares.getDark().getWidth(), squares.getLight().getWidth());
int height = Math.max(squares.getDark().getHeight(), squares.getLight().getHeight());
this.squareSize = Math.max(width, height);
}
+ private Board(BufferedImage board) {
+ this.board = board;
+ this.squareSize = Math.max(board.getWidth(), board.getHeight()) / Square.getSize();
+ }
+
public int squareSize() {
return squareSize;
}
return squareSize * Square.getSize();
}
- public BufferedImage render() {
+ public BufferedImage getBoard() {
+ if (board == null && squares != null) {
+ board = renderBoard();
+ }
+ return board;
+ }
+
+ private BufferedImage renderBoard() {
BufferedImage board = new BufferedImage(
squareSize * Square.getSize(),
squareSize * Square.getSize(),
return board;
}
+ public static Board create(BufferedImage board) {
+ return new Board(board);
+ }
+
public static Board create(SquarePair<BufferedImage> squares) {
return new Board(squares);
}