summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jrummikub/control/network/GameOfferControl.java1
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java111
2 files changed, 90 insertions, 22 deletions
diff --git a/src/jrummikub/control/network/GameOfferControl.java b/src/jrummikub/control/network/GameOfferControl.java
index 0e90078..8d3e8c8 100644
--- a/src/jrummikub/control/network/GameOfferControl.java
+++ b/src/jrummikub/control/network/GameOfferControl.java
@@ -16,6 +16,7 @@ public class GameOfferControl {
this.view = view;
view.getSettingsPanel().setSettingsMode(SettingsMode.NETWORK_OFFER);
+ view.getSettingsPanel().enableAddPlayerButton(false);
view.getSettingsPanel().setGameSettings(settings);
}
diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java
index 273be03..60fe20c 100644
--- a/src/jrummikub/view/impl/SettingsPanel.java
+++ b/src/jrummikub/view/impl/SettingsPanel.java
@@ -67,6 +67,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private List<Boolean> removeButtonsEnabled = Collections.emptyList();
private List<Boolean> playerNamesEditable = Collections.emptyList();
+ private SettingsMode settingsMode = SettingsMode.DEFAULT;
+
private JTabbedPane tabbedPane;
private JPanel playerSetupPanel;
private JPanel playerSettingsViewport;
@@ -369,7 +371,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,
+ settingsMode != SettingsMode.NETWORK_OFFER);
playerSettingsPanels.add(panel);
playerSettingsViewport.add(panel,
playerSettingsViewport.getComponentCount() - 1);
@@ -742,6 +745,12 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
@Override
public void setSettingsMode(SettingsMode mode) {
+ settingsMode = mode;
+
+ while (!playerSettingsPanels.isEmpty()) {
+ removePlayerSettingsPanel();
+ }
+
switch (mode) {
case DEFAULT:
addDefaultButtons();
@@ -774,25 +783,41 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private JComboBox playerType;
private List<Type> playerTypeChoices;
+ private JLabel nameLabel;
+ private JLabel typeLabel;
+
public void setSettings(PlayerSettings settings) {
- if (!nameField.getText().equals(settings.getName())) {
+ if (nameField != null && !nameField.getText().equals(settings.getName())) {
nameField.setText(settings.getName());
}
- int index = playerTypeChoices.indexOf(settings.getType());
- if (index != playerType.getSelectedIndex() && index >= 0
- && index < playerType.getModel().getSize()) {
- playerType.setSelectedIndex(index);
+ if (nameLabel != null) {
+ nameLabel.setText(settings.getName());
+ }
+
+ if (playerType != null) {
+ int index = playerTypeChoices.indexOf(settings.getType());
+ if (index != playerType.getSelectedIndex() && index >= 0
+ && index < playerType.getModel().getSize()) {
+ playerType.setSelectedIndex(index);
+ }
+ }
+ if (typeLabel != null) {
+ typeLabel.setText(getTypeLabel(settings.getType()));
}
colorButton
.setIcon(ImageUtil.createColorIcon(settings.getColor(), 16, 2));
}
public void setPlayerNameEditable(boolean editable) {
- nameField.setEditable(editable);
+ if (nameField != null) {
+ nameField.setEditable(editable);
+ }
}
public void enableRemoveButton(boolean enable) {
- removeButton.setEnabled(enable);
+ if (removeButton != null) {
+ removeButton.setEnabled(enable);
+ }
}
class NameChangeListener implements DocumentListener {
@@ -813,34 +838,46 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
public PlayerSettingsPanel(int playerNumber, PlayerSettings settings,
- List<Type> choices) {
+ List<Type> choices, boolean editable) {
setLayout(new GridBagLayout());
this.playerNumber = playerNumber;
- createControls(settings);
+
+ if (editable) {
+ createControls(settings);
+ } else {
+ createLabels();
+ }
+
setChoices(choices);
setSettings(settings);
}
+ private String getTypeLabel(Type type) {
+ switch (type) {
+ case COMPUTER:
+ return "Computer";
+ case HUMAN:
+ return "Mensch";
+ case NETWORK:
+ return "Netzwerk";
+ }
+
+ return null;
+ }
+
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;
- }
+ choices.add(getTypeLabel(t));
+ }
+
+ if (playerType != null) {
+ playerType.setModel(new DefaultComboBoxModel(choices));
}
- playerType.setModel(new DefaultComboBoxModel(choices));
}
private void createControls(PlayerSettings settings) {
@@ -889,6 +926,36 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
add(removeButton, c);
}
+ private void createLabels() {
+ GridBagConstraints c = new GridBagConstraints();
+ GridBagConstraints c2 = new GridBagConstraints();
+ colorButton = new JButton();
+ nameLabel = new JLabel();
+ nameLabel.setBorder(new EmptyBorder(3, 7, 3, 7));
+
+ colorButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ new ColorMenu();
+ }
+ });
+ c.gridy = 0;
+ add(colorButton, c);
+
+ c2.gridy = 0;
+ c2.weightx = 1;
+ c2.fill = GridBagConstraints.HORIZONTAL;
+ add(nameLabel, c2);
+
+ typeLabel = new JLabel(" ");
+ typeLabel.setBorder(new EmptyBorder(3, 7, 3, 7));
+ typeLabel.setPreferredSize(new Dimension(120, typeLabel
+ .getPreferredSize().height));
+ typeLabel.setMinimumSize(new Dimension(120,
+ typeLabel.getMinimumSize().height));
+ add(typeLabel, c);
+ }
+
@Override
public Dimension getPreferredSize() {
Dimension preferredSize = super.getPreferredSize();