1 package org.argosfields.widget;
2
3 import org.apache.commons.lang.NullArgumentException;
4 import org.argosfields.multi.IGameClientListener;
5 import org.argosfields.multi.server.ServerInfo;
6 import org.argosfields.resource.ResourceManager;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.custom.StyledText;
9 import org.eclipse.swt.layout.GridData;
10 import org.eclipse.swt.layout.GridLayout;
11 import org.eclipse.swt.widgets.Button;
12 import org.eclipse.swt.widgets.Composite;
13 import org.eclipse.swt.widgets.Text;
14
15 /***
16 * MessagePanel.java
17 * @author Xavier Cho
18 * @version $Revision: 1.6 $ $Date: 2004/04/17 08:59:17 $
19 */
20 public class MessagePanel extends Composite implements IGameClientListener {
21
22 private StyledText messagePane;
23
24 /***
25 * @param parent
26 * @param style
27 */
28 public MessagePanel(final Composite parent, final int style) {
29 super(parent, style);
30
31 createContents();
32 }
33
34 private void createContents() {
35 ResourceManager resources = ResourceManager.getInstance();
36
37 GridLayout gridLayout = new GridLayout();
38 gridLayout.numColumns = 1;
39 gridLayout.marginWidth = 0;
40 gridLayout.marginHeight = 0;
41 gridLayout.horizontalSpacing = 0;
42 gridLayout.verticalSpacing = 2;
43
44 setLayout(gridLayout);
45
46 this.messagePane = new StyledText(this, SWT.BORDER | SWT.V_SCROLL);
47
48 messagePane.setEditable(false);
49 messagePane.setLayoutData(new GridData(GridData.FILL_BOTH));
50
51 GridLayout gridLayout2 = new GridLayout();
52 gridLayout2.numColumns = 2;
53 gridLayout2.marginWidth = 0;
54 gridLayout2.marginHeight = 0;
55 gridLayout2.horizontalSpacing = 2;
56 gridLayout2.verticalSpacing = 0;
57
58 Composite composite = new Composite(this, SWT.NONE);
59 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
60 composite.setLayout(gridLayout2);
61
62 Text inputBox = new Text(composite, SWT.BORDER);
63 inputBox.setLayoutData(new GridData(GridData.FILL_BOTH));
64
65 Button button = new Button(composite, SWT.PUSH);
66 button.setText(resources.getString("button.send"));
67
68 GridData data = new GridData(GridData.FILL_VERTICAL);
69 data.widthHint = 100;
70
71 button.setLayoutData(data);
72 }
73
74 /***
75 * @param message
76 */
77 public void addMessage(final String message) {
78 if (message == null) {
79 SWT.error(SWT.ERROR_NULL_ARGUMENT);
80 }
81
82 messagePane.append(message);
83
84 int count = messagePane.getCharCount();
85 messagePane.setSelection(count);
86 messagePane.showSelection();
87 }
88
89 /***
90 * @see org.argosfields.multi.IGameClientListener#systemMessageReceived(java.lang.String)
91 */
92 public void systemMessageReceived(final String message) {
93 if (message == null) {
94 throw new NullArgumentException("message");
95 }
96
97 Runnable runner = new Runnable() {
98
99 public void run() {
100 //TODO apply appropriate coloring
101 int start = messagePane.getCharCount();
102 int end = start + message.length();
103
104 messagePane.append(message);
105 }
106 };
107
108 getShell().getDisplay().asyncExec(runner);
109 }
110
111 /***
112 * @see org.argosfields.multi.IGameClientListener#sessionStarted(org.argosfields.multi.server.ServerInfo)
113 */
114 public void sessionStarted(final ServerInfo info) {
115 }
116
117 /***
118 * @see org.argosfields.multi.IGameClientListener#sessionEnded()
119 */
120 public void sessionEnded() {
121 }
122 }
This page was automatically generated by Maven