summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/model/StoneTray.java2
-rw-r--r--src/jrummikub/view/impl/TablePanel.java32
2 files changed, 29 insertions, 5 deletions
diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java
index 176c5f0..21412a9 100644
--- a/src/jrummikub/model/StoneTray.java
+++ b/src/jrummikub/model/StoneTray.java
@@ -1,9 +1,7 @@
package jrummikub.model;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import jrummikub.util.Pair;
diff --git a/src/jrummikub/view/impl/TablePanel.java b/src/jrummikub/view/impl/TablePanel.java
index 6a91b41..02d67dc 100644
--- a/src/jrummikub/view/impl/TablePanel.java
+++ b/src/jrummikub/view/impl/TablePanel.java
@@ -32,7 +32,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
private final static ImageIcon background = new ImageIcon(
HandPanel.class.getResource("/jrummikub/resource/felt.png"));
- private final static float DEFAULT_SCALE = 1;
+ private final static float MIN_VISIBLE_WIDTH = 15;
+ private final static float MIN_VISIBLE_HEIGHT = 7.5f;
private final static float CONNECTOR_WIDTH = 0.25f;
private final int COLLECTION_GAP = 5;
@@ -117,14 +118,39 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
stoneCollection.setLocation(x + width / 2 - stoneCollection.getWidth() / 2,
y + height - stoneCollection.getHeight() - COLLECTION_GAP);
+
+ float minx = -MIN_VISIBLE_WIDTH / 2, maxx = MIN_VISIBLE_WIDTH / 2;
+ float miny = -MIN_VISIBLE_HEIGHT / 2, maxy = MIN_VISIBLE_HEIGHT / 2;
+
+ for (Map.Entry<StoneSet, Position> entry : stoneSets.entrySet()) {
+ Position p = entry.getValue();
+ StoneSet stoneSet = entry.getKey();
+
+ if (p.getX() < minx)
+ minx = p.getX();
+
+ if (p.getY() < miny)
+ miny = p.getY();
+
+ if (p.getX() + stoneSet.size() > maxx)
+ maxx = p.getX() + stoneSet.size();
+
+ if (p.getY() + 1 > maxy)
+ maxy = p.getY() + 1;
+ }
+
+ float widthScale = width / (maxx - minx) * StonePainter.WIDTH_SCALE;
+ float heightScale = height / (maxy - miny) * StonePainter.HEIGHT_SCALE;
+
+ getStonePainter().setScale(Math.min(widthScale, heightScale));
+
+ repaint();
}
/**
* Creates a new Table instance
*/
TablePanel() {
- super(DEFAULT_SCALE);
-
setLayout(null);
leftPlayerLabel = new JLabel();