|
|
|
@ -25,8 +25,8 @@ import jrummikub.view.IPlayerPanel;
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
|
|
class PlayerPanel extends JPanel implements IPlayerPanel {
|
|
|
|
|
private final static int SIDE_PANEL_INSET = 15;
|
|
|
|
|
private final static int SIDE_PANEL_SEPARATOR = 10;
|
|
|
|
|
private final static int SIDE_PANEL_INSET = 10;
|
|
|
|
|
private final static int SIDE_PANEL_SEPARATOR = 5;
|
|
|
|
|
private final static float SIDE_PANEL_FIRST_LINE_HEIGHT = 0.375f;
|
|
|
|
|
private final static int SIDE_PANEL_MAX_WIDTH = 180;
|
|
|
|
|
private final static float HAND_ROW_BUTTON_RATIO = 0.03f;
|
|
|
|
@ -39,6 +39,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|
|
|
|
private JPanel leftPanel, rightPanel;
|
|
|
|
|
|
|
|
|
|
private JLabel currentPlayerNameLabel;
|
|
|
|
|
private JLabel hasLaidOutLabel;
|
|
|
|
|
private JButton sortByGroupsButton;
|
|
|
|
|
private JButton sortByRunsButton;
|
|
|
|
|
private JButton handRowUpButton;
|
|
|
|
@ -48,7 +49,6 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|
|
|
|
private JButton keepStonesButton;
|
|
|
|
|
private JButton redealButton;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Event sortByGroupsEvent = new Event();
|
|
|
|
|
private Event sortByRunsEvent = new Event();
|
|
|
|
|
private Event endTurnEvent = new Event();
|
|
|
|
@ -68,6 +68,18 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|
|
|
|
currentPlayerNameLabel.setText(playerName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setCurrentPlayerColor(Color color) {
|
|
|
|
|
currentPlayerNameLabel.setIcon(ImageUtil.createColorIcon(color, 12, 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setHasLaidOut(boolean hasLaidOut) {
|
|
|
|
|
if (hasLaidOut) {
|
|
|
|
|
hasLaidOutLabel.setText("ist rausgekommen");
|
|
|
|
|
} else {
|
|
|
|
|
hasLaidOutLabel.setText("ist nicht rausgekommen");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setTimeLeft(int time) {
|
|
|
|
|
timeBar.setValue(time);
|
|
|
|
@ -108,19 +120,25 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|
|
|
|
|
|
|
|
|
currentPlayerNameLabel = new JLabel();
|
|
|
|
|
currentPlayerNameLabel.setHorizontalAlignment(JLabel.CENTER);
|
|
|
|
|
currentPlayerNameLabel.setHorizontalTextPosition(JLabel.CENTER);
|
|
|
|
|
currentPlayerNameLabel.setVerticalAlignment(JLabel.CENTER);
|
|
|
|
|
currentPlayerNameLabel.setVerticalTextPosition(JLabel.CENTER);
|
|
|
|
|
leftPanel.add(currentPlayerNameLabel);
|
|
|
|
|
|
|
|
|
|
sortByGroupsButton = createButton(leftPanel, "<html><center>Nach Sammlungen sortieren", new ActionListener() {
|
|
|
|
|
hasLaidOutLabel = new JLabel();
|
|
|
|
|
hasLaidOutLabel.setHorizontalAlignment(JLabel.CENTER);
|
|
|
|
|
hasLaidOutLabel.setVerticalAlignment(JLabel.CENTER);
|
|
|
|
|
leftPanel.add(hasLaidOutLabel);
|
|
|
|
|
|
|
|
|
|
sortByGroupsButton = createButton(leftPanel,
|
|
|
|
|
"<html><center>Nach Sammlungen sortieren",
|
|
|
|
|
new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent arg0) {
|
|
|
|
|
sortByGroupsEvent.emit();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
sortByRunsButton = createButton(leftPanel, "<html><center>Nach Reihen sortieren", new ActionListener() {
|
|
|
|
|
sortByRunsButton = createButton(leftPanel,
|
|
|
|
|
"<html><center>Nach Reihen sortieren", new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent arg0) {
|
|
|
|
|
sortByRunsEvent.emit();
|
|
|
|
@ -133,17 +151,19 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|
|
|
|
private void createRightPanel() {
|
|
|
|
|
rightPanel = new JPanel();
|
|
|
|
|
rightPanel.setLayout(null);
|
|
|
|
|
rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
|
|
|
|
|
SIDE_PANEL_INSET, SIDE_PANEL_INSET));
|
|
|
|
|
rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET,
|
|
|
|
|
SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET));
|
|
|
|
|
|
|
|
|
|
handRowUpButton = createButton(rightPanel, "<html><center>\u25B2", new ActionListener() {
|
|
|
|
|
handRowUpButton = createButton(rightPanel, "<html><center>\u25B2",
|
|
|
|
|
new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
hand.rowUp();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
handRowDownButton = createButton(rightPanel, "<html><center>\u25BC", new ActionListener() {
|
|
|
|
|
handRowDownButton = createButton(rightPanel, "<html><center>\u25BC",
|
|
|
|
|
new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
hand.rowDown();
|
|
|
|
@ -161,14 +181,16 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
keepStonesButton = createButton(rightPanel, "<html><center>Steine<br>behalten", new ActionListener() {
|
|
|
|
|
keepStonesButton = createButton(rightPanel,
|
|
|
|
|
"<html><center>Steine<br>behalten", new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
endTurnEvent.emit();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
redealButton = createButton(rightPanel, "<html><center>Neu<br>geben", new ActionListener() {
|
|
|
|
|
redealButton = createButton(rightPanel, "<html><center>Neu<br>geben",
|
|
|
|
|
new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
redealEvent.emit();
|
|
|
|
@ -178,7 +200,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|
|
|
|
rightPanel.addComponentListener(new RightPanelResizeListener());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private JButton createButton(JPanel panel, String caption, ActionListener listener) {
|
|
|
|
|
private JButton createButton(JPanel panel, String caption,
|
|
|
|
|
ActionListener listener) {
|
|
|
|
|
JButton button = new JButton(caption);
|
|
|
|
|
button.setFont(button.getFont().deriveFont(0));
|
|
|
|
|
button.setMargin(new Insets(0, 0, 0, 0));
|
|
|
|
@ -190,7 +213,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|
|
|
|
private void rescale() {
|
|
|
|
|
Insets insets = getInsets();
|
|
|
|
|
int x = insets.left, y = insets.top, width = getWidth() - insets.left
|
|
|
|
|
- insets.right, height = getHeight() - insets.top - insets.bottom;
|
|
|
|
|
- insets.right, height = getHeight() - insets.top
|
|
|
|
|
- insets.bottom;
|
|
|
|
|
int boardWidth = hand.getWidth();
|
|
|
|
|
int handButtonWidth = (int) (width * HAND_ROW_BUTTON_RATIO);
|
|
|
|
|
int meanPanelWidth = (width - boardWidth) / 2;
|
|
|
|
@ -199,8 +223,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|
|
|
|
|
|
|
|
|
leftPanel.setBounds(x, y, leftPanelWidth, height);
|
|
|
|
|
hand.setBounds(x + leftPanelWidth, y, boardWidth, height);
|
|
|
|
|
rightPanel.setBounds(x + leftPanelWidth + boardWidth, y, rightPanelWidth,
|
|
|
|
|
height);
|
|
|
|
|
rightPanel.setBounds(x + leftPanelWidth + boardWidth, y,
|
|
|
|
|
rightPanelWidth, height);
|
|
|
|
|
|
|
|
|
|
leftPanel.validate();
|
|
|
|
|
rightPanel.validate();
|
|
|
|
@ -208,7 +232,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|
|
|
|
|
|
|
|
|
void updateButtons() {
|
|
|
|
|
handRowUpButton.setEnabled(hand.canRowUp());
|
|
|
|
|
handRowUpButton.setForeground(hand.canRowUp() ? Color.BLACK : Color.GRAY);
|
|
|
|
|
handRowUpButton.setForeground(hand.canRowUp() ? Color.BLACK
|
|
|
|
|
: Color.GRAY);
|
|
|
|
|
handRowDownButton.setEnabled(hand.canRowDown());
|
|
|
|
|
handRowDownButton.setForeground(hand.canRowDown() ? Color.BLACK
|
|
|
|
|
: Color.GRAY);
|
|
|
|
@ -247,30 +272,39 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|
|
|
|
public void componentResized(ComponentEvent e) {
|
|
|
|
|
Insets insets = leftPanel.getInsets();
|
|
|
|
|
int x = insets.left, y = insets.top, width = leftPanel.getWidth()
|
|
|
|
|
- insets.left - insets.right, height = leftPanel.getHeight()
|
|
|
|
|
- insets.top - insets.bottom;
|
|
|
|
|
- insets.left - insets.right, height = leftPanel
|
|
|
|
|
.getHeight() - insets.top - insets.bottom;
|
|
|
|
|
|
|
|
|
|
if (width > SIDE_PANEL_MAX_WIDTH) {
|
|
|
|
|
x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
|
|
|
|
|
width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
|
|
|
|
|
int labelHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
|
|
|
|
|
int oneLabelHeight = labelHeight / 2;
|
|
|
|
|
int buttonWidth = (width - SIDE_PANEL_SEPARATOR) / 2;
|
|
|
|
|
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
|
|
|
|
|
int buttonHeight = height - SIDE_PANEL_SEPARATOR - labelHeight;
|
|
|
|
|
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 6;
|
|
|
|
|
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
|
|
|
|
fontSize = MAX_BUTTON_FONT_SIZE;
|
|
|
|
|
|
|
|
|
|
currentPlayerNameLabel.setBounds(x, y, width, firstLineHeight);
|
|
|
|
|
sortByGroupsButton.setBounds(x, y + firstLineHeight
|
|
|
|
|
currentPlayerNameLabel.setBounds(x, y, width, oneLabelHeight);
|
|
|
|
|
hasLaidOutLabel.setBounds(x, y + oneLabelHeight, width,
|
|
|
|
|
oneLabelHeight);
|
|
|
|
|
sortByGroupsButton.setBounds(x, y + labelHeight
|
|
|
|
|
+ SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
|
|
|
|
|
sortByRunsButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y
|
|
|
|
|
+ firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
|
|
|
|
|
sortByRunsButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR,
|
|
|
|
|
y + labelHeight + SIDE_PANEL_SEPARATOR, buttonWidth,
|
|
|
|
|
buttonHeight);
|
|
|
|
|
|
|
|
|
|
currentPlayerNameLabel.setFont(currentPlayerNameLabel.getFont()
|
|
|
|
|
.deriveFont(fontSize));
|
|
|
|
|
hasLaidOutLabel.setFont(hasLaidOutLabel.getFont().deriveFont(
|
|
|
|
|
fontSize));
|
|
|
|
|
sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(
|
|
|
|
|
fontSize));
|
|
|
|
|
sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont(fontSize));
|
|
|
|
|
sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont(
|
|
|
|
|
fontSize));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -294,7 +328,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|
|
|
|
int smallButtonWidth = (width - SIDE_PANEL_SEPARATOR) / 2;
|
|
|
|
|
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
|
|
|
|
|
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
|
|
|
|
|
float smallFontSize = (float) Math.sqrt(smallButtonWidth * buttonHeight) / 5;
|
|
|
|
|
float smallFontSize = (float) Math.sqrt(smallButtonWidth
|
|
|
|
|
* buttonHeight) / 5;
|
|
|
|
|
if (fontSize > MAX_BUTTON_FONT_SIZE)
|
|
|
|
|
fontSize = MAX_BUTTON_FONT_SIZE;
|
|
|
|
|
|
|
|
|
@ -307,15 +342,19 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
|
|
|
|
fontSize * 1.5f));
|
|
|
|
|
|
|
|
|
|
timeBar.setBounds(x, y, width, firstLineHeight);
|
|
|
|
|
endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
|
|
|
|
|
buttonWidth, buttonHeight);
|
|
|
|
|
endTurnButton.setBounds(x, y + firstLineHeight
|
|
|
|
|
+ SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
|
|
|
|
|
endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize));
|
|
|
|
|
|
|
|
|
|
redealButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR, smallButtonWidth, buttonHeight);
|
|
|
|
|
redealButton.setFont(redealButton.getFont().deriveFont(smallFontSize));
|
|
|
|
|
keepStonesButton.setBounds(x + smallButtonWidth + SIDE_PANEL_SEPARATOR, y
|
|
|
|
|
+ firstLineHeight + SIDE_PANEL_SEPARATOR, smallButtonWidth, buttonHeight);
|
|
|
|
|
keepStonesButton.setFont(keepStonesButton.getFont().deriveFont(smallFontSize));
|
|
|
|
|
redealButton.setBounds(x, y + firstLineHeight
|
|
|
|
|
+ SIDE_PANEL_SEPARATOR, smallButtonWidth, buttonHeight);
|
|
|
|
|
redealButton.setFont(redealButton.getFont().deriveFont(
|
|
|
|
|
smallFontSize));
|
|
|
|
|
keepStonesButton.setBounds(x + smallButtonWidth
|
|
|
|
|
+ SIDE_PANEL_SEPARATOR, y + firstLineHeight
|
|
|
|
|
+ SIDE_PANEL_SEPARATOR, smallButtonWidth, buttonHeight);
|
|
|
|
|
keepStonesButton.setFont(keepStonesButton.getFont().deriveFont(
|
|
|
|
|
smallFontSize));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|