Disable player panel while settings panel is shown

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@313 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-05-29 21:19:20 +02:00
parent e4a1246f01
commit d6b8b23c6d
5 changed files with 106 additions and 47 deletions

View file

@ -131,4 +131,10 @@ public class MockView implements IView {
return newGameEvent; return newGameEvent;
} }
@Override
public void showInterface(boolean enable) {
// TODO Auto-generated method stub
}
} }

View file

@ -28,6 +28,7 @@ public class ApplicationControl {
public void startApplication() { public void startApplication() {
view.showScorePanel(false); view.showScorePanel(false);
view.enableWinPanel(false); view.enableWinPanel(false);
view.showInterface(false);
SettingsControl settingsControl = new SettingsControl(view, SettingsControl settingsControl = new SettingsControl(view,
new GameSettings()); new GameSettings());
settingsControl.getStartGameEvent().add(new IListener1<GameSettings>() { settingsControl.getStartGameEvent().add(new IListener1<GameSettings>() {
@ -41,6 +42,7 @@ public class ApplicationControl {
startApplication(); startApplication();
} }
}); });
view.showInterface(true);
gameControl.startGame(); gameControl.startGame();
} }

View file

@ -47,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);
@ -55,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);
@ -63,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);
@ -78,7 +78,7 @@ 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
*/ */
public void enableWinPanel(boolean enable); public void enableWinPanel(boolean enable);
@ -100,7 +100,7 @@ public interface IView {
* 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
*/ */
public void showSettingsPanel(boolean show); public void showSettingsPanel(boolean show);
@ -108,7 +108,7 @@ public interface IView {
* 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
*/ */
public void showScorePanel(boolean show); public void showScorePanel(boolean show);
@ -116,15 +116,15 @@ public interface IView {
* Is used for the PlayerPanel and ScorePanel to display a player's color * Is used for the PlayerPanel and ScorePanel to display a player's color
* along with the name * along with the name
* *
* @param color * @param color the current player's color
*/ */
public void setCurrentPlayerColor(Color color); public void setCurrentPlayerColor(Color color);
/** /**
* Is used for the PlayerPanel to display if a player has laid out along * Is used for the PlayerPanel to display if a player has laid out along with
* with the name * the name
* *
* @param hasLaidOut * @param hasLaidOut specifies if the current player has laid out or not
*/ */
public void setHasLaidOut(boolean hasLaidOut); public void setHasLaidOut(boolean hasLaidOut);
@ -134,4 +134,12 @@ public interface IView {
* @return newGameEvent * @return newGameEvent
*/ */
IEvent getNewGameEvent(); IEvent getNewGameEvent();
/**
* Enables or disables most parts of the interface
*
* @param enable
* specifies if the interface is to be enabled or disabled
*/
void showInterface(boolean enable);
} }

View file

@ -62,7 +62,7 @@ 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);
@ -129,8 +129,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
leftPanel.add(hasLaidOutLabel); leftPanel.add(hasLaidOutLabel);
sortByGroupsButton = createButton(leftPanel, sortByGroupsButton = createButton(leftPanel,
"<html><center>Nach Sammlungen sortieren", "<html><center>Nach Sammlungen sortieren", new ActionListener() {
new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent arg0) { public void actionPerformed(ActionEvent arg0) {
sortByGroupsEvent.emit(); sortByGroupsEvent.emit();
@ -151,8 +150,8 @@ 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, rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET)); SIDE_PANEL_INSET, SIDE_PANEL_INSET));
handRowUpButton = createButton(rightPanel, "<html><center>\u25B2", handRowUpButton = createButton(rightPanel, "<html><center>\u25B2",
new ActionListener() { new ActionListener() {
@ -213,8 +212,7 @@ 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.right, height = getHeight() - insets.top - insets.bottom;
- 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;
@ -223,8 +221,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, rightPanel.setBounds(x + leftPanelWidth + boardWidth, y, rightPanelWidth,
rightPanelWidth, height); height);
leftPanel.validate(); leftPanel.validate();
rightPanel.validate(); rightPanel.validate();
@ -232,8 +230,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
void updateButtons() { void updateButtons() {
handRowUpButton.setEnabled(hand.canRowUp()); handRowUpButton.setEnabled(hand.canRowUp());
handRowUpButton.setForeground(hand.canRowUp() ? Color.BLACK handRowUpButton.setForeground(hand.canRowUp() ? Color.BLACK : Color.GRAY);
: 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);
@ -272,8 +269,8 @@ 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 - insets.left - insets.right, height = leftPanel.getHeight()
.getHeight() - insets.top - insets.bottom; - 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;
@ -289,22 +286,18 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
fontSize = MAX_BUTTON_FONT_SIZE; fontSize = MAX_BUTTON_FONT_SIZE;
currentPlayerNameLabel.setBounds(x, y, width, oneLabelHeight); currentPlayerNameLabel.setBounds(x, y, width, oneLabelHeight);
hasLaidOutLabel.setBounds(x, y + oneLabelHeight, width, hasLaidOutLabel.setBounds(x, y + oneLabelHeight, width, oneLabelHeight);
oneLabelHeight); sortByGroupsButton.setBounds(x, y + labelHeight + SIDE_PANEL_SEPARATOR,
sortByGroupsButton.setBounds(x, y + labelHeight buttonWidth, buttonHeight);
+ SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight); sortByRunsButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y
sortByRunsButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, + labelHeight + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
y + labelHeight + SIDE_PANEL_SEPARATOR, buttonWidth,
buttonHeight);
currentPlayerNameLabel.setFont(currentPlayerNameLabel.getFont() currentPlayerNameLabel.setFont(currentPlayerNameLabel.getFont()
.deriveFont(fontSize)); .deriveFont(fontSize));
hasLaidOutLabel.setFont(hasLaidOutLabel.getFont().deriveFont( hasLaidOutLabel.setFont(hasLaidOutLabel.getFont().deriveFont(fontSize));
fontSize));
sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont( sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(
fontSize)); fontSize));
sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont( sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont(fontSize));
fontSize));
} }
} }
@ -328,8 +321,7 @@ 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 float smallFontSize = (float) Math.sqrt(smallButtonWidth * buttonHeight) / 5;
* buttonHeight) / 5;
if (fontSize > MAX_BUTTON_FONT_SIZE) if (fontSize > MAX_BUTTON_FONT_SIZE)
fontSize = MAX_BUTTON_FONT_SIZE; fontSize = MAX_BUTTON_FONT_SIZE;
@ -342,17 +334,16 @@ 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 endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
+ SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight); buttonWidth, buttonHeight);
endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize)); endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize));
redealButton.setBounds(x, y + firstLineHeight redealButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
+ SIDE_PANEL_SEPARATOR, smallButtonWidth, buttonHeight); smallButtonWidth, buttonHeight);
redealButton.setFont(redealButton.getFont().deriveFont( redealButton.setFont(redealButton.getFont().deriveFont(smallFontSize));
smallFontSize)); keepStonesButton.setBounds(x + smallButtonWidth + SIDE_PANEL_SEPARATOR, y
keepStonesButton.setBounds(x + smallButtonWidth + firstLineHeight + SIDE_PANEL_SEPARATOR, smallButtonWidth,
+ SIDE_PANEL_SEPARATOR, y + firstLineHeight buttonHeight);
+ SIDE_PANEL_SEPARATOR, smallButtonWidth, buttonHeight);
keepStonesButton.setFont(keepStonesButton.getFont().deriveFont( keepStonesButton.setFont(keepStonesButton.getFont().deriveFont(
smallFontSize)); smallFontSize));
@ -371,4 +362,20 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
keepStonesButton.setVisible(smallButtons); keepStonesButton.setVisible(smallButtons);
redealButton.setVisible(smallButtons); redealButton.setVisible(smallButtons);
} }
void showButtons(boolean show) {
currentPlayerNameLabel.setVisible(show);
hasLaidOutLabel.setVisible(show);
sortByGroupsButton.setVisible(show);
sortByRunsButton.setVisible(show);
timeBar.setVisible(show);
if (!show) {
handRowDownButton.setEnabled(false);
handRowUpButton.setEnabled(false);
endTurnButton.setVisible(false);
redealButton.setVisible(false);
keepStonesButton.setVisible(false);
}
}
} }

View file

@ -4,15 +4,22 @@ import java.awt.Color;
import java.awt.Insets; import java.awt.Insets;
import java.awt.event.ComponentAdapter; import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent; import java.awt.event.ComponentEvent;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLayeredPane; import javax.swing.JLayeredPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.border.MatteBorder; import javax.swing.border.MatteBorder;
import jrummikub.model.Position;
import jrummikub.model.Stone; import jrummikub.model.Stone;
import jrummikub.model.StoneColor;
import jrummikub.model.StoneSet;
import jrummikub.util.IEvent; import jrummikub.util.IEvent;
import jrummikub.util.Pair;
import jrummikub.view.IHandPanel; import jrummikub.view.IHandPanel;
import jrummikub.view.IPlayerPanel; import jrummikub.view.IPlayerPanel;
import jrummikub.view.IScorePanel; import jrummikub.view.IScorePanel;
@ -90,8 +97,8 @@ 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, playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0,
0, Color.BLACK)); Color.BLACK));
mainLayer.add(playerPanel); mainLayer.add(playerPanel);
startTurnPanel = new StartTurnPanel(); startTurnPanel = new StartTurnPanel();
@ -214,4 +221,33 @@ public class View extends JFrame implements IView {
return winPanel.getEndProgramEvent(); return winPanel.getEndProgramEvent();
} }
@SuppressWarnings("unchecked")
private List<Pair<Stone, Position>> createDecorationStones() {
Pair<Stone, Position> stone1 = new Pair<Stone, Position>(new Stone(
StoneColor.RED), new Position(3.5f, 0));
Pair<Stone, Position> stone2 = new Pair<Stone, Position>(new Stone(13,
StoneColor.BLACK), new Position(5, 0));
Pair<Stone, Position> stone3 = new Pair<Stone, Position>(new Stone(13,
StoneColor.ORANGE), new Position(6, 0));
Pair<Stone, Position> stone4 = new Pair<Stone, Position>(new Stone(13,
StoneColor.BLUE), new Position(7, 0));
Pair<Stone, Position> stone5 = new Pair<Stone, Position>(new Stone(13,
StoneColor.RED), new Position(8, 0));
Pair<Stone, Position> stone6 = new Pair<Stone, Position>(new Stone(
StoneColor.BLACK), new Position(9.5f, 0));
return Arrays.asList(stone1, stone2, stone3, stone4, stone5, stone6);
}
@Override
public void showInterface(boolean enable) {
if (enable) {
playerPanel.showButtons(true);
} else {
List<Pair<StoneSet, Position>> emptyTable = Collections.emptyList();
table.setStoneSets(emptyTable);
playerPanel.getHandPanel().setStones(createDecorationStones());
playerPanel.showButtons(false);
}
}
} }