From 70d6ae6d749d11ced007fa781ce65c6e27229007 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Mon, 13 Jun 2011 18:22:55 +0200 Subject: Player Type in player settings verschoben git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@420 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/RoundControl.java | 2 +- src/jrummikub/control/SettingsControl.java | 39 +++---- src/jrummikub/control/turn/TurnControlFactory.java | 14 +-- src/jrummikub/model/PlayerSettings.java | 28 ++++-- src/jrummikub/view/ISettingsPanel.java | 4 +- src/jrummikub/view/impl/SettingsPanel.java | 112 +++++++++++---------- 6 files changed, 106 insertions(+), 93 deletions(-) (limited to 'src/jrummikub') diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index 281b367..a420b6d 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -1,6 +1,6 @@ package jrummikub.control; -import static jrummikub.control.turn.TurnControlFactory.Type.*; +import static jrummikub.model.PlayerSettings.Type.*; import java.util.ArrayList; import java.util.HashSet; diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java index ad88b70..0da2f19 100644 --- a/src/jrummikub/control/SettingsControl.java +++ b/src/jrummikub/control/SettingsControl.java @@ -6,10 +6,9 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import jrummikub.control.turn.TurnControlFactory; -import jrummikub.control.turn.TurnControlFactory.Type; import jrummikub.model.GameSettings; import jrummikub.model.PlayerSettings; +import jrummikub.model.PlayerSettings.Type; import jrummikub.model.StoneColor; import jrummikub.util.Connection; import jrummikub.util.Event1; @@ -34,9 +33,9 @@ public class SettingsControl { * Create a new settings control * * @param view - * the view to use + * the view to use * @param settings - * initial game settings + * initial game settings */ public SettingsControl(IView view, GameSettings settings) { this.view = view; @@ -44,8 +43,8 @@ public class SettingsControl { } /** - * the start game event is emitted when the user wants to start a game and the - * settings made are valid + * the start game event is emitted when the user wants to start a game and + * the settings made are valid * * @return the event */ @@ -78,7 +77,8 @@ public class SettingsControl { private void addOptionListeners1() { connections.add(view.getSettingsPanel() - .getChangeInitialMeldThresholdEvent().add(new IListener1() { + .getChangeInitialMeldThresholdEvent() + .add(new IListener1() { @Override public void handle(Integer value) { settings.setInitialMeldThreshold(value); @@ -103,7 +103,8 @@ public class SettingsControl { update(); } })); - connections.add(view.getSettingsPanel().getChangeNumberOfStonesDealtEvent() + connections.add(view.getSettingsPanel() + .getChangeNumberOfStonesDealtEvent() .add(new IListener1() { @Override public void handle(Integer value) { @@ -206,9 +207,9 @@ public class SettingsControl { } })); connections.add(view.getSettingsPanel().getChangePlayerTypeEvent() - .add(new IListener2() { + .add(new IListener2() { @Override - public void handle(Integer i, TurnControlFactory.Type type) { + public void handle(Integer i, Type type) { setPlayerType(i, type); } })); @@ -246,7 +247,8 @@ public class SettingsControl { break; } - settings.getPlayerList().add(new PlayerSettings("Spieler " + num, color)); + settings.getPlayerList().add( + new PlayerSettings("Spieler " + num, color)); update(); } @@ -287,8 +289,9 @@ public class SettingsControl { protected void update() { view.getSettingsPanel().enableRemovePlayerButtons( settings.getPlayerList().size() > 2); - view.getSettingsPanel().enableAddPlayerButton( - settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); + view.getSettingsPanel() + .enableAddPlayerButton( + settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); checkSettings(); @@ -322,8 +325,9 @@ public class SettingsControl { for (int j = i + 1; j < settings.getPlayerList().size(); ++j) { if (settings.getPlayerList().get(j).getName().equals(name)) { - view.getSettingsPanel().setError( - ISettingsPanel.SettingsError.DUPLICATE_PLAYER_NAME_ERROR); + view.getSettingsPanel() + .setError( + ISettingsPanel.SettingsError.DUPLICATE_PLAYER_NAME_ERROR); view.getSettingsPanel().enableStartGameButton(false); return false; } @@ -332,7 +336,8 @@ public class SettingsControl { int totalStonesDealt = settings.getNumberOfStonesDealt() * settings.getPlayerList().size(); - int totalStones = settings.getHighestValue() * settings.getStoneSetNumber() + int totalStones = settings.getHighestValue() + * settings.getStoneSetNumber() * settings.getStoneColors().size() + settings.getJokerNumber(); if (totalStones <= totalStonesDealt) { @@ -361,7 +366,7 @@ public class SettingsControl { boolean humanPlayerFound = false; for (PlayerSettings player : settings.getPlayerList()) { - if (player.getTurnControlType() == TurnControlFactory.Type.HUMAN) { + if (player.getTurnControlType() == Type.HUMAN) { humanPlayerFound = true; break; } diff --git a/src/jrummikub/control/turn/TurnControlFactory.java b/src/jrummikub/control/turn/TurnControlFactory.java index b42f7ff..4d143e7 100644 --- a/src/jrummikub/control/turn/TurnControlFactory.java +++ b/src/jrummikub/control/turn/TurnControlFactory.java @@ -1,21 +1,13 @@ package jrummikub.control.turn; +import jrummikub.model.PlayerSettings; + /** * Creates a turn control for the active player, regarding if layer is human or * computer * */ public abstract class TurnControlFactory { - /** - * Type of turn control. - */ - public enum Type { - /** */ - HUMAN, - /** */ - COMPUTER - }; - /** * Creates a new turn control instance * @@ -30,7 +22,7 @@ public abstract class TurnControlFactory { * Human or Computer * @return TurnControlFactory for the player kind */ - static public TurnControlFactory getFactory(Type type) { + static public TurnControlFactory getFactory(PlayerSettings.Type type) { switch (type) { case HUMAN: return HumanTurnControl.getFactory(); diff --git a/src/jrummikub/model/PlayerSettings.java b/src/jrummikub/model/PlayerSettings.java index 17e521c..afa610c 100644 --- a/src/jrummikub/model/PlayerSettings.java +++ b/src/jrummikub/model/PlayerSettings.java @@ -9,24 +9,34 @@ import jrummikub.control.turn.TurnControlFactory; * The settings of a player */ public class PlayerSettings implements Serializable { + /** + * Type of turn control. + */ + public enum Type { + /** */ + HUMAN, + /** */ + COMPUTER + } + private static final long serialVersionUID = 1963640115089275992L; private String name; private Color color; - private TurnControlFactory.Type turnControlType; + private Type turnControlType; /** * Create a new human player * * @param name - * the player's name + * the player's name * @param color - * the player's color + * the player's color */ public PlayerSettings(String name, Color color) { this.name = name; this.color = color; - this.turnControlType = TurnControlFactory.Type.HUMAN; + this.turnControlType = Type.HUMAN; } /** @@ -51,7 +61,7 @@ public class PlayerSettings implements Serializable { * Sets the player's color * * @param color - * the new color + * the new color */ public void setColor(Color color) { this.color = color; @@ -61,7 +71,7 @@ public class PlayerSettings implements Serializable { * Sets the player's name * * @param name - * the new name + * the new name */ public void setName(String name) { this.name = name; @@ -71,9 +81,9 @@ public class PlayerSettings implements Serializable { * Set the player's TurnControlFactory type * * @param turnControlType - * player's TurnControlFactory type + * player's TurnControlFactory type */ - public void setTurnControlType(TurnControlFactory.Type turnControlType) { + public void setTurnControlType(Type turnControlType) { this.turnControlType = turnControlType; } @@ -82,7 +92,7 @@ public class PlayerSettings implements Serializable { * * @return player's TurnControlFactory type */ - public TurnControlFactory.Type getTurnControlType() { + public Type getTurnControlType() { return turnControlType; } } diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java index 4fca9ad..e5a73ed 100644 --- a/src/jrummikub/view/ISettingsPanel.java +++ b/src/jrummikub/view/ISettingsPanel.java @@ -3,8 +3,8 @@ package jrummikub.view; import java.awt.Color; import java.util.Set; -import jrummikub.control.turn.TurnControlFactory; import jrummikub.model.GameSettings; +import jrummikub.model.PlayerSettings.Type; import jrummikub.model.StoneColor; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; @@ -73,7 +73,7 @@ public interface ISettingsPanel { * * @return the event */ - public IEvent2 getChangePlayerTypeEvent(); + public IEvent2 getChangePlayerTypeEvent(); /** * The change initial meld threshold event is emitted when the user wants diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java index 271be53..cc34a35 100644 --- a/src/jrummikub/view/impl/SettingsPanel.java +++ b/src/jrummikub/view/impl/SettingsPanel.java @@ -48,9 +48,9 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import jrummikub.control.turn.TurnControlFactory; -import jrummikub.control.turn.TurnControlFactory.Type; import jrummikub.model.GameSettings; import jrummikub.model.PlayerSettings; +import jrummikub.model.PlayerSettings.Type; import jrummikub.model.StoneColor; import jrummikub.util.Event; import jrummikub.util.Event1; @@ -93,7 +93,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { private Event1 removePlayerEvent = new Event1(); private Event2 changePlayerColorEvent = new Event2(); private Event2 changePlayerNameEvent = new Event2(); - private Event2 changePlayerTypeEvent = new Event2(); + private Event2 changePlayerTypeEvent = new Event2(); private Event1 changeInitialMeldThresholdEvent = new Event1(); private Event1 changeJokerNumberEvent = new Event1(); private Event1 changeStoneSetNumberEvent = new Event1(); @@ -196,37 +196,37 @@ class SettingsPanel extends JPanel implements ISettingsPanel { @Override public void setError(SettingsError error) { switch (error) { - case NO_ERROR: - errorMessageLabel.setText(" "); - break; - case DUPLICATE_PLAYER_NAME_ERROR: - errorMessageLabel - .setText("Jeder Spielername darf nur einmal verwendet werden."); - errorMessageLabel.setForeground(Color.RED); - break; - case NO_PLAYER_NAME_ERROR: - errorMessageLabel.setText("Jeder Spieler muss einen Namen haben."); - errorMessageLabel.setForeground(Color.RED); - break; - case NOT_ENOUGH_STONES_ERROR: - errorMessageLabel - .setText("Es gibt nicht genug Steine f\u00fcr die gew\u00e4hlte Spieleranzahl."); - errorMessageLabel.setForeground(Color.RED); - break; - case NOT_ENOUGH_COLORS_ERROR: - errorMessageLabel - .setText("Es m\u00fcssen mindestens drei Farben ausgew\u00e4hlt werden."); - errorMessageLabel.setForeground(Color.RED); - break; - case COMPUTER_PLAYERS_ONLY_WARNING: - errorMessageLabel.setText("Es gibt keinen menschlichen Spieler."); - errorMessageLabel.setForeground(Color.ORANGE.darker()); - break; - case TOO_HIGH_THRESHOLD_WARNING: - errorMessageLabel - .setText("Die gew\u00e4hlte Schranke ist m\u00f6glicherweise zu hoch"); - errorMessageLabel.setForeground(Color.ORANGE.darker()); - break; + case NO_ERROR: + errorMessageLabel.setText(" "); + break; + case DUPLICATE_PLAYER_NAME_ERROR: + errorMessageLabel + .setText("Jeder Spielername darf nur einmal verwendet werden."); + errorMessageLabel.setForeground(Color.RED); + break; + case NO_PLAYER_NAME_ERROR: + errorMessageLabel.setText("Jeder Spieler muss einen Namen haben."); + errorMessageLabel.setForeground(Color.RED); + break; + case NOT_ENOUGH_STONES_ERROR: + errorMessageLabel + .setText("Es gibt nicht genug Steine f\u00fcr die gew\u00e4hlte Spieleranzahl."); + errorMessageLabel.setForeground(Color.RED); + break; + case NOT_ENOUGH_COLORS_ERROR: + errorMessageLabel + .setText("Es m\u00fcssen mindestens drei Farben ausgew\u00e4hlt werden."); + errorMessageLabel.setForeground(Color.RED); + break; + case COMPUTER_PLAYERS_ONLY_WARNING: + errorMessageLabel.setText("Es gibt keinen menschlichen Spieler."); + errorMessageLabel.setForeground(Color.ORANGE.darker()); + break; + case TOO_HIGH_THRESHOLD_WARNING: + errorMessageLabel + .setText("Die gew\u00e4hlte Schranke ist m\u00f6glicherweise zu hoch"); + errorMessageLabel.setForeground(Color.ORANGE.darker()); + break; } } @@ -251,7 +251,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { @Override public void setGameSettings(GameSettings gameSettings) { - while (playerSettingsPanels.size() > gameSettings.getPlayerList().size()) { + while (playerSettingsPanels.size() > gameSettings.getPlayerList() + .size()) { removePlayerSettingsPanel(); } @@ -259,11 +260,12 @@ class SettingsPanel extends JPanel implements ISettingsPanel { updatePlayerSettingsPanel(i, gameSettings.getPlayerList().get(i)); } - initialMeldThresholdSpinner - .setValue(gameSettings.getInitialMeldThreshold()); + initialMeldThresholdSpinner.setValue(gameSettings + .getInitialMeldThreshold()); stoneSetNumberSpinner.setValue(gameSettings.getStoneSetNumber()); highestValueSpinner.setValue(gameSettings.getHighestValue()); - numberOfStonesDealtSpinner.setValue(gameSettings.getNumberOfStonesDealt()); + numberOfStonesDealtSpinner.setValue(gameSettings + .getNumberOfStonesDealt()); jokerNumberSpinner.setValue(gameSettings.getJokerNumber()); timeSpinner.setValue(gameSettings.getTotalTime()); noLimitsBox.setSelected(gameSettings.isNoLimits()); @@ -292,8 +294,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { } private void removePlayerSettingsPanel() { - PlayerSettingsPanel p = playerSettingsPanels.remove(playerSettingsPanels - .size() - 1); + PlayerSettingsPanel p = playerSettingsPanels + .remove(playerSettingsPanels.size() - 1); playerSettingsViewport.remove(p); } @@ -315,7 +317,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { playerSettingsViewport.add(addPlayerPanel); 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) { @@ -480,8 +483,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { c.insets = new Insets(2, 2, 2, 2); final JSpinner spinner = new JSpinner(); spinner.setModel(new SpinnerNumberModel(min, min, max, step)); - spinner - .setPreferredSize(new Dimension(60, spinner.getMinimumSize().height)); + spinner.setPreferredSize(new Dimension(60, + spinner.getMinimumSize().height)); spinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { @@ -544,8 +547,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { c.gridwidth = GridBagConstraints.REMAINDER; addButton("Netzwerkspiel...", networkGameEvent, 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))); } void resetTabbedPane() { @@ -577,13 +580,13 @@ class SettingsPanel extends JPanel implements ISettingsPanel { nameField.setText(settings.getName()); } // playerType.setSelectedIndex(0); - int index = Arrays.binarySearch(TurnControlFactory.Type.values(), + int index = Arrays.binarySearch(Type.values(), settings.getTurnControlType()); if (index != playerType.getSelectedIndex()) { playerType.setSelectedIndex(index); } - colorButton - .setIcon(ImageUtil.createColorIcon(settings.getColor(), 16, 2)); + colorButton.setIcon(ImageUtil.createColorIcon(settings.getColor(), + 16, 2)); } public void enableRemoveButton(boolean enable) { @@ -631,7 +634,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { c.gridy = 0; add(colorButton, c); - nameField.getDocument().addDocumentListener(new NameChangeListener()); + nameField.getDocument().addDocumentListener( + new NameChangeListener()); c2.gridy = 0; c2.weightx = 1; c2.fill = GridBagConstraints.HORIZONTAL; @@ -664,8 +668,9 @@ class SettingsPanel extends JPanel implements ISettingsPanel { public Dimension getPreferredSize() { Dimension preferredSize = super.getPreferredSize(); for (Component component : this.getComponents()) { - preferredSize - .setSize(preferredSize.width, Math.max(preferredSize.height, + preferredSize.setSize( + preferredSize.width, + Math.max(preferredSize.height, component.getPreferredSize().height)); } return preferredSize; @@ -675,8 +680,9 @@ class SettingsPanel extends JPanel implements ISettingsPanel { public Dimension getMaximumSize() { Dimension preferredSize = super.getPreferredSize(); for (Component component : this.getComponents()) { - preferredSize - .setSize(Integer.MAX_VALUE, Math.max(preferredSize.height, + preferredSize.setSize( + Integer.MAX_VALUE, + Math.max(preferredSize.height, component.getPreferredSize().height)); } return preferredSize; @@ -692,7 +698,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { private void changeType() { changePlayerTypeEvent.emit(playerNumber, - TurnControlFactory.Type.values()[playerType.getSelectedIndex()]); + Type.values()[playerType.getSelectedIndex()]); } private void remove() { -- cgit v1.2.3