diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-11 04:45:28 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-11 04:45:28 +0200 |
commit | 6ac71b62e309ec04feb7ebda41dd795df678e1e4 (patch) | |
tree | f81ee556e357ae11bc425ae8533c39e568529c48 /src/jrummikub | |
parent | 4fbbcb5e06443cd8a0a879034cd365ca70f6450b (diff) | |
download | JRummikub-6ac71b62e309ec04feb7ebda41dd795df678e1e4.tar JRummikub-6ac71b62e309ec04feb7ebda41dd795df678e1e4.zip |
Added variant buttons to option panel
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@416 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub')
-rw-r--r-- | src/jrummikub/control/SettingsControl.java | 50 | ||||
-rw-r--r-- | src/jrummikub/model/GameSettings.java | 4 | ||||
-rw-r--r-- | src/jrummikub/view/ISettingsPanel.java | 6 | ||||
-rw-r--r-- | src/jrummikub/view/impl/SettingsPanel.java | 196 |
4 files changed, 161 insertions, 95 deletions
diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java index 4351c59..4ad30ce 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<Integer>() { + .getChangeInitialMeldThresholdEvent().add(new IListener1<Integer>() { @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<Integer>() { @Override public void handle(Integer value) { @@ -149,6 +147,26 @@ public class SettingsControl { update(); } })); + 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.setTime(120); + settings.setInitialMeldThreshold(20); + update(); + } + })); } private void addPlayerSettingsListeners() { @@ -221,8 +239,7 @@ public class SettingsControl { break; } - settings.getPlayerList().add( - new PlayerSettings("Spieler " + num, color)); + settings.getPlayerList().add(new PlayerSettings("Spieler " + num, color)); update(); } @@ -263,9 +280,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(); @@ -286,9 +302,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; } @@ -297,8 +312,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) { diff --git a/src/jrummikub/model/GameSettings.java b/src/jrummikub/model/GameSettings.java index 42f76a6..f52f8cf 100644 --- a/src/jrummikub/model/GameSettings.java +++ b/src/jrummikub/model/GameSettings.java @@ -31,6 +31,10 @@ public class GameSettings implements Serializable { * Creates new GameSettings with default values */ public GameSettings() { + reset(); + } + + public void reset() { initialMeldThreshold = 30; jokerPoints = 50; jokerNumber = 2; diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java index bc2593d..b00046f 100644 --- a/src/jrummikub/view/ISettingsPanel.java +++ b/src/jrummikub/view/ISettingsPanel.java @@ -6,7 +6,6 @@ import java.util.Set; import jrummikub.control.turn.TurnControlFactory; import jrummikub.model.GameSettings; import jrummikub.model.StoneColor; -import jrummikub.util.Event1; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.util.IEvent2; @@ -175,6 +174,10 @@ public interface ISettingsPanel { public IEvent1<Boolean> getChangeNoLimitsEvent(); + public IEvent getSetVariantDefaultEvent(); + + public IEvent getSetVariantChildrenEvent(); + /** * Specifies the different kinds of settings errors that can be displayed */ @@ -196,5 +199,4 @@ public interface ISettingsPanel { /** Only computer players added */ COMPUTER_PLAYERS_ONLY_WARNING } - }
\ No newline at end of file diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java index a509e8b..6b80641 100644 --- a/src/jrummikub/view/impl/SettingsPanel.java +++ b/src/jrummikub/view/impl/SettingsPanel.java @@ -10,6 +10,7 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.Insets; +import java.awt.LayoutManager; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; @@ -68,17 +69,19 @@ class SettingsPanel extends JPanel implements ISettingsPanel { private JButton addPlayerButton; private JLabel errorMessageLabel; private JButton startButton; - private JCheckBox noLimitsBox; private boolean removeButtonsEnabled = true; private List<PlayerSettingsPanel> playerSettingsPanels = new ArrayList<PlayerSettingsPanel>(); + private JButton setVariantDefaultButton; + private JButton setVariantChildrenButton; private JSpinner initialMeldThresholdSpinner; private JSpinner stoneSetNumberSpinner; private JSpinner highestValueSpinner; private JSpinner numberOfStonesDealtSpinner; private JSpinner jokerNumberSpinner; private JSpinner timeSpinner; + private JCheckBox noLimitsBox; private JPanel colorSelectionPanel; private Map<StoneColor, JToggleButton> colorButtons = new HashMap<StoneColor, JToggleButton>(); @@ -99,6 +102,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { private Event1<Set<StoneColor>> changeStoneColorsEvent = new Event1<Set<StoneColor>>(); private Event1<Integer> changeTimeEvent = new Event1<Integer>(); private Event1<Boolean> changeNoLimitsEvent = new Event1<Boolean>(); + private Event setVariantDefaultEvent = new Event(); + private Event setVariantChildrenEvent = new Event(); @Override public IEvent getStartGameEvent() { @@ -179,39 +184,49 @@ class SettingsPanel extends JPanel implements ISettingsPanel { } @Override + public IEvent getSetVariantDefaultEvent() { + return setVariantDefaultEvent; + } + + @Override + public IEvent getSetVariantChildrenEvent() { + return setVariantChildrenEvent; + } + + @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; } } @@ -236,8 +251,7 @@ 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(); } @@ -245,12 +259,11 @@ 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.getTime()); noLimitsBox.setSelected(gameSettings.isNoLimits()); @@ -279,8 +292,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); } @@ -302,8 +315,7 @@ 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) { @@ -323,38 +335,43 @@ class SettingsPanel extends JPanel implements ISettingsPanel { GridBagLayout layout = new GridBagLayout(); optionsPanel.setLayout(layout); - makeOptionLabel(0, "Auslegeschranke:"); - initialMeldThresholdSpinner = makeOptionSpinner(0, 1, 999, 1, + int row = 0; + + makeOptionLabel(row, "Variante:"); + makeVariantPanel(row++); + + makeOptionLabel(row, "Auslegeschranke:"); + initialMeldThresholdSpinner = makeOptionSpinner(row++, 1, 999, 1, changeInitialMeldThresholdEvent); - makeOptionLabel(1, "Anzahl Steins\u00e4tze:"); - stoneSetNumberSpinner = makeOptionSpinner(1, 1, 999, 1, + makeOptionLabel(row, "Anzahl Steins\u00e4tze:"); + stoneSetNumberSpinner = makeOptionSpinner(row++, 1, 999, 1, changeStoneSetNumberEvent); - makeOptionLabel(2, "H\u00f6chster Steinwert:"); - highestValueSpinner = makeOptionSpinner(2, 3, 99, 1, + makeOptionLabel(row, "H\u00f6chster Steinwert:"); + highestValueSpinner = makeOptionSpinner(row++, 3, 99, 1, changeHighestValueEvent); - makeOptionLabel(3, "Anzahl Startsteine:"); - numberOfStonesDealtSpinner = makeOptionSpinner(3, 1, 999, 1, + makeOptionLabel(row, "Anzahl Startsteine:"); + numberOfStonesDealtSpinner = makeOptionSpinner(row++, 1, 999, 1, changeNumberOfStonesDealtEvent); - makeOptionLabel(4, "Jokeranzahl:"); - jokerNumberSpinner = makeOptionSpinner(4, 1, 999, 1, + makeOptionLabel(row, "Jokeranzahl:"); + jokerNumberSpinner = makeOptionSpinner(row++, 1, 999, 1, changeJokerNumberEvent); - makeOptionLabel(5, "Zeit für Spielzug:"); - timeSpinner = makeOptionSpinner(5, 1, 999, 1, changeTimeEvent); + makeOptionLabel(row, "Zeit für Spielzug:"); + timeSpinner = makeOptionSpinner(row++, 1, 999, 1, changeTimeEvent); - makeOptionLabel(6, "No Limits:"); - noLimitsBox = makeOptionCheckbox(6, changeNoLimitsEvent); + makeOptionLabel(row, "No Limits:"); + noLimitsBox = makeOptionCheckbox(row++, changeNoLimitsEvent); - makeOptionLabel(7, "Steinfarben:"); - createColorSelectionPanel(7); + makeOptionLabel(row, "Steinfarben:"); + createColorSelectionPanel(row++); GridBagConstraints c = new GridBagConstraints(); c.gridx = 1; - c.gridy = 8; + c.gridy = row; c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; @@ -404,6 +421,38 @@ class SettingsPanel extends JPanel implements ISettingsPanel { changeStoneColorsEvent.emit(colors); } + private void makeVariantPanel(int row) { + JPanel panel = makeOptionSubpanel(row, new GridLayout(1, 2, 5, 0)); + + setVariantDefaultButton = new JButton("Standard"); + panel.add(setVariantDefaultButton); + setVariantDefaultButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + setVariantDefaultEvent.emit(); + } + }); + setVariantChildrenButton = new JButton("Kinder"); + panel.add(setVariantChildrenButton); + setVariantChildrenButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + setVariantChildrenEvent.emit(); + } + }); + } + + private JPanel makeOptionSubpanel(int row, LayoutManager layout) { + GridBagConstraints c = new GridBagConstraints(); + c.anchor = GridBagConstraints.WEST; + c.gridx = 1; + c.gridy = row; + c.insets = new Insets(2, 2, 2, 2); + JPanel panel = new JPanel(layout); + optionsPanel.add(panel, c); + return panel; + } + private JCheckBox makeOptionCheckbox(int row, final Event1<Boolean> targetEvent) { GridBagConstraints c = new GridBagConstraints(); @@ -431,8 +480,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) { @@ -495,8 +544,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() { @@ -533,8 +582,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { 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) { @@ -582,8 +631,7 @@ 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; @@ -616,9 +664,8 @@ 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; @@ -628,9 +675,8 @@ 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; @@ -645,8 +691,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { } private void changeType() { - changePlayerTypeEvent.emit(playerNumber, TurnControlFactory.Type - .values()[playerType.getSelectedIndex()]); + changePlayerTypeEvent.emit(playerNumber, + TurnControlFactory.Type.values()[playerType.getSelectedIndex()]); } private void remove() { |