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.33 by tdb, Sat May 18 18:15:56 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   //---PACKAGE DECLARATION---
21 + package uk.org.iscream.cms.conient;
22  
23   //---IMPORTS---
24   import javax.swing.*;
25   import javax.swing.border.*;
6 import java.awt.Color;
7
26   import java.awt.*;
27   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;
28  
29   /**
30 < * NASTY AND BASIC, PLEASE DON'T COMPLAIN
30 > * This is the main class of the Conient client.
31   *
32 + * This sets up the control panel, the data panel
33 + * and its own display.
34 + *
35   * @author  $Author$
36   * @version $Id$
37   */
38 < public class SwingClient extends JFrame implements Runnable {
38 > public class Conient extends JFrame {
39  
40   //---FINAL ATTRIBUTES---
41  
# Line 28 | Line 43 | public class SwingClient extends JFrame implements Run
43       * The current CVS revision of this class
44       */
45      public final String REVISION = "$Revision$";
46 +
47 +    /**
48 +     * The initial width of the window
49 +     */        
50 +    private final int DEFAULT_WIDTH = 700;
51      
52 <    private final int width = 300;
53 <    private final int height = 700;
52 >    /**
53 >     * The initial height of the window
54 >     */
55 >    private final int DEFAULT_HEIGHT = 600;
56      
57 +    /**
58 +     * The default configuration fle
59 +     * This can be specified on the command line
60 +     */
61 +    public static final String DEFAULT_CONFIG_FILE = "./etc/default.conf";
62 +    
63 +    /**
64 +     * The time in seconds to display the splash
65 +     * screen for
66 +     */
67 +    public static final int DISPLAY_SPLASH_TIME_SECONDS = 3;
68 +    
69   //---STATIC METHODS---
70  
71 +    /**
72 +     * The first method that is called.
73 +     * Sets up the various panels
74 +     *
75 +     * @param args the command line arguments
76 +     */
77      public static void main(String[] args) {
78 <        try {
79 <            String host = args[0];
80 <            int port = 4510;
81 <            Socket socket = new Socket(host, port);
82 <            BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream()));
83 <            PrintWriter outBound = new PrintWriter(socket.getOutputStream());
84 <            DataReader data = new DataReader(inBound);
78 >        // get the host from the command line if they gave it
79 >        String host = null;
80 >        String configFile = DEFAULT_CONFIG_FILE;
81 >        if (args.length == 1) {
82 >            configFile = args[0];
83 >        }
84 >
85 >        // start the configuration system
86 >        Configuration.initialise(configFile);
87 >
88 >        // the data display panel
89 >        DataPanel data = new DataPanel();
90          
91 <            SwingClient cli = new SwingClient(data);
92 <            Thread cliThread = new Thread(cli);
93 <            cliThread.start();
94 <        } catch (Exception e) {
95 <            System.err.println("ERROR START: " + e);
96 <        }  
91 >        // the control panel
92 >        ControlPanel control = new ControlPanel(data);
93 >        
94 >        // the main frame (passed the two panels)
95 >        Conient client = new Conient(data, control);
96 >        conientFrame = (Frame) client;
97 >        Conient.addMessage("Conient {an i-scream Client} (c) 2001 The i-scream Project (http://www.i-scream.org.uk)");
98 >
99 >        Conient.addMessage("Conient ready.");
100 >        
101      }
102      
103 +    /**
104 +     * A static accessor, allowing components of the system
105 +     * to get hold of the root frame of the system.
106 +     *
107 +     * see conientFrame attribute for details.
108 +     *
109 +     * @return the root Conient frame
110 +     */
111 +    public static Frame getFrame() {
112 +        return conientFrame;
113 +    }
114 +    
115   //---CONSTRUCTORS---
116  
117      /**
118 <     * Creates a new Swing Client.
118 >     * Creates a new Swing Client Frame
119       */
120 <    public SwingClient(DataReader data) {
60 <        _data = data;
120 >    private Conient(JSplitPane data, ControlPanel control) {
121          // set up the Frame
122 <        setTitle("I-Scream Client");
123 <        setSize(width, height);
124 <        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);
122 >        super("Conient {an i-scream Client}");
123 >        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
124 >        setJMenuBar(control.getMenuBar());
125          
126 <        
127 <        
128 <        //_tabbedPane.setSelectedIndex(0);
129 <        
80 <        // build the frame
81 <        box.add(header);
82 <        box.add(_tabbedPane);
83 <        box.add(_status);
84 <        getContentPane().add(box);
126 >        // set what happens when the X in the corner is clicked        
127 >        addWindowListener(new WindowAdapter() {
128 >            public void windowClosing(WindowEvent e) {System.exit(0);}
129 >        });
130  
131 <        // show the window
132 <        show();
133 <        _status.setText("Running...");
134 <    }
131 >        // add the control pane to the top border
132 >        getContentPane().add(control, "North");
133 >        // add the data pane to the centre        
134 >        getContentPane().add(data);
135  
136 < //---PUBLIC METHODS---
136 >        // setup the status panel        
137 >        JPanel bottom = new JPanel();
138 >        bottom.setLayout(new BorderLayout());
139 >        _messages.setEditable(false);
140 >        _messages.setRows(3);
141 >        JScrollPane messagesPane = new JScrollPane(_messages);
142 >        messagesPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
143 >        bottom.add(messagesPane, "Center");
144 >        JPanel statusPanel = new JPanel();
145 >        JPanel linkPanel = new JPanel();
146 >        linkPanel.setLayout(new GridLayout(1,2));
147 >        linkPanel.add(_controlStatus);
148 >        linkPanel.add(_dataStatus);
149 >        statusPanel.setLayout(new GridLayout(2,1));
150 >        statusPanel.add(linkPanel);
151 >        statusPanel.add(_queueStatus);
152 >        bottom.add(statusPanel, "South");
153  
154 <    public void run() {
155 <        HashMap hostList = new HashMap();
154 >        // add the status panel to the bottom border
155 >        getContentPane().add(bottom, "South");
156 >        
157 >        // a nice icon for the window
158 >        setIconImage((new ImageIcon("./resources/server.gif")).getImage());
159 >
160 >        // and just because we can, a silly splash screen
161 >        // of the dudes that did this funky jibble
162 >        Splash splash = new Splash();
163 >        splash.show();
164 >        // wait
165          try {
166 <        _data.start();
167 <        while(true) {
168 <            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 <            }
166 >            Thread.sleep(DISPLAY_SPLASH_TIME_SECONDS * 1000);
167 >        } catch (InterruptedException e) {
168 >            // don't do anything, we don't care
169          }
170 <        } catch (Exception e) {
171 <            System.err.println("ERROR RUN: " + e);
172 <        }
170 >        //loose the window
171 >        splash.dispose();
172 >        splash = null;        
173 >        // show the main window
174 >        show();
175      }
176  
177 + //---PUBLIC METHODS---
178 +
179   //---PRIVATE METHODS---
180 +
181 + //---ACCESSOR/MUTATOR METHODS---
182 +
183 +    /**
184 +     * Sets the control link status.
185 +     *
186 +     * @param status the message
187 +     */
188 +    public static void setControlStatus(String status) {
189 +        _controlStatus.setText("Control Link: " + status);
190 +        _controlStatus.repaint();
191 +    }
192      
193 <    protected JPanel makeTextPanel(String text, Component item) {
194 <        JPanel panel = new JPanel(false);
195 <        JLabel label = new JLabel(text);
196 <        label.setHorizontalAlignment(JLabel.RIGHT);
197 <        //item.setHorizontalAlignment(JLabel.LEFT);
198 <        panel.setLayout(new GridLayout(1, 2));
199 <        panel.add(label);
200 <        panel.add(item);
143 <        return panel;
193 >    /**
194 >     * Sets the data link status.
195 >     *
196 >     * @param status the message
197 >     */
198 >    public static void setDataStatus(String status) {
199 >        _dataStatus.setText("Data Link: " + status);
200 >        _dataStatus.repaint();
201      }
202  
203 +    /**
204 +     * Updates the queue status.
205 +     *
206 +     * @param currentQueue
207 +     * @param numElements
208 +     */
209 +    public static void setQueueStatus(int currentQueue, int numElements) {
210 +        _queueStatus.setText("Data Queue : " + currentQueue + " Packets Recieved : " + numElements);
211 +        _queueStatus.repaint();
212 +    }
213  
214 < //---ACCESSOR/MUTATOR METHODS---
214 >    /**
215 >     * Adds a system message to the messages list
216 >     *
217 >     * @param message the new message
218 >     */
219 >    public static void addMessage(String message) {
220 >        _messages.insert(message + "\n", 0);
221 >    }
222  
223   //---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();
224      
225 <    JLabel _sTime = new JLabel();
225 > //---STATIC ATTRIBUTES---
226      
227 <    JLabel _load_load1 = new JLabel();
228 <    JLabel _load_load5 = new JLabel();
229 <    JLabel _load_load15 = new JLabel();
230 <    
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);
227 >    /**
228 >     * Displays information about the data link
229 >     */
230 >    static JLabel _controlStatus = new JLabel("Control Link: Disconnected", JLabel.LEFT);
231      {
232 <        _cpu_idle.setStringPainted(true);
232 >        _controlStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
233      }
234 <    JProgressBar _cpu_user = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
234 >    
235 >    /**
236 >     * Displays information about the data link
237 >     */
238 >    static JLabel _dataStatus = new JLabel("Data Link: Disconnected", JLabel.LEFT);
239      {
240 <        _cpu_user.setStringPainted(true);
240 >        _dataStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
241      }
242 <    JProgressBar _cpu_kernel = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
242 >    
243 >    /**
244 >     * Displays information about the inbound data queue.
245 >     */
246 >    static JLabel _queueStatus = new JLabel(" ", JLabel.LEFT);
247      {
248 <        _cpu_kernel.setStringPainted(true);
248 >        _queueStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
249      }
250 <    JProgressBar _cpu_iowait = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
250 >    
251 >    /**
252 >     * The place where system messages are written.
253 >     */
254 >    static JTextArea _messages = new JTextArea();
255      {
256 <        _cpu_iowait.setStringPainted(true);
256 >        _messages.setLineWrap(true);
257      }
187    JProgressBar _cpu_swap = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
188    {
189        _cpu_swap.setStringPainted(true);
190    }
258      
259 <    JLabel _memory_real = new JLabel();
260 <    JLabel _memory_free = new JLabel();
261 <    JLabel _memory_swapinuse = new JLabel();
262 <    JLabel _memory_swapfree = new JLabel();
263 <    DataReader _data;
264 <    JLabel _status = new JLabel();
198 <    ImageIcon _serverIcon = new ImageIcon("server.gif");
259 >    /**
260 >     * Holds a reference to the root frame for Conient
261 >     * This is only used by dialogs (specifically the configurationn
262 >     * dialog) so that it can be modal, please use the accessor.
263 >     */
264 >    private static Frame conientFrame;
265      
266 < //---STATIC ATTRIBUTES---
267 <    
268 < }
266 > //---INNER CLASSES----
267 >
268 >    /**
269 >     * An inner class to display a splash screen
270 >     */
271 >    private class Splash extends JWindow {
272 >        
273 >        /**
274 >         * Constructs a new splash screen
275 >         */
276 >        public Splash() {
277 >            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
278 >            JPanel splash = new JPanel();
279 >            splash.setBackground(Color.black);
280 >            JLabel image = new JLabel((new ImageIcon("./resources/i-scream-splash.gif")));
281 >            splash.add(image);
282 >            setContentPane(splash);
283 >            Dimension screen = getToolkit().getScreenSize();
284 >            pack();
285 >            setLocation((screen.width - getSize().width) / 2,
286 >                        (screen.height - getSize().height) / 2);
287 >            
288 >            
289 >        }
290 >    }
291 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines