View Javadoc

1   package net.sourceforge.simplegamenet.framework.gui;
2   
3   import javax.swing.*;
4   import net.sourceforge.simplegamenet.util.proportionlayout.ProportionConstraints;
5   import net.sourceforge.simplegamenet.util.proportionlayout.ProportionLayout;
6   import net.sourceforge.simplegamenet.framework.gui.ConnectionWizardDialog;
7   
8   class JoinHostGamePanel extends JPanel {
9   
10      private ConnectionWizardDialog connectionWizardDialog;
11  
12      private ButtonGroup joinHostGameButtonGroup = new ButtonGroup();
13      private JRadioButton[] joinHostGameRadioButtons = new JRadioButton[2];
14      // [0] Join game
15      // [1] Host game
16  
17      private int connectionType = ConnectionWizardDialog.JOIN_CONNECTION;
18  
19      JoinHostGamePanel(ConnectionWizardDialog connectionWizardDialog) {
20          this.connectionWizardDialog = connectionWizardDialog;
21          this.connectionType = connectionType;
22          ProportionLayout layout = new ProportionLayout();
23          layout.appendColumn(10);                                 // 0 empty
24          layout.appendColumn(0, 1.0);                             // 1
25          layout.appendColumn(10);                                 // 2 empty
26          layout.appendRow(0, 1.0);                            // 0 empty
27          layout.appendRow(0, ProportionLayout.NO_PROPORTION); // 1
28          layout.appendRow(10);                                // 2 empty
29          layout.appendRow(0, ProportionLayout.NO_PROPORTION); // 3
30          layout.appendRow(0, 1.0);                            // 4 empty
31          setLayout(layout);
32          joinHostGameRadioButtons[0] = new JRadioButton("Join game", true);
33          joinHostGameRadioButtons[1] = new JRadioButton("Host game", false);
34          for (int i = 0; i < joinHostGameRadioButtons.length; i++) {
35              joinHostGameButtonGroup.add(joinHostGameRadioButtons[i]);
36              add(joinHostGameRadioButtons[i], new ProportionConstraints(1, 1 + (2 * i)));
37          }
38      }
39  
40      boolean areSettingsAcceptable() {
41          if (joinHostGameRadioButtons[0].isSelected()) {
42              connectionType = ConnectionWizardDialog.JOIN_CONNECTION;
43          } else {
44              connectionType = ConnectionWizardDialog.HOST_CONNECTION;
45          }
46          return true;
47      }
48  
49      int getConnectionType() {
50          return connectionType;
51      }
52  
53      public void setConnectionType(int connectionType) {
54          switch (connectionType) {
55              case ConnectionWizardDialog.JOIN_CONNECTION:
56                  joinHostGameRadioButtons[0].setSelected(true);
57                  this.connectionType = connectionType;
58                  break;
59              case ConnectionWizardDialog.HOST_CONNECTION:
60                  joinHostGameRadioButtons[1].setSelected(true);
61                  this.connectionType = connectionType;
62                  break;
63          }
64      }
65  
66  }