1 |
ajm |
1.5 |
//---PACKAGE DECLARATION--- |
2 |
|
|
package uk.ac.ukc.iscream.conient; |
3 |
|
|
|
4 |
|
|
//---IMPORTS--- |
5 |
ajm |
1.1 |
import uk.ac.ukc.iscream.util.*; |
6 |
ajm |
1.5 |
import java.util.HashMap; |
7 |
|
|
import javax.swing.ImageIcon; |
8 |
|
|
import javax.swing.JTabbedPane; |
9 |
|
|
import javax.swing.JPanel; |
10 |
|
|
|
11 |
|
|
/** |
12 |
|
|
* This thread reads data from the DataReader |
13 |
|
|
* it then asks the appropriate HostDisplayPanel |
14 |
|
|
* to update its data. |
15 |
|
|
* |
16 |
ajm |
1.6 |
* @author $Author: ajm4 $ |
17 |
ajm |
1.8 |
* @version $Id: DataPanel.java,v 1.7 2001/01/29 17:03:33 ajm4 Exp $ |
18 |
ajm |
1.5 |
*/ |
19 |
|
|
public class DataPanel extends JPanel implements Runnable { |
20 |
ajm |
1.1 |
|
21 |
ajm |
1.5 |
//---FINAL ATTRIBUTES--- |
22 |
ajm |
1.2 |
|
23 |
ajm |
1.5 |
/** |
24 |
|
|
* The current CVS revision of this class |
25 |
|
|
*/ |
26 |
ajm |
1.8 |
public final String REVISION = "$Revision: 1.7 $"; |
27 |
ajm |
1.5 |
|
28 |
|
|
//---STATIC METHODS--- |
29 |
|
|
|
30 |
|
|
//---CONSTRUCTORS--- |
31 |
|
|
|
32 |
|
|
//---PUBLIC METHODS--- |
33 |
|
|
|
34 |
|
|
/** |
35 |
|
|
* Starts the DataPanel running |
36 |
|
|
*/ |
37 |
ajm |
1.1 |
public void run() { |
38 |
ajm |
1.5 |
// add the tabbed pane to ourselves |
39 |
ajm |
1.2 |
add(_tabbedPane); |
40 |
ajm |
1.5 |
|
41 |
|
|
// the hosts we are interested in go here |
42 |
ajm |
1.1 |
HashMap hostList = new HashMap(); |
43 |
ajm |
1.5 |
|
44 |
ajm |
1.1 |
try { |
45 |
ajm |
1.5 |
while(_running) { |
46 |
ajm |
1.1 |
|
47 |
|
|
String xml = (String) _dataQueue.get(_myQueue); |
48 |
ajm |
1.6 |
Conient.setQueueStatus(_dataQueue.queueSize(_myQueue), _dataQueue.elementCount()); |
49 |
ajm |
1.1 |
if (xml == null) { |
50 |
|
|
// shouldn't really happen...but not sure |
51 |
|
|
//_status.insert("No XML to update...",0); |
52 |
|
|
} else { |
53 |
|
|
|
54 |
|
|
// Get a string without any null characters in it. |
55 |
|
|
// -- maybe String.trim() would be better ? |
56 |
|
|
if (xml.indexOf(0) != -1) { |
57 |
|
|
xml = xml.substring(0, xml.indexOf(0)); |
58 |
|
|
} |
59 |
|
|
else { |
60 |
|
|
xml = xml.substring(0, xml.length()); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
// Use XMLPacketMaker to make an XMLPacket object. |
64 |
|
|
XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml); |
65 |
|
|
XMLPacket packet = xmlPacketMaker.createXMLPacket(); |
66 |
|
|
String hostName = packet.getParam("packet.attributes.machine_name"); |
67 |
|
|
if(!hostList.containsKey(hostName)) { |
68 |
|
|
|
69 |
ajm |
1.9 |
HostDisplayPanel host = new HostDisplayPanel(hostName); |
70 |
ajm |
1.1 |
_tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName); |
71 |
|
|
hostList.put(hostName, host); |
72 |
ajm |
1.6 |
Conient.addMessage("New Host added: " + hostName); |
73 |
ajm |
1.5 |
} |
74 |
|
|
if (!((HostDisplayPanel) hostList.get(hostName)).updateHost(packet)) { |
75 |
|
|
throw new Exception(hostName + " sent an invalid data packet stopping data update!"); |
76 |
|
|
} |
77 |
ajm |
1.1 |
} |
78 |
|
|
} |
79 |
|
|
} catch (Exception e) { |
80 |
ajm |
1.8 |
Conient.addMessage("ERROR{data panel}: +" + e); |
81 |
ajm |
1.1 |
} |
82 |
|
|
} |
83 |
|
|
|
84 |
ajm |
1.5 |
/** |
85 |
|
|
* This method allows other classes |
86 |
|
|
* to shutdown this data panel. |
87 |
|
|
*/ |
88 |
|
|
public void shutdown() { |
89 |
|
|
_running = false; |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
//---PRIVATE METHODS--- |
93 |
|
|
|
94 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
95 |
|
|
|
96 |
|
|
//---ATTRIBUTES--- |
97 |
|
|
|
98 |
|
|
/** |
99 |
|
|
* The state of this thread. |
100 |
|
|
*/ |
101 |
|
|
boolean _running = true; |
102 |
|
|
|
103 |
|
|
/** |
104 |
|
|
* Assigns the queue that this panel |
105 |
|
|
* will use to obtain data |
106 |
|
|
* |
107 |
|
|
* @param queue the queue |
108 |
|
|
*/ |
109 |
ajm |
1.1 |
public void setQueue(Queue queue) { |
110 |
|
|
_dataQueue = queue; |
111 |
|
|
_myQueue = _dataQueue.getQueue(); |
112 |
tdb |
1.4 |
} |
113 |
|
|
|
114 |
ajm |
1.5 |
/** |
115 |
|
|
* Removes all the tabs on display |
116 |
|
|
* Used to tidy up when a new data |
117 |
|
|
* channel is opened. |
118 |
|
|
*/ |
119 |
tdb |
1.4 |
public void cleanUpTabs() { |
120 |
|
|
_tabbedPane.removeAll(); |
121 |
ajm |
1.1 |
} |
122 |
|
|
|
123 |
ajm |
1.5 |
/** |
124 |
|
|
* The tabbed pane is where HostDisplayPanel's |
125 |
|
|
* are placed |
126 |
|
|
*/ |
127 |
ajm |
1.1 |
JTabbedPane _tabbedPane = new JTabbedPane(); |
128 |
ajm |
1.5 |
|
129 |
|
|
/** |
130 |
|
|
* The queue new data will be read from |
131 |
|
|
*/ |
132 |
ajm |
1.1 |
Queue _dataQueue; |
133 |
ajm |
1.5 |
|
134 |
|
|
/** |
135 |
|
|
* Our queue number |
136 |
|
|
*/ |
137 |
ajm |
1.1 |
int _myQueue; |
138 |
ajm |
1.5 |
|
139 |
|
|
/** |
140 |
|
|
* An icon to represent a host |
141 |
|
|
*/ |
142 |
ajm |
1.7 |
ImageIcon _serverIcon = new ImageIcon("./uk/ac/ukc/iscream/conient/server.gif"); |
143 |
|
|
} |