summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/TablePanel.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view/impl/TablePanel.java')
-rw-r--r--src/jrummikub/view/impl/TablePanel.java32
1 files changed, 29 insertions, 3 deletions
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();