summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
authorBennet Gerlach <bennet_gerlach@web.de>2011-05-03 21:08:56 +0200
committerBennet Gerlach <bennet_gerlach@web.de>2011-05-03 21:08:56 +0200
commit14bb9dd4c2dbe0bcab9d599773138b94b3a09181 (patch)
treeb67d2544ab4277d035ed1089600075b10476d26f /src/jrummikub
parent9a07c68710f3bd1248cb5ddd3a0cc5db7e27d5b5 (diff)
downloadJRummikub-14bb9dd4c2dbe0bcab9d599773138b94b3a09181.tar
JRummikub-14bb9dd4c2dbe0bcab9d599773138b94b3a09181.zip
Rescale table panel
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@96 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub')
-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();