Rework collection border
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@164 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
367aa6a65c
commit
d6fc29d326
2 changed files with 13 additions and 17 deletions
|
@ -2,16 +2,15 @@ package jrummikub.view.impl;
|
||||||
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Insets;
|
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.awt.geom.RoundRectangle2D;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.border.EmptyBorder;
|
|
||||||
|
|
||||||
import jrummikub.model.Position;
|
import jrummikub.model.Position;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
|
@ -28,10 +27,7 @@ class StoneCollectionPanel extends AbstractStonePanel implements
|
||||||
HandPanel.class.getResource("/jrummikub/resource/felt.png"));
|
HandPanel.class.getResource("/jrummikub/resource/felt.png"));
|
||||||
private final static ImageIcon DARK_BACKGROUND = new ImageIcon(
|
private final static ImageIcon DARK_BACKGROUND = new ImageIcon(
|
||||||
HandPanel.class.getResource("/jrummikub/resource/dark_felt.png"));
|
HandPanel.class.getResource("/jrummikub/resource/dark_felt.png"));
|
||||||
/**
|
private final static float INSET_RATIO = 0.1f;
|
||||||
* The width of the border of the collection panel
|
|
||||||
*/
|
|
||||||
public final static int INSET = 7;
|
|
||||||
|
|
||||||
private Collection<Stone> selectedStones = Collections.emptyList();
|
private Collection<Stone> selectedStones = Collections.emptyList();
|
||||||
|
|
||||||
|
@ -39,8 +35,6 @@ class StoneCollectionPanel extends AbstractStonePanel implements
|
||||||
* Creates a new StoneCollection instance
|
* Creates a new StoneCollection instance
|
||||||
*/
|
*/
|
||||||
StoneCollectionPanel() {
|
StoneCollectionPanel() {
|
||||||
setBorder(new EmptyBorder(INSET, INSET, INSET, INSET));
|
|
||||||
|
|
||||||
addComponentListener(new ComponentAdapter() {
|
addComponentListener(new ComponentAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
|
@ -50,8 +44,7 @@ class StoneCollectionPanel extends AbstractStonePanel implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rescale() {
|
private void rescale() {
|
||||||
Insets insets = getInsets();
|
int height = getHeight() - 2 * (int) (getHeight() * INSET_RATIO);
|
||||||
int height = getHeight() - insets.top - insets.bottom;
|
|
||||||
|
|
||||||
getStonePainter().setScale(height * StonePainter.HEIGHT_SCALE);
|
getStonePainter().setScale(height * StonePainter.HEIGHT_SCALE);
|
||||||
repaint();
|
repaint();
|
||||||
|
@ -80,11 +73,12 @@ class StoneCollectionPanel extends AbstractStonePanel implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Pair<Integer, Integer> getTranslation() {
|
protected Pair<Integer, Integer> getTranslation() {
|
||||||
|
int inset = (int) (getHeight() * INSET_RATIO);
|
||||||
int width = getStonePainter().getStoneWidth() * selectedStones.size() + 2
|
int width = getStonePainter().getStoneWidth() * selectedStones.size() + 2
|
||||||
* INSET;
|
* inset;
|
||||||
int x = (getWidth() - width) / 2;
|
int x = (getWidth() - width) / 2;
|
||||||
|
|
||||||
return new Pair<Integer, Integer>(x + INSET, INSET);
|
return new Pair<Integer, Integer>(x + inset, inset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,10 +89,13 @@ class StoneCollectionPanel extends AbstractStonePanel implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int inset = (int) (getHeight() * INSET_RATIO);
|
||||||
int width = getStonePainter().getStoneWidth() * selectedStones.size() + 2
|
int width = getStonePainter().getStoneWidth() * selectedStones.size() + 2
|
||||||
* INSET, height = getHeight();
|
* inset, height = getHeight();
|
||||||
int x = (getWidth() - width) / 2;
|
int x = (getWidth() - width) / 2;
|
||||||
Graphics2D g = (Graphics2D) g1.create(x, 0, width, height);
|
Graphics2D g = (Graphics2D) g1.create(x, 0, width, height);
|
||||||
|
g.setClip(new RoundRectangle2D.Float(0, 0, width, height, inset * 1.5f,
|
||||||
|
inset * 1.5f));
|
||||||
|
|
||||||
if (!selectedStones.isEmpty()) {
|
if (!selectedStones.isEmpty()) {
|
||||||
for (int xpos = 0; xpos < width; xpos += DARK_BACKGROUND.getIconWidth()) {
|
for (int xpos = 0; xpos < width; xpos += DARK_BACKGROUND.getIconWidth()) {
|
||||||
|
@ -108,7 +105,7 @@ class StoneCollectionPanel extends AbstractStonePanel implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g.translate(INSET, INSET);
|
g.translate(inset, inset);
|
||||||
|
|
||||||
float xpos = 0;
|
float xpos = 0;
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
private final static float HORIZONTAL_MARGIN = 1.5f;
|
private final static float HORIZONTAL_MARGIN = 1.5f;
|
||||||
private final static float VERTICAL_MARGIN = 1;
|
private final static float VERTICAL_MARGIN = 1;
|
||||||
private final static float CONNECTOR_WIDTH = 0.25f;
|
private final static float CONNECTOR_WIDTH = 0.25f;
|
||||||
private final float COLLECTION_RATIO = 0.1f;
|
private final float COLLECTION_RATIO = 0.12f;
|
||||||
private final int COLLECTION_GAP = 5;
|
private final int COLLECTION_GAP = 5;
|
||||||
|
|
||||||
private JLabel leftPlayerLabel, topPlayerLabel, rightPlayerLabel;
|
private JLabel leftPlayerLabel, topPlayerLabel, rightPlayerLabel;
|
||||||
|
@ -191,8 +191,7 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
|
|
||||||
getStonePainter().setScale(Math.min(widthScale, heightScale));
|
getStonePainter().setScale(Math.min(widthScale, heightScale));
|
||||||
|
|
||||||
int collectionHeight = (int) (height * COLLECTION_RATIO) + 2
|
int collectionHeight = (int) (height * COLLECTION_RATIO);
|
||||||
* StoneCollectionPanel.INSET;
|
|
||||||
stoneCollection
|
stoneCollection
|
||||||
.setBounds(x, y + height - collectionHeight - COLLECTION_GAP, width,
|
.setBounds(x, y + height - collectionHeight - COLLECTION_GAP, width,
|
||||||
collectionHeight);
|
collectionHeight);
|
||||||
|
|
Reference in a new issue