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;
import java.awt.Color;
import java.util.Collection;
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.setCurrentPlayerName(roundState.getActivePlayer()
.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
*
* @param scores the round scores
* @param scores
* the round scores
*/
public void setScores(Iterable<Score> scores);
/**
* Sets the accumulated scores to display
*
* @param accumulatedScore the accumulated score
* @param accumulatedScore
* the accumulated score
*/
public void setAccumulatedScore(Score accumulatedScore);
/**
* Sets the player list to display
*
* @param players the player list
* @param players
* the player list
*/
void setPlayers(Iterable<PlayerSettings> players);
/**
* Updates the score display
*/

View file

@ -1,5 +1,6 @@
package jrummikub.view;
import java.awt.Color;
import java.util.Collection;
import jrummikub.model.Stone;
@ -46,7 +47,7 @@ public interface IView {
* Sets the current player's name
*
* @param playerName
* the player name
* the player name
*/
public void setCurrentPlayerName(String playerName);
@ -54,7 +55,7 @@ public interface IView {
* Sets the stones that are to be painted selected
*
* @param stones
* the stones to be painted selected
* the stones to be painted selected
*/
public void setSelectedStones(Collection<Stone> stones);
@ -62,7 +63,7 @@ public interface IView {
* Enables or disables the player's StartTurnPanel
*
* @param enable
* enable/disable
* enable/disable
*/
public void enableStartTurnPanel(boolean enable);
@ -77,9 +78,9 @@ public interface IView {
* Enables or disables the panel shown when a player has won
*
* @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
@ -93,21 +94,25 @@ public interface IView {
*
* @return the event
*/
IEvent getNewRoundEvent();
public IEvent getNewRoundEvent();
/**
* Shows or hides the game settings panel
*
* @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
*
* @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")
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();
}
});
hasLaidOutLabel = new JLabel();
hasLaidOutLabel.setHorizontalAlignment(JLabel.CENTER);
hasLaidOutLabel.setVerticalAlignment(JLabel.CENTER);
leftPanel.add(hasLaidOutLabel);
sortByRunsButton = createButton(leftPanel, "<html><center>Nach Reihen sortieren", new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
sortByRunsEvent.emit();
}
});
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));
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();
}
});
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();
}
});
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) {

View file

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