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.1 by ajm, Sun Jan 14 21:22:34 2001 UTC vs.
Revision 1.23 by ajm, Mon Feb 26 18:40:25 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.*;
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 24 | 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 +    /**
45 +     * The time in seconds to display the splash
46 +     * screen for
47 +     */
48 +    public static final int DISPLAY_SPLASH_TIME_SECONDS = 3;
49 +    
50   //---STATIC METHODS---
51  
52 +    /**
53 +     * The first method that is called.
54 +     * Sets up the various panels
55 +     *
56 +     * @param args the command line arguments
57 +     */
58      public static void main(String[] args) {
59 <        try {
60 <            String host = args[0];
61 <            int port = 4510;
62 <            Socket socket = new Socket(host, port);
63 <            BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream()));
64 <            PrintWriter outBound = new PrintWriter(socket.getOutputStream());
65 <            DataReader data = new DataReader(inBound);
59 >        // get the host from the command line if they gave it
60 >        String host = null;
61 >        String configFile = DEFAULT_CONFIG_FILE;
62 >        if (args.length == 1) {
63 >            configFile = args[0];
64 >        }
65 >
66 >        // start the configuration system
67 >        Configuration.initialise(configFile);
68 >
69 >        // the data display panel
70 >        DataPanel data = new DataPanel();
71          
72 <            SwingClient cli = new SwingClient(data);
73 <            Thread cliThread = new Thread(cli);
74 <            cliThread.start();
75 <        } catch (Exception e) {
76 <            System.err.println("ERROR: " + e);
77 <        }  
72 >        // the control panel
73 >        ControlPanel control = new ControlPanel(data);
74 >        
75 >        // the main frame (passed the two panels)
76 >        Conient client = new Conient(data, control);
77 >        conientFrame = (Frame) client;
78 >        Conient.addMessage("Conient {an i-scream Client} © 2001 University of Kent & Project i-scream");
79 >
80 >        Conient.addMessage("Conient ready.");
81 >        
82      }
83      
84 +    /**
85 +     * A static accessor, allowing components of the system
86 +     * to get hold of the root frame of the system.
87 +     *
88 +     * see conientFrame attribute for details.
89 +     *
90 +     * @return the root Conient frame
91 +     */
92 +    public static Frame getFrame() {
93 +        return conientFrame;
94 +    }
95 +    
96   //---CONSTRUCTORS---
97  
98      /**
99 <     * Creates a new Swing Client.
99 >     * Creates a new Swing Client Frame
100       */
101 <    public SwingClient(DataReader data) {
56 <        _data = data;
101 >    private Conient(JPanel data, JPanel control) {
102          // set up the Frame
103 <        setTitle("I-Scream Client");
104 <        setSize(width, height);
60 <        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
61 <        Box box = Box.createVerticalBox();
103 >        super("Conient {an i-scream Client}");
104 >        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
105  
106 <        // create the i-scream logo at the top
107 <        JLabel iscream = new JLabel(new ImageIcon("i-scream.gif"));
108 <        JLabel comment = new JLabel("   I-Scream Client");
109 <        comment.setForeground( new Color(0, 0, 102));
67 <        Box header = Box.createHorizontalBox();
68 <        header.add(comment);
69 <        header.add(Box.createHorizontalGlue());
70 <        header.add(iscream);
71 <        
72 <        ImageIcon icon = new ImageIcon("server.gif");
73 <        JTabbedPane tabbedPane = new JTabbedPane();
74 <        JPanel mainPanel = new JPanel();
75 <        mainPanel.setLayout(new GridLayout(21, 1));
106 >        // set what happens when the X in the corner is clicked        
107 >        addWindowListener(new WindowAdapter() {
108 >            public void windowClosing(WindowEvent e) {System.exit(0);}
109 >        });
110  
111 <        JPanel panel1 = makeTextPanel("Machine Name : ", _machine_name);
112 <        JPanel panel2 = makeTextPanel("IP : ", _ip);
79 <        JPanel panel3 = makeTextPanel("Date : ", _date);
80 <        JPanel panel4 = makeTextPanel("Sequence Number : ", _seq_no);
81 <        JPanel panel5 = makeTextPanel("sTime : ", _sTime);
82 <        JPanel panel6 = makeTextPanel("Load Average (1 min) : ", _load_load1);
83 <        JPanel panel7 = makeTextPanel("Load Average (5 min) : ", _load_load5);
84 <        JPanel panel8 = makeTextPanel("Load Average (15 min) : ", _load_load15);
85 <        JPanel panel9 = makeTextPanel("Processes Total : ", _processes_total);
86 <        JPanel panel10 = makeTextPanel("Processes Sleeping : ", _processes_sleeping);
87 <        JPanel panel11 = makeTextPanel("Processes Zombie : ", _processes_zombie);
88 <        JPanel panel12 = makeTextPanel("Processes Stopped : ", _processes_stopped);
89 <        JPanel panel13 = makeTextPanel("CPU % idle : ", _cpu_idle);
90 <        JPanel panel14 = makeTextPanel("CPU % user : ", _cpu_user);
91 <        JPanel panel15 = makeTextPanel("CPU % kernel : ", _cpu_kernel);
92 <        JPanel panel16 = makeTextPanel("CPU % i/o wait : ", _cpu_iowait);
93 <        JPanel panel17 = makeTextPanel("CPU % swapping : ", _cpu_swap);
94 <        JPanel panel18 = makeTextPanel("Real Memory : ", _memory_real);
95 <        JPanel panel19 = makeTextPanel("Real Free : ", _memory_free);
96 <        JPanel panel20 = makeTextPanel("Swap in use : ", _memory_swapinuse);
97 <        JPanel panel21 = makeTextPanel("Swap free : ", _memory_swapfree);
98 <        mainPanel.add(panel1);
99 <        mainPanel.add(panel2);
100 <        mainPanel.add(panel3);
101 <        mainPanel.add(panel4);
102 <        mainPanel.add(panel5);
103 <        mainPanel.add(panel6);
104 <        mainPanel.add(panel7);
105 <        mainPanel.add(panel8);
106 <        mainPanel.add(panel9);
107 <        mainPanel.add(panel10);
108 <        mainPanel.add(panel11);
109 <        mainPanel.add(panel12);
110 <        mainPanel.add(panel13);
111 <        mainPanel.add(panel14);
112 <        mainPanel.add(panel15);
113 <        mainPanel.add(panel16);
114 <        mainPanel.add(panel17);
115 <        mainPanel.add(panel18);
116 <        mainPanel.add(panel19);
117 <        mainPanel.add(panel20);
118 <        mainPanel.add(panel21);
111 >        // add the control pane to the top border
112 >        getContentPane().add(control, "North");
113          
114 <        tabbedPane.addTab("Raptor", icon, mainPanel, "Monitor raptor.ukc.ac.uk");
115 <        
116 <        tabbedPane.setSelectedIndex(0);
114 >        // create a scrollable pane for the data in the centre
115 >        JScrollPane scrollPane = new JScrollPane(data);
116 >        getContentPane().add(scrollPane, "Center");
117  
118 <        // build the frame
119 <        box.add(header);
120 <        box.add(tabbedPane);
121 <        getContentPane().add(box);
118 >        // setup the status panel        
119 >        JPanel bottom = new JPanel();
120 >        bottom.setLayout(new BorderLayout());
121 >        _messages.setEditable(false);
122 >        _messages.setRows(3);
123 >        JScrollPane messagesPane = new JScrollPane(_messages);
124 >        messagesPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
125 >        bottom.add(messagesPane, "Center");
126 >        JPanel statusPanel = new JPanel();
127 >        JPanel linkPanel = new JPanel();
128 >        linkPanel.setLayout(new GridLayout(1,2));
129 >        linkPanel.add(_controlStatus);
130 >        linkPanel.add(_dataStatus);
131 >        statusPanel.setLayout(new GridLayout(2,1));
132 >        statusPanel.add(linkPanel);
133 >        statusPanel.add(_queueStatus);
134 >        bottom.add(statusPanel, "South");
135  
136 <        // show the window
136 >        // add the status panel to the bottom border
137 >        getContentPane().add(bottom, "South");
138 >        
139 >        // a nice icon for the window
140 >        setIconImage((new ImageIcon("./uk/ac/ukc/iscream/conient/server.gif")).getImage());
141 >
142 >        // and just because we can, a silly splash screen
143 >        // of the dudes that did this funky gibble
144 >        Splash splash = new Splash();
145 >        splash.show();
146 >        // wait
147 >        try {
148 >            Thread.sleep(DISPLAY_SPLASH_TIME_SECONDS * 1000);
149 >        } catch (InterruptedException e) {
150 >            // don't do anything, we don't care
151 >        }
152 >        //loose the window
153 >        splash.dispose();
154 >        splash = null;        
155 >        // show the main window
156          show();
157      }
158  
159   //---PUBLIC METHODS---
160  
135    public void run() {
136        _data.start();
137        while(true) {
138            String xml = _data.getXML();
139            if (xml == null) {
140                // nothing
141            } else {
142            
143            // Get a string without any null characters in it.
144            //  -- maybe String.trim() would be better here ?
145            if (xml.indexOf(0) != -1) {
146                xml = xml.substring(0, xml.indexOf(0));
147            }
148            else {
149                xml = xml.substring(0, xml.length());
150            }
151            
152            // Use XMLPacketMaker to make an XMLPacket object.
153            XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
154            XMLPacket packet = xmlPacketMaker.createXMLPacket();
155            
156            _machine_name.setText(packet.getParam("packet.attributes.machine_name"));
157            _ip.setText(packet.getParam("packet.attributes.ip"));
158            _date.setText(packet.getParam("packet.attributes.date"));
159            _seq_no.setText(packet.getParam("packet.attributes.seq_no"));
160            
161            _sTime.setText(packet.getParam("packet.sTime"));
162            
163            _load_load1.setText(packet.getParam("packet.load.load1"));
164            _load_load5.setText(packet.getParam("packet.load.load5"));
165            _load_load15.setText(packet.getParam("packet.load.load15"));
166            
167            _processes_total.setText(packet.getParam("packet.processes.total"));
168            _processes_sleeping.setText(packet.getParam("packet.processes.sleeping"));
169            _processes_zombie.setText(packet.getParam("packet.processes.zombie"));
170            _processes_stopped.setText(packet.getParam("packet.processes.stopped"));
171            
172            _cpu_idle.setText(packet.getParam("packet.cpu.idle"));
173            _cpu_user.setText(packet.getParam("packet.cpu.user"));
174            _cpu_kernel.setText(packet.getParam("packet.cpu.kernel"));
175            _cpu_iowait.setText(packet.getParam("packet.cpu.iowait"));
176            _cpu_swap.setText(packet.getParam("packet.cpu.swap"));
177            
178            _memory_real.setText(packet.getParam("packet.memory.real"));
179            _memory_free.setText(packet.getParam("packet.memory.free"));
180            _memory_swapinuse.setText(packet.getParam("packet.memory.swapinuse"));
181            _memory_swapfree.setText(packet.getParam("packet.memory.swapfree"));
182            }
183        }
184    }
185
161   //---PRIVATE METHODS---
162 +
163 + //---ACCESSOR/MUTATOR METHODS---
164 +
165 +    /**
166 +     * Sets the control link status.
167 +     *
168 +     * @param status the message
169 +     */
170 +    public static void setControlStatus(String status) {
171 +        _controlStatus.setText("Control Link: " + status);
172 +        _controlStatus.repaint();
173 +    }
174      
175 <    protected JPanel makeTextPanel(String text, JLabel item) {
176 <        JPanel panel = new JPanel(false);
177 <        JLabel label = new JLabel(text);
178 <        label.setHorizontalAlignment(JLabel.RIGHT);
179 <        item.setHorizontalAlignment(JLabel.LEFT);
180 <        panel.setLayout(new GridLayout(1, 2));
181 <        panel.add(label);
182 <        panel.add(item);
196 <        return panel;
175 >    /**
176 >     * Sets the data link status.
177 >     *
178 >     * @param status the message
179 >     */
180 >    public static void setDataStatus(String status) {
181 >        _dataStatus.setText("Data Link: " + status);
182 >        _dataStatus.repaint();
183      }
184  
185 +    /**
186 +     * Updates the queue status.
187 +     *
188 +     * @param currentQueue
189 +     * @param numElements
190 +     */
191 +    public static void setQueueStatus(int currentQueue, int numElements) {
192 +        _queueStatus.setText("Data Queue : " + currentQueue + " Packets Recieved : " + numElements);
193 +        _queueStatus.repaint();
194 +    }
195  
196 < //---ACCESSOR/MUTATOR METHODS---
196 >    /**
197 >     * Adds a system message to the messages list
198 >     *
199 >     * @param message the new message
200 >     */
201 >    public static void addMessage(String message) {
202 >        _messages.insert(message + "\n", 0);
203 >    }
204  
205   //---ATTRIBUTES---
203
204    JLabel _machine_name = new JLabel();
205    JLabel _ip = new JLabel();
206    JLabel _date = new JLabel();
207    JLabel _seq_no = new JLabel();
206      
207 <    JLabel _sTime = new JLabel();
207 > //---STATIC ATTRIBUTES---
208      
209 <    JLabel _load_load1 = new JLabel();
210 <    JLabel _load_load5 = new JLabel();
211 <    JLabel _load_load15 = new JLabel();
209 >    /**
210 >     * Displays information about the data link
211 >     */
212 >    static JLabel _controlStatus = new JLabel("Control Link: Disconnected", JLabel.LEFT);
213 >    {
214 >        _controlStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
215 >    }
216      
217 <    JLabel _processes_total = new JLabel();
218 <    JLabel _processes_sleeping = new JLabel();
219 <    JLabel _processes_zombie = new JLabel();
220 <    JLabel _processes_stopped = new JLabel();
217 >    /**
218 >     * Displays information about the data link
219 >     */
220 >    static JLabel _dataStatus = new JLabel("Data Link: Disconnected", JLabel.LEFT);
221 >    {
222 >        _dataStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
223 >    }
224      
225 <    JLabel _cpu_idle = new JLabel();
226 <    JLabel _cpu_user = new JLabel();
227 <    JLabel _cpu_kernel = new JLabel();
228 <    JLabel _cpu_iowait = new JLabel();
229 <    JLabel _cpu_swap = new JLabel();
225 >    /**
226 >     * Displays information about the inbound data queue.
227 >     */
228 >    static JLabel _queueStatus = new JLabel(" ", JLabel.LEFT);
229 >    {
230 >        _queueStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
231 >    }
232      
233 <    JLabel _memory_real = new JLabel();
234 <    JLabel _memory_free = new JLabel();
235 <    JLabel _memory_swapinuse = new JLabel();
236 <    JLabel _memory_swapfree = new JLabel();
237 <    DataReader _data;
233 >    /**
234 >     * The place where system messages are written.
235 >     */
236 >    static JTextArea _messages = new JTextArea();
237 >    {
238 >        _messages.setLineWrap(true);
239 >    }
240      
241 < //---STATIC ATTRIBUTES---
241 >    /**
242 >     * Holds a reference to the root frame for Conient
243 >     * This is only used by dialogs (specifically the configurationn
244 >     * dialog) so that it can be modal, please use the accessor.
245 >     */
246 >    private static Frame conientFrame;
247      
248 < }
248 > //---INNER CLASSES----
249 >
250 >    /**
251 >     * An inner class to display a splash screen
252 >     */
253 >    private class Splash extends JWindow {
254 >        
255 >        /**
256 >         * Constructs a new splash screen
257 >         */
258 >        public Splash() {
259 >            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
260 >            JPanel splash = new JPanel();
261 >            splash.setBackground(Color.black);
262 >            JLabel image = new JLabel((new ImageIcon("./uk/ac/ukc/iscream/conient/i-scream-splash.gif")));
263 >            splash.add(image);
264 >            setContentPane(splash);
265 >            Dimension screen = getToolkit().getScreenSize();
266 >            pack();
267 >            setLocation((screen.width - getSize().width) / 2,
268 >                        (screen.height - getSize().height) / 2);
269 >            
270 >            
271 >        }
272 >    }
273 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines