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
(Generate patch)

Comparing projects/cms/source/conient/uk/org/iscream/cms/conient/Conient.java (file contents):
Revision 1.4 by ajm, Mon Jan 15 00:12:31 2001 UTC vs.
Revision 1.19 by ajm, Tue Jan 30 02:15:11 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 + package uk.ac.ukc.iscream.conient;
3  
4   //---IMPORTS---
5   import javax.swing.*;
6   import javax.swing.border.*;
6 import java.awt.Color;
7
7   import java.awt.*;
8   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;
9  
10   /**
11 < * NASTY AND BASIC, PLEASE DON'T COMPLAIN
11 > * This is the main class of the Conient client.
12   *
13 + * This sets up the control panel, the data panel
14 + * and its own display.
15 + *
16   * @author  $Author$
17   * @version $Id$
18   */
19 < public class SwingClient extends JFrame implements Runnable {
19 > public class Conient extends JFrame {
20  
21   //---FINAL ATTRIBUTES---
22  
# Line 28 | Line 24 | public class SwingClient extends JFrame implements Run
24       * The current CVS revision of this class
25       */
26      public final String REVISION = "$Revision$";
27 +
28 +    /**
29 +     * The initial width of the window
30 +     */        
31 +    private final int DEFAULT_WIDTH = 600;
32      
33 <    private final int width = 300;
34 <    private final int height = 700;
33 >    /**
34 >     * The initial height of the window
35 >     */
36 >    private final int DEFAULT_HEIGHT = 600;
37      
38 +    /**
39 +     * The default configuration fle
40 +     * This can be specified on the command line
41 +     */
42 +    public static final String DEFAULT_CONFIG_FILE = "./etc/default.conf";
43 +    
44   //---STATIC METHODS---
45  
46 +    /**
47 +     * The first method that is called.
48 +     * Sets up the various panels
49 +     *
50 +     * @param args the command line arguments
51 +     */
52      public static void main(String[] args) {
53 <        try {
54 <            String host = args[0];
55 <            int port = 4510;
56 <            Socket socket = new Socket(host, port);
57 <            BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream()));
58 <            PrintWriter outBound = new PrintWriter(socket.getOutputStream());
59 <            DataReader data = new DataReader(inBound);
53 >        // get the host from the command line if they gave it
54 >        String host = null;
55 >        String configFile = DEFAULT_CONFIG_FILE;
56 >        if (args.length == 1) {
57 >            configFile = args[0];
58 >        }
59 >
60 >        // start the configuration system
61 >        Configuration.initialise(configFile);
62 >
63 >        // the data display panel
64 >        DataPanel data = new DataPanel();
65          
66 <            SwingClient cli = new SwingClient(data);
67 <            Thread cliThread = new Thread(cli);
68 <            cliThread.start();
69 <        } catch (Exception e) {
70 <            System.err.println("ERROR START: " + e);
71 <        }  
66 >        // the control panel
67 >        ControlPanel control = new ControlPanel(data);
68 >        
69 >        // the main frame (passed the two panels)
70 >        Conient client = new Conient(data, control);
71 >        Conient.addMessage("Conient {an i-scream Client} © 2001 University of Kent & Project i-scream");
72 >
73 >        Conient.addMessage("Conient ready.");
74      }
75 +
76      
77   //---CONSTRUCTORS---
78  
79      /**
80 <     * Creates a new Swing Client.
80 >     * Creates a new Swing Client Frame
81       */
82 <    public SwingClient(DataReader data) {
60 <        _data = data;
82 >    private Conient(JPanel data, JPanel control) {
83          // set up the Frame
84 <        setTitle("I-Scream Client");
85 <        setSize(width, height);
64 <        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
65 <        Box box = Box.createVerticalBox();
84 >        super("Conient {an i-scream Client}");
85 >        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
86  
87 <        // create the i-scream logo at the top
88 <        JLabel iscream = new JLabel(new ImageIcon("i-scream.gif"));
89 <        JLabel comment = new JLabel("   I-Scream Client");
90 <        comment.setForeground( new Color(0, 0, 102));
91 <        Box header = Box.createHorizontalBox();
92 <        header.add(comment);
93 <        header.add(Box.createHorizontalGlue());
74 <        header.add(iscream);
87 >        // set what happens when the X in the corner is clicked        
88 >        addWindowListener(new WindowAdapter() {
89 >            public void windowClosing(WindowEvent e) {System.exit(0);}
90 >        });
91 >
92 >        // add the control pane to the top border
93 >        getContentPane().add(control, "North");
94          
95 <        
96 <        
97 <        //_tabbedPane.setSelectedIndex(0);
79 <        
80 <        // build the frame
81 <        box.add(header);
82 <        box.add(_tabbedPane);
83 <        box.add(_status);
84 <        getContentPane().add(box);
95 >        // create a scrollable pane for the data in the centre
96 >        JScrollPane scrollPane = new JScrollPane(data);
97 >        getContentPane().add(scrollPane, "Center");
98  
99 +        // setup the status panel        
100 +        JPanel bottom = new JPanel();
101 +        bottom.setLayout(new BorderLayout());
102 +        _messages.setEditable(false);
103 +        _messages.setRows(3);
104 +        JScrollPane messagesPane = new JScrollPane(_messages);
105 +        messagesPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
106 +        bottom.add(messagesPane, "Center");
107 +        JPanel statusPanel = new JPanel();
108 +        JPanel linkPanel = new JPanel();
109 +        linkPanel.setLayout(new GridLayout(2,1));
110 +        linkPanel.add(_controlStatus);
111 +        linkPanel.add(_dataStatus);
112 +        statusPanel.setLayout(new GridLayout(1,3));
113 +        statusPanel.add(linkPanel);
114 +        statusPanel.add(_queueStatus);
115 +        bottom.add(statusPanel, "South");
116 +
117 +        // add the status panel to the bottom border
118 +        getContentPane().add(bottom, "South");
119 +        
120          // show the window
121          show();
88        _status.setText("Running...");
122      }
123  
124   //---PUBLIC METHODS---
125  
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
126   //---PRIVATE METHODS---
127 +
128 + //---ACCESSOR/MUTATOR METHODS---
129 +
130 +    /**
131 +     * Sets the control link status.
132 +     *
133 +     * @param status the message
134 +     */
135 +    public static void setControlStatus(String status) {
136 +        _controlStatus.setText("Control Link: " + status);
137 +        _controlStatus.repaint();
138 +    }
139      
140 <    protected JPanel makeTextPanel(String text, Component item) {
141 <        JPanel panel = new JPanel(false);
142 <        JLabel label = new JLabel(text);
143 <        label.setHorizontalAlignment(JLabel.RIGHT);
144 <        //item.setHorizontalAlignment(JLabel.LEFT);
145 <        panel.setLayout(new GridLayout(1, 2));
146 <        panel.add(label);
147 <        panel.add(item);
143 <        return panel;
140 >    /**
141 >     * Sets the data link status.
142 >     *
143 >     * @param status the message
144 >     */
145 >    public static void setDataStatus(String status) {
146 >        _dataStatus.setText("Data Link: " + status);
147 >        _dataStatus.repaint();
148      }
149  
150 +    /**
151 +     * Updates the queue status.
152 +     *
153 +     * @param currentQueue
154 +     * @param numElements
155 +     */
156 +    public static void setQueueStatus(int currentQueue, int numElements) {
157 +        _queueStatus.setText("Data Queue : " + currentQueue + " Packets Recieved : " + numElements);
158 +        _queueStatus.repaint();
159 +    }
160  
161 < //---ACCESSOR/MUTATOR METHODS---
161 >    /**
162 >     * Adds a system message to the messages list
163 >     *
164 >     * @param message the new message
165 >     */
166 >    public static void addMessage(String message) {
167 >        _messages.insert(message + "\n", 0);
168 >    }
169  
170   //---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();
171      
172 <    JLabel _sTime = new JLabel();
172 > //---STATIC ATTRIBUTES---
173      
174 <    JLabel _load_load1 = new JLabel();
175 <    JLabel _load_load5 = new JLabel();
176 <    JLabel _load_load15 = new JLabel();
177 <    
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);
174 >    /**
175 >     * Displays information about the data link
176 >     */
177 >    static JLabel _controlStatus = new JLabel("Control Link: Disconnected", JLabel.LEFT);
178      {
179 <        _cpu_idle.setStringPainted(true);
179 >        _controlStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
180      }
181 <    JProgressBar _cpu_user = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
181 >    
182 >    /**
183 >     * Displays information about the data link
184 >     */
185 >    static JLabel _dataStatus = new JLabel("Data Link: Disconnected", JLabel.LEFT);
186      {
187 <        _cpu_user.setStringPainted(true);
187 >        _dataStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
188      }
189 <    JProgressBar _cpu_kernel = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
189 >    
190 >    /**
191 >     * Displays information about the inbound data queue.
192 >     */
193 >    static JLabel _queueStatus = new JLabel(" ", JLabel.LEFT);
194      {
195 <        _cpu_kernel.setStringPainted(true);
195 >        _queueStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
196      }
197 <    JProgressBar _cpu_iowait = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
197 >    
198 >    /**
199 >     * The place where system messages are written.
200 >     */
201 >    static JTextArea _messages = new JTextArea();
202      {
203 <        _cpu_iowait.setStringPainted(true);
203 >        _messages.setLineWrap(true);
204      }
205 <    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 < }
205 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines