summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/HandPanel.java
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-05-16 20:49:11 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-05-16 20:49:11 +0200
commit9ad7f0822eb66972f740fb3da58c85d7a555d549 (patch)
tree884c67b386014e8bf7f9a0d20c75bd3203493053 /src/jrummikub/view/impl/HandPanel.java
parentbe4b1b41200f5383850db3b20fb9aabf38374010 (diff)
downloadJRummikub-9ad7f0822eb66972f740fb3da58c85d7a555d549.tar
JRummikub-9ad7f0822eb66972f740fb3da58c85d7a555d549.zip
Add hand row controls to view
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@241 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view/impl/HandPanel.java')
-rw-r--r--src/jrummikub/view/impl/HandPanel.java99
1 files changed, 70 insertions, 29 deletions
diff --git a/src/jrummikub/view/impl/HandPanel.java b/src/jrummikub/view/impl/HandPanel.java
index 6ad6270..bede319 100644
--- a/src/jrummikub/view/impl/HandPanel.java
+++ b/src/jrummikub/view/impl/HandPanel.java
@@ -15,6 +15,7 @@ import java.util.Collections;
import javax.swing.ImageIcon;
import javax.swing.border.MatteBorder;
+import jrummikub.model.Hand;
import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.util.Pair;
@@ -25,42 +26,34 @@ import jrummikub.view.IHandPanel;
*/
@SuppressWarnings("serial")
class HandPanel extends AbstractStonePanel implements IHandPanel {
- private int handWidth = 1;
- private int handHeight = 1;
+ private final static int HEIGHT = 2;
private final static BufferedImage BACKGROUND;
static {
ImageIcon image = new ImageIcon(
HandPanel.class.getResource("/jrummikub/resource/wood.png"));
- BACKGROUND = new BufferedImage(image.getIconWidth(),
- image.getIconHeight(), BufferedImage.TYPE_INT_RGB);
+ BACKGROUND = new BufferedImage(image.getIconWidth(), image.getIconHeight(),
+ BufferedImage.TYPE_INT_RGB);
image.paintIcon(null, BACKGROUND.createGraphics(), 0, 0);
}
+
private BufferedImage scaledBackground = BACKGROUND;
- private boolean repaintAll = true;
+ private PlayerPanel playerPanel;
- private Collection<Stone> selectedStones = Collections.emptyList();
-
- @Override
- public void setHandWidth(int width) {
- handWidth = width;
- rescale();
- repaint();
- }
+ private int currentRow = 0;
+ private int maxRow = 0;
- @Override
- public void setHandHeight(int height) {
- handHeight = height;
- rescale();
- repaint();
- }
+ private boolean repaintAll = true;
+ private Collection<Stone> selectedStones = Collections.emptyList();
/**
* Creates a new Board instance
*/
- HandPanel() {
+ HandPanel(PlayerPanel playerPanel) {
+ this.playerPanel = playerPanel;
+
setBorder(new MatteBorder(0, 1, 0, 1, Color.DARK_GRAY));
addComponentListener(new ComponentAdapter() {
@@ -88,26 +81,27 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
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;
+ - insets.right, height = getHeight() - insets.top - insets.bottom;
Graphics2D g = (Graphics2D) g1.create(x, y, width, height);
- int size = height / handHeight;
+ int size = height / HEIGHT;
if (repaintAll) {
if (scaledBackground.getHeight() != size)
scaledBackground = getScaledBackground(size);
- for (int i = 0; i < handHeight; ++i) {
+ for (int i = 0; i < HEIGHT; ++i) {
for (int xpos = -size * i / 3; xpos < width; xpos += size) {
g.drawImage(scaledBackground, xpos, size * i, null);
}
}
}
+ Pair<Integer, Integer> trans = getTranslation();
+ g.translate(trans.getFirst(), trans.getSecond());
+
for (Pair<Stone, Position> entry : getStones()) {
- getStonePainter().paintStone(g, entry.getFirst(),
- entry.getSecond(),
+ getStonePainter().paintStone(g, entry.getFirst(), entry.getSecond(),
selectedStones.contains(entry.getFirst()),
entry.getFirst() == getHoveredStone());
}
@@ -116,15 +110,62 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
@Override
public void setStones(Iterable<Pair<Stone, Position>> stones) {
super.setStones(stones);
+
+ maxRow = 0;
+ for (Pair<Stone, Position> entry : stones) {
+ if (entry.getSecond().getY() > maxRow) {
+ maxRow = (int) entry.getSecond().getY();
+ }
+ }
+
+ repaintAll = true;
+ repaint();
+
+ playerPanel.updateButtons();
+ }
+
+ void rowUp() {
+ currentRow--;
+ repaintAll = true;
+ repaint();
+
+ playerPanel.updateButtons();
+ }
+
+ void rowDown() {
+ currentRow++;
repaintAll = true;
repaint();
+
+ playerPanel.updateButtons();
+ }
+
+ @Override
+ public void resetCurrentRow() {
+ currentRow = Math.max(0, maxRow - 1);
+
+ playerPanel.updateButtons();
+ }
+
+ boolean canRowUp() {
+ return (currentRow > 0);
+ }
+
+ boolean canRowDown() {
+ return (currentRow < maxRow);
+ }
+
+ @Override
+ public Pair<Integer, Integer> getTranslation() {
+ return new Pair<Integer, Integer>(0, -getStonePainter().getStoneHeight()
+ * currentRow);
}
/**
* Sets the stones that are to be painted selected
*
* @param stones
- * the selected stones
+ * the selected stones
*/
void setSelectedStones(Collection<Stone> stones) {
selectedStones = stones;
@@ -133,11 +174,11 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
private void rescale() {
Insets insets = getInsets();
- int size = (getHeight() - insets.top - insets.bottom) / handHeight;
+ int size = (getHeight() - insets.top - insets.bottom) / HEIGHT;
getStonePainter().setScale(size * StonePainter.HEIGHT_SCALE);
- setSize(new Dimension(handWidth * getStonePainter().getStoneWidth()
+ setSize(new Dimension(Hand.WIDTH * getStonePainter().getStoneWidth()
+ insets.left + insets.right, getHeight()));
repaintAll = true;