Rescale table panel
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@96 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
9a07c68710
commit
14bb9dd4c2
2 changed files with 29 additions and 5 deletions
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
Reference in a new issue