summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view/impl')
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java149
1 files changed, 93 insertions, 56 deletions
diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java
index d7d9069..9536838 100644
--- a/src/jrummikub/view/impl/SettingsPanel.java
+++ b/src/jrummikub/view/impl/SettingsPanel.java
@@ -26,6 +26,7 @@ import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.JButton;
+import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
@@ -67,6 +68,7 @@ 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>();
@@ -96,6 +98,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private Event1<Integer> changeHighestValueEvent = new Event1<Integer>();
private Event1<Set<StoneColor>> changeStoneColorsEvent = new Event1<Set<StoneColor>>();
private Event1<Integer> changeTimeEvent = new Event1<Integer>();
+ private Event1<Boolean> changeNoLimitsEvent = new Event1<Boolean>();
@Override
public IEvent getStartGameEvent() {
@@ -161,11 +164,16 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
@Override
- public Event1<Integer> getChangeTimeEvent() {
+ public IEvent1<Integer> getChangeTimeEvent() {
return changeTimeEvent;
}
@Override
+ public IEvent1<Boolean> getChangeNoLimitsEvent() {
+ return changeNoLimitsEvent;
+ }
+
+ @Override
public IEvent1<Set<StoneColor>> getChangeStoneColorsEvent() {
return changeStoneColorsEvent;
}
@@ -173,37 +181,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;
}
}
@@ -228,7 +236,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();
}
@@ -236,13 +245,15 @@ 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());
for (StoneColor color : StoneColor.values()) {
colorButtons.get(color).getModel()
@@ -268,8 +279,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);
}
@@ -291,7 +302,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) {
@@ -328,17 +340,21 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
changeNumberOfStonesDealtEvent);
makeOptionLabel(4, "Jokeranzahl:");
- jokerNumberSpinner = makeOptionSpinner(4, 1, 999, 1, changeJokerNumberEvent);
+ jokerNumberSpinner = makeOptionSpinner(4, 1, 999, 1,
+ changeJokerNumberEvent);
makeOptionLabel(5, "Zeit für Spielzug:");
timeSpinner = makeOptionSpinner(5, 1, 999, 1, changeTimeEvent);
- makeOptionLabel(6, "Steinfarben:");
- createColorSelectionPanel(6);
+ makeOptionLabel(6, "No Limits:");
+ noLimitsBox = makeOptionCheckbox(6, changeNoLimitsEvent);
+
+ makeOptionLabel(7, "Steinfarben:");
+ createColorSelectionPanel(7);
GridBagConstraints c = new GridBagConstraints();
c.gridx = 1;
- c.gridy = 7;
+ c.gridy = 8;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 1;
@@ -388,6 +404,24 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
changeStoneColorsEvent.emit(colors);
}
+ private JCheckBox makeOptionCheckbox(int row,
+ final Event1<Boolean> targetEvent) {
+ GridBagConstraints c = new GridBagConstraints();
+ c.anchor = GridBagConstraints.WEST;
+ c.gridx = 1;
+ c.gridy = row;
+ c.insets = new Insets(2, 2, 2, 2);
+ final JCheckBox box = new JCheckBox();
+ box.addChangeListener(new ChangeListener() {
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ targetEvent.emit(box.isSelected());
+ }
+ });
+ optionsPanel.add(box, c);
+ return box;
+ }
+
private JSpinner makeOptionSpinner(int row, int min, int max, int step,
final Event1<Integer> targetEvent) {
GridBagConstraints c = new GridBagConstraints();
@@ -397,8 +431,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) {
@@ -458,8 +492,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() {
@@ -496,8 +530,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) {
@@ -545,7 +579,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;
@@ -578,8 +613,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;
@@ -589,8 +625,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;
@@ -605,8 +642,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() {