From 50f1d6c05ac0e943e670dae719b6371c7048e765 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Wed, 4 May 2011 23:28:39 +0200 Subject: 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 --- src/jrummikub/view/IHandPanel.java | 5 ++--- src/jrummikub/view/impl/AbstractStonePanel.java | 13 ++++++------- src/jrummikub/view/impl/HandPanel.java | 9 +++++---- src/jrummikub/view/impl/StoneCollectionPanel.java | 9 +++++---- src/jrummikub/view/impl/TablePanel.java | 8 ++++---- 5 files changed, 22 insertions(+), 22 deletions(-) (limited to 'src/jrummikub/view') 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 stones); + public void setStones(Iterable> 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 rangeClickEvent = new Event2(); private Event2 setClickEvent = new Event2(); - private Map stones = Collections.emptyMap(); + private Iterable> 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 entry : stones.entrySet()) { - Stone stone = entry.getKey(); - Position p = entry.getValue(); + for (Pair 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 stones) { + protected void setStones(Iterable> stones) { this.stones = stones; } @@ -134,7 +133,7 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel, * * @return the stones */ - protected Map getStones() { + protected Iterable> 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 entry : getStones().entrySet()) { - getStonePainter().paintStone(g, entry.getKey(), entry.getValue(), - selectedStones.contains(entry.getKey())); + for (Pair entry : getStones()) { + getStonePainter().paintStone(g, entry.getFirst(), entry.getSecond(), + selectedStones.contains(entry.getFirst())); } } @Override - public void setStones(Map stones) { + public void setStones(Iterable> 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 selectedStones) { this.selectedStones = selectedStones; - Map stones = new HashMap(); + List> stones = new ArrayList>(); float x = 0; for (Stone stone : selectedStones) { - stones.put(stone, new Position(x, 0)); + stones.add(new Pair(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> stoneSets) { - Map stones = new HashMap(); + List> stones = new ArrayList>(); for (Pair 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, new Position(x, y))); x++; } } -- cgit v1.2.3