summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-04-30 23:17:48 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-04-30 23:17:48 +0200
commitd262d91b076cbaa322d49818476b251c06cee42e (patch)
tree5289130de3d010483318e6559dd3ad59a6829e71
parent28f1ecd987dbe86a59ce474f3f58eb75838edc68 (diff)
downloadJRummikub-d262d91b076cbaa322d49818476b251c06cee42e.tar
JRummikub-d262d91b076cbaa322d49818476b251c06cee42e.zip
Add display for selected stones above board
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@41 72836036-5685-4462-b002-a69064685172
-rw-r--r--src/jrummikub/JRummikub.java7
-rw-r--r--src/jrummikub/view/IBoard.java2
-rw-r--r--src/jrummikub/view/ITable.java3
-rw-r--r--src/jrummikub/view/IView.java6
-rw-r--r--src/jrummikub/view/impl/Board.java9
-rw-r--r--src/jrummikub/view/impl/PlayerPanel.java3
-rw-r--r--src/jrummikub/view/impl/StonePainter.java16
-rw-r--r--src/jrummikub/view/impl/Table.java31
-rw-r--r--src/jrummikub/view/impl/View.java8
9 files changed, 59 insertions, 26 deletions
diff --git a/src/jrummikub/JRummikub.java b/src/jrummikub/JRummikub.java
index da2a0e9..c9047a1 100644
--- a/src/jrummikub/JRummikub.java
+++ b/src/jrummikub/JRummikub.java
@@ -1,7 +1,7 @@
package jrummikub;
import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -65,7 +65,6 @@ public class JRummikub {
stones.put(new Stone(0, StoneColor.BLACK, true), new Position(3.5f, 0));
view.getPlayerPanel().getBoard().setStones(stones);
- view.getPlayerPanel().getBoard().setHighlightedStones(Collections.singleton(stoneJoker));
view.getPlayerPanel().getBoard().getClickEvent().add(new IListener1<Position>(){
@@ -99,8 +98,8 @@ public class JRummikub {
stoneSets.put(new StoneSet(stoneList), new Position(3.5f, 4));
view.getTable().setStoneSets(stoneSets);
- view.getTable().setHighlightedStones(Collections.singleton(stone8));
-
+
+ view.setSelectedStones(Arrays.asList(stoneJoker, stone8));
}
}
diff --git a/src/jrummikub/view/IBoard.java b/src/jrummikub/view/IBoard.java
index deb2735..237518f 100644
--- a/src/jrummikub/view/IBoard.java
+++ b/src/jrummikub/view/IBoard.java
@@ -1,6 +1,5 @@
package jrummikub.view;
-import java.util.Collection;
import java.util.Map;
import jrummikub.model.Position;
@@ -9,7 +8,6 @@ import jrummikub.util.IEvent1;
public interface IBoard {
public void setStones(Map<Stone, Position> stones);
- public void setHighlightedStones(Collection<Stone> stones);
public IEvent1<Position> getClickEvent();
}
diff --git a/src/jrummikub/view/ITable.java b/src/jrummikub/view/ITable.java
index 628b56f..e10f6f9 100644
--- a/src/jrummikub/view/ITable.java
+++ b/src/jrummikub/view/ITable.java
@@ -1,10 +1,8 @@
package jrummikub.view;
-import java.util.Collection;
import java.util.Map;
import jrummikub.model.Position;
-import jrummikub.model.Stone;
import jrummikub.model.StoneSet;
import jrummikub.util.IEvent1;
@@ -14,7 +12,6 @@ public interface ITable {
public void setRightPlayerName(String playerName);
public void setStoneSets(Map<StoneSet, Position> stoneSets);
- public void setHighlightedStones(Collection<Stone> stones);
public IEvent1<Position> getClickEvent();
} \ No newline at end of file
diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java
index a5f54b8..1fcc6dc 100644
--- a/src/jrummikub/view/IView.java
+++ b/src/jrummikub/view/IView.java
@@ -1,7 +1,10 @@
package jrummikub.view;
-public interface IView {
+import java.util.Collection;
+
+import jrummikub.model.Stone;
+public interface IView {
/**
* @return the table
*/
@@ -12,4 +15,5 @@ public interface IView {
*/
public IPlayerPanel getPlayerPanel();
+ public void setSelectedStones(Collection<Stone> stones);
} \ No newline at end of file
diff --git a/src/jrummikub/view/impl/Board.java b/src/jrummikub/view/impl/Board.java
index 2678204..555819e 100644
--- a/src/jrummikub/view/impl/Board.java
+++ b/src/jrummikub/view/impl/Board.java
@@ -25,7 +25,7 @@ public class Board extends JPanel implements IBoard {
private final static ImageIcon background = new ImageIcon(Board.class.getResource("/jrummikub/resource/wood.png"));
private Map<Stone, Position> stones = Collections.emptyMap();
- private Collection<Stone> highlightedStones = Collections.emptyList();
+ private Collection<Stone> selectedStones = Collections.emptyList();
private StonePainter stonePainter = new StonePainter(StonePainter.BOARD_SCALE);
@@ -70,7 +70,7 @@ public class Board extends JPanel implements IBoard {
for (Map.Entry<Stone, Position> entry : stones.entrySet()) {
stonePainter.paintStone(g, entry.getKey(), entry.getValue(),
- highlightedStones.contains(entry.getKey()));
+ selectedStones.contains(entry.getKey()));
}
}
@@ -80,9 +80,8 @@ public class Board extends JPanel implements IBoard {
repaint();
}
- @Override
- public void setHighlightedStones(Collection<Stone> stones) {
- highlightedStones = stones;
+ public void setSelectedStones(Collection<Stone> stones) {
+ selectedStones = stones;
repaint();
}
}
diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java
index 5c29e7e..55a06c3 100644
--- a/src/jrummikub/view/impl/PlayerPanel.java
+++ b/src/jrummikub/view/impl/PlayerPanel.java
@@ -16,7 +16,6 @@ import javax.swing.JProgressBar;
import jrummikub.util.Event;
import jrummikub.util.IEvent;
-import jrummikub.view.IBoard;
import jrummikub.view.IPlayerPanel;
@SuppressWarnings("serial")
@@ -37,7 +36,7 @@ public class PlayerPanel extends JPanel implements IPlayerPanel {
@Override
- public IBoard getBoard() {
+ public Board getBoard() {
return board;
}
diff --git a/src/jrummikub/view/impl/StonePainter.java b/src/jrummikub/view/impl/StonePainter.java
index 9bdca05..600a570 100644
--- a/src/jrummikub/view/impl/StonePainter.java
+++ b/src/jrummikub/view/impl/StonePainter.java
@@ -73,12 +73,20 @@ class StonePainter {
* @return position in grid coordinates
*/
public Position calculatePosition(int x, int y){
- float width = even(DEFAULT_WIDTH*scale);
- float height = (int)(DEFAULT_WIDTH*scale/ASPECT_RATIO);
+ float width = getStoneWidth();
+ float height = getStoneHeight();
return new Position(x/width, y/height);
}
+ public int getStoneWidth() {
+ return even(DEFAULT_WIDTH*scale);
+ }
+
+ public int getStoneHeight() {
+ return (int)(DEFAULT_WIDTH*scale/ASPECT_RATIO);
+ }
+
StonePainter(float scale) {
this.scale = scale;
}
@@ -199,8 +207,8 @@ class StonePainter {
public void paintStone(Graphics2D g, Stone stone, Position p, boolean highlighted) {
Color background = highlighted ? HIGHLIGHTED_COLOR : BACKGROUND_COLOR;
- int width = even(DEFAULT_WIDTH*scale);
- int height = (int)(DEFAULT_WIDTH*scale/ASPECT_RATIO);
+ int width = getStoneWidth();
+ int height = getStoneHeight();
int x = (int)(p.getX()*width);
int y = (int)(p.getY()*height);
diff --git a/src/jrummikub/view/impl/Table.java b/src/jrummikub/view/impl/Table.java
index 8e12569..a42a2a9 100644
--- a/src/jrummikub/view/impl/Table.java
+++ b/src/jrummikub/view/impl/Table.java
@@ -32,9 +32,10 @@ public class Table extends JPanel implements ITable {
private JPanel innerPanel;
private StonePainter stonePainter = new StonePainter(1);
+ private StonePainter selectedStonePainter = new StonePainter(1.2f);
private Map<StoneSet, Position> stoneSets = Collections.emptyMap();
- private Collection<Stone> highlightedStones = Collections.emptyList();
+ private Collection<Stone> selectedStones = Collections.emptyList();
private Event1<Position> clickEvent = new Event1<Position>();
@@ -60,9 +61,8 @@ public class Table extends JPanel implements ITable {
repaint();
}
- @Override
- public void setHighlightedStones(Collection<Stone> stones) {
- highlightedStones = stones;
+ public void setSelectedStones(Collection<Stone> stones) {
+ selectedStones = stones;
repaint();
}
@@ -109,7 +109,7 @@ public class Table extends JPanel implements ITable {
for (Stone stone : stoneSet) {
stonePainter.paintStone(g, stone, new Position(x, pos.getY()),
- highlightedStones.contains(stone));
+ selectedStones.contains(stone));
x++;
}
}
@@ -130,5 +130,26 @@ public class Table extends JPanel implements ITable {
for (Map.Entry<StoneSet, Position> stoneSet : stoneSets.entrySet()) {
paintStoneSet(g, stoneSet.getKey(), stoneSet.getValue());
}
+
+ int selectedStonesWidth = getWidth()*3/5-14;
+ int selectedStonesHeight = selectedStonePainter.getStoneHeight();
+ int selectedStonesX = getWidth() / 2 - selectedStonesWidth / 2;
+ int selectedStonesY = getHeight() - selectedStonesHeight - 12;
+
+ if (!selectedStones.isEmpty()) {
+ g.setColor(new Color(0, 0, 0, 0.3f));
+ g.fillRect(selectedStonesX-7, selectedStonesY-7, selectedStonesWidth + 14,
+ selectedStonesHeight + 14);
+
+ Graphics2D translatedG = (Graphics2D) g.create(selectedStonesX,
+ selectedStonesY, selectedStonesWidth, selectedStonesHeight);
+
+ float x = 0;
+
+ for (Stone stone : selectedStones) {
+ selectedStonePainter.paintStone(translatedG, stone, new Position(x, 0), false);
+ x++;
+ }
+ }
}
}
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index 1c1ab2d..4e38a56 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -3,9 +3,11 @@ package jrummikub.view.impl;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
+import java.util.Collection;
import javax.swing.JFrame;
+import jrummikub.model.Stone;
import jrummikub.view.IPlayerPanel;
import jrummikub.view.ITable;
import jrummikub.view.IView;
@@ -45,4 +47,10 @@ public class View extends JFrame implements IView {
setVisible(true);
}
+
+ @Override
+ public void setSelectedStones(Collection<Stone> stones) {
+ table.setSelectedStones(stones);
+ playerPanel.getBoard().setSelectedStones(stones);
+ }
}