summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/PlayerPanel.java
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-05-29 18:42:36 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-05-29 18:42:36 +0200
commit05107f6035e93d8fe37de0b6beb627b11a05b87b (patch)
tree4cc4218db5457c3b7f8f95755c9a96ab833787de /src/jrummikub/view/impl/PlayerPanel.java
parent9cf3dc09ae319b6e627a4c52923bbc325137ef34 (diff)
downloadJRummikub-05107f6035e93d8fe37de0b6beb627b11a05b87b.tar
JRummikub-05107f6035e93d8fe37de0b6beb627b11a05b87b.zip
Rauskommen ist in der View zu sehen, genauso wie Farben
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@299 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view/impl/PlayerPanel.java')
-rw-r--r--src/jrummikub/view/impl/PlayerPanel.java193
1 files changed, 116 insertions, 77 deletions
diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java
index 4dd38d6..e3bf2b8 100644
--- a/src/jrummikub/view/impl/PlayerPanel.java
+++ b/src/jrummikub/view/impl/PlayerPanel.java
@@ -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;
@@ -47,7 +48,6 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
private JButton endTurnButton;
private JButton keepStonesButton;
private JButton redealButton;
-
private Event sortByGroupsEvent = new Event();
private Event sortByRunsEvent = new Event();
@@ -62,12 +62,24 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
* Sets the current player name
*
* @param playerName
- * the player name
+ * the player name
*/
void setCurrentPlayerName(String playerName) {
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);
@@ -94,7 +106,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
public IEvent getEndTurnEvent() {
return endTurnEvent;
}
-
+
@Override
public IEvent getRedealEvent() {
return redealEvent;
@@ -108,24 +120,30 @@ 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() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- sortByGroupsEvent.emit();
- }
- });
-
- sortByRunsButton = createButton(leftPanel, "<html><center>Nach Reihen sortieren", new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- sortByRunsEvent.emit();
- }
- });
+ 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() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ sortByRunsEvent.emit();
+ }
+ });
leftPanel.addComponentListener(new LeftPanelResizeListener());
}
@@ -133,22 +151,24 @@ 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));
-
- handRowUpButton = createButton(rightPanel, "<html><center>\u25B2", new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- hand.rowUp();
- }
- });
-
- handRowDownButton = createButton(rightPanel, "<html><center>\u25BC", new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- hand.rowDown();
- }
- });
+ rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET,
+ SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET));
+
+ handRowUpButton = createButton(rightPanel, "<html><center>\u25B2",
+ new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ hand.rowUp();
+ }
+ });
+
+ handRowDownButton = createButton(rightPanel, "<html><center>\u25BC",
+ new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ hand.rowDown();
+ }
+ });
timeBar = new JProgressBar(0, 60);
timeBar.setStringPainted(true);
@@ -160,25 +180,28 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
endTurnEvent.emit();
}
});
-
- 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() {
- @Override
- public void actionPerformed(ActionEvent e) {
- redealEvent.emit();
- }
- });
-
+ 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() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ redealEvent.emit();
+ }
+ });
+
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);
@@ -238,7 +263,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
addComponentListener(rescaleListener);
hand.addComponentListener(rescaleListener);
-
+
setEndTurnMode(true, true);
}
@@ -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,19 +342,23 @@ 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));
+
}
}
-
+
@Override
public void setEndTurnMode(boolean inspectOnly, boolean mayRedeal) {
if (!inspectOnly) {