summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-04-30 21:16:42 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-04-30 21:16:42 +0200
commit482d7e7f86ed0343c0a4102562a82bd65dd52f37 (patch)
treebb5fb7ef9f84e4165b2b6eb956ce098139ac5eca /src
parentf9b396875add92f9cfc64ee74c82d3275e4d7dd6 (diff)
downloadJRummikub-482d7e7f86ed0343c0a4102562a82bd65dd52f37.tar
JRummikub-482d7e7f86ed0343c0a4102562a82bd65dd52f37.zip
Paint stones on table
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@32 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/JRummikub.java21
-rw-r--r--src/jrummikub/view/ITable.java6
-rw-r--r--src/jrummikub/view/impl/StonePainter.java12
-rw-r--r--src/jrummikub/view/impl/Table.java28
4 files changed, 63 insertions, 4 deletions
diff --git a/src/jrummikub/JRummikub.java b/src/jrummikub/JRummikub.java
index 1990fda..e4820bc 100644
--- a/src/jrummikub/JRummikub.java
+++ b/src/jrummikub/JRummikub.java
@@ -1,6 +1,8 @@
package jrummikub;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.swing.UIManager;
@@ -8,6 +10,7 @@ import javax.swing.UIManager;
import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.model.StoneColor;
+import jrummikub.model.StoneSet;
import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.view.IView;
@@ -49,6 +52,7 @@ public class JRummikub {
System.out.println("'End turn' fired");
}});
+ //stones on the board
Map<Stone, Position> stones = new HashMap<Stone, Position>();
stones.put(new Stone(1, StoneColor.ORANGE, false), new Position(0, 0));
stones.put(new Stone(10, StoneColor.BLUE, false), new Position(1, 0));
@@ -66,7 +70,22 @@ public class JRummikub {
System.out.println("Board clicked at "+value);
}});
-
+
+ //stoneSets on the table
+ Map<StoneSet, Position> stoneSets = new HashMap<StoneSet, Position>();
+
+ stoneSets.put(new StoneSet(new Stone(5, StoneColor.ORANGE, false)), new Position(0.5f, 1));
+
+ List<Stone> stoneList = new ArrayList<Stone>();
+
+ stoneList.add(new Stone(7, StoneColor.BLACK, false));
+ stoneList.add(new Stone(8, StoneColor.BLACK, false));
+ stoneList.add(new Stone(9, StoneColor.BLACK, false));
+ stoneList.add(new Stone(10, StoneColor.BLACK, false));
+
+ stoneSets.put(new StoneSet(stoneList), new Position(3.5f, 4));
+
+ view.getTable().setStoneSets(stoneSets);
}
diff --git a/src/jrummikub/view/ITable.java b/src/jrummikub/view/ITable.java
index 30582d0..ce508bd 100644
--- a/src/jrummikub/view/ITable.java
+++ b/src/jrummikub/view/ITable.java
@@ -1,7 +1,13 @@
package jrummikub.view;
+import java.util.Map;
+
+import jrummikub.model.Position;
+import jrummikub.model.StoneSet;
+
public interface ITable {
public void setLeftPlayerName(String playerName);
public void setTopPlayerName(String playerName);
public void setRightPlayerName(String playerName);
+ void setStoneSets(Map<StoneSet, Position> stoneSets);
} \ No newline at end of file
diff --git a/src/jrummikub/view/impl/StonePainter.java b/src/jrummikub/view/impl/StonePainter.java
index 6fa5f38..c1b6d2c 100644
--- a/src/jrummikub/view/impl/StonePainter.java
+++ b/src/jrummikub/view/impl/StonePainter.java
@@ -12,6 +12,7 @@ import java.awt.geom.Rectangle2D;
import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.model.StoneColor;
+import jrummikub.model.StoneSet;
class StonePainter {
private static final float ASPECT_RATIO = 0.75f;
@@ -204,4 +205,15 @@ class StonePainter {
paintCircle(g, x, y, width, height);
}
+
+
+ public void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos) {
+ float x = pos.getX();
+
+ for(Stone stone : stoneSet){
+ paintStone(g, stone, new Position(x, pos.getY()));
+ x++;
+ }
+
+ }
}
diff --git a/src/jrummikub/view/impl/Table.java b/src/jrummikub/view/impl/Table.java
index c3c6a71..f7460e2 100644
--- a/src/jrummikub/view/impl/Table.java
+++ b/src/jrummikub/view/impl/Table.java
@@ -3,11 +3,18 @@ package jrummikub.view.impl;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.util.Collections;
+import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
+import jrummikub.model.Position;
+import jrummikub.model.Stone;
+import jrummikub.model.StoneSet;
import jrummikub.view.ITable;
@SuppressWarnings("serial")
@@ -17,7 +24,10 @@ public class Table extends JPanel implements ITable {
private JLabel leftPlayerLabel, topPlayerLabel, rightPlayerLabel;
private JPanel innerPanel;
-
+ private StonePainter stonePainter = new StonePainter(1);
+
+ private Map<StoneSet, Position> stoneSets = Collections.emptyMap();
+
@Override
public void setLeftPlayerName(String playerName) {
leftPlayerLabel.setText(playerName);
@@ -33,6 +43,11 @@ public class Table extends JPanel implements ITable {
rightPlayerLabel.setText(playerName);
}
+ @Override
+ public void setStoneSets(Map<StoneSet, Position> stoneSets) {
+ this.stoneSets = stoneSets;
+ }
+
Table() {
super(true); // set double buffered
setLayout(new BorderLayout());
@@ -57,13 +72,20 @@ public class Table extends JPanel implements ITable {
}
@Override
- protected void paintComponent(Graphics g) {
+ protected void paintComponent(Graphics g1) {
+ Graphics2D g = (Graphics2D)g1;
+
for(int x = 0; x < getWidth(); x += background.getIconWidth()) {
for(int y = 0; y < getHeight(); y += background.getIconHeight()) {
background.paintIcon(this, g, x, y);
}
}
- // TODO Rest of painting code
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ for (Map.Entry<StoneSet, Position> stoneSet : stoneSets.entrySet()) {
+ stonePainter.paintStoneSet(g, stoneSet.getKey(), stoneSet.getValue());
+ }
}
}