/*
- * Copyright (c) 2018. Developed by Hedgecode.
+ * Copyright (c) 2018-2019. Developed by Hedgecode.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
-import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import java.util.Map;
}
@Override
- public String build(Position position) {
- return ""; // todo
- }
-
- @Override
- public RenderedImage build(Position position, String boardType, String pieceType)
+ public Diagram build(Position position, String boardType, String pieceType)
throws ImageException
{
Map<Square, ColorPiece> squares = position.getSquares();
PieceSet pieces = pieceSetLoader.load(pieceType);
if (board == null || pieces == null) {
- throw new ImageException("Couldn't find image resources!"); // todo: locale
+ throw new ImageException("image.unable.find.resource");
}
int squareSize = board.squareSize();
- BufferedImage diagram = board.render();
- Graphics diagramGraphics = diagram.getGraphics();
+ BufferedImage image = board.render();
+ Graphics imageGraphics = image.getGraphics();
for (int y = 0; y < Square.getSize(); ++y) {
for (int x = 0; x < Square.getSize(); ++x) {
Square square = Square.getSquare(x, Square.getSize() - (y + 1));
ColorPiece colorPiece = squares.get(square);
if (colorPiece != null) {
- diagramGraphics.drawImage(
+ imageGraphics.drawImage(
pieces.get(colorPiece).getScaledInstance(
squareSize, squareSize, Image.SCALE_SMOOTH
),
}
}
}
- return diagram;
+ return new Diagram(
+ position, image
+ );
}
public static ImageBuilder getInstance() {
public static void main(String[] args) throws IOException, ImageException {
ImageIO.write(
- DiagramBuilder.getInstance().build(Positions.INITIAL.getPosition(), "test", "shade"),
+ DiagramBuilder.getInstance().build(
+ Positions.INITIAL.getPosition(), "test", "shade"
+ ).getImage(),
ImageFormat.PNG.name(),
new File("chessboard" + "." + ImageFormat.PNG.getExt())
);