Paint stones on table

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@32 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-04-30 21:16:42 +02:00
parent f9b396875a
commit 482d7e7f86
4 changed files with 63 additions and 4 deletions

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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++;
}
}
}

View file

@ -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());
}
}
}