diff options
Diffstat (limited to 'src/jrummikub/view')
-rw-r--r-- | src/jrummikub/view/ISettingsPanel.java | 6 | ||||
-rw-r--r-- | src/jrummikub/view/impl/SettingsPanel.java | 196 |
2 files changed, 125 insertions, 77 deletions
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() { |