1 package net.sourceforge.simplegamenet.specs.tools;
2
3 import javax.swing.*;
4 import net.sourceforge.simplegamenet.specs.gui.GameSettingsPanel;
5 import net.sourceforge.simplegamenet.util.proportionlayout.ProportionConstraints;
6 import net.sourceforge.simplegamenet.util.proportionlayout.ProportionLayout;
7
8 public class TwoPlayerGameSettingsPanel extends GameSettingsPanel {
9
10 private JLabel maximumConnectionsAmountLabel;
11 private JComboBox maximumConnectionsAmountComboBox;
12
13 public TwoPlayerGameSettingsPanel() throws IllegalArgumentException {
14 this(2, 2, 8);
15 }
16
17 public TwoPlayerGameSettingsPanel(int defaultMaximumConnectionsAmount)
18 throws IllegalArgumentException {
19 this(defaultMaximumConnectionsAmount, 2, defaultMaximumConnectionsAmount);
20
21 }
22
23 public TwoPlayerGameSettingsPanel(int defaultMaximumConnectionsAmount,
24 int minimumMaximumConnectionsAmount,
25 int maximumMaximumConnectionsAmount)
26 throws IllegalArgumentException {
27 ProportionLayout layout = new ProportionLayout();
28 layout.appendColumn(0, ProportionLayout.NO_PROPORTION);
29 layout.appendColumn(10);
30 layout.appendColumn(0, 1.0);
31 layout.appendRow(0, 1.0);
32 layout.appendRow(0, ProportionLayout.NO_PROPORTION);
33 layout.appendRow(0, 1.0);
34 setLayout(layout);
35
36 maximumConnectionsAmountLabel = new JLabel("Maximum amount of connections:");
37 maximumConnectionsAmountComboBox = new JComboBox();
38 for (int i = minimumMaximumConnectionsAmount; i <= maximumMaximumConnectionsAmount;
39 i++) {
40 Integer integer = new Integer(i);
41 maximumConnectionsAmountComboBox.addItem(integer);
42 if (i == defaultMaximumConnectionsAmount) {
43 maximumConnectionsAmountComboBox.setSelectedItem(integer);
44 }
45 }
46 add(maximumConnectionsAmountLabel, new ProportionConstraints(0, 1));
47 add(maximumConnectionsAmountComboBox, new ProportionConstraints(2, 1));
48 }
49
50 public int getMaximumConnectionsAmount() {
51 return ((Integer) maximumConnectionsAmountComboBox.getSelectedItem()).intValue();
52 }
53
54 public void setEnabled(boolean enabled) {
55 super.setEnabled(enabled);
56 maximumConnectionsAmountComboBox.setEnabled(enabled);
57 }
58
59 }