diff options
Diffstat (limited to 'src/jrummikub/view/impl/StoneCollectionPanel.java')
-rw-r--r-- | src/jrummikub/view/impl/StoneCollectionPanel.java | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/jrummikub/view/impl/StoneCollectionPanel.java b/src/jrummikub/view/impl/StoneCollectionPanel.java index e4ca1c6..8729170 100644 --- a/src/jrummikub/view/impl/StoneCollectionPanel.java +++ b/src/jrummikub/view/impl/StoneCollectionPanel.java @@ -6,6 +6,8 @@ import java.awt.Graphics2D; import java.awt.Insets; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import javax.swing.border.EmptyBorder; @@ -17,7 +19,8 @@ import jrummikub.view.IStoneCollectionPanel; * Implementation of the stone collection (selection) */ @SuppressWarnings("serial") -class StoneCollectionPanel extends AbstractStonePanel implements IStoneCollectionPanel { +class StoneCollectionPanel extends AbstractStonePanel implements + IStoneCollectionPanel { private final static int INSET = 7; private final static float STONE_SCALE = 1.1f; @@ -37,17 +40,27 @@ class StoneCollectionPanel extends AbstractStonePanel implements IStoneCollectio /** * Sets the stones to be shown in the collection * - * @param stones + * @param selectedStones * the selected stones */ - void setSelectedStones(Collection<Stone> stones) { - selectedStones = stones; + void setSelectedStones(Collection<Stone> selectedStones) { + this.selectedStones = selectedStones; - if (stones.isEmpty()) { + Map<Stone, Position> stones = new HashMap<Stone, Position>(); + float x = 0; + + for (Stone stone : selectedStones) { + stones.put(stone, new Position(x, 0)); + x += stone.getWidth(); + } + + setStones(stones); + + if (selectedStones.isEmpty()) { setVisible(false); } else { - setSize(getStonePainter().getStoneWidth() * stones.size() + 2 * INSET, - getStonePainter().getStoneHeight() + 2 * INSET); + setSize(getStonePainter().getStoneWidth() * selectedStones.size() + 2 + * INSET, getStonePainter().getStoneHeight() + 2 * INSET); setVisible(true); repaint(); |