1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
package jrummikub.view.impl;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.util.Collections;
import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.model.StoneSet;
import jrummikub.view.ITable;
@SuppressWarnings("serial")
public class Table extends JPanel implements ITable {
private final static ImageIcon background = new ImageIcon(Board.class.getResource("/jrummikub/resource/felt.png"));
private JLabel leftPlayerLabel, topPlayerLabel, rightPlayerLabel;
private JPanel innerPanel;
private StonePainter stonePainter = new StonePainter(1);
private Map<StoneSet, Position> stoneSets = Collections.emptyMap();
@Override
public void setLeftPlayerName(String playerName) {
leftPlayerLabel.setText(playerName);
}
@Override
public void setTopPlayerName(String playerName) {
topPlayerLabel.setText(playerName);
}
@Override
public void setRightPlayerName(String playerName) {
rightPlayerLabel.setText(playerName);
}
@Override
public void setStoneSets(Map<StoneSet, Position> stoneSets) {
this.stoneSets = stoneSets;
}
Table() {
super(true); // set double buffered
setLayout(new BorderLayout());
leftPlayerLabel = new JLabel();
leftPlayerLabel.setForeground(Color.WHITE);
add(leftPlayerLabel, BorderLayout.WEST);
topPlayerLabel = new JLabel();
topPlayerLabel.setHorizontalAlignment(JLabel.CENTER);
topPlayerLabel.setHorizontalTextPosition(JLabel.CENTER);
topPlayerLabel.setForeground(Color.WHITE);
add(topPlayerLabel, BorderLayout.NORTH);
rightPlayerLabel = new JLabel();
rightPlayerLabel.setForeground(Color.WHITE);
add(rightPlayerLabel, BorderLayout.EAST);
innerPanel = new JPanel();
innerPanel.setOpaque(false);
add(innerPanel, BorderLayout.CENTER);
}
@Override
protected void paintComponent(Graphics g1) {
Graphics2D g = (Graphics2D)g1;
for(int x = 0; x < getWidth(); x += background.getIconWidth()) {
for(int y = 0; y < getHeight(); y += background.getIconHeight()) {
background.paintIcon(this, g, x, y);
}
}
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
for (Map.Entry<StoneSet, Position> stoneSet : stoneSets.entrySet()) {
stonePainter.paintStoneSet(g, stoneSet.getKey(), stoneSet.getValue());
}
}
}
|