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
This commit is contained in:
Ida Massow 2011-05-29 18:42:36 +02:00
parent 9cf3dc09ae
commit 05107f6035
6 changed files with 166 additions and 93 deletions

View file

@ -1,5 +1,6 @@
package jrummikub.view; package jrummikub.view;
import java.awt.Color;
import java.util.Collection; import java.util.Collection;
import jrummikub.model.Stone; import jrummikub.model.Stone;
@ -110,4 +111,16 @@ public class MockView implements IView {
} }
@Override
public void setCurrentPlayerColor(Color color) {
// TODO Auto-generated method stub
}
@Override
public void setHasLaidOut(boolean hasLaidOut) {
// TODO Auto-generated method stub
}
} }

View file

@ -79,6 +79,9 @@ public class RoundControl {
view.getTablePanel().setStoneSets(clonedTable); view.getTablePanel().setStoneSets(clonedTable);
view.setCurrentPlayerName(roundState.getActivePlayer() view.setCurrentPlayerName(roundState.getActivePlayer()
.getPlayerSettings().getName()); .getPlayerSettings().getName());
view.setCurrentPlayerColor(roundState.getActivePlayer()
.getPlayerSettings().getColor());
view.setHasLaidOut(roundState.getActivePlayer().getLaidOut());
} }

View file

@ -10,24 +10,27 @@ public interface IScorePanel {
/** /**
* Sets the scores of the played rounds * Sets the scores of the played rounds
* *
* @param scores the round scores * @param scores
* the round scores
*/ */
public void setScores(Iterable<Score> scores); public void setScores(Iterable<Score> scores);
/** /**
* Sets the accumulated scores to display * Sets the accumulated scores to display
* *
* @param accumulatedScore the accumulated score * @param accumulatedScore
* the accumulated score
*/ */
public void setAccumulatedScore(Score accumulatedScore); public void setAccumulatedScore(Score accumulatedScore);
/** /**
* Sets the player list to display * Sets the player list to display
* *
* @param players the player list * @param players
* the player list
*/ */
void setPlayers(Iterable<PlayerSettings> players); void setPlayers(Iterable<PlayerSettings> players);
/** /**
* Updates the score display * Updates the score display
*/ */

View file

@ -1,5 +1,6 @@
package jrummikub.view; package jrummikub.view;
import java.awt.Color;
import java.util.Collection; import java.util.Collection;
import jrummikub.model.Stone; import jrummikub.model.Stone;
@ -46,7 +47,7 @@ public interface IView {
* Sets the current player's name * Sets the current player's name
* *
* @param playerName * @param playerName
* the player name * the player name
*/ */
public void setCurrentPlayerName(String playerName); public void setCurrentPlayerName(String playerName);
@ -54,7 +55,7 @@ public interface IView {
* Sets the stones that are to be painted selected * Sets the stones that are to be painted selected
* *
* @param stones * @param stones
* the stones to be painted selected * the stones to be painted selected
*/ */
public void setSelectedStones(Collection<Stone> stones); public void setSelectedStones(Collection<Stone> stones);
@ -62,7 +63,7 @@ public interface IView {
* Enables or disables the player's StartTurnPanel * Enables or disables the player's StartTurnPanel
* *
* @param enable * @param enable
* enable/disable * enable/disable
*/ */
public void enableStartTurnPanel(boolean enable); public void enableStartTurnPanel(boolean enable);
@ -77,9 +78,9 @@ public interface IView {
* Enables or disables the panel shown when a player has won * Enables or disables the panel shown when a player has won
* *
* @param enable * @param enable
* enable/disable * enable/disable
*/ */
void enableWinPanel(boolean enable); public void enableWinPanel(boolean enable);
/** /**
* The quit event is emitted when the player wants to quit the game * The quit event is emitted when the player wants to quit the game
@ -93,21 +94,25 @@ public interface IView {
* *
* @return the event * @return the event
*/ */
IEvent getNewRoundEvent(); public IEvent getNewRoundEvent();
/** /**
* Shows or hides the game settings panel * Shows or hides the game settings panel
* *
* @param show * @param show
* specifies if the panel shall be shown or hidden * specifies if the panel shall be shown or hidden
*/ */
void showSettingsPanel(boolean show); public void showSettingsPanel(boolean show);
/** /**
* Shows or hides the score panel * Shows or hides the score panel
* *
* @param show * @param show
* specifies if the panel shall be shown or hidden * specifies if the panel shall be shown or hidden
*/ */
void showScorePanel(boolean show); public void showScorePanel(boolean show);
public void setCurrentPlayerColor(Color color);
public void setHasLaidOut(boolean hasLaidOut);
} }

View file

@ -25,8 +25,8 @@ import jrummikub.view.IPlayerPanel;
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
class PlayerPanel extends JPanel implements IPlayerPanel { class PlayerPanel extends JPanel implements IPlayerPanel {
private final static int SIDE_PANEL_INSET = 15; private final static int SIDE_PANEL_INSET = 10;
private final static int SIDE_PANEL_SEPARATOR = 10; private final static int SIDE_PANEL_SEPARATOR = 5;
private final static float SIDE_PANEL_FIRST_LINE_HEIGHT = 0.375f; private final static float SIDE_PANEL_FIRST_LINE_HEIGHT = 0.375f;
private final static int SIDE_PANEL_MAX_WIDTH = 180; private final static int SIDE_PANEL_MAX_WIDTH = 180;
private final static float HAND_ROW_BUTTON_RATIO = 0.03f; 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 JPanel leftPanel, rightPanel;
private JLabel currentPlayerNameLabel; private JLabel currentPlayerNameLabel;
private JLabel hasLaidOutLabel;
private JButton sortByGroupsButton; private JButton sortByGroupsButton;
private JButton sortByRunsButton; private JButton sortByRunsButton;
private JButton handRowUpButton; private JButton handRowUpButton;
@ -47,7 +48,6 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
private JButton endTurnButton; private JButton endTurnButton;
private JButton keepStonesButton; private JButton keepStonesButton;
private JButton redealButton; private JButton redealButton;
private Event sortByGroupsEvent = new Event(); private Event sortByGroupsEvent = new Event();
private Event sortByRunsEvent = new Event(); private Event sortByRunsEvent = new Event();
@ -62,12 +62,24 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
* Sets the current player name * Sets the current player name
* *
* @param playerName * @param playerName
* the player name * the player name
*/ */
void setCurrentPlayerName(String playerName) { void setCurrentPlayerName(String playerName) {
currentPlayerNameLabel.setText(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 @Override
public void setTimeLeft(int time) { public void setTimeLeft(int time) {
timeBar.setValue(time); timeBar.setValue(time);
@ -94,7 +106,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
public IEvent getEndTurnEvent() { public IEvent getEndTurnEvent() {
return endTurnEvent; return endTurnEvent;
} }
@Override @Override
public IEvent getRedealEvent() { public IEvent getRedealEvent() {
return redealEvent; return redealEvent;
@ -108,24 +120,30 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
currentPlayerNameLabel = new JLabel(); currentPlayerNameLabel = new JLabel();
currentPlayerNameLabel.setHorizontalAlignment(JLabel.CENTER); currentPlayerNameLabel.setHorizontalAlignment(JLabel.CENTER);
currentPlayerNameLabel.setHorizontalTextPosition(JLabel.CENTER);
currentPlayerNameLabel.setVerticalAlignment(JLabel.CENTER); currentPlayerNameLabel.setVerticalAlignment(JLabel.CENTER);
currentPlayerNameLabel.setVerticalTextPosition(JLabel.CENTER);
leftPanel.add(currentPlayerNameLabel); leftPanel.add(currentPlayerNameLabel);
sortByGroupsButton = createButton(leftPanel, "<html><center>Nach Sammlungen sortieren", new ActionListener() { hasLaidOutLabel = new JLabel();
@Override hasLaidOutLabel.setHorizontalAlignment(JLabel.CENTER);
public void actionPerformed(ActionEvent arg0) { hasLaidOutLabel.setVerticalAlignment(JLabel.CENTER);
sortByGroupsEvent.emit(); leftPanel.add(hasLaidOutLabel);
}
});
sortByRunsButton = createButton(leftPanel, "<html><center>Nach Reihen sortieren", new ActionListener() { sortByGroupsButton = createButton(leftPanel,
@Override "<html><center>Nach Sammlungen sortieren",
public void actionPerformed(ActionEvent arg0) { new ActionListener() {
sortByRunsEvent.emit(); @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()); leftPanel.addComponentListener(new LeftPanelResizeListener());
} }
@ -133,22 +151,24 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
private void createRightPanel() { private void createRightPanel() {
rightPanel = new JPanel(); rightPanel = new JPanel();
rightPanel.setLayout(null); rightPanel.setLayout(null);
rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET, rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET,
SIDE_PANEL_INSET, 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",
@Override new ActionListener() {
public void actionPerformed(ActionEvent e) { @Override
hand.rowUp(); public void actionPerformed(ActionEvent e) {
} hand.rowUp();
}); }
});
handRowDownButton = createButton(rightPanel, "<html><center>\u25BC", new ActionListener() { handRowDownButton = createButton(rightPanel, "<html><center>\u25BC",
@Override new ActionListener() {
public void actionPerformed(ActionEvent e) { @Override
hand.rowDown(); public void actionPerformed(ActionEvent e) {
} hand.rowDown();
}); }
});
timeBar = new JProgressBar(0, 60); timeBar = new JProgressBar(0, 60);
timeBar.setStringPainted(true); timeBar.setStringPainted(true);
@ -160,25 +180,28 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
endTurnEvent.emit(); 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() { keepStonesButton = createButton(rightPanel,
@Override "<html><center>Steine<br>behalten", new ActionListener() {
public void actionPerformed(ActionEvent e) { @Override
redealEvent.emit(); 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()); 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); JButton button = new JButton(caption);
button.setFont(button.getFont().deriveFont(0)); button.setFont(button.getFont().deriveFont(0));
button.setMargin(new Insets(0, 0, 0, 0)); button.setMargin(new Insets(0, 0, 0, 0));
@ -190,7 +213,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
private void rescale() { private void rescale() {
Insets insets = getInsets(); Insets insets = getInsets();
int x = insets.left, y = insets.top, width = getWidth() - insets.left 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 boardWidth = hand.getWidth();
int handButtonWidth = (int) (width * HAND_ROW_BUTTON_RATIO); int handButtonWidth = (int) (width * HAND_ROW_BUTTON_RATIO);
int meanPanelWidth = (width - boardWidth) / 2; int meanPanelWidth = (width - boardWidth) / 2;
@ -199,8 +223,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
leftPanel.setBounds(x, y, leftPanelWidth, height); leftPanel.setBounds(x, y, leftPanelWidth, height);
hand.setBounds(x + leftPanelWidth, y, boardWidth, height); hand.setBounds(x + leftPanelWidth, y, boardWidth, height);
rightPanel.setBounds(x + leftPanelWidth + boardWidth, y, rightPanelWidth, rightPanel.setBounds(x + leftPanelWidth + boardWidth, y,
height); rightPanelWidth, height);
leftPanel.validate(); leftPanel.validate();
rightPanel.validate(); rightPanel.validate();
@ -208,7 +232,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
void updateButtons() { void updateButtons() {
handRowUpButton.setEnabled(hand.canRowUp()); 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.setEnabled(hand.canRowDown());
handRowDownButton.setForeground(hand.canRowDown() ? Color.BLACK handRowDownButton.setForeground(hand.canRowDown() ? Color.BLACK
: Color.GRAY); : Color.GRAY);
@ -238,7 +263,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
addComponentListener(rescaleListener); addComponentListener(rescaleListener);
hand.addComponentListener(rescaleListener); hand.addComponentListener(rescaleListener);
setEndTurnMode(true, true); setEndTurnMode(true, true);
} }
@ -247,30 +272,39 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
public void componentResized(ComponentEvent e) { public void componentResized(ComponentEvent e) {
Insets insets = leftPanel.getInsets(); Insets insets = leftPanel.getInsets();
int x = insets.left, y = insets.top, width = leftPanel.getWidth() int x = insets.left, y = insets.top, width = leftPanel.getWidth()
- insets.left - insets.right, height = leftPanel.getHeight() - insets.left - insets.right, height = leftPanel
- insets.top - insets.bottom; .getHeight() - insets.top - insets.bottom;
if (width > SIDE_PANEL_MAX_WIDTH) { if (width > SIDE_PANEL_MAX_WIDTH) {
x += (width - SIDE_PANEL_MAX_WIDTH) / 4; x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2; 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 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; float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 6;
if (fontSize > MAX_BUTTON_FONT_SIZE) if (fontSize > MAX_BUTTON_FONT_SIZE)
fontSize = MAX_BUTTON_FONT_SIZE; fontSize = MAX_BUTTON_FONT_SIZE;
currentPlayerNameLabel.setBounds(x, y, width, firstLineHeight); currentPlayerNameLabel.setBounds(x, y, width, oneLabelHeight);
sortByGroupsButton.setBounds(x, y + firstLineHeight hasLaidOutLabel.setBounds(x, y + oneLabelHeight, width,
oneLabelHeight);
sortByGroupsButton.setBounds(x, y + labelHeight
+ SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight); + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
sortByRunsButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y sortByRunsButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR,
+ firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight); y + labelHeight + SIDE_PANEL_SEPARATOR, buttonWidth,
buttonHeight);
currentPlayerNameLabel.setFont(currentPlayerNameLabel.getFont()
.deriveFont(fontSize));
hasLaidOutLabel.setFont(hasLaidOutLabel.getFont().deriveFont(
fontSize));
sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont( sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(
fontSize)); 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 smallButtonWidth = (width - SIDE_PANEL_SEPARATOR) / 2;
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight; int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5; 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) if (fontSize > MAX_BUTTON_FONT_SIZE)
fontSize = MAX_BUTTON_FONT_SIZE; fontSize = MAX_BUTTON_FONT_SIZE;
@ -307,19 +342,23 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
fontSize * 1.5f)); fontSize * 1.5f));
timeBar.setBounds(x, y, width, firstLineHeight); timeBar.setBounds(x, y, width, firstLineHeight);
endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR, endTurnButton.setBounds(x, y + firstLineHeight
buttonWidth, buttonHeight); + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize)); endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize));
redealButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR, smallButtonWidth, buttonHeight); redealButton.setBounds(x, y + firstLineHeight
redealButton.setFont(redealButton.getFont().deriveFont(smallFontSize)); + SIDE_PANEL_SEPARATOR, smallButtonWidth, buttonHeight);
keepStonesButton.setBounds(x + smallButtonWidth + SIDE_PANEL_SEPARATOR, y redealButton.setFont(redealButton.getFont().deriveFont(
+ firstLineHeight + SIDE_PANEL_SEPARATOR, smallButtonWidth, buttonHeight); smallFontSize));
keepStonesButton.setFont(keepStonesButton.getFont().deriveFont(smallFontSize)); keepStonesButton.setBounds(x + smallButtonWidth
+ SIDE_PANEL_SEPARATOR, y + firstLineHeight
+ SIDE_PANEL_SEPARATOR, smallButtonWidth, buttonHeight);
keepStonesButton.setFont(keepStonesButton.getFont().deriveFont(
smallFontSize));
} }
} }
@Override @Override
public void setEndTurnMode(boolean inspectOnly, boolean mayRedeal) { public void setEndTurnMode(boolean inspectOnly, boolean mayRedeal) {
if (!inspectOnly) { if (!inspectOnly) {

View file

@ -90,12 +90,12 @@ public class View extends JFrame implements IView {
mainLayer.add(table); mainLayer.add(table);
playerPanel = new PlayerPanel(); playerPanel = new PlayerPanel();
playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0, playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0,
Color.BLACK)); 0, Color.BLACK));
playerPanel.setVisible(false);
mainLayer.add(playerPanel); mainLayer.add(playerPanel);
startTurnPanel = new StartTurnPanel(); startTurnPanel = new StartTurnPanel();
startTurnPanel.setVisible(false);
mainLayer.add(startTurnPanel); mainLayer.add(startTurnPanel);
winPanel = new WinPanel(); winPanel = new WinPanel();
@ -184,6 +184,16 @@ public class View extends JFrame implements IView {
winPanel.setCurrentPlayerName(playerName); winPanel.setCurrentPlayerName(playerName);
} }
@Override
public void setCurrentPlayerColor(Color color) {
playerPanel.setCurrentPlayerColor(color);
}
@Override
public void setHasLaidOut(boolean hasLaidOut) {
playerPanel.setHasLaidOut(hasLaidOut);
}
@Override @Override
public IEvent getStartTurnEvent() { public IEvent getStartTurnEvent() {
return startTurnPanel.getStartTurnEvent(); return startTurnPanel.getStartTurnEvent();