package jrummikub.view.impl; import java.awt.Color; import java.awt.Graphics; import java.awt.Insets; import java.util.Collections; import java.util.Map; import javax.swing.ImageIcon; import javax.swing.JPanel; import jrummikub.model.Position; import jrummikub.model.Stone; import jrummikub.view.IBoard; @SuppressWarnings("serial") public class Board extends JPanel implements IBoard { private final static ImageIcon background = new ImageIcon(Board.class.getResource("/jrummikub/resource/wood.png")); private Map stones = Collections.emptyMap(); Board() { super(true); setBorder(new CustomBorder(Color.DARK_GRAY, 0, 1, 0, 1)); } @Override protected void paintComponent(Graphics g) { Insets insets = getInsets(); int x = insets.left, y = insets.top, width = getWidth()-insets.left-insets.right, height = getHeight()-insets.top-insets.bottom; g = g.create(x, y, width, height); for(int xpos = 0; xpos < width; xpos += background.getIconWidth()) { background.paintIcon(this, g, xpos, 0); } for(int xpos = -32; xpos < width; xpos += background.getIconWidth()) { background.paintIcon(this, g, xpos, 75); } for (Map.Entry stone : stones.entrySet()) { StonePainter.paintStone(g, stone.getKey(), stone.getValue(), StonePainter.BOARD_SCALE); } } @Override public void setStones(Map stones) { this.stones = stones; } }