From a4faa8db23589930a828250816ebaeddf787c689 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 13 Jun 2011 17:19:26 +0200 Subject: Fix SettingsControl.checkSettings method length git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@419 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/SettingsControl.java | 48 ++++++++++++++++-------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java index 17d37a9..ad88b70 100644 --- a/src/jrummikub/control/SettingsControl.java +++ b/src/jrummikub/control/SettingsControl.java @@ -34,9 +34,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 +44,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,8 +78,7 @@ 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); @@ -104,8 +103,7 @@ public class SettingsControl { update(); } })); - connections.add(view.getSettingsPanel() - .getChangeNumberOfStonesDealtEvent() + connections.add(view.getSettingsPanel().getChangeNumberOfStonesDealtEvent() .add(new IListener1() { @Override public void handle(Integer value) { @@ -248,8 +246,7 @@ public class SettingsControl { break; } - settings.getPlayerList().add( - new PlayerSettings("Spieler " + num, color)); + settings.getPlayerList().add(new PlayerSettings("Spieler " + num, color)); update(); } @@ -290,9 +287,8 @@ 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(); @@ -300,6 +296,19 @@ public class SettingsControl { } private boolean checkSettings() { + if (!checkErrors()) { + return false; + } + + view.getSettingsPanel().setError(ISettingsPanel.SettingsError.NO_ERROR); + view.getSettingsPanel().enableStartGameButton(true); + + checkWarnings(); + + return true; + } + + private boolean checkErrors() { for (PlayerSettings player : settings.getPlayerList()) { if (player.getName().isEmpty()) { view.getSettingsPanel().setError( @@ -313,9 +322,8 @@ 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; } @@ -324,8 +332,7 @@ 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) { @@ -342,11 +349,6 @@ public class SettingsControl { return false; } - view.getSettingsPanel().setError(ISettingsPanel.SettingsError.NO_ERROR); - view.getSettingsPanel().enableStartGameButton(true); - - checkWarnings(); - return true; } -- cgit v1.2.3