summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view')
-rw-r--r--src/jrummikub/view/ISettingsPanel.java27
-rw-r--r--src/jrummikub/view/impl/GameListPanel.java2
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java198
3 files changed, 130 insertions, 97 deletions
diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java
index 2b5aa58..f1737a9 100644
--- a/src/jrummikub/view/ISettingsPanel.java
+++ b/src/jrummikub/view/ISettingsPanel.java
@@ -10,7 +10,6 @@ import jrummikub.model.StoneColor;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2;
-import jrummikub.util.Pair;
/**
* The panel for the game setup
@@ -40,8 +39,8 @@ public interface ISettingsPanel {
public void enableNetworkMode(boolean enable);
/**
- * The add player event is emitted when the user wants to add a player to
- * the player list
+ * The add player event is emitted when the user wants to add a player to the
+ * player list
*
* @return the event
*/
@@ -88,8 +87,8 @@ public interface ISettingsPanel {
public IEvent1<Integer> getChangeInitialMeldThresholdEvent();
/**
- * The change StoneSet number event is emitted when the user wants to use
- * more or less than 2 StoneSets per color
+ * The change StoneSet number event is emitted when the user wants to use more
+ * or less than 2 StoneSets per color
*
* @return number of SoneSets
*/
@@ -130,7 +129,7 @@ public interface ISettingsPanel {
* Sets an error to display
*
* @param error
- * the kind of error
+ * the kind of error
*/
public void setError(SettingsError error);
@@ -138,7 +137,7 @@ public interface ISettingsPanel {
* Enables or disables the start game button
*
* @param enable
- * specifies if the button is to be enabled or disabled
+ * specifies if the button is to be enabled or disabled
*/
public void enableStartGameButton(boolean enable);
@@ -146,7 +145,7 @@ public interface ISettingsPanel {
* Enables or disables the add player button
*
* @param enable
- * specifies if the button is to be enabled or disabled
+ * specifies if the button is to be enabled or disabled
*/
public void enableAddPlayerButton(boolean enable);
@@ -154,16 +153,16 @@ public interface ISettingsPanel {
* Enables or disables the remove player buttons
*
* @param enable
- * specifies if the buttons are to be enabled or disabled
+ * specifies if the buttons are to be enabled or disabled
*/
- public void enableRemovePlayerButtons(boolean enable);
+ public void enableRemovePlayerButtons(List<Boolean> enable);
/**
* Sets the game settings to display
*
* @param gameSettings
- * the settings
+ * the settings
*/
public void setGameSettings(GameSettings gameSettings);
@@ -203,9 +202,13 @@ public interface ISettingsPanel {
public IEvent getSetVariantChildrenEvent();
public IEvent getBackEvent();
-
+
public void setPlayerTypeChoices(List<List<Type>> choices);
+ public void setPlayerNamesEditable(List<Boolean> editable);
+
+ public IEvent getOfferGameEvent();
+
/**
* Specifies the different kinds of settings errors that can be displayed
*/
diff --git a/src/jrummikub/view/impl/GameListPanel.java b/src/jrummikub/view/impl/GameListPanel.java
index 99807f8..28c7634 100644
--- a/src/jrummikub/view/impl/GameListPanel.java
+++ b/src/jrummikub/view/impl/GameListPanel.java
@@ -187,7 +187,7 @@ class GameListPanel extends JPanel implements IGameListPanel {
int index, boolean isSelected, boolean cellHasFocus) {
String host = "", playerCount = "";
- if (value instanceof GameData) {
+ if (value instanceof GameData && ((GameData)value).getGameSettings() != null) {
GameData gameData = (GameData) value;
host = gameData.getHost();
diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java
index 0292d2c..1d3e1b5 100644
--- a/src/jrummikub/view/impl/SettingsPanel.java
+++ b/src/jrummikub/view/impl/SettingsPanel.java
@@ -16,10 +16,10 @@ import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -60,12 +60,13 @@ import jrummikub.util.Event2;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2;
-import jrummikub.util.Pair;
import jrummikub.view.ISettingsPanel;
@SuppressWarnings("serial")
class SettingsPanel extends JPanel implements ISettingsPanel {
- private List<List<Type>> playerTypeChoices = new ArrayList<List<Type>>();
+ private List<List<Type>> playerTypeChoices = Collections.emptyList();
+ private List<Boolean> removeButtonsEnabled = Collections.emptyList();
+ private List<Boolean> playerNamesEditable = Collections.emptyList();
private JTabbedPane tabbedPane;
private JPanel playerSetupPanel;
@@ -74,8 +75,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private JButton addPlayerButton;
private JLabel errorMessageLabel;
private JButton startButton;
+ private JButton offerButton;
- private boolean removeButtonsEnabled = true;
private List<PlayerSettingsPanel> playerSettingsPanels = new ArrayList<PlayerSettingsPanel>();
private JButton setVariantDefaultButton;
@@ -98,6 +99,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private Event startGameEvent = new Event();
private Event loadGameEvent = new Event();
private Event networkGameEvent = new Event();
+ private Event offerGameEvent = new Event();
+ private Event backEvent = new Event();
private Event addPlayerEvent = new Event();
private Event1<Integer> removePlayerEvent = new Event1<Integer>();
private Event2<Integer, Color> changePlayerColorEvent = new Event2<Integer, Color>();
@@ -113,13 +116,17 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private Event1<Boolean> changeNoLimitsEvent = new Event1<Boolean>();
private Event setVariantDefaultEvent = new Event();
private Event setVariantChildrenEvent = new Event();
- private Event backEvent = new Event();
@Override
public IEvent getStartGameEvent() {
return startGameEvent;
}
+ @Override
+ public IEvent getOfferGameEvent() {
+ return offerGameEvent;
+ }
+
IEvent getLoadGameEvent() {
return loadGameEvent;
}
@@ -216,37 +223,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;
}
}
@@ -262,17 +269,35 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
@Override
- public void enableRemovePlayerButtons(boolean enable) {
+ public void enableRemovePlayerButtons(List<Boolean> enable) {
removeButtonsEnabled = enable;
+ Iterator<Boolean> it = enable.iterator();
+ for (PlayerSettingsPanel psp : playerSettingsPanels) {
+ if (!it.hasNext()) {
+ psp.enableRemoveButton(false);
+ } else {
+ psp.enableRemoveButton(it.next());
+ }
+ }
+ }
+
+ @Override
+ public void setPlayerNamesEditable(List<Boolean> editable) {
+ playerNamesEditable = editable;
+
+ Iterator<Boolean> it = editable.iterator();
for (PlayerSettingsPanel psp : playerSettingsPanels) {
- psp.enableRemoveButton(enable);
+ if (!it.hasNext()) {
+ psp.setPlayerNameEditable(true);
+ } else {
+ psp.setPlayerNameEditable(it.next());
+ }
}
}
@Override
public void setGameSettings(GameSettings gameSettings) {
- while (playerSettingsPanels.size() > gameSettings.getPlayerList()
- .size()) {
+ while (playerSettingsPanels.size() > gameSettings.getPlayerList().size()) {
removePlayerSettingsPanel();
}
@@ -281,16 +306,14 @@ 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());
@@ -315,16 +338,17 @@ 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);
+ enableRemovePlayerButtons(removeButtonsEnabled);
+ setPlayerNamesEditable(playerNamesEditable);
}
private void removePlayerSettingsPanel() {
- PlayerSettingsPanel p = playerSettingsPanels
- .remove(playerSettingsPanels.size() - 1);
+ PlayerSettingsPanel p = playerSettingsPanels.remove(playerSettingsPanels
+ .size() - 1);
playerSettingsViewport.remove(p);
}
@@ -346,8 +370,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) {
@@ -512,8 +535,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) {
@@ -535,7 +558,6 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
optionsPanel.add(label, c);
}
- // TODO wiederfinden
SettingsPanel() {
setLayout(new GridBagLayout());
@@ -566,15 +588,16 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
add(buttonPanel, c);
startButton = createButton("Spiel starten", startGameEvent);
-
loadButton = createButton("Spiel laden...", loadGameEvent);
networkButton = createButton("Netzwerkspiel...", networkGameEvent);
+
+ offerButton = createButton("Spiel anbieten", offerGameEvent);
backButton = createButton("Zur\u00fcck", backEvent);
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() {
@@ -609,7 +632,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
c.weightx = 1;
c.weighty = 1;
- buttonPanel.add(startButton, c);
+ buttonPanel.add(offerButton, c);
c.weightx = 0;
buttonPanel.add(Box.createHorizontalStrut(10), c);
c.weightx = 1;
@@ -643,19 +666,23 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private JTextField nameField;
private JButton removeButton;
private JComboBox playerType;
+ private List<Type> playerTypeChoices;
public void setSettings(PlayerSettings settings) {
if (!nameField.getText().equals(settings.getName())) {
nameField.setText(settings.getName());
}
- // playerType.setSelectedIndex(0);
- int index = Arrays.binarySearch(Type.values(),
- settings.getTurnControlType());
- if (index != playerType.getSelectedIndex()) {
+ int index = playerTypeChoices.indexOf(settings.getType());
+ if (index != playerType.getSelectedIndex() && index >= 0
+ && 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) {
+ nameField.setEditable(editable);
}
public void enableRemoveButton(boolean enable) {
@@ -691,18 +718,20 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
public void setChoices(List<Type> playerTypeChoices) {
+ this.playerTypeChoices = playerTypeChoices;
+
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));
@@ -723,8 +752,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;
@@ -737,6 +765,10 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
changeType();
}
});
+ playerType.setPreferredSize(new Dimension(120, playerType
+ .getPreferredSize().height));
+ playerType.setMinimumSize(new Dimension(120,
+ playerType.getMinimumSize().height));
add(playerType, c);
removeButton = new JButton("\u00d7");
@@ -747,7 +779,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
remove();
}
});
- removeButton.setEnabled(removeButtonsEnabled);
+
add(removeButton, c);
}
@@ -755,9 +787,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;
@@ -767,9 +798,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;
@@ -785,7 +815,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private void changeType() {
changePlayerTypeEvent.emit(playerNumber,
- Type.values()[playerType.getSelectedIndex()]);
+ playerTypeChoices.get(playerType.getSelectedIndex()));
}
private void remove() {