1 |
//---PACKAGE DECLARATION--- |
2 |
package uk.ac.ukc.iscream.conient; |
3 |
|
4 |
//---IMPORTS--- |
5 |
import uk.ac.ukc.iscream.util.*; |
6 |
import uk.ac.ukc.iscream.conient.datacomponents.*; |
7 |
import javax.swing.*; |
8 |
import javax.swing.border.*; |
9 |
import java.util.*; |
10 |
import java.awt.*; |
11 |
import java.awt.event.*; |
12 |
|
13 |
/** |
14 |
* |
15 |
* @author $Author: ajm4 $ |
16 |
* @version $Id: QueueFrame.java,v 1.1 2001/02/25 21:23:38 ajm4 Exp $ |
17 |
*/ |
18 |
public class QueueFrame extends JFrame { |
19 |
|
20 |
//---FINAL ATTRIBUTES--- |
21 |
|
22 |
/** |
23 |
* The current CVS revision of this class |
24 |
*/ |
25 |
public final String REVISION = "$Revision: 1.1 $"; |
26 |
|
27 |
//---STATIC METHODS--- |
28 |
|
29 |
//---CONSTRUCTORS--- |
30 |
|
31 |
/** |
32 |
* |
33 |
*/ |
34 |
public QueueFrame() { |
35 |
super("Server Queue Status"); |
36 |
//addVisibleDataComponent(_conent, new StringDataComponent("Host Name", "packet.attributes.machine_name")); |
37 |
|
38 |
getContentPane().add(_content, "Center"); |
39 |
JButton close = new JButton("Close Window"); |
40 |
close.addActionListener(new ActionListener() { |
41 |
public void actionPerformed(ActionEvent e) { |
42 |
dispose(); |
43 |
} |
44 |
}); |
45 |
getContentPane().add(close, "South"); |
46 |
setIconImage((new ImageIcon("./uk/ac/ukc/iscream/conient/server.gif")).getImage()); |
47 |
pack(); |
48 |
setVisible(true); |
49 |
} |
50 |
|
51 |
//---PUBLIC METHODS--- |
52 |
|
53 |
/** |
54 |
* Process an incoming packet, updates the components. |
55 |
* |
56 |
* @param packet the packet to process |
57 |
* |
58 |
* @return if the proceesing was successful |
59 |
*/ |
60 |
public boolean update(XMLPacket packet) { |
61 |
// iterate over the packets data |
62 |
boolean displaySucessful = true; |
63 |
String queueName = packet.getParam("packet.attributes.name"); |
64 |
|
65 |
// if there are no components looking after this data |
66 |
// create a new StringDataComponent for it |
67 |
if(!_queues.containsKey(queueName)) { |
68 |
addQueue(packet); |
69 |
} |
70 |
|
71 |
// try and update the component, if it doesn't like what it gets |
72 |
// warn the user and set that this was an unsucessful display |
73 |
try { |
74 |
updateQueueInformation(packet); |
75 |
} catch (DataFormatException e) { |
76 |
Conient.addMessage("WARNING{queue frame}: " + e.getMessage()); |
77 |
displaySucessful = false; |
78 |
} |
79 |
return displaySucessful; |
80 |
} |
81 |
|
82 |
//---PRIVATE METHODS--- |
83 |
|
84 |
private void addQueue(XMLPacket packet) { |
85 |
HashMap newQueue = new HashMap(); |
86 |
String queueName = packet.getParam("packet.attributes.name"); |
87 |
VisibleDataComponent date = new DateDataComponent("Last timestamp", "packet.attributes.date"); |
88 |
VisibleDataComponent total = new StringDataComponent("Total queued to date", "packet.queue.attributes.total"); |
89 |
newQueue.put("packet.attributes.name", new StringDataComponent("Name", "packet.attributes.name")); |
90 |
newQueue.put("packet.queue.attributes.total", total); |
91 |
newQueue.put("packet.attributes.date", date); |
92 |
JPanel newQueueDisplay = new JPanel(); |
93 |
newQueueDisplay.setLayout(new BoxLayout(newQueueDisplay, BoxLayout.Y_AXIS)); |
94 |
newQueueDisplay.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), queueName)); |
95 |
newQueueDisplay.add(date); |
96 |
newQueueDisplay.add(total); |
97 |
_queuesDisplays.put(queueName, newQueueDisplay); |
98 |
try { |
99 |
SwingSafeAdd task = new SwingSafeAdd(_content, newQueueDisplay); |
100 |
SwingUtilities.invokeAndWait(task); |
101 |
} catch (Exception e) { |
102 |
// don't care |
103 |
} |
104 |
pack(); |
105 |
_queues.put(queueName, newQueue); |
106 |
} |
107 |
|
108 |
private void updateQueueInformation(XMLPacket packet) throws DataFormatException { |
109 |
String queueName = packet.getParam("packet.attributes.name"); |
110 |
HashMap components = (HashMap) _queues.get(queueName); |
111 |
Set packetSet = packet.getSet(); |
112 |
Iterator i = packetSet.iterator(); |
113 |
while (i.hasNext()) { |
114 |
String dataKey = (String) i.next(); |
115 |
// if there are no components looking after this data |
116 |
// create a new StringDataComponent for it |
117 |
if(!components.containsKey(dataKey)) { |
118 |
// check if its a disk drive, if it is then we need to deal with it |
119 |
if(dataKey.startsWith("packet.queue.attributes.queue")) { |
120 |
VisibleDataComponent queue = new StringDataComponent("Current length of " + dataKey.substring(dataKey.lastIndexOf('.') + 1), dataKey); |
121 |
components.put(dataKey, queue); |
122 |
try { |
123 |
SwingSafeAdd task = new SwingSafeAdd((JPanel)_queuesDisplays.get(queueName), queue); |
124 |
SwingUtilities.invokeAndWait(task); |
125 |
} catch (Exception e) { |
126 |
// don't care |
127 |
} |
128 |
pack(); |
129 |
} |
130 |
// note we ignore all other attributes |
131 |
} |
132 |
if(components.containsKey(dataKey)) { |
133 |
((DataComponent) components.get(dataKey)).setValue(packet.getParam(dataKey)); |
134 |
} |
135 |
} |
136 |
} |
137 |
|
138 |
//---ACCESSOR/MUTATOR METHODS--- |
139 |
|
140 |
//---ATTRIBUTES--- |
141 |
|
142 |
/** |
143 |
* The components that we already know about |
144 |
* connected with the attributes they care about |
145 |
* are stored here. |
146 |
*/ |
147 |
private HashMap _queues = new HashMap(); |
148 |
private HashMap _queuesDisplays = new HashMap(); |
149 |
|
150 |
private Box _content = Box.createVerticalBox(); |
151 |
|
152 |
//---STATIC ATTRIBUTES--- |
153 |
|
154 |
} |