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.5 by ajm, Mon Jan 15 03:01:37 2001 UTC vs.
Revision 1.22 by ajm, Wed Feb 21 23:45:16 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 = 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);
44 <                }
45 <                host = (String) response;
46 <            } else {
47 <                host = args[0];
48 <            }
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);
68 <            BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream()));
69 <            PrintWriter outBound = new PrintWriter(socket.getOutputStream());
70 <            DataReader data = new DataReader(inBound);
66 >        // start the configuration system
67 >        Configuration.initialise(configFile);
68 >
69 >        // the data display panel
70 >        DataPanel data = new DataPanel();
71          
72 <            SwingClient client = new SwingClient(data);
73 <            Thread clientThread = new Thread(client);
74 <            clientThread.start();
75 <        } catch (Exception e) {
76 <            System.err.println("ERROR START: " + e);
77 <            System.exit(1);
78 <        }  
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 >        Conient.addMessage("Conient {an i-scream Client} © 2001 University of Kent & Project i-scream");
78 >
79 >        Conient.addMessage("Conient ready.");
80 >        
81      }
82 +
83      
84   //---CONSTRUCTORS---
85  
86      /**
87 <     * Creates a new Swing Client.
87 >     * Creates a new Swing Client Frame
88       */
89 <    public SwingClient(DataReader data) {
71 <        _data = data;
89 >    private Conient(JPanel data, JPanel control) {
90          // set up the Frame
91 <        setTitle("I-Scream Client");
92 <        setSize(width, height);
75 <        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
76 <        Box box = Box.createVerticalBox();
91 >        super("Conient {an i-scream Client}");
92 >        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
93  
94 <        // create the i-scream logo at the top
95 <        JLabel iscream = new JLabel(new ImageIcon("i-scream.gif"));
96 <        JLabel comment = new JLabel("   I-Scream Client");
97 <        comment.setForeground( new Color(0, 0, 102));
98 <        Box header = Box.createHorizontalBox();
99 <        header.add(comment);
100 <        header.add(Box.createHorizontalGlue());
85 <        header.add(iscream);
94 >        // set what happens when the X in the corner is clicked        
95 >        addWindowListener(new WindowAdapter() {
96 >            public void windowClosing(WindowEvent e) {System.exit(0);}
97 >        });
98 >
99 >        // add the control pane to the top border
100 >        getContentPane().add(control, "North");
101          
102 <        //_tabbedPane.setSelectedIndex(0);
103 <        
104 <        // build the frame
90 <        box.add(header);
91 <        box.add(_tabbedPane);
92 <        box.add(_status);
93 <        getContentPane().add(box);
102 >        // create a scrollable pane for the data in the centre
103 >        JScrollPane scrollPane = new JScrollPane(data);
104 >        getContentPane().add(scrollPane, "Center");
105  
106 <        // show the window
107 <        show();
108 <        _status.setText("Running...");
109 <    }
106 >        // setup the status panel        
107 >        JPanel bottom = new JPanel();
108 >        bottom.setLayout(new BorderLayout());
109 >        _messages.setEditable(false);
110 >        _messages.setRows(3);
111 >        JScrollPane messagesPane = new JScrollPane(_messages);
112 >        messagesPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
113 >        bottom.add(messagesPane, "Center");
114 >        JPanel statusPanel = new JPanel();
115 >        JPanel linkPanel = new JPanel();
116 >        linkPanel.setLayout(new GridLayout(1,2));
117 >        linkPanel.add(_controlStatus);
118 >        linkPanel.add(_dataStatus);
119 >        statusPanel.setLayout(new GridLayout(2,1));
120 >        statusPanel.add(linkPanel);
121 >        statusPanel.add(_queueStatus);
122 >        bottom.add(statusPanel, "South");
123  
124 < //---PUBLIC METHODS---
124 >        // add the status panel to the bottom border
125 >        getContentPane().add(bottom, "South");
126 >        
127 >        // a nice icon for the window
128 >        setIconImage((new ImageIcon("./uk/ac/ukc/iscream/conient/server.gif")).getImage());
129  
130 <    public void run() {
131 <        HashMap hostList = new HashMap();
130 >        // and just because we can, a silly splash screen
131 >        // of the dudes that did this funky gibble
132 >        Splash splash = new Splash();
133 >        splash.show();
134 >        // wait
135          try {
136 <        _data.start();
137 <        while(true) {
138 <            synchronized (_data) {
108 <                _data.wait();
109 <            }
110 <            String xml = _data.getXML();
111 <            if (xml == null) {
112 <                _status.setText("No XML to update...");
113 <            } 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 <            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 <            }
136 >            Thread.sleep(DISPLAY_SPLASH_TIME_SECONDS * 1000);
137 >        } catch (InterruptedException e) {
138 >            // don't do anything, we don't care
139          }
140 <        } catch (Exception e) {
141 <            System.err.println("ERROR RUN: " + e);
142 <        }
140 >        //loose the window
141 >        splash.dispose();
142 >        splash = null;        
143 >        // show the main window
144 >        show();
145      }
146  
147 + //---PUBLIC METHODS---
148 +
149   //---PRIVATE METHODS---
150 +
151 + //---ACCESSOR/MUTATOR METHODS---
152 +
153 +    /**
154 +     * Sets the control link status.
155 +     *
156 +     * @param status the message
157 +     */
158 +    public static void setControlStatus(String status) {
159 +        _controlStatus.setText("Control Link: " + status);
160 +        _controlStatus.repaint();
161 +    }
162      
163 <    protected JPanel makeTextPanel(String text, Component item) {
164 <        JPanel panel = new JPanel(false);
165 <        JLabel label = new JLabel(text);
166 <        label.setHorizontalAlignment(JLabel.RIGHT);
167 <        //item.setHorizontalAlignment(JLabel.LEFT);
168 <        panel.setLayout(new GridLayout(1, 2));
169 <        panel.add(label);
170 <        panel.add(item);
152 <        return panel;
163 >    /**
164 >     * Sets the data link status.
165 >     *
166 >     * @param status the message
167 >     */
168 >    public static void setDataStatus(String status) {
169 >        _dataStatus.setText("Data Link: " + status);
170 >        _dataStatus.repaint();
171      }
172  
173 +    /**
174 +     * Updates the queue status.
175 +     *
176 +     * @param currentQueue
177 +     * @param numElements
178 +     */
179 +    public static void setQueueStatus(int currentQueue, int numElements) {
180 +        _queueStatus.setText("Data Queue : " + currentQueue + " Packets Recieved : " + numElements);
181 +        _queueStatus.repaint();
182 +    }
183  
184 < //---ACCESSOR/MUTATOR METHODS---
184 >    /**
185 >     * Adds a system message to the messages list
186 >     *
187 >     * @param message the new message
188 >     */
189 >    public static void addMessage(String message) {
190 >        _messages.insert(message + "\n", 0);
191 >    }
192  
193   //---ATTRIBUTES---
159
160    HostDisplayPanel host;
161    JTabbedPane _tabbedPane = new JTabbedPane();
162    DataReader _data;
163    JLabel _status = new JLabel();
164    ImageIcon _serverIcon = new ImageIcon("server.gif");
194      
195   //---STATIC ATTRIBUTES---
196      
197 < }
197 >    /**
198 >     * Displays information about the data link
199 >     */
200 >    static JLabel _controlStatus = new JLabel("Control Link: Disconnected", JLabel.LEFT);
201 >    {
202 >        _controlStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
203 >    }
204 >    
205 >    /**
206 >     * Displays information about the data link
207 >     */
208 >    static JLabel _dataStatus = new JLabel("Data Link: Disconnected", JLabel.LEFT);
209 >    {
210 >        _dataStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
211 >    }
212 >    
213 >    /**
214 >     * Displays information about the inbound data queue.
215 >     */
216 >    static JLabel _queueStatus = new JLabel(" ", JLabel.LEFT);
217 >    {
218 >        _queueStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
219 >    }
220 >    
221 >    /**
222 >     * The place where system messages are written.
223 >     */
224 >    static JTextArea _messages = new JTextArea();
225 >    {
226 >        _messages.setLineWrap(true);
227 >    }
228 >    
229 > //---INNER CLASSES----
230 >
231 >    /**
232 >     * An inner class to display a splash screen
233 >     */
234 >    private class Splash extends JWindow {
235 >        
236 >        /**
237 >         * Constructs a new splash screen
238 >         */
239 >        public Splash() {
240 >            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
241 >            JPanel splash = new JPanel();
242 >            splash.setBackground(Color.black);
243 >            JLabel image = new JLabel((new ImageIcon("./uk/ac/ukc/iscream/conient/i-scream-splash.gif")));
244 >            splash.add(image);
245 >            setContentPane(splash);
246 >            Dimension screen = getToolkit().getScreenSize();
247 >            pack();
248 >            setLocation((screen.width - getSize().width) / 2,
249 >                        (screen.height - getSize().height) / 2);
250 >            
251 >            
252 >        }
253 >    }
254 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines