From a274c2b02ed0a5baa6da61d36f4d16e7b10d3dc1 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 3 May 2011 21:55:14 +0200 Subject: Rescale collection; add bottom margin to table for collection git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@99 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/impl/StoneCollectionPanel.java | 24 ++++-- src/jrummikub/view/impl/TablePanel.java | 91 ++++++++++++----------- 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 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((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) { -- cgit v1.2.3