diff options
-rw-r--r-- | src/jrummikub/control/AbstractSettingsControl.java | 76 | ||||
-rw-r--r-- | src/jrummikub/control/SettingsControl.java | 23 | ||||
-rw-r--r-- | src/jrummikub/control/network/NetworkSettingsControl.java | 32 |
3 files changed, 61 insertions, 70 deletions
diff --git a/src/jrummikub/control/AbstractSettingsControl.java b/src/jrummikub/control/AbstractSettingsControl.java index 79f8274..45802a7 100644 --- a/src/jrummikub/control/AbstractSettingsControl.java +++ b/src/jrummikub/control/AbstractSettingsControl.java @@ -2,6 +2,8 @@ package jrummikub.control; import java.awt.Color; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -31,13 +33,18 @@ public abstract class AbstractSettingsControl { * Create a new settings control * * @param view - * the view to use + * the view to use * @param settings - * initial game settings + * initial game settings */ protected AbstractSettingsControl(IView view, GameSettings settings) { this.view = view; this.settings = settings; + + view.getSettingsPanel().setPlayerNamesEditable( + Collections.<Boolean> emptyList()); + view.getSettingsPanel().setPlayerColors( + new HashSet<Color>(Arrays.asList(ISettingsPanel.PLAYER_COLORS))); } protected void addListeners() { @@ -49,15 +56,15 @@ public abstract class AbstractSettingsControl { } private void addPlayerSettingsListeners() { - connections.add(view.getSettingsPanel().getAddPlayerEvent().add( - new IListener() { + connections.add(view.getSettingsPanel().getAddPlayerEvent() + .add(new IListener() { @Override public void handle() { addPlayer(); } })); - connections.add(view.getSettingsPanel().getRemovePlayerEvent().add( - new IListener1<Integer>() { + connections.add(view.getSettingsPanel().getRemovePlayerEvent() + .add(new IListener1<Integer>() { @Override public void handle(Integer i) { removePlayer(i); @@ -70,15 +77,15 @@ public abstract class AbstractSettingsControl { setPlayerColor(i, color); } })); - connections.add(view.getSettingsPanel().getChangePlayerNameEvent().add( - new IListener2<Integer, String>() { + connections.add(view.getSettingsPanel().getChangePlayerNameEvent() + .add(new IListener2<Integer, String>() { @Override public void handle(Integer i, String name) { setPlayerName(i, name); } })); - connections.add(view.getSettingsPanel().getChangePlayerTypeEvent().add( - new IListener2<Integer, Type>() { + connections.add(view.getSettingsPanel().getChangePlayerTypeEvent() + .add(new IListener2<Integer, Type>() { @Override public void handle(Integer i, Type type) { setPlayerType(i, type); @@ -88,14 +95,13 @@ public abstract class AbstractSettingsControl { private void addOptionListeners1() { connections.add(view.getSettingsPanel() - .getChangeInitialMeldThresholdEvent().add( - new IListener1<Integer>() { - @Override - public void handle(Integer value) { - settings.setInitialMeldThreshold(value); - update(); - } - })); + .getChangeInitialMeldThresholdEvent().add(new IListener1<Integer>() { + @Override + public void handle(Integer value) { + settings.setInitialMeldThreshold(value); + update(); + } + })); connections.add(view.getSettingsPanel().getChangeJokerNumberEvent() .add(new IListener1<Integer>() { @@ -114,15 +120,14 @@ public abstract class AbstractSettingsControl { update(); } })); - connections.add(view.getSettingsPanel() - .getChangeNumberOfStonesDealtEvent().add( - new IListener1<Integer>() { - @Override - public void handle(Integer value) { - settings.setNumberOfStonesDealt(value); - update(); - } - })); + connections.add(view.getSettingsPanel().getChangeNumberOfStonesDealtEvent() + .add(new IListener1<Integer>() { + @Override + public void handle(Integer value) { + settings.setNumberOfStonesDealt(value); + update(); + } + })); } private void addOptionListeners2() { @@ -134,8 +139,8 @@ public abstract class AbstractSettingsControl { update(); } })); - connections.add(view.getSettingsPanel().getChangeTimeEvent().add( - new IListener1<Integer>() { + connections.add(view.getSettingsPanel().getChangeTimeEvent() + .add(new IListener1<Integer>() { @Override public void handle(Integer value) { settings.setTotalTime(value); @@ -151,8 +156,8 @@ public abstract class AbstractSettingsControl { } })); - connections.add(view.getSettingsPanel().getChangeNoLimitsEvent().add( - new IListener1<Boolean>() { + connections.add(view.getSettingsPanel().getChangeNoLimitsEvent() + .add(new IListener1<Boolean>() { @Override public void handle(Boolean value) { settings.setNoLimits(value); @@ -273,10 +278,8 @@ public abstract class AbstractSettingsControl { for (int j = i + 1; j < settings.getPlayerList().size(); ++j) { PlayerSettings player2 = settings.getPlayerList().get(j); if (player2.getName().equals(name) && player2.getType() == type) { - view - .getSettingsPanel() - .setError( - ISettingsPanel.SettingsError.DUPLICATE_PLAYER_NAME_ERROR); + view.getSettingsPanel().setError( + ISettingsPanel.SettingsError.DUPLICATE_PLAYER_NAME_ERROR); view.getSettingsPanel().enableStartGameButton(false); return false; } @@ -288,8 +291,7 @@ public abstract class AbstractSettingsControl { private boolean checkErrors() { 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) { diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java index e54fa6d..6576101 100644 --- a/src/jrummikub/control/SettingsControl.java +++ b/src/jrummikub/control/SettingsControl.java @@ -1,10 +1,8 @@ package jrummikub.control; -import java.awt.Color; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.List; import jrummikub.model.GameSettings; @@ -22,21 +20,18 @@ import jrummikub.view.IView; */ public class SettingsControl extends AbstractSettingsControl { private Event1<GameSettings> startGameEvent = new Event1<GameSettings>(); - + /** * 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) { super(view, settings); view.getSettingsPanel().setSettingsMode(SettingsMode.DEFAULT); - view.getSettingsPanel().setPlayerNamesEditable( - Collections.<Boolean> emptyList()); - view.getSettingsPanel().setPlayerColors(new HashSet<Color>(Arrays.asList(ISettingsPanel.PLAYER_COLORS))); addPlayer(); addPlayer(); @@ -52,17 +47,16 @@ public class SettingsControl extends AbstractSettingsControl { })); } - /** - * 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 */ public IEvent1<GameSettings> getStartGameEvent() { return startGameEvent; } - + @Override protected void addPlayer() { if (settings.getPlayerList().size() >= ISettingsPanel.PLAYER_COLORS.length) { @@ -102,9 +96,8 @@ public class SettingsControl extends AbstractSettingsControl { view.getSettingsPanel().enableRemovePlayerButtons( Collections.nCopies(settings.getPlayerList().size(), enableRemoveButtons)); - view.getSettingsPanel() - .enableAddPlayerButton( - settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); + view.getSettingsPanel().enableAddPlayerButton( + settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); checkSettings(); diff --git a/src/jrummikub/control/network/NetworkSettingsControl.java b/src/jrummikub/control/network/NetworkSettingsControl.java index 41cf5f8..1f6cc3d 100644 --- a/src/jrummikub/control/network/NetworkSettingsControl.java +++ b/src/jrummikub/control/network/NetworkSettingsControl.java @@ -28,11 +28,11 @@ public class NetworkSettingsControl extends AbstractSettingsControl { * Creates a new network settings control * * @param nickname - * to be set as player name + * to be set as player name * @param view - * for events and handlers + * for events and handlers * @param settings - * for playerNumber, color... + * for playerNumber, color... */ public NetworkSettingsControl(String nickname, IView view, GameSettings settings) { @@ -40,8 +40,6 @@ public class NetworkSettingsControl extends AbstractSettingsControl { this.nickname = nickname; view.getSettingsPanel().setSettingsMode(SettingsMode.NETWORK_SETUP); - view.getSettingsPanel().setPlayerNamesEditable( - Collections.<Boolean> emptyList()); addFirstPlayer(); addPlayer(); @@ -56,19 +54,18 @@ public class NetworkSettingsControl extends AbstractSettingsControl { } })); - connections.add(view.getSettingsPanel().getBackEvent() - .add(new IListener() { - @Override - public void handle() { - abort(); - backEvent.emit(); - } - })); + connections.add(view.getSettingsPanel().getBackEvent().add(new IListener() { + @Override + public void handle() { + abort(); + backEvent.emit(); + } + })); } /** - * The game offer event is emitted when a player wants to offer a new - * network game + * The game offer event is emitted when a player wants to offer a new network + * game * * @return the event */ @@ -96,9 +93,8 @@ public class NetworkSettingsControl extends AbstractSettingsControl { @Override protected void update() { - view.getSettingsPanel() - .enableAddPlayerButton( - settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); + view.getSettingsPanel().enableAddPlayerButton( + settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); checkSettings(); |