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.8 by ajm, Sat Jan 20 16:06:53 2001 UTC vs.
Revision 1.28 by ajm, Mon Mar 19 00:23:50 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 + package uk.org.iscream.conient;
3  
4   //---IMPORTS---
5   import javax.swing.*;
6   import javax.swing.border.*;
6 import java.awt.Color;
7 import uk.ac.ukc.iscream.util.*;
8
7   import java.awt.*;
8   import java.awt.event.*;
11 import java.net.*;
12 import java.io.*;
13 import java.util.Date;
14 import java.text.DateFormat;
15 import java.util.Locale;
16 import java.util.HashMap;
17 import javax.swing.border.*;
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 30 | 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 = 700;
32      
33 <    private final int width = 400;
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 = null;
61 <            if (args.length != 1) {
62 <                Object response = null;
63 <                while(!(response instanceof String)) {
64 <                    response = JOptionPane.showInputDialog(null, "Please enter the name of a server running the I-Scream client interface:", "I-Scream Server", JOptionPane.INFORMATION_MESSAGE);
46 <                }
47 <                host = (String) response;
48 <            } else {
49 <                host = args[0];
50 <            }
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 <            int port = 4510;
67 <            Socket socket = new Socket(host, port);
54 <            BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream()));
55 <            PrintWriter outBound = new PrintWriter(socket.getOutputStream());
66 >        // start the configuration system
67 >        Configuration.initialise(configFile);
68  
69 <            Queue dataQueue = new Queue();
70 <            DataReader data = new DataReader(inBound, dataQueue);
69 >        // the data display panel
70 >        DataPanel data = new DataPanel();
71          
72 <            SwingClient client = new SwingClient(dataQueue);
73 <            Thread clientThread = new Thread(client);
74 <            
75 <            clientThread.start();
76 <            data.start();
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 <        } catch (Exception e) {
81 <            System.err.println("ERROR START: " + e);
68 <            System.exit(1);
69 <        }  
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(Queue dataQueue) {
78 <        
79 <        _dataQueue = dataQueue;
80 <        _myQueue = _dataQueue.getQueue();
101 >    private Conient(JSplitPane data, ControlPanel control) {
102          // set up the Frame
82        setTitle("I-Scream Client");
83        //setSize(width, height);
84        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
85        Box box = Box.createVerticalBox();
86
87        // create the i-scream logo at the top
88        JLabel iscream = new JLabel(new ImageIcon("i-scream.gif"));
89        _serverCountLabel = new JLabel("   Monitoring 0 hosts...");
90        _serverCountLabel.setForeground( new Color(0, 0, 102));
91        Box header = Box.createHorizontalBox();
92        header.add(_serverCountLabel);
93        header.add(Box.createHorizontalGlue());
94        header.add(iscream);
95        Box main = Box.createHorizontalBox();
96        JButton
103   utton = new JButton("Connect");
104 +        super("Conient {an i-scream Client}");
105 +        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
106 +        setJMenuBar(control.getMenuBar());
107          
108 <        // set up the text area
109 <        _status.setEditable(false);
110 <        JScrollPane statusPane = new JScrollPane(_status);
111 <        statusPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
103 <        
104 <        Box controlPane = Box.createVerticalBox();
105 <        controlPane.add(button);
106 <        //controlPane.add(Box.createVerticalGlue());
107 <        controlPane.add(statusPane);
108 <        main.add(controlPane);
109 <        main.add(_tabbedPane);
108 >        // set what happens when the X in the corner is clicked        
109 >        addWindowListener(new WindowAdapter() {
110 >            public void windowClosing(WindowEvent e) {System.exit(0);}
111 >        });
112  
113 <        //_tabbedPane.setSelectedIndex(0);
114 <        
115 <        // build the frame
116 <        box.add(header);
115 <        box.add(main);
116 <        
117 <        getContentPane().add(box);
113 >        // add the control pane to the top border
114 >        getContentPane().add(control, "North");
115 >        // add the data pane to the centre        
116 >        getContentPane().add(data);
117  
118 <        // show the window
119 <        show();
120 <        _status.insert("Running...\n",0);
121 <    }
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 < //---PUBLIC METHODS---
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("./resources/server.gif")).getImage());
141  
142 <    public void run() {
143 <        HashMap hostList = new HashMap();
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 <            while(true) {
149 <                
150 <                String xml = (String) _dataQueue.get(_myQueue);
132 <                if (xml == null) {
133 <                    // shouldn't really happen...but not sure
134 <                    _status.insert("No XML to update...",0);
135 <                } else {
136 <                    
137 <                    // Get a string without any null characters in it.
138 <                    //  -- maybe String.trim() would be better ?
139 <                    if (xml.indexOf(0) != -1) {
140 <                        xml = xml.substring(0, xml.indexOf(0));
141 <                    }
142 <                    else {
143 <                        xml = xml.substring(0, xml.length());
144 <                    }
145 <                    
146 <                    // Use XMLPacketMaker to make an XMLPacket object.
147 <                    XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
148 <                    XMLPacket packet = xmlPacketMaker.createXMLPacket();
149 <                    String hostName = packet.getParam("packet.attributes.machine_name");
150 <                    if(!hostList.containsKey(hostName)) {
151 <                        _serverCount++;
152 <                        _serverCountLabel.setText("   Monitoring " + _serverCount + " hosts...");
153 <                        host = new HostDisplayPanel();      
154 <                        _tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName);
155 <                        hostList.put(hostName, host);
156 <                        _status.insert("New Host added: " + hostName + "\n", 0);
157 <                    }
158 <                    ((HostDisplayPanel) hostList.get(hostName)).updateHost(packet);
159 <                }
160 <            }
161 <        } catch (Exception e) {
162 <            System.err.println("ERROR RUN: " + e);
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 +
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, java.awt.Component 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);
176 <        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---
183
184    HostDisplayPanel host;
185    JTabbedPane _tabbedPane = new JTabbedPane();
186    Queue _dataQueue;
187    int _myQueue;
188    JTextArea _status = new JTextArea();
189    ImageIcon _serverIcon = new ImageIcon("server.gif");
190    JLabel _serverCountLabel;
191    int _serverCount = 0;
206      
193    
207   //---STATIC ATTRIBUTES---
208      
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 +    /**
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 +    /**
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 +    /**
234 +     * The place where system messages are written.
235 +     */
236 +    static JTextArea _messages = new JTextArea();
237 +    {
238 +        _messages.setLineWrap(true);
239 +    }
240 +    
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 + //---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("./resources/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