ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/conient/uk/org/iscream/cms/conient/Conient.java
Revision: 1.7
Committed: Mon Jan 15 03:26:26 2001 UTC (23 years, 4 months ago) by ajm
Branch: MAIN
Changes since 1.6: +10 -6 lines
Log Message:
fixed bug and added one feature

File Contents

# Content
1 //---PACKAGE DECLARATION---
2
3 //---IMPORTS---
4 import javax.swing.*;
5 import javax.swing.border.*;
6 import java.awt.Color;
7
8 import java.awt.*;
9 import java.awt.event.*;
10 import java.net.*;
11 import java.io.*;
12 import java.util.Date;
13 import java.text.DateFormat;
14 import java.util.Locale;
15 import java.util.HashMap;
16
17 /**
18 * NASTY AND BASIC, PLEASE DON'T COMPLAIN
19 *
20 * @author $Author: ajm4 $
21 * @version $Id: SwingClient.java,v 1.6 2001/01/15 03:15:06 ajm4 Exp $
22 */
23 public class SwingClient extends JFrame implements Runnable {
24
25 //---FINAL ATTRIBUTES---
26
27 /**
28 * The current CVS revision of this class
29 */
30 public final String REVISION = "$Revision: 1.6 $";
31
32 private final int width = 400;
33 private final int height = 700;
34
35 //---STATIC METHODS---
36
37 public static void main(String[] args) {
38 try {
39 String host = null;
40 if (args.length != 1) {
41 Object response = null;
42 while(!(response instanceof String)) {
43 response = JOptionPane.showInputDialog(null, "Please enter the name of a server running the I-Scream client interface:", "I-Scream Server", JOptionPane.INFORMATION_MESSAGE);
44 }
45 host = (String) response;
46 } else {
47 host = args[0];
48 }
49
50 int port = 4510;
51 Socket socket = new Socket(host, port);
52 BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream()));
53 PrintWriter outBound = new PrintWriter(socket.getOutputStream());
54 DataReader data = new DataReader(inBound);
55
56 SwingClient client = new SwingClient(data);
57 Thread clientThread = new Thread(client);
58 clientThread.start();
59 } catch (Exception e) {
60 System.err.println("ERROR START: " + e);
61 System.exit(1);
62 }
63 }
64
65 //---CONSTRUCTORS---
66
67 /**
68 * Creates a new Swing Client.
69 */
70 public SwingClient(DataReader data) {
71 _data = data;
72 // set up the Frame
73 setTitle("I-Scream Client");
74 setSize(width, height);
75 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
76 Box box = Box.createVerticalBox();
77
78 // create the i-scream logo at the top
79 JLabel iscream = new JLabel(new ImageIcon("i-scream.gif"));
80 _serverCountLabel = new JLabel(" Monitoring 0 hosts...");
81 _serverCountLabel.setForeground( new Color(0, 0, 102));
82 Box header = Box.createHorizontalBox();
83 header.add(_serverCountLabel);
84 header.add(Box.createHorizontalGlue());
85 header.add(iscream);
86
87 //_tabbedPane.setSelectedIndex(0);
88
89 // build the frame
90 box.add(header);
91 box.add(_tabbedPane);
92 box.add(_status);
93 getContentPane().add(box);
94
95 // show the window
96 show();
97 _status.setText("Running...");
98 }
99
100 //---PUBLIC METHODS---
101
102 public void run() {
103 HashMap hostList = new HashMap();
104 try {
105 _data.start();
106 while(true) {
107 synchronized (_data) {
108 _data.wait();
109 }
110 String xml = _data.getXML();
111 if (xml == null) {
112 // shouldn't really happen...but not sure
113 _status.setText("No XML to update...");
114 } else {
115 _status.setText("Got inbound data...handling");
116 // Get a string without any null characters in it.
117 // -- maybe String.trim() would be better ?
118 if (xml.indexOf(0) != -1) {
119 xml = xml.substring(0, xml.indexOf(0));
120 }
121 else {
122 xml = xml.substring(0, xml.length());
123 }
124
125 // Use XMLPacketMaker to make an XMLPacket object.
126 XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
127 XMLPacket packet = xmlPacketMaker.createXMLPacket();
128 String hostName = packet.getParam("packet.attributes.machine_name");
129 if(!hostList.containsKey(hostName)) {
130 _serverCount++;
131 _serverCountLabel.setText(" Monitoring " + _serverCount + " hosts...");
132 host = new HostDisplayPanel();
133 _tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName);
134 hostList.put(hostName, host);
135 _status.setText("New Host added: " + hostName);
136 }
137 ((HostDisplayPanel) hostList.get(hostName)).updateHost(packet);
138 }
139 }
140 } catch (Exception e) {
141 System.err.println("ERROR RUN: " + e);
142 }
143 }
144
145 //---PRIVATE METHODS---
146
147 protected JPanel makeTextPanel(String text, Component item) {
148 JPanel panel = new JPanel(false);
149 JLabel label = new JLabel(text);
150 label.setHorizontalAlignment(JLabel.RIGHT);
151 //item.setHorizontalAlignment(JLabel.LEFT);
152 panel.setLayout(new GridLayout(1, 2));
153 panel.add(label);
154 panel.add(item);
155 return panel;
156 }
157
158
159 //---ACCESSOR/MUTATOR METHODS---
160
161 //---ATTRIBUTES---
162
163 HostDisplayPanel host;
164 JTabbedPane _tabbedPane = new JTabbedPane();
165 DataReader _data;
166 JLabel _status = new JLabel();
167 ImageIcon _serverIcon = new ImageIcon("server.gif");
168 JLabel _serverCountLabel;
169 int _serverCount = 0;
170
171 //---STATIC ATTRIBUTES---
172
173 }