summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub')
-rw-r--r--src/jrummikub/view/impl/StoneCollectionPanel.java24
-rw-r--r--src/jrummikub/view/impl/TablePanel.java91
2 files changed, 67 insertions, 48 deletions
diff --git a/src/jrummikub/view/impl/StoneCollectionPanel.java b/src/jrummikub/view/impl/StoneCollectionPanel.java
index 9548b3b..d74ef43 100644
--- a/src/jrummikub/view/impl/StoneCollectionPanel.java
+++ b/src/jrummikub/view/impl/StoneCollectionPanel.java
@@ -22,7 +22,6 @@ import jrummikub.view.IStoneCollectionPanel;
class StoneCollectionPanel extends AbstractStonePanel implements
IStoneCollectionPanel {
private final static int INSET = 7;
- private final static float STONE_SCALE = 1.1f;
private Collection<Stone> selectedStones = Collections.emptyList();
@@ -30,13 +29,29 @@ class StoneCollectionPanel extends AbstractStonePanel implements
* Creates a new StoneCollection instance
*/
StoneCollectionPanel() {
- super(STONE_SCALE);
-
setOpaque(false);
setVisible(false);
setBorder(new EmptyBorder(INSET, INSET, INSET, INSET));
}
+ private void rescale() {
+ setSize(getStonePainter().getStoneWidth() * selectedStones.size() + 2
+ * INSET, getStonePainter().getStoneHeight() + 2 * INSET);
+ }
+
+ /**
+ * Sets the height to paint the collected stones in
+ *
+ * @param height
+ * the height in pixels
+ */
+ void setStoneHeight(int height) {
+ getStonePainter().setScale(height * StonePainter.HEIGHT_SCALE);
+
+ rescale();
+ repaint();
+ }
+
/**
* Sets the stones to be shown in the collection
*
@@ -59,8 +74,7 @@ class StoneCollectionPanel extends AbstractStonePanel implements
if (selectedStones.isEmpty()) {
setVisible(false);
} else {
- setSize(getStonePainter().getStoneWidth() * selectedStones.size() + 2
- * INSET, getStonePainter().getStoneHeight() + 2 * INSET);
+ rescale();
setVisible(true);
repaint();
diff --git a/src/jrummikub/view/impl/TablePanel.java b/src/jrummikub/view/impl/TablePanel.java
index dbe5496..abbb867 100644
--- a/src/jrummikub/view/impl/TablePanel.java
+++ b/src/jrummikub/view/impl/TablePanel.java
@@ -39,6 +39,7 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
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 float COLLECTION_RATIO = 0.1f;
private final int COLLECTION_GAP = 5;
private JLabel leftPlayerLabel, topPlayerLabel, rightPlayerLabel;
@@ -111,6 +112,46 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
repaint();
}
+ /**
+ * Creates a new Table instance
+ */
+ TablePanel() {
+ setLayout(null);
+
+ leftPlayerLabel = new JLabel();
+ leftPlayerLabel.setForeground(Color.WHITE);
+ leftPlayerLabel.setHorizontalAlignment(JLabel.LEFT);
+ leftPlayerLabel.setHorizontalTextPosition(JLabel.LEFT);
+ add(leftPlayerLabel);
+
+ topPlayerLabel = new JLabel();
+ topPlayerLabel.setHorizontalAlignment(JLabel.CENTER);
+ topPlayerLabel.setHorizontalTextPosition(JLabel.CENTER);
+ topPlayerLabel.setVerticalAlignment(JLabel.TOP);
+ topPlayerLabel.setVerticalTextPosition(JLabel.TOP);
+ topPlayerLabel.setForeground(Color.WHITE);
+ add(topPlayerLabel);
+
+ rightPlayerLabel = new JLabel();
+ rightPlayerLabel.setForeground(Color.WHITE);
+ rightPlayerLabel.setHorizontalAlignment(JLabel.RIGHT);
+ rightPlayerLabel.setHorizontalTextPosition(JLabel.RIGHT);
+ add(rightPlayerLabel);
+
+ stoneCollection = new StoneCollectionPanel();
+ add(stoneCollection);
+
+ ComponentListener rescaleListener = new ComponentAdapter() {
+ @Override
+ public void componentResized(ComponentEvent e) {
+ rescale();
+ }
+ };
+
+ addComponentListener(rescaleListener);
+ stoneCollection.addComponentListener(rescaleListener);
+ }
+
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;
@@ -153,52 +194,14 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
float widthScale = width / (float) extent.getWidth()
* StonePainter.WIDTH_SCALE;
- float heightScale = height / (float) extent.getHeight()
- * StonePainter.HEIGHT_SCALE;
+ float heightScale = height * (1 - COLLECTION_RATIO)
+ / (float) extent.getHeight() * StonePainter.HEIGHT_SCALE;
getStonePainter().setScale(Math.min(widthScale, heightScale));
- repaint();
- }
-
- /**
- * Creates a new Table instance
- */
- TablePanel() {
- setLayout(null);
-
- leftPlayerLabel = new JLabel();
- leftPlayerLabel.setForeground(Color.WHITE);
- leftPlayerLabel.setHorizontalAlignment(JLabel.LEFT);
- leftPlayerLabel.setHorizontalTextPosition(JLabel.LEFT);
- add(leftPlayerLabel);
-
- topPlayerLabel = new JLabel();
- topPlayerLabel.setHorizontalAlignment(JLabel.CENTER);
- topPlayerLabel.setHorizontalTextPosition(JLabel.CENTER);
- topPlayerLabel.setVerticalAlignment(JLabel.TOP);
- topPlayerLabel.setVerticalTextPosition(JLabel.TOP);
- topPlayerLabel.setForeground(Color.WHITE);
- add(topPlayerLabel);
-
- rightPlayerLabel = new JLabel();
- rightPlayerLabel.setForeground(Color.WHITE);
- rightPlayerLabel.setHorizontalAlignment(JLabel.RIGHT);
- rightPlayerLabel.setHorizontalTextPosition(JLabel.RIGHT);
- add(rightPlayerLabel);
-
- stoneCollection = new StoneCollectionPanel();
- add(stoneCollection);
+ stoneCollection.setStoneHeight((int) (height * COLLECTION_RATIO));
- ComponentListener rescaleListener = new ComponentAdapter() {
- @Override
- public void componentResized(ComponentEvent e) {
- rescale();
- }
- };
-
- addComponentListener(rescaleListener);
- stoneCollection.addComponentListener(rescaleListener);
+ repaint();
}
protected boolean handleOtherClickEvent(Position pos) {
@@ -235,7 +238,9 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
Rectangle2D extent = calculateTableExtent();
return new Pair<Integer, Integer>((int) (width / 2 - extent.getCenterX()
- * stoneWidth), (int) (height / 2 - extent.getCenterY() * stoneHeight));
+ * stoneWidth),
+ (int) ((height * (1 - COLLECTION_RATIO)) / 2 - extent.getCenterY()
+ * stoneHeight));
}
private void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos) {