summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view')
-rw-r--r--src/jrummikub/view/ISettingsPanel.java14
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java183
2 files changed, 129 insertions, 68 deletions
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;