From 3e257e3979f1f58d8b5ceb7a2d4472201bb94c34 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 3 May 2011 16:03:09 +0200 Subject: Renamed everything in the view git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@75 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/impl/Board.java | 122 ------------------------------------- 1 file changed, 122 deletions(-) delete mode 100644 src/jrummikub/view/impl/Board.java (limited to 'src/jrummikub/view/impl/Board.java') diff --git a/src/jrummikub/view/impl/Board.java b/src/jrummikub/view/impl/Board.java deleted file mode 100644 index 94571e0..0000000 --- a/src/jrummikub/view/impl/Board.java +++ /dev/null @@ -1,122 +0,0 @@ -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; -import java.util.Map; - -import javax.swing.ImageIcon; -import javax.swing.border.MatteBorder; - -import jrummikub.model.Position; -import jrummikub.model.Stone; -import jrummikub.view.IBoard; - -/** - * Implementation of the board - */ -@SuppressWarnings("serial") -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( - Board.class.getResource("/jrummikub/resource/wood.png")); - BACKGROUND = new BufferedImage(image.getIconWidth(), image.getIconHeight(), - BufferedImage.TYPE_INT_RGB); - - image.paintIcon(null, BACKGROUND.createGraphics(), 0, 0); - } - private BufferedImage scaledBackground = BACKGROUND; - - private Map stones = Collections.emptyMap(); - private Collection selectedStones = Collections.emptyList(); - - /** - * Creates a new Board instance - */ - Board() { - setBorder(new MatteBorder(0, 1, 0, 1, Color.DARK_GRAY)); - - 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) { - BufferedImage scaled = new BufferedImage(size, size, - BufferedImage.TYPE_INT_RGB); - Graphics2D g = scaled.createGraphics(); - g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, - RenderingHints.VALUE_INTERPOLATION_BICUBIC); - - g.drawImage(BACKGROUND, 0, 0, size, size, null); - - return scaled; - } - - @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); - int size = height / BOARD_HEIGHT; - - 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); - - for (Map.Entry entry : stones.entrySet()) { - getStonePainter().paintStone(g, entry.getKey(), entry.getValue(), - selectedStones.contains(entry.getKey())); - } - } - - @Override - public void setStones(Map stones) { - this.stones = stones; - repaint(); - } - - /** - * Sets the stones that are to be painted selected - * - * @param stones - * the selected stones - */ - void setSelectedStones(Collection stones) { - selectedStones = stones; - repaint(); - } -} -- cgit v1.2.3