1 package org.argosfields.widget;
2
3 import java.lang.reflect.InvocationTargetException;
4 import java.util.Iterator;
5
6 import org.apache.commons.lang.NullArgumentException;
7 import org.argosfields.multi.Player;
8 import org.argosfields.multi.server.ServerInfo;
9 import org.argosfields.resource.ResourceManager;
10 import org.argosfields.service.IGameManager;
11 import org.argosfields.spring.ClientContextHelper;
12 import org.argosfields.util.RunnableContextHelper;
13 import org.eclipse.core.runtime.IProgressMonitor;
14 import org.eclipse.jface.operation.IRunnableContext;
15 import org.eclipse.jface.operation.IRunnableWithProgress;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.custom.SashForm;
18 import org.eclipse.swt.custom.StyledText;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Group;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.List;
26 import org.eclipse.swt.widgets.Table;
27 import org.eclipse.swt.widgets.TableColumn;
28
29 /***
30 * ServerInfoTab.java
31 * @author Xavier Cho
32 * @version $Revision: 1.2 $ $Date: 2004/04/17 18:21:01 $
33 */
34 public class ServerInfoTab extends Composite {
35
36 private ServerInfo info;
37 private List listUsers;
38
39 /***
40 * @param parent
41 * @param style
42 * @param info
43 */
44 public ServerInfoTab(
45 final Composite parent,
46 final int style,
47 final ServerInfo info) {
48 super(parent, style);
49
50 if (info == null) {
51 throw new NullArgumentException("info");
52 }
53
54 this.info = info;
55
56 ResourceManager resources = ResourceManager.getInstance();
57
58 GridLayout layout = new GridLayout();
59 layout.numColumns = 1;
60 layout.marginWidth = 5;
61 layout.marginHeight = 5;
62
63 setLayout(layout);
64
65 Group groupInfo = new Group(this, SWT.NONE);
66 groupInfo.setText("Server Info");
67
68 groupInfo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
69
70 createInfoPanel(groupInfo);
71
72 SashForm sash = new SashForm(this, SWT.HORIZONTAL);
73 sash.setLayoutData(new GridData(GridData.FILL_BOTH));
74
75 Group groupRooms = new Group(sash, SWT.NONE);
76 groupRooms.setText("Rooms");
77 groupRooms.setLayoutData(new GridData(GridData.FILL_BOTH));
78
79 createRoomsPanel(groupRooms);
80
81 Group groupUsers = new Group(sash, SWT.NONE);
82 groupUsers.setText("Users");
83
84 createUsersPanel(groupUsers);
85
86 sash.setWeights(new int[] {80, 20});
87 }
88
89 private void createInfoPanel(final Composite parent) {
90 ResourceManager resources = ResourceManager.getInstance();
91
92 GridLayout layout = new GridLayout();
93 layout.numColumns = 2;
94 layout.marginWidth = 10;
95 layout.marginHeight = 10;
96 layout.horizontalSpacing = 5;
97 layout.verticalSpacing = 5;
98
99 parent.setLayout(layout);
100
101 Label label = new Label(parent, SWT.NONE);
102 label.setText("Address :");
103
104 GridData data = new GridData();
105 data.horizontalAlignment = GridData.END;
106
107 label.setLayoutData(data);
108
109 Label labelAddress = new Label(parent, SWT.NONE);
110 labelAddress.setText(info.getHostName());
111 labelAddress.setLayoutData(new GridData(GridData.FILL_BOTH));
112
113 label = new Label(parent, SWT.NONE);
114 label.setText("Message :");
115
116 data = new GridData();
117 data.horizontalAlignment = GridData.END;
118 data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
119 data.heightHint = 80;
120
121 label.setLayoutData(data);
122
123 StyledText textMessage = new StyledText(parent, SWT.READ_ONLY
124 | SWT.BORDER | SWT.V_SCROLL);
125 textMessage.setText(info.getWelcomeMessage());
126 textMessage.setLayoutData(new GridData(GridData.FILL_BOTH));
127 }
128
129 private void createRoomsPanel(final Composite parent) {
130 ResourceManager resources = ResourceManager.getInstance();
131
132 GridLayout layout = new GridLayout();
133 layout.numColumns = 1;
134 layout.marginWidth = 10;
135 layout.marginHeight = 10;
136 layout.horizontalSpacing = 5;
137 layout.verticalSpacing = 5;
138
139 parent.setLayout(layout);
140
141 Table roomsTable = new Table(parent, SWT.BORDER);
142 roomsTable.setHeaderVisible(true);
143
144 TableColumn column = new TableColumn(roomsTable, SWT.LEFT);
145 column.setWidth(140);
146 column.setText("Name");
147 column.setResizable(true);
148 column.pack();
149
150 column = new TableColumn(roomsTable, SWT.RIGHT);
151 column.setWidth(40);
152 column.setText("Players");
153 column.setResizable(true);
154 column.pack();
155
156 column = new TableColumn(roomsTable, SWT.LEFT);
157 column.setWidth(200);
158 column.setText("Description");
159 column.setResizable(true);
160 column.pack();
161
162 roomsTable.setLayoutData(new GridData(GridData.FILL_BOTH));
163
164 Composite buttonPanel = new Composite(parent, SWT.NONE);
165
166 layout = new GridLayout();
167 layout.numColumns = 3;
168 layout.marginWidth = 0;
169 layout.marginHeight = 0;
170 layout.horizontalSpacing = 5;
171 layout.verticalSpacing = 5;
172
173 buttonPanel.setLayout(layout);
174 buttonPanel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
175
176 Button buttonJoin = new Button(buttonPanel, SWT.NONE);
177 buttonJoin.setText("Join");
178 buttonJoin.setLayoutData(new GridData());
179
180 Button buttonCreate = new Button(buttonPanel, SWT.NONE);
181 buttonCreate.setText("Create");
182 buttonCreate.setLayoutData(new GridData());
183
184 Button buttonRefresh = new Button(buttonPanel, SWT.NONE);
185 buttonRefresh.setText("Refresh");
186 buttonRefresh.setLayoutData(new GridData());
187 }
188
189 private void createUsersPanel(final Composite parent) {
190 ResourceManager resources = ResourceManager.getInstance();
191
192 GridLayout layout = new GridLayout();
193 layout.numColumns = 1;
194 layout.marginWidth = 10;
195 layout.marginHeight = 10;
196 layout.horizontalSpacing = 5;
197 layout.verticalSpacing = 5;
198
199 parent.setLayout(layout);
200
201 this.listUsers = new List(parent, SWT.BORDER | SWT.V_SCROLL);
202 listUsers.setLayoutData(new GridData(GridData.FILL_BOTH));
203
204 IRunnableContext context = RunnableContextHelper.getContext();
205
206 try {
207 context.run(false, false, new Worker());
208 } catch (Exception e) {
209 e.printStackTrace();
210 }
211 }
212
213 private class Worker implements IRunnableWithProgress {
214
215 public void run(final IProgressMonitor monitor)
216 throws InvocationTargetException, InterruptedException {
217 monitor.beginTask("Reading user list...", IProgressMonitor.UNKNOWN);
218
219 listUsers.removeAll();
220
221 try {
222 ClientContextHelper helper = ClientContextHelper.getInstance();
223
224 IGameManager manager = helper.getGameManager();
225 java.util.List players = manager.getPlayers();
226
227 Iterator it = players.iterator();
228 while (it.hasNext()) {
229 Player player = (Player) it.next();
230 listUsers.add(player.getUserName());
231 }
232 } finally {
233 monitor.done();
234 }
235 }
236 }
237 }
This page was automatically generated by Maven