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.4
Committed: Mon Jan 15 00:12:31 2001 UTC (23 years, 4 months ago) by ajm
Branch: MAIN
Changes since 1.3: +24 -88 lines
Log Message:
now supports multiple hosts....!!! oh yes!

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.3 2001/01/14 23:14:35 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.3 $";
31
32 private final int width = 300;
33 private final int height = 700;
34
35 //---STATIC METHODS---
36
37 public static void main(String[] args) {
38 try {
39 String host = args[0];
40 int port = 4510;
41 Socket socket = new Socket(host, port);
42 BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream()));
43 PrintWriter outBound = new PrintWriter(socket.getOutputStream());
44 DataReader data = new DataReader(inBound);
45
46 SwingClient cli = new SwingClient(data);
47 Thread cliThread = new Thread(cli);
48 cliThread.start();
49 } catch (Exception e) {
50 System.err.println("ERROR START: " + e);
51 }
52 }
53
54 //---CONSTRUCTORS---
55
56 /**
57 * Creates a new Swing Client.
58 */
59 public SwingClient(DataReader data) {
60 _data = data;
61 // set up the Frame
62 setTitle("I-Scream Client");
63 setSize(width, height);
64 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
65 Box box = Box.createVerticalBox();
66
67 // create the i-scream logo at the top
68 JLabel iscream = new JLabel(new ImageIcon("i-scream.gif"));
69 JLabel comment = new JLabel(" I-Scream Client");
70 comment.setForeground( new Color(0, 0, 102));
71 Box header = Box.createHorizontalBox();
72 header.add(comment);
73 header.add(Box.createHorizontalGlue());
74 header.add(iscream);
75
76
77
78 //_tabbedPane.setSelectedIndex(0);
79
80 // build the frame
81 box.add(header);
82 box.add(_tabbedPane);
83 box.add(_status);
84 getContentPane().add(box);
85
86 // show the window
87 show();
88 _status.setText("Running...");
89 }
90
91 //---PUBLIC METHODS---
92
93 public void run() {
94 HashMap hostList = new HashMap();
95 try {
96 _data.start();
97 while(true) {
98 synchronized (_data) {
99 _data.wait();
100 }
101 String xml = _data.getXML();
102 if (xml == null) {
103 _status.setText("No XML to update...");
104 } else {
105
106 // Get a string without any null characters in it.
107 // -- maybe String.trim() would be better here ?
108 if (xml.indexOf(0) != -1) {
109 xml = xml.substring(0, xml.indexOf(0));
110 }
111 else {
112 xml = xml.substring(0, xml.length());
113 }
114
115 // Use XMLPacketMaker to make an XMLPacket object.
116 XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
117 XMLPacket packet = xmlPacketMaker.createXMLPacket();
118 String hostName = packet.getParam("packet.attributes.machine_name");
119 if(!hostList.containsKey(hostName)) {
120 host = new HostDisplayPanel();
121 _tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName);
122 hostList.put(hostName, host);
123 _status.setText("New Host added: " + hostName);
124 }
125 ((HostDisplayPanel) hostList.get(hostName)).updateHost(packet);
126 }
127 }
128 } catch (Exception e) {
129 System.err.println("ERROR RUN: " + e);
130 }
131 }
132
133 //---PRIVATE METHODS---
134
135 protected JPanel makeTextPanel(String text, Component item) {
136 JPanel panel = new JPanel(false);
137 JLabel label = new JLabel(text);
138 label.setHorizontalAlignment(JLabel.RIGHT);
139 //item.setHorizontalAlignment(JLabel.LEFT);
140 panel.setLayout(new GridLayout(1, 2));
141 panel.add(label);
142 panel.add(item);
143 return panel;
144 }
145
146
147 //---ACCESSOR/MUTATOR METHODS---
148
149 //---ATTRIBUTES---
150 HostDisplayPanel host;
151 JTabbedPane _tabbedPane = new JTabbedPane();
152
153 JLabel _machine_name = new JLabel();
154 JLabel _ip = new JLabel();
155 JLabel _date = new JLabel();
156 JLabel _seq_no = new JLabel();
157
158 JLabel _sTime = new JLabel();
159
160 JLabel _load_load1 = new JLabel();
161 JLabel _load_load5 = new JLabel();
162 JLabel _load_load15 = new JLabel();
163
164 JLabel _processes_total = new JLabel();
165 JLabel _processes_sleeping = new JLabel();
166 JLabel _processes_zombie = new JLabel();
167 JLabel _processes_stopped = new JLabel();
168
169 int min = 0;
170 int max = 100;
171 JProgressBar _cpu_idle = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
172 {
173 _cpu_idle.setStringPainted(true);
174 }
175 JProgressBar _cpu_user = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
176 {
177 _cpu_user.setStringPainted(true);
178 }
179 JProgressBar _cpu_kernel = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
180 {
181 _cpu_kernel.setStringPainted(true);
182 }
183 JProgressBar _cpu_iowait = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
184 {
185 _cpu_iowait.setStringPainted(true);
186 }
187 JProgressBar _cpu_swap = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
188 {
189 _cpu_swap.setStringPainted(true);
190 }
191
192 JLabel _memory_real = new JLabel();
193 JLabel _memory_free = new JLabel();
194 JLabel _memory_swapinuse = new JLabel();
195 JLabel _memory_swapfree = new JLabel();
196 DataReader _data;
197 JLabel _status = new JLabel();
198 ImageIcon _serverIcon = new ImageIcon("server.gif");
199
200 //---STATIC ATTRIBUTES---
201
202 }