Implement settings control

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@291 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-05-28 20:13:35 +02:00
parent 5029ff206a
commit 5aa79ea898
4 changed files with 268 additions and 55 deletions

View file

@ -11,14 +11,65 @@ import jrummikub.util.IEvent2;
* The panel for the game setup
*/
public interface ISettingsPanel {
/**
* The list of player colors
*/
public final static Color[] PLAYER_COLORS = { new Color(1.0f, 0, 0), // red
new Color(0, 1.0f, 0), // lime
new Color(1.0f, 1.0f, 0), // yellow
new Color(0, 0, 1.0f), // blue
new Color(1.0f, 0, 1.0f), // fuchsia
new Color(0, 1.0f, 1.0f), // aqua
new Color(0.5f, 0, 0), // maroon
new Color(0, 0.5f, 0), // green
new Color(0.5f, 0.5f, 0), // olive
new Color(0, 0, 0.5f), // navy
new Color(0.5f, 0, 0.5f), // purple
new Color(0, 0.5f, 0.5f), // teal
new Color(0, 0, 0), // black
new Color(0.5f, 0.5f, 0.5f), // gray
new Color(0.75f, 0.75f, 0.75f), // silver
new Color(1.0f, 1.0f, 1.0f), // white
};
/**
* The add player event is emitted when the user wants to add a player to the
* player list
*
* @return the event
*/
public IEvent getAddPlayerEvent();
/**
* The remove player event is emitted when the user wants to remove a player
* remove the player list
*
* @return the event
*/
public IEvent1<Integer> getRemovePlayerEvent();
/**
* The change player color event is emitted when the user wants change a
* player's color
*
* @return the event
*/
public IEvent2<Integer, Color> getChangePlayerColorEvent();
/**
* The change player color event is emitted when the user wants change a
* player's name
*
* @return the event
*/
public IEvent2<Integer, String> getChangePlayerNameEvent();
/**
* The change initial meld threshold event is emitted when the user wants
* change the initial meld threshold
*
* @return the event
*/
public IEvent1<Integer> getChangeInitialMeldThresholdEvent();
/**
@ -28,17 +79,56 @@ public interface ISettingsPanel {
*/
public IEvent getStartGameEvent();
/**
* Sets an error to display
*
* @param error
* the kind of error
*/
public void setError(SettingsError error);
/**
* Enables or disables the start game button
*
* @param enable
* specifies if the button is to be enabled or disabled
*/
public void enableStartGameButton(boolean enable);
/**
* Enables or disables the add player button
*
* @param enable
* specifies if the button is to be enabled or disabled
*/
public void enableAddPlayerButton(boolean enable);
/**
* Enables or disables the remove player buttons
*
* @param enable
* specifies if the buttons are to be enabled or disabled
*/
public void enableRemovePlayerButtons(boolean enable);
/**
* Sets the game settings to display
*
* @param gameSettings
* the settings
*/
public void setGameSettings(GameSettings gameSettings);
/**
* Specifies the different kinds of settings errors that can be displayed
*/
public enum SettingsError {
NO_ERROR, DUPLICATE_PLAYER_NAME, NO_PLAYER_NAME
/** Everything is ok */
NO_ERROR,
/** A player name is used twice */
DUPLICATE_PLAYER_NAME,
/** A player has an empty name */
NO_PLAYER_NAME
}
}

View file

@ -40,24 +40,6 @@ import jrummikub.view.ISettingsPanel;
@SuppressWarnings("serial")
class SettingsPanel extends JPanel implements ISettingsPanel {
private final static Color[] PLAYER_COLORS = { new Color(1.0f, 0, 0), // red
new Color(0, 1.0f, 0), // lime
new Color(1.0f, 1.0f, 0), // yellow
new Color(0, 0, 1.0f), // blue
new Color(1.0f, 0, 1.0f), // fuchsia
new Color(0, 1.0f, 1.0f), // aqua
new Color(0.5f, 0, 0), // maroon
new Color(0, 0.5f, 0), // green
new Color(0.5f, 0.5f, 0), // olive
new Color(0, 0, 0.5f), // navy
new Color(0.5f, 0, 0.5f), // purple
new Color(0, 0.5f, 0.5f), // teal
new Color(0, 0, 0), // black
new Color(0.5f, 0.5f, 0.5f), // gray
new Color(0.75f, 0.75f, 0.75f), // silver
new Color(1.0f, 1.0f, 1.0f), // white
};
private JPanel playerSetupPanel;
private JPanel playerSettingsViewport;
private JPanel ruleSetupPanel;
@ -97,8 +79,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
break;
}
PlayerSettingsPanel panel = new PlayerSettingsPanel("Spieler " + num,
color);
PlayerSettingsPanel panel = new PlayerSettingsPanel("Spieler " + num, color);
playerSettingsPanels.add(panel);
playerSettingsViewport.add(panel,
playerSettingsViewport.getComponentCount() - 1);
@ -124,8 +105,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
playerSettingsViewport.add(addPlayerPanel);
JButton addPlayerButton = new JButton("+");
addPlayerButton
.setFont(addPlayerButton.getFont().deriveFont(Font.BOLD));
addPlayerButton.setFont(addPlayerButton.getFont().deriveFont(Font.BOLD));
addPlayerButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -175,8 +155,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
});
add(startButton, c);
setBorder(new CompoundBorder(new LineBorder(Color.BLACK),
new EmptyBorder(10, 10, 10, 10)));
setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(
10, 10, 10, 10)));
}
private class PlayerSettingsPanel extends JPanel {
@ -195,8 +175,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
private void updateColor() {
colorButton.setIcon(ImageUtil.createColorIcon(settings.getColor(),
16, 2));
colorButton
.setIcon(ImageUtil.createColorIcon(settings.getColor(), 16, 2));
}
private void setName() {