diff options
author | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-05-04 23:28:39 +0200 |
---|---|---|
committer | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-05-04 23:28:39 +0200 |
commit | 50f1d6c05ac0e943e670dae719b6371c7048e765 (patch) | |
tree | ed774a01903815f5348bbf2b2c40250b5227f450 /src/jrummikub/view | |
parent | e2f82f3f28a0872ed626439809a292e701c9b01e (diff) | |
download | JRummikub-50f1d6c05ac0e943e670dae719b6371c7048e765.tar JRummikub-50f1d6c05ac0e943e670dae719b6371c7048e765.zip |
Changed view implementation to use Iterable of Pairs
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@129 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view')
-rw-r--r-- | src/jrummikub/view/IHandPanel.java | 5 | ||||
-rw-r--r-- | src/jrummikub/view/impl/AbstractStonePanel.java | 13 | ||||
-rw-r--r-- | src/jrummikub/view/impl/HandPanel.java | 9 | ||||
-rw-r--r-- | src/jrummikub/view/impl/StoneCollectionPanel.java | 9 | ||||
-rw-r--r-- | src/jrummikub/view/impl/TablePanel.java | 8 |
5 files changed, 22 insertions, 22 deletions
diff --git a/src/jrummikub/view/IHandPanel.java b/src/jrummikub/view/IHandPanel.java index 23cd0ca..a58edab 100644 --- a/src/jrummikub/view/IHandPanel.java +++ b/src/jrummikub/view/IHandPanel.java @@ -1,9 +1,8 @@ package jrummikub.view; -import java.util.Map; - import jrummikub.model.Position; import jrummikub.model.Stone; +import jrummikub.util.Pair; /** * The view for a player's hand that displays his stones @@ -15,5 +14,5 @@ public interface IHandPanel extends IStonePanel, IClickable { * @param stones * the stones */ - public void setStones(Map<Stone, Position> stones); + public void setStones(Iterable<Pair<Stone, Position>> stones); } diff --git a/src/jrummikub/view/impl/AbstractStonePanel.java b/src/jrummikub/view/impl/AbstractStonePanel.java index e858662..0c64305 100644 --- a/src/jrummikub/view/impl/AbstractStonePanel.java +++ b/src/jrummikub/view/impl/AbstractStonePanel.java @@ -5,7 +5,6 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.geom.Rectangle2D; import java.util.Collections; -import java.util.Map; import javax.swing.JPanel; @@ -30,7 +29,7 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel, private Event2<Stone, Boolean> rangeClickEvent = new Event2<Stone, Boolean>(); private Event2<Stone, Boolean> setClickEvent = new Event2<Stone, Boolean>(); - private Map<Stone, Position> stones = Collections.emptyMap(); + private Iterable<Pair<Stone, Position>> stones = Collections.emptySet(); /** * @return the stone painter @@ -98,9 +97,9 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel, } private Stone getStoneAt(Position pos) { - for (Map.Entry<Stone, Position> entry : stones.entrySet()) { - Stone stone = entry.getKey(); - Position p = entry.getValue(); + for (Pair<Stone, Position> entry : stones) { + Stone stone = entry.getFirst(); + Position p = entry.getSecond(); Rectangle2D rect = new Rectangle2D.Float(p.getX(), p.getY(), 1, 1); if (rect.contains(pos.getX(), pos.getY())) @@ -116,7 +115,7 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel, * @param stones * the stones and positions */ - protected void setStones(Map<Stone, Position> stones) { + protected void setStones(Iterable<Pair<Stone, Position>> stones) { this.stones = stones; } @@ -134,7 +133,7 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel, * * @return the stones */ - protected Map<Stone, Position> getStones() { + protected Iterable<Pair<Stone, Position>> getStones() { return stones; } diff --git a/src/jrummikub/view/impl/HandPanel.java b/src/jrummikub/view/impl/HandPanel.java index 0533181..a2d643c 100644 --- a/src/jrummikub/view/impl/HandPanel.java +++ b/src/jrummikub/view/impl/HandPanel.java @@ -18,6 +18,7 @@ import javax.swing.border.MatteBorder; import jrummikub.model.Position; import jrummikub.model.Stone; +import jrummikub.util.Pair; import jrummikub.view.IHandPanel; /** @@ -96,14 +97,14 @@ class HandPanel extends AbstractStonePanel implements IHandPanel { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - for (Map.Entry<Stone, Position> entry : getStones().entrySet()) { - getStonePainter().paintStone(g, entry.getKey(), entry.getValue(), - selectedStones.contains(entry.getKey())); + for (Pair<Stone, Position> entry : getStones()) { + getStonePainter().paintStone(g, entry.getFirst(), entry.getSecond(), + selectedStones.contains(entry.getFirst())); } } @Override - public void setStones(Map<Stone, Position> stones) { + public void setStones(Iterable<Pair<Stone, Position>> stones) { super.setStones(stones); repaint(); } diff --git a/src/jrummikub/view/impl/StoneCollectionPanel.java b/src/jrummikub/view/impl/StoneCollectionPanel.java index d74ef43..253160c 100644 --- a/src/jrummikub/view/impl/StoneCollectionPanel.java +++ b/src/jrummikub/view/impl/StoneCollectionPanel.java @@ -4,15 +4,16 @@ import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; -import java.util.Map; +import java.util.List; import javax.swing.border.EmptyBorder; import jrummikub.model.Position; import jrummikub.model.Stone; +import jrummikub.util.Pair; import jrummikub.view.IStoneCollectionPanel; /** @@ -61,11 +62,11 @@ class StoneCollectionPanel extends AbstractStonePanel implements void setSelectedStones(Collection<Stone> selectedStones) { this.selectedStones = selectedStones; - Map<Stone, Position> stones = new HashMap<Stone, Position>(); + List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(); float x = 0; for (Stone stone : selectedStones) { - stones.put(stone, new Position(x, 0)); + stones.add(new Pair<Stone, Position>(stone, new Position(x, 0))); x++; } diff --git a/src/jrummikub/view/impl/TablePanel.java b/src/jrummikub/view/impl/TablePanel.java index f400fac..080d476 100644 --- a/src/jrummikub/view/impl/TablePanel.java +++ b/src/jrummikub/view/impl/TablePanel.java @@ -10,10 +10,10 @@ import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; -import java.util.Map; +import java.util.List; import javax.swing.ImageIcon; import javax.swing.JLabel; @@ -78,13 +78,13 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { @Override public void setStoneSets(Iterable<Pair<StoneSet, Position>> stoneSets) { - Map<Stone, Position> stones = new HashMap<Stone, Position>(); + List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(); for (Pair<StoneSet, Position> entry : stoneSets) { float x = entry.getSecond().getX(), y = entry.getSecond().getY(); for (Stone stone : entry.getFirst()) { - stones.put(stone, new Position(x, y)); + stones.add(new Pair<Stone, Position>(stone, new Position(x, y))); x++; } } |