X-Git-Url: https://git.hedgecode.org/?p=chesshog.git;a=blobdiff_plain;f=chesshog-graphics%2Fsrc%2Fmain%2Fjava%2Forg%2Fhedgecode%2Fchess%2Fimg%2Fboard%2FBoard.java;h=ab4371f574a77611ee4e717064b5d29dd294693b;hp=f251e137a51d1d9e6429bc2f6b0c7a29c880f899;hb=0b24d5b71c19ba38060297084ad39685f76a8539;hpb=cc2bc357ce3c21a0b092af8b2ba3e174d10cac81 diff --git a/chesshog-graphics/src/main/java/org/hedgecode/chess/img/board/Board.java b/chesshog-graphics/src/main/java/org/hedgecode/chess/img/board/Board.java index f251e13..ab4371f 100644 --- a/chesshog-graphics/src/main/java/org/hedgecode/chess/img/board/Board.java +++ b/chesshog-graphics/src/main/java/org/hedgecode/chess/img/board/Board.java @@ -22,22 +22,29 @@ import java.awt.image.BufferedImage; 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 squares; + private int squareSize; - Board(SquarePair squares) { + private Board(SquarePair 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; } @@ -46,7 +53,14 @@ public class Board { 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(), @@ -68,6 +82,10 @@ public class Board { return board; } + public static Board create(BufferedImage board) { + return new Board(board); + } + public static Board create(SquarePair squares) { return new Board(squares); }