summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/TablePanel.java
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-05-03 21:34:59 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-05-03 21:34:59 +0200
commit51f70cafe316a1284db82a4cfb3c09cba8c12293 (patch)
tree56033af3432746f9c61e9ee04de5ce9c9991aeb9 /src/jrummikub/view/impl/TablePanel.java
parent2aeedc62418ab7816887f20e4ccb461fe6a0fcc0 (diff)
downloadJRummikub-51f70cafe316a1284db82a4cfb3c09cba8c12293.tar
JRummikub-51f70cafe316a1284db82a4cfb3c09cba8c12293.zip
Translate table origin
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@98 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view/impl/TablePanel.java')
-rw-r--r--src/jrummikub/view/impl/TablePanel.java62
1 files changed, 48 insertions, 14 deletions
diff --git a/src/jrummikub/view/impl/TablePanel.java b/src/jrummikub/view/impl/TablePanel.java
index 02d67dc..dbe5496 100644
--- a/src/jrummikub/view/impl/TablePanel.java
+++ b/src/jrummikub/view/impl/TablePanel.java
@@ -8,6 +8,7 @@ import java.awt.RenderingHints;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
+import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.util.Collection;
import java.util.Collections;
@@ -21,6 +22,7 @@ import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.model.StoneSet;
import jrummikub.util.Event1;
+import jrummikub.util.Pair;
import jrummikub.view.IStoneCollectionPanel;
import jrummikub.view.ITablePanel;
@@ -34,6 +36,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
private final static float MIN_VISIBLE_WIDTH = 15;
private final static float MIN_VISIBLE_HEIGHT = 7.5f;
+ private final static float HORIZONTAL_MARGIN = 1.5f;
+ private final static float VERTICAL_MARGIN = 1;
private final static float CONNECTOR_WIDTH = 0.25f;
private final int COLLECTION_GAP = 5;
@@ -107,18 +111,7 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
repaint();
}
- private void rescale() {
- Insets insets = getInsets();
- int x = insets.left, y = insets.top, width = getWidth() - insets.left
- - insets.right, height = getHeight() - insets.top - insets.bottom;
-
- leftPlayerLabel.setBounds(x, y, width, height);
- topPlayerLabel.setBounds(x, y, width, height);
- rightPlayerLabel.setBounds(x, y, width, height);
-
- stoneCollection.setLocation(x + width / 2 - stoneCollection.getWidth() / 2,
- y + height - stoneCollection.getHeight() - COLLECTION_GAP);
-
+ private Rectangle2D calculateTableExtent() {
float minx = -MIN_VISIBLE_WIDTH / 2, maxx = MIN_VISIBLE_WIDTH / 2;
float miny = -MIN_VISIBLE_HEIGHT / 2, maxy = MIN_VISIBLE_HEIGHT / 2;
@@ -139,8 +132,29 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
maxy = p.getY() + 1;
}
- float widthScale = width / (maxx - minx) * StonePainter.WIDTH_SCALE;
- float heightScale = height / (maxy - miny) * StonePainter.HEIGHT_SCALE;
+ return new Rectangle2D.Float(minx - HORIZONTAL_MARGIN, miny
+ - VERTICAL_MARGIN, maxx - minx + 2 * HORIZONTAL_MARGIN, maxy - miny + 2
+ * VERTICAL_MARGIN);
+ }
+
+ private void rescale() {
+ Insets insets = getInsets();
+ int x = insets.left, y = insets.top, width = getWidth() - insets.left
+ - insets.right, height = getHeight() - insets.top - insets.bottom;
+
+ leftPlayerLabel.setBounds(x, y, width, height);
+ topPlayerLabel.setBounds(x, y, width, height);
+ rightPlayerLabel.setBounds(x, y, width, height);
+
+ stoneCollection.setLocation(x + width / 2 - stoneCollection.getWidth() / 2,
+ y + height - stoneCollection.getHeight() - COLLECTION_GAP);
+
+ Rectangle2D extent = calculateTableExtent();
+
+ float widthScale = width / (float) extent.getWidth()
+ * StonePainter.WIDTH_SCALE;
+ float heightScale = height / (float) extent.getHeight()
+ * StonePainter.HEIGHT_SCALE;
getStonePainter().setScale(Math.min(widthScale, heightScale));
@@ -211,6 +225,19 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
return false;
}
+ @Override
+ protected Pair<Integer, Integer> getTranslation() {
+ Insets insets = getInsets();
+ int width = getWidth() - insets.left - insets.right, height = getHeight()
+ - insets.top - insets.bottom;
+ int stoneWidth = getStonePainter().getStoneWidth(), stoneHeight = getStonePainter()
+ .getStoneHeight();
+ Rectangle2D extent = calculateTableExtent();
+
+ return new Pair<Integer, Integer>((int) (width / 2 - extent.getCenterX()
+ * stoneWidth), (int) (height / 2 - extent.getCenterY() * stoneHeight));
+ }
+
private void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos) {
float x = pos.getX();
int width = getStonePainter().getStoneWidth(), height = getStonePainter()
@@ -241,11 +268,18 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
}
}
+ AffineTransform oldTransform = g.getTransform();
+
+ Pair<Integer, Integer> translation = getTranslation();
+ g.translate(translation.getFirst(), translation.getSecond());
+
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
for (Map.Entry<StoneSet, Position> entry : stoneSets.entrySet()) {
paintStoneSet(g, entry.getKey(), entry.getValue());
}
+
+ g.setTransform(oldTransform);
}
}