1 package net.sourceforge.simplegamenet.framework.gui;
2
3 import java.awt.*;
4 import java.net.InetAddress;
5 import javax.swing.*;
6 import net.sourceforge.simplegamenet.specs.model.GameFactory;
7 import net.sourceforge.simplegamenet.specs.to.PlayerSettingsMap;
8 import net.sourceforge.simplegamenet.util.proportionlayout.ProportionConstraints;
9 import net.sourceforge.simplegamenet.util.proportionlayout.ProportionLayout;
10
11 public class StatusTabPanel extends JPanel {
12
13 private static final String[] stateStrings = {
14 "Not connected", "Joined game",
15 "Hosting game"
16 };
17
18
19
20
21 private JLabel appStateLabel = new JLabel("State:");
22 private JTextField appStateTextField = new JTextField(stateStrings[0]);
23 private JLabel hostIPNumberLabel = new JLabel("Host IP-address:");
24 private JTextField hostIPNumberTextField = new JTextField("N/A");
25 private JLabel hostPortNumberLabel = new JLabel("Host port:");
26 private JTextField hostPortNumberTextField = new JTextField("N/A");
27
28 private JLabel gameNameLabel = new JLabel("Game name:");
29 private JTextField gameNameTextField = new JTextField("N/A");
30 private JTextArea gameDescriptionTextArea = new JTextArea("");
31 private JLabel gameAuthorLabel = new JLabel("Game author:");
32 private JTextField gameAuthorTextField = new JTextField("N/A");
33 private JLabel gameVersionLabel = new JLabel("Game version:");
34 private JTextField gameVersionTextField = new JTextField("N/A");
35
36 private JLabel numberOfParticipantsLabel = new JLabel("Number of players:");
37 private JTextField numberOfParticipantsTextField = new JTextField("N/A");
38 private JLabel numberOfConnectionsLabel = new JLabel("Number of connections:");
39 private JTextField numberOfConnectionsTextField = new JTextField("N/A");
40
41
42 private JTextArea logTextArea = new JTextArea("");
43
44 public StatusTabPanel() {
45 ProportionLayout layout = new ProportionLayout();
46 layout.appendColumn(10);
47 layout.appendColumn(0, ProportionLayout.NO_PROPORTION);
48 layout.appendColumn(10);
49 layout.appendColumn(0, 3.0);
50 layout.appendColumn(10);
51 layout.appendColumn(0, ProportionLayout.NO_PROPORTION);
52 layout.appendColumn(10);
53 layout.appendColumn(0, 1.0);
54 layout.appendColumn(10);
55 layout.appendRow(10);
56 layout.appendRow(0, ProportionLayout.NO_PROPORTION);
57 layout.appendRow(10);
58 layout.appendRow(0, ProportionLayout.NO_PROPORTION);
59 layout.appendRow(10);
60 layout.appendRow(0, ProportionLayout.NO_PROPORTION);
61 layout.appendRow(10);
62 layout.appendRow(0, 1.0);
63 layout.appendRow(10);
64 layout.appendRow(0, ProportionLayout.NO_PROPORTION);
65 layout.appendRow(10);
66 layout.appendRow(0, ProportionLayout.NO_PROPORTION);
67 layout.appendRow(10);
68 layout.appendRow(10, 1.0);
69 layout.appendRow(10);
70 setLayout(layout);
71
72 add(appStateLabel, new ProportionConstraints(1, 1));
73 appStateTextField.setEditable(false);
74 add(appStateTextField, new ProportionConstraints(3, 1));
75 add(hostIPNumberLabel, new ProportionConstraints(1, 3));
76 hostIPNumberTextField.setEditable(false);
77 add(hostIPNumberTextField, new ProportionConstraints(3, 3));
78 add(hostPortNumberLabel, new ProportionConstraints(5, 3));
79 hostPortNumberTextField.setEditable(false);
80 add(hostPortNumberTextField, new ProportionConstraints(7, 3));
81 add(gameNameLabel, new ProportionConstraints(1, 5));
82 gameNameTextField.setEditable(false);
83 add(gameNameTextField, new ProportionConstraints(3, 5));
84 ProportionLayout gameDescriptionLayout = new ProportionLayout();
85 gameDescriptionLayout.appendColumn(5);
86 gameDescriptionLayout.appendColumn(0, 1.0);
87 gameDescriptionLayout.appendColumn(5);
88 gameDescriptionLayout.appendRow(0);
89 gameDescriptionLayout.appendRow(0, 1.0);
90 gameDescriptionLayout.appendRow(5);
91 JPanel gameDescriptionPanel = new JPanel(gameDescriptionLayout);
92 gameDescriptionTextArea.setEditable(false);
93 gameDescriptionTextArea.setLineWrap(true);
94 gameDescriptionTextArea.setWrapStyleWord(true);
95 JScrollPane gameDescriptionScrollPane = new JScrollPane(gameDescriptionTextArea,
96 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
97 JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
98 gameDescriptionScrollPane.setPreferredSize(new Dimension(400, 150));
99 gameDescriptionPanel.setBorder(BorderFactory.createTitledBorder("Description"));
100 gameDescriptionPanel.add(gameDescriptionScrollPane,
101 new ProportionConstraints(1, 1));
102 add(gameDescriptionPanel, new ProportionConstraints(1, 7, 7, 1, 4, 7));
103 add(gameAuthorLabel, new ProportionConstraints(1, 9));
104 gameAuthorTextField.setEditable(false);
105 add(gameAuthorTextField, new ProportionConstraints(3, 9));
106 add(gameVersionLabel, new ProportionConstraints(5, 9));
107 gameVersionTextField.setEditable(false);
108 add(gameVersionTextField, new ProportionConstraints(7, 9));
109 add(numberOfParticipantsLabel, new ProportionConstraints(1, 11));
110 numberOfParticipantsTextField.setEditable(false);
111 add(numberOfParticipantsTextField, new ProportionConstraints(3, 11));
112 add(numberOfConnectionsLabel, new ProportionConstraints(5, 11));
113 numberOfConnectionsTextField.setEditable(false);
114 add(numberOfConnectionsTextField, new ProportionConstraints(7, 11));
115 ProportionLayout logLayout = new ProportionLayout();
116 logLayout.appendColumn(5);
117 logLayout.appendColumn(0, 1.0);
118 logLayout.appendColumn(5);
119 logLayout.appendRow(0);
120 logLayout.appendRow(0, 1.0);
121 logLayout.appendRow(5);
122 JPanel logPanel = new JPanel(logLayout);
123 logTextArea.setEditable(false);
124 logTextArea.setLineWrap(true);
125 logTextArea.setWrapStyleWord(true);
126 JScrollPane logTextAreaScrollPane = new JScrollPane(logTextArea,
127 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
128 JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
129 logTextAreaScrollPane.setPreferredSize(new Dimension(400, 150));
130 logPanel.setBorder(BorderFactory.createTitledBorder("Log"));
131 logPanel.add(logTextAreaScrollPane, new ProportionConstraints(1, 1));
132 add(logPanel, new ProportionConstraints(1, 13, 7, 1, 4, 13));
133
134 }
135
136 public JTextArea getLogTextArea() {
137 return logTextArea;
138 }
139
140 public void gameJoined(InetAddress hostInetAddress, int port, GameFactory gameFactory,
141 PlayerSettingsMap playerSettingsMap, boolean clientIsHost) {
142 appStateTextField.setText(clientIsHost ? stateStrings[2] : stateStrings[1]);
143 hostIPNumberTextField.setText(hostInetAddress.getHostAddress());
144 hostPortNumberTextField.setText(Integer.toString(port));
145 gameNameTextField.setText(gameFactory.getName());
146 gameDescriptionTextArea.setText(gameFactory.getDescription());
147 gameAuthorTextField.setText(gameFactory.getAuthor());
148 gameVersionTextField.setText(gameFactory.getVersion().toString());
149 numberOfParticipantsTextField.setText(Integer.toString(
150 playerSettingsMap.getParticipantsAmount()));
151 numberOfConnectionsTextField.setText(Integer.toString(
152 playerSettingsMap.getConnectionsAmount()));
153 }
154
155 public void playerSettingsUpdated(PlayerSettingsMap playerSettingsMap) {
156 numberOfParticipantsTextField.setText(Integer.toString(
157 playerSettingsMap.getParticipantsAmount()));
158 numberOfConnectionsTextField.setText(Integer.toString(
159 playerSettingsMap.getConnectionsAmount()));
160 }
161
162 public void joinedGameQuit() {
163 appStateTextField.setText(stateStrings[0]);
164 hostIPNumberTextField.setText("N/A");
165 hostPortNumberTextField.setText("N/A");
166 gameNameTextField.setText("N/A");
167 gameDescriptionTextArea.setText("");
168 gameAuthorTextField.setText("N/A");
169 gameVersionTextField.setText("N/A");
170 numberOfParticipantsTextField.setText("N/A");
171 numberOfConnectionsTextField.setText("N/A");
172 }
173
174 }