summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-06-14 02:43:53 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-06-14 02:43:53 +0200
commitf6b1c638a17a9e3c9c1dcbac0fd748a3f13d70f3 (patch)
tree0ef679ce67ed783a21cc392d35a6d63dbd99f7a9 /src
parentd2e65f43461e97546799a42530872ea12afb0f8e (diff)
downloadJRummikub-f6b1c638a17a9e3c9c1dcbac0fd748a3f13d70f3.tar
JRummikub-f6b1c638a17a9e3c9c1dcbac0fd748a3f13d70f3.zip
Adjust SettingsPanel player settings tab for game offer panel
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@432 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src')
-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();