4 |
|
import javax.swing.*; |
5 |
|
import javax.swing.border.*; |
6 |
|
import java.awt.Color; |
7 |
+ |
import uk.ac.ukc.iscream.util.*; |
8 |
|
|
9 |
|
import java.awt.*; |
10 |
|
import java.awt.event.*; |
14 |
|
import java.text.DateFormat; |
15 |
|
import java.util.Locale; |
16 |
|
import java.util.HashMap; |
17 |
+ |
import javax.swing.border.*; |
18 |
|
|
19 |
|
/** |
20 |
|
* NASTY AND BASIC, PLEASE DON'T COMPLAIN |
53 |
|
Socket socket = new Socket(host, port); |
54 |
|
BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream())); |
55 |
|
PrintWriter outBound = new PrintWriter(socket.getOutputStream()); |
56 |
< |
DataReader data = new DataReader(inBound); |
56 |
> |
|
57 |
> |
Queue dataQueue = new Queue(); |
58 |
> |
DataReader data = new DataReader(inBound, dataQueue); |
59 |
|
|
60 |
< |
SwingClient client = new SwingClient(data); |
60 |
> |
SwingClient client = new SwingClient(dataQueue); |
61 |
|
Thread clientThread = new Thread(client); |
62 |
+ |
|
63 |
|
clientThread.start(); |
64 |
+ |
data.start(); |
65 |
+ |
|
66 |
|
} catch (Exception e) { |
67 |
|
System.err.println("ERROR START: " + e); |
68 |
|
System.exit(1); |
74 |
|
/** |
75 |
|
* Creates a new Swing Client. |
76 |
|
*/ |
77 |
< |
public SwingClient(DataReader data) { |
78 |
< |
_data = data; |
77 |
> |
public SwingClient(Queue dataQueue) { |
78 |
> |
|
79 |
> |
_dataQueue = dataQueue; |
80 |
> |
_myQueue = _dataQueue.getQueue(); |
81 |
|
// set up the Frame |
82 |
|
setTitle("I-Scream Client"); |
83 |
< |
setSize(width, height); |
83 |
> |
//setSize(width, height); |
84 |
|
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
85 |
|
Box box = Box.createVerticalBox(); |
86 |
|
|
92 |
|
header.add(_serverCountLabel); |
93 |
|
header.add(Box.createHorizontalGlue()); |
94 |
|
header.add(iscream); |
95 |
+ |
Box main = Box.createHorizontalBox(); |
96 |
+ |
JButton |
97 |
|
utton = new JButton("Connect"); |
98 |
|
|
99 |
+ |
// set up the text area |
100 |
+ |
_status.setEditable(false); |
101 |
+ |
JScrollPane statusPane = new JScrollPane(_status); |
102 |
+ |
statusPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages ")); |
103 |
+ |
|
104 |
+ |
Box controlPane = Box.createVerticalBox(); |
105 |
+ |
controlPane.add(button); |
106 |
+ |
//controlPane.add(Box.createVerticalGlue()); |
107 |
+ |
controlPane.add(statusPane); |
108 |
+ |
main.add(controlPane); |
109 |
+ |
main.add(_tabbedPane); |
110 |
+ |
|
111 |
|
//_tabbedPane.setSelectedIndex(0); |
112 |
|
|
113 |
|
// build the frame |
114 |
|
box.add(header); |
115 |
< |
box.add(_tabbedPane); |
116 |
< |
box.add(_status); |
115 |
> |
box.add(main); |
116 |
> |
|
117 |
|
getContentPane().add(box); |
118 |
|
|
119 |
|
// show the window |
120 |
|
show(); |
121 |
< |
_status.setText("Running..."); |
121 |
> |
_status.insert("Running...\n",0); |
122 |
|
} |
123 |
|
|
124 |
|
//---PUBLIC METHODS--- |
125 |
|
public void run() { |
126 |
|
HashMap hostList = new HashMap(); |
127 |
|
try { |
105 |
– |
_data.start(); |
128 |
|
while(true) { |
129 |
< |
synchronized (_data) { |
130 |
< |
_data.wait(); |
109 |
< |
} |
110 |
< |
String xml = _data.getXML(); |
129 |
> |
|
130 |
> |
String xml = (String) _dataQueue.get(_myQueue); |
131 |
|
if (xml == null) { |
132 |
|
// shouldn't really happen...but not sure |
133 |
< |
_status.setText("No XML to update..."); |
133 |
> |
_status.insert("No XML to update...",0); |
134 |
|
} else { |
135 |
< |
_status.setText("Got inbound data...handling"); |
135 |
> |
|
136 |
|
// Get a string without any null characters in it. |
137 |
|
// -- maybe String.trim() would be better ? |
138 |
|
if (xml.indexOf(0) != -1) { |
152 |
|
host = new HostDisplayPanel(); |
153 |
|
_tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName); |
154 |
|
hostList.put(hostName, host); |
155 |
< |
_status.setText("New Host added: " + hostName); |
155 |
> |
_status.insert("New Host added: " + hostName + "\n", 0); |
156 |
|
} |
157 |
|
((HostDisplayPanel) hostList.get(hostName)).updateHost(packet); |
158 |
|
} |
164 |
|
|
165 |
|
//---PRIVATE METHODS--- |
166 |
|
|
167 |
< |
protected JPanel makeTextPanel(String text, Component item) { |
167 |
> |
protected JPanel makeTextPanel(String text, java.awt.Component item) { |
168 |
|
JPanel panel = new JPanel(false); |
169 |
|
JLabel label = new JLabel(text); |
170 |
|
label.setHorizontalAlignment(JLabel.RIGHT); |
182 |
|
|
183 |
|
HostDisplayPanel host; |
184 |
|
JTabbedPane _tabbedPane = new JTabbedPane(); |
185 |
< |
DataReader _data; |
186 |
< |
JLabel _status = new JLabel(); |
185 |
> |
Queue _dataQueue; |
186 |
> |
int _myQueue; |
187 |
> |
JTextArea _status = new JTextArea(); |
188 |
|
ImageIcon _serverIcon = new ImageIcon("server.gif"); |
189 |
|
JLabel _serverCountLabel; |
190 |
|
int _serverCount = 0; |
191 |
+ |
|
192 |
|
|
193 |
|
//---STATIC ATTRIBUTES--- |
194 |
|
|
195 |
< |
} |
195 |
> |
} |