From dd46130c8c8718fd108362d8133b6ca9e8c78325 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 30 Apr 2011 22:12:00 +0200 Subject: Add highlighting to board and table git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@37 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/IBoard.java | 2 ++ src/jrummikub/view/ITable.java | 5 +++++ src/jrummikub/view/impl/Board.java | 13 +++++++++++-- src/jrummikub/view/impl/Table.java | 15 ++++++++++++--- 4 files changed, 30 insertions(+), 5 deletions(-) (limited to 'src/jrummikub/view') diff --git a/src/jrummikub/view/IBoard.java b/src/jrummikub/view/IBoard.java index 237518f..deb2735 100644 --- a/src/jrummikub/view/IBoard.java +++ b/src/jrummikub/view/IBoard.java @@ -1,5 +1,6 @@ package jrummikub.view; +import java.util.Collection; import java.util.Map; import jrummikub.model.Position; @@ -8,6 +9,7 @@ import jrummikub.util.IEvent1; public interface IBoard { public void setStones(Map stones); + public void setHighlightedStones(Collection stones); public IEvent1 getClickEvent(); } diff --git a/src/jrummikub/view/ITable.java b/src/jrummikub/view/ITable.java index 9781f78..628b56f 100644 --- a/src/jrummikub/view/ITable.java +++ b/src/jrummikub/view/ITable.java @@ -1,8 +1,10 @@ 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; @@ -10,6 +12,9 @@ public interface ITable { public void setLeftPlayerName(String playerName); public void setTopPlayerName(String playerName); public void setRightPlayerName(String playerName); + public void setStoneSets(Map stoneSets); + public void setHighlightedStones(Collection stones); + public IEvent1 getClickEvent(); } \ No newline at end of file diff --git a/src/jrummikub/view/impl/Board.java b/src/jrummikub/view/impl/Board.java index 82794b3..be5ec26 100644 --- a/src/jrummikub/view/impl/Board.java +++ b/src/jrummikub/view/impl/Board.java @@ -7,6 +7,7 @@ import java.awt.Insets; import java.awt.RenderingHints; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -24,6 +25,8 @@ public class Board extends JPanel implements IBoard { private final static ImageIcon background = new ImageIcon(Board.class.getResource("/jrummikub/resource/wood.png")); private Map stones = Collections.emptyMap(); + private Collection highlightedStones = Collections.emptyList(); + private StonePainter stonePainter = new StonePainter(StonePainter.BOARD_SCALE); private Event1 clickEvent = new Event1(); @@ -65,8 +68,9 @@ public class Board extends JPanel implements IBoard { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - for (Map.Entry stone : stones.entrySet()) { - stonePainter.paintStone(g, stone.getKey(), stone.getValue(), false); + for (Map.Entry entry : stones.entrySet()) { + stonePainter.paintStone(g, entry.getKey(), entry.getValue(), + highlightedStones.contains(entry.getKey())); } } @@ -74,4 +78,9 @@ public class Board extends JPanel implements IBoard { public void setStones(Map stones) { this.stones = stones; } + + @Override + public void setHighlightedStones(Collection stones) { + highlightedStones = stones; + } } diff --git a/src/jrummikub/view/impl/Table.java b/src/jrummikub/view/impl/Table.java index e4601c5..653167e 100644 --- a/src/jrummikub/view/impl/Table.java +++ b/src/jrummikub/view/impl/Table.java @@ -8,6 +8,7 @@ import java.awt.Insets; import java.awt.RenderingHints; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -33,6 +34,7 @@ public class Table extends JPanel implements ITable { private StonePainter stonePainter = new StonePainter(1); private Map stoneSets = Collections.emptyMap(); + private Collection highlightedStones = Collections.emptyList(); private Event1 clickEvent = new Event1(); @@ -57,6 +59,12 @@ public class Table extends JPanel implements ITable { this.stoneSets = stoneSets; } + @Override + public void setHighlightedStones(Collection stones) { + highlightedStones = stones; + + } + @Override public IEvent1 getClickEvent() { return clickEvent; @@ -97,9 +105,10 @@ public class Table extends JPanel implements ITable { public void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos) { float x = pos.getX(); - - for(Stone stone : stoneSet){ - stonePainter.paintStone(g, stone, new Position(x, pos.getY()), false); + + for (Stone stone : stoneSet) { + stonePainter.paintStone(g, stone, new Position(x, pos.getY()), + highlightedStones.contains(stone)); x++; } } -- cgit v1.2.3