1 |
|
//---PACKAGE DECLARATION--- |
2 |
+ |
package uk.ac.ukc.iscream.conient; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import javax.swing.*; |
8 |
|
import java.awt.event.*; |
9 |
|
|
10 |
|
/** |
11 |
< |
* Root for the SwingClient...starts the whole show off... |
11 |
> |
* This is the main class of the Conient client. |
12 |
|
* |
13 |
+ |
* This sets up the control panel, the data panel |
14 |
+ |
* and its own display. |
15 |
+ |
* |
16 |
|
* @author $Author$ |
17 |
|
* @version $Id$ |
18 |
|
*/ |
24 |
|
* The current CVS revision of this class |
25 |
|
*/ |
26 |
|
public final String REVISION = "$Revision$"; |
27 |
< |
|
28 |
< |
private final int width = 600; |
29 |
< |
private final int height = 600; |
27 |
> |
|
28 |
> |
/** |
29 |
> |
* The initial width of the window |
30 |
> |
*/ |
31 |
> |
private final int DEFAULT_WIDTH = 600; |
32 |
|
|
33 |
< |
// the well known port |
33 |
> |
/** |
34 |
> |
* The initial height of the window |
35 |
> |
*/ |
36 |
> |
private final int DEFAULT_HEIGHT = 600; |
37 |
> |
|
38 |
> |
/** |
39 |
> |
* The i-scream server port |
40 |
> |
*/ |
41 |
|
public static final int PORT = 4510; |
42 |
|
|
43 |
|
//---STATIC METHODS--- |
44 |
|
|
45 |
+ |
/** |
46 |
+ |
* The first method that is called. |
47 |
+ |
* Sets up the various panels |
48 |
+ |
* |
49 |
+ |
* @param args the command line arguments |
50 |
+ |
*/ |
51 |
|
public static void main(String[] args) { |
52 |
|
// get the host from the command line if they gave it |
53 |
|
String host = null; |
63 |
|
|
64 |
|
// the main frame (passed the two panels) |
65 |
|
SwingClient client = new SwingClient(data, control); |
66 |
< |
SwingClient.addMessage("Client started"); |
66 |
> |
SwingClient.addMessage("Conient {an I-scream Client} © 2001 University of Kent & Project I-Scream"); |
67 |
> |
SwingClient.addMessage("Conient ready."); |
68 |
|
} |
69 |
|
|
70 |
|
|
75 |
|
*/ |
76 |
|
private SwingClient(JPanel data, JPanel control) { |
77 |
|
// set up the Frame |
78 |
< |
super("I-Scream Client"); |
79 |
< |
|
80 |
< |
setSize(width, height); |
78 |
> |
super("Conient {an I-scream Client}"); |
79 |
> |
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); |
80 |
> |
|
81 |
> |
// set what happens when the X in the corner is clicked |
82 |
|
addWindowListener(new WindowAdapter() { |
83 |
|
public void windowClosing(WindowEvent e) {System.exit(0);} |
84 |
|
}); |
85 |
|
|
86 |
+ |
// add the control pane to the top border |
87 |
|
getContentPane().add(control, "North"); |
88 |
|
|
89 |
+ |
// create a scrollable pane for the data in the centre |
90 |
|
JScrollPane scrollPane = new JScrollPane(data); |
91 |
|
getContentPane().add(scrollPane, "Center"); |
92 |
< |
|
93 |
< |
|
92 |
> |
|
93 |
> |
// setup the status panel |
94 |
|
JPanel bottom = new JPanel(); |
95 |
|
bottom.setLayout(new BorderLayout()); |
96 |
|
_messages.setEditable(false); |
97 |
|
_messages.setRows(3); |
98 |
|
JScrollPane messagesPane = new JScrollPane(_messages); |
99 |
|
messagesPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages ")); |
77 |
– |
|
100 |
|
bottom.add(messagesPane, "Center"); |
101 |
|
JPanel statusPanel = new JPanel(); |
102 |
|
JPanel linkPanel = new JPanel(); |
106 |
|
statusPanel.setLayout(new GridLayout(1,3)); |
107 |
|
statusPanel.add(linkPanel); |
108 |
|
statusPanel.add(_queueStatus); |
87 |
– |
|
109 |
|
bottom.add(statusPanel, "South"); |
110 |
+ |
|
111 |
+ |
// add the status panel to the bottom border |
112 |
|
getContentPane().add(bottom, "South"); |
113 |
|
|
114 |
|
// show the window |
121 |
|
|
122 |
|
//---ACCESSOR/MUTATOR METHODS--- |
123 |
|
|
124 |
+ |
/** |
125 |
+ |
* Sets the control link status. |
126 |
+ |
* |
127 |
+ |
* @param status the message |
128 |
+ |
*/ |
129 |
|
public static void setControlStatus(String status) { |
130 |
|
_controlStatus.setText("Control Link: " + status); |
131 |
|
_controlStatus.repaint(); |
132 |
|
} |
133 |
|
|
134 |
+ |
/** |
135 |
+ |
* Sets the data link status. |
136 |
+ |
* |
137 |
+ |
* @param status the message |
138 |
+ |
*/ |
139 |
|
public static void setDataStatus(String status) { |
140 |
|
_dataStatus.setText("Data Link: " + status); |
141 |
|
_dataStatus.repaint(); |
142 |
|
} |
143 |
|
|
144 |
+ |
/** |
145 |
+ |
* Updates the queue status. |
146 |
+ |
* |
147 |
+ |
* @param currentQueue |
148 |
+ |
* @param numElements |
149 |
+ |
*/ |
150 |
|
public static void setQueueStatus(int currentQueue, int numElements) { |
151 |
|
_queueStatus.setText("Data Queue : " + currentQueue + " Packets Recieved : " + numElements); |
152 |
|
_queueStatus.repaint(); |
153 |
|
} |
154 |
|
|
155 |
+ |
/** |
156 |
+ |
* Adds a system message to the messages list |
157 |
+ |
* |
158 |
+ |
* @param message the new message |
159 |
+ |
*/ |
160 |
|
public static void addMessage(String message) { |
161 |
|
_messages.insert(message + "\n", 0); |
162 |
|
} |
163 |
|
|
164 |
|
//---ATTRIBUTES--- |
165 |
|
|
122 |
– |
ImageIcon _serverIcon = new ImageIcon("server.gif"); |
123 |
– |
JLabel _serverCountLabel; |
124 |
– |
int _serverCount = 0; |
125 |
– |
|
166 |
|
//---STATIC ATTRIBUTES--- |
167 |
|
|
168 |
+ |
/** |
169 |
+ |
* Displays information about the data link |
170 |
+ |
*/ |
171 |
|
static JLabel _controlStatus = new JLabel("Control Link: Disconnected", JLabel.LEFT); |
172 |
|
{ |
173 |
|
_controlStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); |
174 |
|
} |
175 |
|
|
176 |
+ |
/** |
177 |
+ |
* Displays information about the data link |
178 |
+ |
*/ |
179 |
|
static JLabel _dataStatus = new JLabel("Data Link: Disconnected", JLabel.LEFT); |
180 |
|
{ |
181 |
|
_dataStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); |
182 |
|
} |
183 |
|
|
184 |
+ |
/** |
185 |
+ |
* Displays information about the inbound data queue. |
186 |
+ |
*/ |
187 |
|
static JLabel _queueStatus = new JLabel(" ", JLabel.LEFT); |
188 |
|
{ |
189 |
|
_queueStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); |
190 |
|
} |
191 |
+ |
|
192 |
+ |
/** |
193 |
+ |
* The place where system messages are written. |
194 |
+ |
*/ |
195 |
|
static JTextArea _messages = new JTextArea(); |
196 |
|
} |