Start implementing NETWORK_OFFER mode of the settings panel

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@431 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-06-14 01:53:59 +02:00
parent eee80d605c
commit d2e65f4346
2 changed files with 222 additions and 165 deletions

View file

@ -192,12 +192,6 @@ public class MockSettingsPanel implements ISettingsPanel {
return setVariantChildrenEvent; return setVariantChildrenEvent;
} }
@Override
public void setSettingsMode(boolean enable) {
// TODO Auto-generated method stub
}
@Override @Override
public IEvent getBackEvent() { public IEvent getBackEvent() {
return backEvent; return backEvent;
@ -219,4 +213,10 @@ public class MockSettingsPanel implements ISettingsPanel {
public IEvent getOfferGameEvent() { public IEvent getOfferGameEvent() {
return offerGameEvent; return offerGameEvent;
} }
@Override
public void setSettingsMode(SettingsMode mode) {
// TODO Auto-generated method stub
}
} }

View file

@ -10,7 +10,6 @@ import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import java.awt.GridLayout; import java.awt.GridLayout;
import java.awt.Insets; import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
@ -61,7 +60,6 @@ import jrummikub.util.IEvent;
import jrummikub.util.IEvent1; import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2; import jrummikub.util.IEvent2;
import jrummikub.view.ISettingsPanel; import jrummikub.view.ISettingsPanel;
import jrummikub.view.ISettingsPanel.SettingsMode;
@SuppressWarnings("serial") @SuppressWarnings("serial")
class SettingsPanel extends JPanel implements ISettingsPanel { class SettingsPanel extends JPanel implements ISettingsPanel {
@ -80,8 +78,12 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private List<PlayerSettingsPanel> playerSettingsPanels = new ArrayList<PlayerSettingsPanel>(); private List<PlayerSettingsPanel> playerSettingsPanels = new ArrayList<PlayerSettingsPanel>();
private JLabel variantLabel;
private JPanel variantPanel;
private JButton setVariantDefaultButton; private JButton setVariantDefaultButton;
private JButton setVariantChildrenButton; private JButton setVariantChildrenButton;
private JSpinner initialMeldThresholdSpinner; private JSpinner initialMeldThresholdSpinner;
private JSpinner stoneSetNumberSpinner; private JSpinner stoneSetNumberSpinner;
private JSpinner highestValueSpinner; private JSpinner highestValueSpinner;
@ -89,14 +91,23 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private JSpinner jokerNumberSpinner; private JSpinner jokerNumberSpinner;
private JSpinner timeSpinner; private JSpinner timeSpinner;
private JCheckBox noLimitsBox; private JCheckBox noLimitsBox;
private JPanel colorSelectionPanel;
private Map<StoneColor, JToggleButton> colorButtons = new HashMap<StoneColor, JToggleButton>();
private JPanel colorLabelPanel;
private JLabel initialMeldThresholdLabel;
private JLabel stoneSetNumberLabel;
private JLabel highestValueLabel;
private JLabel numberOfStonesDealtLabel;
private JLabel jokerNumberLabel;
private JLabel timeLabel;
private JLabel noLimitsLabel;
private JButton loadButton; private JButton loadButton;
private JButton networkButton; private JButton networkButton;
private JButton backButton; private JButton backButton;
private JPanel buttonPanel; private JPanel buttonPanel;
private JPanel colorSelectionPanel;
private Map<StoneColor, JToggleButton> colorButtons = new HashMap<StoneColor, JToggleButton>();
private Event startGameEvent = new Event(); private Event startGameEvent = new Event();
private Event loadGameEvent = new Event(); private Event loadGameEvent = new Event();
private Event networkGameEvent = new Event(); private Event networkGameEvent = new Event();
@ -224,37 +235,37 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
@Override @Override
public void setError(SettingsError error) { public void setError(SettingsError error) {
switch (error) { switch (error) {
case NO_ERROR: case NO_ERROR:
errorMessageLabel.setText(" "); errorMessageLabel.setText(" ");
break; break;
case DUPLICATE_PLAYER_NAME_ERROR: case DUPLICATE_PLAYER_NAME_ERROR:
errorMessageLabel errorMessageLabel
.setText("Jeder Spielername darf nur einmal verwendet werden."); .setText("Jeder Spielername darf nur einmal verwendet werden.");
errorMessageLabel.setForeground(Color.RED); errorMessageLabel.setForeground(Color.RED);
break; break;
case NO_PLAYER_NAME_ERROR: case NO_PLAYER_NAME_ERROR:
errorMessageLabel.setText("Jeder Spieler muss einen Namen haben."); errorMessageLabel.setText("Jeder Spieler muss einen Namen haben.");
errorMessageLabel.setForeground(Color.RED); errorMessageLabel.setForeground(Color.RED);
break; break;
case NOT_ENOUGH_STONES_ERROR: case NOT_ENOUGH_STONES_ERROR:
errorMessageLabel errorMessageLabel
.setText("Es gibt nicht genug Steine f\u00fcr die gew\u00e4hlte Spieleranzahl."); .setText("Es gibt nicht genug Steine f\u00fcr die gew\u00e4hlte Spieleranzahl.");
errorMessageLabel.setForeground(Color.RED); errorMessageLabel.setForeground(Color.RED);
break; break;
case NOT_ENOUGH_COLORS_ERROR: case NOT_ENOUGH_COLORS_ERROR:
errorMessageLabel errorMessageLabel
.setText("Es m\u00fcssen mindestens drei Farben ausgew\u00e4hlt werden."); .setText("Es m\u00fcssen mindestens drei Farben ausgew\u00e4hlt werden.");
errorMessageLabel.setForeground(Color.RED); errorMessageLabel.setForeground(Color.RED);
break; break;
case COMPUTER_PLAYERS_ONLY_WARNING: case COMPUTER_PLAYERS_ONLY_WARNING:
errorMessageLabel.setText("Es gibt keinen menschlichen Spieler."); errorMessageLabel.setText("Es gibt keinen menschlichen Spieler.");
errorMessageLabel.setForeground(Color.ORANGE.darker()); errorMessageLabel.setForeground(Color.ORANGE.darker());
break; break;
case TOO_HIGH_THRESHOLD_WARNING: case TOO_HIGH_THRESHOLD_WARNING:
errorMessageLabel errorMessageLabel
.setText("Die gew\u00e4hlte Schranke ist m\u00f6glicherweise zu hoch"); .setText("Die gew\u00e4hlte Schranke ist m\u00f6glicherweise zu hoch");
errorMessageLabel.setForeground(Color.ORANGE.darker()); errorMessageLabel.setForeground(Color.ORANGE.darker());
break; break;
} }
} }
@ -298,8 +309,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
@Override @Override
public void setGameSettings(GameSettings gameSettings) { public void setGameSettings(GameSettings gameSettings) {
while (playerSettingsPanels.size() > gameSettings.getPlayerList() while (playerSettingsPanels.size() > gameSettings.getPlayerList().size()) {
.size()) {
removePlayerSettingsPanel(); removePlayerSettingsPanel();
} }
@ -308,23 +318,40 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
if (i < playerTypeChoices.size()) { if (i < playerTypeChoices.size()) {
choices = playerTypeChoices.get(i); choices = playerTypeChoices.get(i);
} }
updatePlayerSettingsPanel(i, gameSettings.getPlayerList().get(i), updatePlayerSettingsPanel(i, gameSettings.getPlayerList().get(i), choices);
choices);
} }
initialMeldThresholdSpinner.setValue(gameSettings initialMeldThresholdSpinner
.getInitialMeldThreshold()); .setValue(gameSettings.getInitialMeldThreshold());
stoneSetNumberSpinner.setValue(gameSettings.getStoneSetNumber()); stoneSetNumberSpinner.setValue(gameSettings.getStoneSetNumber());
highestValueSpinner.setValue(gameSettings.getHighestValue()); highestValueSpinner.setValue(gameSettings.getHighestValue());
numberOfStonesDealtSpinner.setValue(gameSettings numberOfStonesDealtSpinner.setValue(gameSettings.getNumberOfStonesDealt());
.getNumberOfStonesDealt());
jokerNumberSpinner.setValue(gameSettings.getJokerNumber()); jokerNumberSpinner.setValue(gameSettings.getJokerNumber());
timeSpinner.setValue(gameSettings.getTotalTime()); timeSpinner.setValue(gameSettings.getTotalTime());
noLimitsBox.setSelected(gameSettings.isNoLimits()); noLimitsBox.setSelected(gameSettings.isNoLimits());
initialMeldThresholdLabel.setText(gameSettings.getInitialMeldThreshold()
+ " Punkte");
stoneSetNumberLabel.setText(Integer.toString(gameSettings
.getStoneSetNumber()));
highestValueLabel.setText(Integer.toString(gameSettings.getHighestValue()));
numberOfStonesDealtLabel.setText(Integer.toString(gameSettings
.getNumberOfStonesDealt()));
jokerNumberLabel.setText(Integer.toString(gameSettings.getJokerNumber()));
timeLabel.setText(gameSettings.getTotalTime() + " Sekunden");
noLimitsLabel.setText(gameSettings.isNoLimits() ? "An" : "Aus");
colorLabelPanel.removeAll();
for (StoneColor color : StoneColor.values()) { for (StoneColor color : StoneColor.values()) {
colorButtons.get(color).getModel() boolean contained = gameSettings.getStoneColors().contains(color);
.setSelected(gameSettings.getStoneColors().contains(color));
colorButtons.get(color).getModel().setSelected(contained);
if (contained) {
colorLabelPanel.add(new JLabel(ImageUtil.createColorIcon(
StonePainter.getColor(color), 16, 1)));
}
} }
playerSettingsViewport.revalidate(); playerSettingsViewport.revalidate();
@ -342,8 +369,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private void addPlayerSettingsPanel(int i, PlayerSettings settings, private void addPlayerSettingsPanel(int i, PlayerSettings settings,
List<Type> choices) { List<Type> choices) {
PlayerSettingsPanel panel = new PlayerSettingsPanel(i, settings, PlayerSettingsPanel panel = new PlayerSettingsPanel(i, settings, choices);
choices);
playerSettingsPanels.add(panel); playerSettingsPanels.add(panel);
playerSettingsViewport.add(panel, playerSettingsViewport.add(panel,
playerSettingsViewport.getComponentCount() - 1); playerSettingsViewport.getComponentCount() - 1);
@ -352,8 +378,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
} }
private void removePlayerSettingsPanel() { private void removePlayerSettingsPanel() {
PlayerSettingsPanel p = playerSettingsPanels PlayerSettingsPanel p = playerSettingsPanels.remove(playerSettingsPanels
.remove(playerSettingsPanels.size() - 1); .size() - 1);
playerSettingsViewport.remove(p); playerSettingsViewport.remove(p);
} }
@ -375,8 +401,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
playerSettingsViewport.add(addPlayerPanel); playerSettingsViewport.add(addPlayerPanel);
addPlayerButton = new JButton("+"); addPlayerButton = new JButton("+");
addPlayerButton addPlayerButton.setFont(addPlayerButton.getFont().deriveFont(Font.BOLD));
.setFont(addPlayerButton.getFont().deriveFont(Font.BOLD));
addPlayerButton.addActionListener(new ActionListener() { addPlayerButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -396,39 +421,45 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
GridBagLayout layout = new GridBagLayout(); GridBagLayout layout = new GridBagLayout();
optionsPanel.setLayout(layout); optionsPanel.setLayout(layout);
int row = 0; int row = 1;
makeOptionLabel(row, "Variante:"); variantLabel = new JLabel("Variante:");
makeVariantPanel(row++); makeVariantPanel();
makeOptionLabel(row, "Auslegeschranke:"); makeOptionLabel(row++, "Auslegeschranke:");
initialMeldThresholdSpinner = makeOptionSpinner(row++, 1, 999, 1, initialMeldThresholdLabel = new JLabel();
initialMeldThresholdSpinner = createOptionSpinner(1, 999, 1,
changeInitialMeldThresholdEvent); changeInitialMeldThresholdEvent);
makeOptionLabel(row, "Anzahl Steins\u00e4tze:"); makeOptionLabel(row++, "Anzahl Steins\u00e4tze:");
stoneSetNumberSpinner = makeOptionSpinner(row++, 1, 999, 1, stoneSetNumberLabel = new JLabel();
stoneSetNumberSpinner = createOptionSpinner(1, 999, 1,
changeStoneSetNumberEvent); changeStoneSetNumberEvent);
makeOptionLabel(row, "H\u00f6chster Steinwert:"); makeOptionLabel(row++, "H\u00f6chster Steinwert:");
highestValueSpinner = makeOptionSpinner(row++, 3, 99, 1, highestValueLabel = new JLabel();
changeHighestValueEvent); highestValueSpinner = createOptionSpinner(3, 99, 1, changeHighestValueEvent);
makeOptionLabel(row, "Anzahl Startsteine:"); makeOptionLabel(row++, "Anzahl Startsteine:");
numberOfStonesDealtSpinner = makeOptionSpinner(row++, 1, 999, 1, numberOfStonesDealtLabel = new JLabel();
numberOfStonesDealtSpinner = createOptionSpinner(1, 999, 1,
changeNumberOfStonesDealtEvent); changeNumberOfStonesDealtEvent);
makeOptionLabel(row, "Jokeranzahl:"); makeOptionLabel(row++, "Jokeranzahl:");
jokerNumberSpinner = makeOptionSpinner(row++, 1, 999, 1, jokerNumberLabel = new JLabel();
changeJokerNumberEvent); jokerNumberSpinner = createOptionSpinner(1, 999, 1, changeJokerNumberEvent);
makeOptionLabel(row, "Zeit für Spielzug:"); makeOptionLabel(row++, "Zeit für Spielzug:");
timeSpinner = makeOptionSpinner(row++, 1, 999, 1, changeTimeEvent); timeLabel = new JLabel();
timeSpinner = createOptionSpinner(1, 999, 1, changeTimeEvent);
makeOptionLabel(row, "No Limits:"); makeOptionLabel(row++, "No Limits:");
noLimitsBox = makeOptionCheckbox(row++, changeNoLimitsEvent); noLimitsLabel = new JLabel();
noLimitsBox = createOptionCheckbox(changeNoLimitsEvent);
makeOptionLabel(row, "Steinfarben:"); makeOptionLabel(row, "Steinfarben:");
createColorSelectionPanel(row++); createColorSelectionPanel();
colorLabelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
c.gridx = 1; c.gridx = 1;
@ -439,14 +470,72 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
optionsPanel.add(makeFiller(), c); optionsPanel.add(makeFiller(), c);
} }
private void createColorSelectionPanel(int row) { private void removeOptionPanelComponentsAndLabels() {
GridBagConstraints c = new GridBagConstraints(); optionsPanel.remove(variantLabel);
c.anchor = GridBagConstraints.WEST; optionsPanel.remove(variantPanel);
c.gridx = 1;
c.gridy = row;
optionsPanel.remove(initialMeldThresholdSpinner);
optionsPanel.remove(initialMeldThresholdLabel);
optionsPanel.remove(stoneSetNumberSpinner);
optionsPanel.remove(stoneSetNumberLabel);
optionsPanel.remove(highestValueSpinner);
optionsPanel.remove(highestValueLabel);
optionsPanel.remove(numberOfStonesDealtSpinner);
optionsPanel.remove(numberOfStonesDealtLabel);
optionsPanel.remove(jokerNumberSpinner);
optionsPanel.remove(jokerNumberLabel);
optionsPanel.remove(timeSpinner);
optionsPanel.remove(timeLabel);
optionsPanel.remove(noLimitsBox);
optionsPanel.remove(noLimitsLabel);
optionsPanel.remove(colorSelectionPanel);
optionsPanel.remove(colorLabelPanel);
}
private void addOptionPanelComponents() {
removeOptionPanelComponentsAndLabels();
int row = 0;
addOptionPanelComponent(variantLabel, true, row);
addOptionPanelComponent(variantPanel, false, row++);
addOptionPanelComponent(initialMeldThresholdSpinner, false, row++);
addOptionPanelComponent(stoneSetNumberSpinner, false, row++);
addOptionPanelComponent(highestValueSpinner, false, row++);
addOptionPanelComponent(numberOfStonesDealtSpinner, false, row++);
addOptionPanelComponent(jokerNumberSpinner, false, row++);
addOptionPanelComponent(timeSpinner, false, row++);
addOptionPanelComponent(noLimitsBox, false, row++);
addOptionPanelComponent(colorSelectionPanel, false, row++);
}
private void addOptionPanelLabels() {
removeOptionPanelComponentsAndLabels();
int row = 1;
addOptionPanelComponent(initialMeldThresholdLabel, false, row++);
addOptionPanelComponent(stoneSetNumberLabel, false, row++);
addOptionPanelComponent(highestValueLabel, false, row++);
addOptionPanelComponent(numberOfStonesDealtLabel, false, row++);
addOptionPanelComponent(jokerNumberLabel, false, row++);
addOptionPanelComponent(timeLabel, false, row++);
addOptionPanelComponent(noLimitsLabel, false, row++);
addOptionPanelComponent(colorLabelPanel, false, row++);
}
private void addOptionPanelComponent(JComponent component, boolean label,
int row) {
GridBagConstraints c = new GridBagConstraints();
c.anchor = label ? GridBagConstraints.EAST : GridBagConstraints.WEST;
c.gridx = label ? 0 : 1;
c.gridy = row;
c.insets = new Insets(2, 2, 2, 2);
optionsPanel.add(component, c);
}
private void createColorSelectionPanel() {
colorSelectionPanel = new JPanel(); colorSelectionPanel = new JPanel();
optionsPanel.add(colorSelectionPanel, c);
for (StoneColor color : StoneColor.values()) { for (StoneColor color : StoneColor.values()) {
createColorButton(color); createColorButton(color);
@ -482,11 +571,11 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
changeStoneColorsEvent.emit(colors); changeStoneColorsEvent.emit(colors);
} }
private void makeVariantPanel(int row) { private void makeVariantPanel() {
JPanel panel = makeOptionSubpanel(row, new GridLayout(1, 2, 5, 0)); variantPanel = new JPanel(new GridLayout(1, 2, 5, 0));
setVariantDefaultButton = new JButton("Standard"); setVariantDefaultButton = new JButton("Standard");
panel.add(setVariantDefaultButton); variantPanel.add(setVariantDefaultButton);
setVariantDefaultButton.addActionListener(new ActionListener() { setVariantDefaultButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -494,7 +583,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
} }
}); });
setVariantChildrenButton = new JButton("Kinder"); setVariantChildrenButton = new JButton("Kinder");
panel.add(setVariantChildrenButton); variantPanel.add(setVariantChildrenButton);
setVariantChildrenButton.addActionListener(new ActionListener() { setVariantChildrenButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -503,24 +592,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}); });
} }
private JPanel makeOptionSubpanel(int row, LayoutManager layout) { private JCheckBox createOptionCheckbox(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);
JPanel panel = new JPanel(layout);
optionsPanel.add(panel, c);
return panel;
}
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(); final JCheckBox box = new JCheckBox();
box.addChangeListener(new ChangeListener() { box.addChangeListener(new ChangeListener() {
@Override @Override
@ -528,32 +600,25 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
targetEvent.emit(box.isSelected()); targetEvent.emit(box.isSelected());
} }
}); });
optionsPanel.add(box, c);
return box; return box;
} }
private JSpinner makeOptionSpinner(int row, int min, int max, int step, private JSpinner createOptionSpinner(int min, int max, int step,
final Event1<Integer> targetEvent) { final Event1<Integer> targetEvent) {
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.WEST;
c.gridx = 1;
c.gridy = row;
c.insets = new Insets(2, 2, 2, 2);
final JSpinner spinner = new JSpinner(); final JSpinner spinner = new JSpinner();
spinner.setModel(new SpinnerNumberModel(min, min, max, step)); spinner.setModel(new SpinnerNumberModel(min, min, max, step));
spinner.setPreferredSize(new Dimension(60, spinner
spinner.getMinimumSize().height)); .setPreferredSize(new Dimension(60, spinner.getMinimumSize().height));
spinner.addChangeListener(new ChangeListener() { spinner.addChangeListener(new ChangeListener() {
@Override @Override
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
targetEvent.emit((Integer) spinner.getValue()); targetEvent.emit((Integer) spinner.getValue());
} }
}); });
optionsPanel.add(spinner, c);
return spinner; return spinner;
} }
private void makeOptionLabel(int row, String name) { private JLabel makeOptionLabel(int row, String name) {
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.EAST; c.anchor = GridBagConstraints.EAST;
c.gridx = 0; c.gridx = 0;
@ -562,6 +627,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
JLabel label = new JLabel(name); JLabel label = new JLabel(name);
optionsPanel.add(label, c); optionsPanel.add(label, c);
return label;
} }
SettingsPanel() { SettingsPanel() {
@ -602,8 +669,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
addDefaultButtons(); addDefaultButtons();
setBorder(new CompoundBorder(new LineBorder(Color.BLACK), setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(
new EmptyBorder(10, 10, 10, 10))); 10, 10, 10, 10)));
} }
void resetTabbedPane() { void resetTabbedPane() {
@ -645,7 +712,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
c.gridwidth = GridBagConstraints.REMAINDER; c.gridwidth = GridBagConstraints.REMAINDER;
buttonPanel.add(backButton, c); buttonPanel.add(backButton, c);
} }
private void addNetworkOfferButtons() { private void addNetworkOfferButtons() {
buttonPanel.removeAll(); buttonPanel.removeAll();
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
@ -676,34 +743,27 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
@Override @Override
public void setSettingsMode(SettingsMode mode) { public void setSettingsMode(SettingsMode mode) {
switch (mode) { switch (mode) {
case DEFAULT: case DEFAULT:
addDefaultButtons(); addDefaultButtons();
enableOptions(true); enableOptions(true);
break; break;
case NETWORK_SETUP: case NETWORK_SETUP:
addNetworkSetupButtons(); addNetworkSetupButtons();
enableOptions(true); enableOptions(true);
break; break;
case NETWORK_OFFER: case NETWORK_OFFER:
addNetworkOfferButtons(); addNetworkOfferButtons();
enableOptions(false); enableOptions(false);
break; break;
} }
} }
private void enableOptions(boolean enable) { private void enableOptions(boolean enable) {
setVariantDefaultButton.setVisible(enable); if (enable) {
setVariantChildrenButton.setVisible(enable); addOptionPanelComponents();
initialMeldThresholdSpinner.setEnabled(enable); } else {
stoneSetNumberSpinner.setEnabled(enable); addOptionPanelLabels();
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 class PlayerSettingsPanel extends JPanel {
@ -723,8 +783,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
&& index < playerType.getModel().getSize()) { && index < playerType.getModel().getSize()) {
playerType.setSelectedIndex(index); playerType.setSelectedIndex(index);
} }
colorButton.setIcon(ImageUtil.createColorIcon(settings.getColor(), colorButton
16, 2)); .setIcon(ImageUtil.createColorIcon(settings.getColor(), 16, 2));
} }
public void setPlayerNameEditable(boolean editable) { public void setPlayerNameEditable(boolean editable) {
@ -769,15 +829,15 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
Vector<String> choices = new Vector<String>(); Vector<String> choices = new Vector<String>();
for (Type t : playerTypeChoices) { for (Type t : playerTypeChoices) {
switch (t) { switch (t) {
case COMPUTER: case COMPUTER:
choices.add("Computer"); choices.add("Computer");
break; break;
case HUMAN: case HUMAN:
choices.add("Mensch"); choices.add("Mensch");
break; break;
case NETWORK: case NETWORK:
choices.add("Netzwerk"); choices.add("Netzwerk");
break; break;
} }
} }
playerType.setModel(new DefaultComboBoxModel(choices)); playerType.setModel(new DefaultComboBoxModel(choices));
@ -798,8 +858,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
c.gridy = 0; c.gridy = 0;
add(colorButton, c); add(colorButton, c);
nameField.getDocument().addDocumentListener( nameField.getDocument().addDocumentListener(new NameChangeListener());
new NameChangeListener());
c2.gridy = 0; c2.gridy = 0;
c2.weightx = 1; c2.weightx = 1;
c2.fill = GridBagConstraints.HORIZONTAL; c2.fill = GridBagConstraints.HORIZONTAL;
@ -814,8 +873,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}); });
playerType.setPreferredSize(new Dimension(120, playerType playerType.setPreferredSize(new Dimension(120, playerType
.getPreferredSize().height)); .getPreferredSize().height));
playerType.setMinimumSize(new Dimension(120, playerType playerType.setMinimumSize(new Dimension(120,
.getMinimumSize().height)); playerType.getMinimumSize().height));
add(playerType, c); add(playerType, c);
removeButton = new JButton("\u00d7"); removeButton = new JButton("\u00d7");
@ -834,9 +893,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
public Dimension getPreferredSize() { public Dimension getPreferredSize() {
Dimension preferredSize = super.getPreferredSize(); Dimension preferredSize = super.getPreferredSize();
for (Component component : this.getComponents()) { for (Component component : this.getComponents()) {
preferredSize.setSize( preferredSize
preferredSize.width, .setSize(preferredSize.width, Math.max(preferredSize.height,
Math.max(preferredSize.height,
component.getPreferredSize().height)); component.getPreferredSize().height));
} }
return preferredSize; return preferredSize;
@ -846,9 +904,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
public Dimension getMaximumSize() { public Dimension getMaximumSize() {
Dimension preferredSize = super.getPreferredSize(); Dimension preferredSize = super.getPreferredSize();
for (Component component : this.getComponents()) { for (Component component : this.getComponents()) {
preferredSize.setSize( preferredSize
Integer.MAX_VALUE, .setSize(Integer.MAX_VALUE, Math.max(preferredSize.height,
Math.max(preferredSize.height,
component.getPreferredSize().height)); component.getPreferredSize().height));
} }
return preferredSize; return preferredSize;