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.5
Committed: Mon Jan 15 03:01:37 2001 UTC (23 years, 4 months ago) by ajm
Branch: MAIN
Changes since 1.4: +19 -53 lines
Log Message:
lots of tidying up...
now supports not using a command line
now has nicer graphical displays for memory
NOTE- bugfixes memory not being sent in uniform size - see HostDisplayPanel.java

File Contents

# User Rev Content
1 ajm 1.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 ajm 1.2 import java.util.Date;
13     import java.text.DateFormat;
14     import java.util.Locale;
15 ajm 1.4 import java.util.HashMap;
16 ajm 1.1
17     /**
18     * NASTY AND BASIC, PLEASE DON'T COMPLAIN
19     *
20     * @author $Author: ajm4 $
21 ajm 1.5 * @version $Id: SwingClient.java,v 1.4 2001/01/15 00:12:31 ajm4 Exp $
22 ajm 1.1 */
23     public class SwingClient extends JFrame implements Runnable {
24    
25     //---FINAL ATTRIBUTES---
26    
27     /**
28     * The current CVS revision of this class
29     */
30 ajm 1.5 public final String REVISION = "$Revision: 1.4 $";
31 ajm 1.1
32 ajm 1.5 private final int width = 400;
33 ajm 1.1 private final int height = 700;
34    
35     //---STATIC METHODS---
36    
37     public static void main(String[] args) {
38     try {
39 ajm 1.5 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 ajm 1.1 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 ajm 1.5 SwingClient client = new SwingClient(data);
57     Thread clientThread = new Thread(client);
58     clientThread.start();
59 ajm 1.1 } catch (Exception e) {
60 ajm 1.4 System.err.println("ERROR START: " + e);
61 ajm 1.5 System.exit(1);
62 ajm 1.1 }
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     JLabel comment = new JLabel(" I-Scream Client");
81     comment.setForeground( new Color(0, 0, 102));
82     Box header = Box.createHorizontalBox();
83     header.add(comment);
84     header.add(Box.createHorizontalGlue());
85     header.add(iscream);
86    
87 ajm 1.4 //_tabbedPane.setSelectedIndex(0);
88    
89 ajm 1.1 // build the frame
90     box.add(header);
91 ajm 1.4 box.add(_tabbedPane);
92     box.add(_status);
93 ajm 1.1 getContentPane().add(box);
94    
95     // show the window
96     show();
97 ajm 1.4 _status.setText("Running...");
98 ajm 1.1 }
99    
100     //---PUBLIC METHODS---
101    
102     public void run() {
103 ajm 1.4 HashMap hostList = new HashMap();
104 ajm 1.3 try {
105 ajm 1.1 _data.start();
106     while(true) {
107 ajm 1.3 synchronized (_data) {
108     _data.wait();
109     }
110 ajm 1.1 String xml = _data.getXML();
111     if (xml == null) {
112 ajm 1.4 _status.setText("No XML to update...");
113 ajm 1.1 } else {
114    
115     // Get a string without any null characters in it.
116     // -- maybe String.trim() would be better here ?
117     if (xml.indexOf(0) != -1) {
118     xml = xml.substring(0, xml.indexOf(0));
119     }
120     else {
121     xml = xml.substring(0, xml.length());
122     }
123    
124     // Use XMLPacketMaker to make an XMLPacket object.
125     XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
126     XMLPacket packet = xmlPacketMaker.createXMLPacket();
127 ajm 1.4 String hostName = packet.getParam("packet.attributes.machine_name");
128     if(!hostList.containsKey(hostName)) {
129     host = new HostDisplayPanel();
130     _tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName);
131     hostList.put(hostName, host);
132     _status.setText("New Host added: " + hostName);
133     }
134     ((HostDisplayPanel) hostList.get(hostName)).updateHost(packet);
135 ajm 1.1 }
136 ajm 1.3 }
137     } catch (Exception e) {
138 ajm 1.4 System.err.println("ERROR RUN: " + e);
139 ajm 1.1 }
140     }
141    
142     //---PRIVATE METHODS---
143    
144 ajm 1.2 protected JPanel makeTextPanel(String text, Component item) {
145 ajm 1.1 JPanel panel = new JPanel(false);
146     JLabel label = new JLabel(text);
147     label.setHorizontalAlignment(JLabel.RIGHT);
148 ajm 1.2 //item.setHorizontalAlignment(JLabel.LEFT);
149 ajm 1.1 panel.setLayout(new GridLayout(1, 2));
150     panel.add(label);
151     panel.add(item);
152     return panel;
153     }
154    
155    
156     //---ACCESSOR/MUTATOR METHODS---
157    
158     //---ATTRIBUTES---
159 ajm 1.5
160 ajm 1.4 HostDisplayPanel host;
161     JTabbedPane _tabbedPane = new JTabbedPane();
162 ajm 1.1 DataReader _data;
163 ajm 1.4 JLabel _status = new JLabel();
164     ImageIcon _serverIcon = new ImageIcon("server.gif");
165 ajm 1.1
166     //---STATIC ATTRIBUTES---
167    
168     }