summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/Board.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view/impl/Board.java')
-rw-r--r--src/jrummikub/view/impl/Board.java41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/jrummikub/view/impl/Board.java b/src/jrummikub/view/impl/Board.java
index 2d51cb2..e633233 100644
--- a/src/jrummikub/view/impl/Board.java
+++ b/src/jrummikub/view/impl/Board.java
@@ -1,10 +1,13 @@
package jrummikub.view.impl;
import java.awt.Color;
+import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.RenderingHints;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
import java.awt.image.BufferedImage;
import java.util.Collection;
import java.util.Collections;
@@ -17,7 +20,10 @@ import jrummikub.model.Stone;
import jrummikub.view.IBoard;
@SuppressWarnings("serial")
-public class Board extends StonePanel implements IBoard {
+class Board extends StonePanel implements IBoard {
+ private final static int BOARD_HEIGHT = 2;
+ private final static int BOARD_WIDTH = 14;
+
private final static BufferedImage BACKGROUND;
static {
ImageIcon image = new ImageIcon(
@@ -27,12 +33,26 @@ public class Board extends StonePanel implements IBoard {
image.paintIcon(null, BACKGROUND.createGraphics(), 0, 0);
}
+ private BufferedImage scaledBackground = BACKGROUND;
private Map<Stone, Position> stones = Collections.emptyMap();
private Collection<Stone> selectedStones = Collections.emptyList();
Board() {
setBorder(new CustomBorder(Color.DARK_GRAY, 0, 1, 0, 1));
+
+ addComponentListener(new ComponentAdapter() {
+
+ @Override
+ public void componentResized(ComponentEvent e) {
+ Insets insets = getInsets();
+ int size = (getHeight()-insets.top-insets.bottom)/BOARD_HEIGHT;
+
+ getStonePainter().setScale(size*StonePainter.HEIGHT_SCALE);
+
+ setSize(new Dimension(BOARD_WIDTH*getStonePainter().getStoneWidth()+insets.left+insets.right, getHeight()));
+ }
+ });
}
private BufferedImage getScaledBackground(int size) {
@@ -50,21 +70,22 @@ public class Board extends StonePanel implements IBoard {
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);
- int size = height/2;
- BufferedImage scaledBackground = getScaledBackground(size);
+ int size = height/BOARD_HEIGHT;
- for(int xpos = 0; xpos < width; xpos += size) {
- g.drawImage(scaledBackground, xpos, 0, null);
- }
- for(int xpos = -size/3; xpos < width; xpos += size) {
- g.drawImage(scaledBackground, xpos, size, null);
+ if (scaledBackground.getHeight() != size)
+ scaledBackground = getScaledBackground(size);
+
+ for (int i = 0; i < BOARD_HEIGHT; ++i) {
+ for (int xpos = -size * i / 3; xpos < width; xpos += size) {
+ g.drawImage(scaledBackground, xpos, size * i, null);
+ }
}
+ getStonePainter().setScale(size*StonePainter.HEIGHT_SCALE);
+
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
- getStonePainter().setScale(size*StonePainter.PIXEL_SCALE);
-
for (Map.Entry<Stone, Position> entry : stones.entrySet()) {
getStonePainter().paintStone(g, entry.getKey(), entry.getValue(),
selectedStones.contains(entry.getKey()));