Make StoneCollectionPanel opaque

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@163 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-05-06 01:46:10 +02:00
parent 794e3573f6
commit 367aa6a65c

View file

@ -25,6 +25,8 @@ import jrummikub.view.IStoneCollectionPanel;
class StoneCollectionPanel extends AbstractStonePanel implements
IStoneCollectionPanel {
private final static ImageIcon BACKGROUND = new ImageIcon(
HandPanel.class.getResource("/jrummikub/resource/felt.png"));
private final static ImageIcon DARK_BACKGROUND = new ImageIcon(
HandPanel.class.getResource("/jrummikub/resource/dark_felt.png"));
/**
* The width of the border of the collection panel
@ -37,7 +39,6 @@ class StoneCollectionPanel extends AbstractStonePanel implements
* Creates a new StoneCollection instance
*/
StoneCollectionPanel() {
setOpaque(false);
setBorder(new EmptyBorder(INSET, INSET, INSET, INSET));
addComponentListener(new ComponentAdapter() {
@ -54,26 +55,8 @@ class StoneCollectionPanel extends AbstractStonePanel implements
getStonePainter().setScale(height * StonePainter.HEIGHT_SCALE);
repaint();
/*
* 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
*
@ -106,16 +89,22 @@ class StoneCollectionPanel extends AbstractStonePanel implements
@Override
public void paintComponent(Graphics g1) {
for (int xpos = 0; xpos < getWidth(); xpos += BACKGROUND.getIconWidth()) {
for (int ypos = 0; ypos < getHeight(); ypos += BACKGROUND.getIconHeight()) {
BACKGROUND.paintIcon(this, g1, xpos, ypos);
}
}
int width = getStonePainter().getStoneWidth() * selectedStones.size() + 2
* INSET, height = getHeight();
int x = (getWidth() - width) / 2;
Graphics2D g = (Graphics2D) g1.create(x, 0, width, height);
if (!selectedStones.isEmpty()) {
for (int xpos = 0; xpos < getWidth(); xpos += BACKGROUND.getIconWidth()) {
for (int ypos = 0; ypos < getHeight(); ypos += BACKGROUND
for (int xpos = 0; xpos < width; xpos += DARK_BACKGROUND.getIconWidth()) {
for (int ypos = 0; ypos < height; ypos += DARK_BACKGROUND
.getIconHeight()) {
BACKGROUND.paintIcon(this, g, xpos, ypos);
DARK_BACKGROUND.paintIcon(this, g, xpos, ypos);
}
}