git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@45 72836036-5685-4462-b002-a69064685172
64 lines
1.9 KiB
Java
64 lines
1.9 KiB
Java
package jrummikub.view.impl;
|
|
|
|
import java.awt.Color;
|
|
import java.awt.Graphics;
|
|
import java.awt.Graphics2D;
|
|
import java.awt.Insets;
|
|
import java.awt.RenderingHints;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.Map;
|
|
|
|
import javax.swing.ImageIcon;
|
|
|
|
import jrummikub.model.Position;
|
|
import jrummikub.model.Stone;
|
|
import jrummikub.view.IBoard;
|
|
|
|
@SuppressWarnings("serial")
|
|
public class Board extends StonePanel implements IBoard {
|
|
private final static ImageIcon BACKGROUND = new ImageIcon(Board.class.getResource("/jrummikub/resource/wood.png"));
|
|
private final static float DEFAULT_SCALE = StonePainter.BOARD_SCALE;
|
|
|
|
private Map<Stone, Position> stones = Collections.emptyMap();
|
|
private Collection<Stone> selectedStones = Collections.emptyList();
|
|
|
|
Board() {
|
|
super(DEFAULT_SCALE);
|
|
|
|
setBorder(new CustomBorder(Color.DARK_GRAY, 0, 1, 0, 1));
|
|
}
|
|
|
|
@Override
|
|
protected void paintComponent(Graphics g1) {
|
|
Insets insets = getInsets();
|
|
int x = insets.left, y = insets.top, width = getWidth()-insets.left-insets.right, height = getHeight()-insets.top-insets.bottom;
|
|
Graphics2D g = (Graphics2D)g1.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);
|
|
}
|
|
|
|
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
|
RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
|
for (Map.Entry<Stone, Position> entry : stones.entrySet()) {
|
|
getStonePainter().paintStone(g, entry.getKey(), entry.getValue(),
|
|
selectedStones.contains(entry.getKey()));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void setStones(Map<Stone, Position> stones) {
|
|
this.stones = stones;
|
|
repaint();
|
|
}
|
|
|
|
public void setSelectedStones(Collection<Stone> stones) {
|
|
selectedStones = stones;
|
|
repaint();
|
|
}
|
|
}
|