diff options
author | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-06-14 00:55:58 +0200 |
---|---|---|
committer | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-06-14 00:55:58 +0200 |
commit | eee80d605c95bac3a2489f0dbadadd81ec1ad753 (patch) | |
tree | 4ffce7c17267fbc209ffc147fcd1799e8836f9b8 | |
parent | 8e0669a737af19cbcb1d6a1cf64ffcbc6acf2394 (diff) | |
download | JRummikub-eee80d605c95bac3a2489f0dbadadd81ec1ad753.tar JRummikub-eee80d605c95bac3a2489f0dbadadd81ec1ad753.zip |
neue GameOfferControl
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@430 72836036-5685-4462-b002-a69064685172
-rw-r--r-- | mock/jrummikub/view/MockSettingsPanel.java | 2 | ||||
-rw-r--r-- | src/jrummikub/control/AbstractSettingsControl.java | 345 | ||||
-rw-r--r-- | src/jrummikub/control/SettingsControl.java | 3 | ||||
-rw-r--r-- | src/jrummikub/control/network/GameOfferControl.java | 27 | ||||
-rw-r--r-- | src/jrummikub/control/network/NetworkControl.java | 50 | ||||
-rw-r--r-- | src/jrummikub/control/network/NetworkSettingsControl.java | 3 | ||||
-rw-r--r-- | src/jrummikub/view/ISettingsPanel.java | 14 | ||||
-rw-r--r-- | src/jrummikub/view/impl/SettingsPanel.java | 183 |
8 files changed, 536 insertions, 91 deletions
diff --git a/mock/jrummikub/view/MockSettingsPanel.java b/mock/jrummikub/view/MockSettingsPanel.java index 2f79178..bc2901d 100644 --- a/mock/jrummikub/view/MockSettingsPanel.java +++ b/mock/jrummikub/view/MockSettingsPanel.java @@ -193,7 +193,7 @@ public class MockSettingsPanel implements ISettingsPanel { } @Override - public void enableNetworkMode(boolean enable) { + public void setSettingsMode(boolean enable) { // TODO Auto-generated method stub } diff --git a/src/jrummikub/control/AbstractSettingsControl.java b/src/jrummikub/control/AbstractSettingsControl.java new file mode 100644 index 0000000..693e0f0 --- /dev/null +++ b/src/jrummikub/control/AbstractSettingsControl.java @@ -0,0 +1,345 @@ +package jrummikub.control; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import jrummikub.model.GameSettings; +import jrummikub.model.PlayerSettings; +import jrummikub.model.PlayerSettings.Type; +import jrummikub.model.StoneColor; +import jrummikub.util.Connection; +import jrummikub.util.IListener; +import jrummikub.util.IListener1; +import jrummikub.util.IListener2; +import jrummikub.view.ISettingsPanel; +import jrummikub.view.IView; + +public abstract class AbstractSettingsControl { + protected IView view; + protected List<Connection> connections = new ArrayList<Connection>(); + + protected GameSettings settings; + + /** + * Create a new settings control + * + * @param view + * the view to use + * @param settings + * initial game settings + */ + protected AbstractSettingsControl(IView view, GameSettings settings) { + this.view = view; + this.settings = settings; + } + + protected void addListeners() { + addPlayerSettingsListeners(); + + addOptionListeners1(); + addOptionListeners2(); + addVariantListeners(); + } + + private void addPlayerSettingsListeners() { + connections.add(view.getSettingsPanel().getAddPlayerEvent() + .add(new IListener() { + @Override + public void handle() { + addPlayer(); + } + })); + connections.add(view.getSettingsPanel().getRemovePlayerEvent() + .add(new IListener1<Integer>() { + @Override + public void handle(Integer i) { + removePlayer(i); + } + })); + connections.add(view.getSettingsPanel().getChangePlayerColorEvent() + .add(new IListener2<Integer, Color>() { + @Override + public void handle(Integer i, Color color) { + setPlayerColor(i, color); + } + })); + 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>() { + @Override + public void handle(Integer i, Type type) { + setPlayerType(i, type); + } + })); + } + + private void addOptionListeners1() { + connections.add(view.getSettingsPanel() + .getChangeInitialMeldThresholdEvent() + .add(new IListener1<Integer>() { + @Override + public void handle(Integer value) { + settings.setInitialMeldThreshold(value); + update(); + } + })); + + connections.add(view.getSettingsPanel().getChangeJokerNumberEvent() + .add(new IListener1<Integer>() { + @Override + public void handle(Integer value) { + settings.setJokerNumber(value); + update(); + } + })); + + connections.add(view.getSettingsPanel().getChangeStoneSetNumberEvent() + .add(new IListener1<Integer>() { + @Override + public void handle(Integer value) { + settings.setStoneSetNumber(value); + update(); + } + })); + connections.add(view.getSettingsPanel() + .getChangeNumberOfStonesDealtEvent() + .add(new IListener1<Integer>() { + @Override + public void handle(Integer value) { + settings.setNumberOfStonesDealt(value); + update(); + } + })); + } + + private void addOptionListeners2() { + connections.add(view.getSettingsPanel().getChangeHighestValueEvent() + .add(new IListener1<Integer>() { + @Override + public void handle(Integer value) { + settings.setHighestValue(value); + update(); + } + })); + connections.add(view.getSettingsPanel().getChangeTimeEvent() + .add(new IListener1<Integer>() { + @Override + public void handle(Integer value) { + settings.setTotalTime(value); + update(); + } + })); + connections.add(view.getSettingsPanel().getChangeStoneColorsEvent() + .add(new IListener1<Set<StoneColor>>() { + @Override + public void handle(Set<StoneColor> value) { + settings.setStoneColors(new HashSet<StoneColor>(value)); + update(); + } + })); + + connections.add(view.getSettingsPanel().getChangeNoLimitsEvent() + .add(new IListener1<Boolean>() { + @Override + public void handle(Boolean value) { + settings.setNoLimits(value); + update(); + } + })); + } + + /** + * Add event listeners for variants, e.g. standard or children + */ + private void addVariantListeners() { + connections.add(view.getSettingsPanel().getSetVariantDefaultEvent() + .add(new IListener() { + @Override + public void handle() { + settings.reset(); + update(); + } + })); + connections.add(view.getSettingsPanel().getSetVariantChildrenEvent() + .add(new IListener() { + @Override + public void handle() { + settings.reset(); + settings.setHighestValue(10); + settings.setJokerNumber(6); + settings.setTotalTime(120); + settings.setInitialMeldThreshold(20); + update(); + } + })); + } + + /** + * Start the operation of the settings control + */ + public void startSettings() { + view.showSettingsPanel(true); + } + + protected Color findUnusedColor() { + Color color = null; + colorLoop: for (Color c : ISettingsPanel.PLAYER_COLORS) { + color = c; + for (PlayerSettings player : settings.getPlayerList()) { + if (c == player.getColor()) { + continue colorLoop; + } + } + break; + } + return color; + } + + private void setPlayerColor(int i, Color color) { + PlayerSettings player = settings.getPlayerList().get(i); + + if (player.getColor() == color) { + return; + } + + for (PlayerSettings other : settings.getPlayerList()) { + if (other.getColor() == color) { + other.setColor(player.getColor()); + break; + } + } + + player.setColor(color); + update(); + } + + private void setPlayerName(int i, String name) { + settings.getPlayerList().get(i).setName(name); + update(); + } + + private void removePlayer(int i) { + settings.getPlayerList().remove(i); + update(); + } + + protected boolean checkSettings() { + if (!checkName()) { + return false; + } + if (!checkErrors()) { + return false; + } + + view.getSettingsPanel().setError(ISettingsPanel.SettingsError.NO_ERROR); + view.getSettingsPanel().enableStartGameButton(true); + + checkWarnings(); + + return true; + } + + private boolean checkName() { + for (PlayerSettings player : settings.getPlayerList()) { + if (player.getName().isEmpty()) { + view.getSettingsPanel().setError( + ISettingsPanel.SettingsError.NO_PLAYER_NAME_ERROR); + view.getSettingsPanel().enableStartGameButton(false); + return false; + } + } + for (int i = 0; i < settings.getPlayerList().size(); ++i) { + PlayerSettings player1 = settings.getPlayerList().get(i); + String name = player1.getName(); + Type type = player1.getType(); + + if (type == Type.NETWORK) { + continue; + } + + 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().enableStartGameButton(false); + return false; + } + } + } + return true; + } + + private boolean checkErrors() { + int totalStonesDealt = settings.getNumberOfStonesDealt() + * settings.getPlayerList().size(); + int totalStones = settings.getHighestValue() + * settings.getStoneSetNumber() + * settings.getStoneColors().size() + settings.getJokerNumber(); + + if (totalStones <= totalStonesDealt) { + view.getSettingsPanel().setError( + ISettingsPanel.SettingsError.NOT_ENOUGH_STONES_ERROR); + view.getSettingsPanel().enableStartGameButton(false); + return false; + } + + if (settings.getStoneColors().size() < 3) { + view.getSettingsPanel().setError( + ISettingsPanel.SettingsError.NOT_ENOUGH_COLORS_ERROR); + view.getSettingsPanel().enableStartGameButton(false); + return false; + } + + return true; + } + + private void checkWarnings() { + if (settings.getInitialMeldThreshold() >= 100) { + view.getSettingsPanel().setError( + ISettingsPanel.SettingsError.TOO_HIGH_THRESHOLD_WARNING); + return; + } + + boolean humanPlayerFound = false; + for (PlayerSettings player : settings.getPlayerList()) { + if (player.getType() == Type.HUMAN) { + humanPlayerFound = true; + break; + } + } + + if (!humanPlayerFound) { + view.getSettingsPanel().setError( + ISettingsPanel.SettingsError.COMPUTER_PLAYERS_ONLY_WARNING); + return; + } + } + + /** + * Abort settings control once settings are set + */ + public void abort() { + view.showSettingsPanel(false); + for (Connection c : connections) { + c.remove(); + } + } + + abstract protected void addPlayer(); + + abstract protected void setPlayerType(int i, Type type); + + abstract protected void update(); + +} diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java index a3fad13..4659828 100644 --- a/src/jrummikub/control/SettingsControl.java +++ b/src/jrummikub/control/SettingsControl.java @@ -14,6 +14,7 @@ import jrummikub.util.IEvent1; import jrummikub.util.IListener; import jrummikub.view.ISettingsPanel; import jrummikub.view.IView; +import jrummikub.view.ISettingsPanel.SettingsMode; /** * The settings control controls the settings panel @@ -31,7 +32,7 @@ public class SettingsControl extends AbstractSettingsControl { */ public SettingsControl(IView view, GameSettings settings) { super(view, settings); - view.getSettingsPanel().enableNetworkMode(false); + view.getSettingsPanel().setSettingsMode(SettingsMode.DEFAULT); view.getSettingsPanel().setPlayerNamesEditable( Collections.<Boolean> emptyList()); diff --git a/src/jrummikub/control/network/GameOfferControl.java b/src/jrummikub/control/network/GameOfferControl.java new file mode 100644 index 0000000..0e90078 --- /dev/null +++ b/src/jrummikub/control/network/GameOfferControl.java @@ -0,0 +1,27 @@ +package jrummikub.control.network; + +import jrummikub.model.GameSettings; +import jrummikub.view.ISettingsPanel.SettingsMode; +import jrummikub.view.IView; + +public class GameOfferControl { + private ConnectionControl connectionControl; + private GameSettings settings; + private IView view; + + public GameOfferControl(ConnectionControl connectionControl, + GameSettings settings, IView view) { + this.connectionControl = connectionControl; + this.settings = settings; + this.view = view; + + view.getSettingsPanel().setSettingsMode(SettingsMode.NETWORK_OFFER); + view.getSettingsPanel().setGameSettings(settings); + } + + public void startGameOffer() { + view.showSettingsPanel(true); + + } + +} diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java index bb60556..e09cdc0 100644 --- a/src/jrummikub/control/network/NetworkControl.java +++ b/src/jrummikub/control/network/NetworkControl.java @@ -26,6 +26,7 @@ public class NetworkControl { private Event stopNetworkEvent = new Event(); private NetworkSettingsControl settingsControl; + private GameOfferControl gameOfferControl; private Map<UUID, GameData> gameMap = new HashMap<UUID, GameData>(); @@ -157,27 +158,36 @@ public class NetworkControl { } private void createSettingsControl() { - if (settingsControl == null) { - view.showGameListPanel(false); - - settingsControl = new NetworkSettingsControl( - connectionControl.getNickname(), view, new GameSettings()); - settingsControl.getOfferGameEvent().add(new IListener1<GameSettings>() { - @Override - public void handle(GameSettings value) { - // TODO Auto-generated method stub - - } - }); - settingsControl.getBackEvent().add(new IListener() { - @Override - public void handle() { - settingsControl=null; - view.showGameListPanel(true); - } - }); - settingsControl.startSettings(); + if (settingsControl != null) { + return; } + view.showGameListPanel(false); + + settingsControl = new NetworkSettingsControl( + connectionControl.getNickname(), view, new GameSettings()); + settingsControl.getOfferGameEvent().add(new IListener1<GameSettings>() { + @Override + public void handle(GameSettings settings) { + settingsControl = null; + createGameOfferControl(settings); + } + }); + settingsControl.getBackEvent().add(new IListener() { + @Override + public void handle() { + settingsControl = null; + view.showGameListPanel(true); + } + }); + settingsControl.startSettings(); + } + + private void createGameOfferControl(GameSettings settings) { + if (gameOfferControl != null) { + return; + } + gameOfferControl = new GameOfferControl(connectionControl, settings, view); + gameOfferControl.startGameOffer(); } } diff --git a/src/jrummikub/control/network/NetworkSettingsControl.java b/src/jrummikub/control/network/NetworkSettingsControl.java index 9c989c6..ca8c74b 100644 --- a/src/jrummikub/control/network/NetworkSettingsControl.java +++ b/src/jrummikub/control/network/NetworkSettingsControl.java @@ -13,6 +13,7 @@ import jrummikub.util.Event; import jrummikub.util.Event1; import jrummikub.util.IListener; import jrummikub.view.ISettingsPanel; +import jrummikub.view.ISettingsPanel.SettingsMode; import jrummikub.view.IView; /** @@ -38,7 +39,7 @@ public class NetworkSettingsControl extends AbstractSettingsControl { super(view, settings); this.nickname = nickname; - view.getSettingsPanel().enableNetworkMode(true); + view.getSettingsPanel().setSettingsMode(SettingsMode.NETWORK_SETUP); view.getSettingsPanel().setPlayerNamesEditable( Collections.<Boolean> emptyList()); diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java index 3e56519..c2bd766 100644 --- a/src/jrummikub/view/ISettingsPanel.java +++ b/src/jrummikub/view/ISettingsPanel.java @@ -42,7 +42,7 @@ public interface ISettingsPanel { * @param enable * starting a network game */ - public void enableNetworkMode(boolean enable); + public void setSettingsMode(SettingsMode mode); /** * The add player event is emitted when the user wants to add a player to @@ -258,4 +258,16 @@ public interface ISettingsPanel { /** Only computer players added */ COMPUTER_PLAYERS_ONLY_WARNING } + + /** + * SettingsPanel can be used with different functions in different situations + */ + public enum SettingsMode { + /**Local game settings */ + DEFAULT, + /** */ + NETWORK_SETUP, + /** */ + NETWORK_OFFER + } }
\ No newline at end of file diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java index 1d3e1b5..e5f0455 100644 --- a/src/jrummikub/view/impl/SettingsPanel.java +++ b/src/jrummikub/view/impl/SettingsPanel.java @@ -61,6 +61,7 @@ import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.util.IEvent2; import jrummikub.view.ISettingsPanel; +import jrummikub.view.ISettingsPanel.SettingsMode; @SuppressWarnings("serial") class SettingsPanel extends JPanel implements ISettingsPanel { @@ -223,37 +224,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; } } @@ -297,7 +298,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(); } @@ -306,14 +308,16 @@ class SettingsPanel extends JPanel implements ISettingsPanel { if (i < playerTypeChoices.size()) { choices = playerTypeChoices.get(i); } - updatePlayerSettingsPanel(i, gameSettings.getPlayerList().get(i), choices); + updatePlayerSettingsPanel(i, gameSettings.getPlayerList().get(i), + choices); } - 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()); @@ -338,7 +342,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { private void addPlayerSettingsPanel(int i, PlayerSettings settings, List<Type> choices) { - PlayerSettingsPanel panel = new PlayerSettingsPanel(i, settings, choices); + PlayerSettingsPanel panel = new PlayerSettingsPanel(i, settings, + choices); playerSettingsPanels.add(panel); playerSettingsViewport.add(panel, playerSettingsViewport.getComponentCount() - 1); @@ -347,8 +352,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); } @@ -370,7 +375,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) { @@ -535,8 +541,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) { @@ -596,8 +602,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { addDefaultButtons(); - 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() { @@ -624,7 +630,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { buttonPanel.add(networkButton, c); } - private void addNetworkButtons() { + private void addNetworkSetupButtons() { buttonPanel.removeAll(); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; @@ -639,6 +645,22 @@ class SettingsPanel extends JPanel implements ISettingsPanel { c.gridwidth = GridBagConstraints.REMAINDER; buttonPanel.add(backButton, c); } + + private void addNetworkOfferButtons() { + buttonPanel.removeAll(); + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.BOTH; + c.gridwidth = 1; + c.weightx = 1; + c.weighty = 1; + + buttonPanel.add(startButton, c); + c.weightx = 0; + buttonPanel.add(Box.createHorizontalStrut(10), c); + c.weightx = 1; + c.gridwidth = GridBagConstraints.REMAINDER; + buttonPanel.add(backButton, c); + } private JButton createButton(String title, final Event event) { JButton button = new JButton(title); @@ -652,14 +674,38 @@ class SettingsPanel extends JPanel implements ISettingsPanel { } @Override - public void enableNetworkMode(boolean enable) { - if (enable) { - addNetworkButtons(); - } else { + public void setSettingsMode(SettingsMode mode) { + switch (mode) { + case DEFAULT: addDefaultButtons(); + enableOptions(true); + break; + case NETWORK_SETUP: + addNetworkSetupButtons(); + enableOptions(true); + break; + case NETWORK_OFFER: + addNetworkOfferButtons(); + enableOptions(false); + break; } } + private void enableOptions(boolean enable) { + setVariantDefaultButton.setVisible(enable); + setVariantChildrenButton.setVisible(enable); + initialMeldThresholdSpinner.setEnabled(enable); + stoneSetNumberSpinner.setEnabled(enable); + highestValueSpinner.setEnabled(enable); + numberOfStonesDealtSpinner.setEnabled(enable); + jokerNumberSpinner.setEnabled(enable); + timeSpinner.setEnabled(enable); + noLimitsBox.setEnabled(enable); + for (JToggleButton colorButton: colorButtons.values()){ + colorButton.setEnabled(enable); + } + } + private class PlayerSettingsPanel extends JPanel { private int playerNumber; private JButton colorButton; @@ -677,8 +723,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { && index < playerType.getModel().getSize()) { playerType.setSelectedIndex(index); } - colorButton - .setIcon(ImageUtil.createColorIcon(settings.getColor(), 16, 2)); + colorButton.setIcon(ImageUtil.createColorIcon(settings.getColor(), + 16, 2)); } public void setPlayerNameEditable(boolean editable) { @@ -723,15 +769,15 @@ class SettingsPanel extends JPanel implements ISettingsPanel { Vector<String> choices = new Vector<String>(); for (Type t : playerTypeChoices) { switch (t) { - case COMPUTER: - choices.add("Computer"); - break; - case HUMAN: - choices.add("Mensch"); - break; - case NETWORK: - choices.add("Netzwerk"); - break; + case COMPUTER: + choices.add("Computer"); + break; + case HUMAN: + choices.add("Mensch"); + break; + case NETWORK: + choices.add("Netzwerk"); + break; } } playerType.setModel(new DefaultComboBoxModel(choices)); @@ -752,7 +798,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; @@ -767,8 +814,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { }); playerType.setPreferredSize(new Dimension(120, playerType .getPreferredSize().height)); - playerType.setMinimumSize(new Dimension(120, - playerType.getMinimumSize().height)); + playerType.setMinimumSize(new Dimension(120, playerType + .getMinimumSize().height)); add(playerType, c); removeButton = new JButton("\u00d7"); @@ -787,8 +834,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; @@ -798,8 +846,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; |