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.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 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 = 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   //---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 = null;
55 <            if (args.length != 1) {
56 <                Object response = null;
57 <                while(!(response instanceof String)) {
58 <                    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 <            }
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 <            int port = 4510;
61 <            Socket socket = new Socket(host, port);
54 <            BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream()));
55 <            PrintWriter outBound = new PrintWriter(socket.getOutputStream());
60 >        // start the configuration system
61 >        Configuration.initialise(configFile);
62  
63 <            Queue dataQueue = new Queue();
64 <            DataReader data = new DataReader(inBound, dataQueue);
63 >        // the data display panel
64 >        DataPanel data = new DataPanel();
65          
66 <            SwingClient client = new SwingClient(dataQueue);
67 <            Thread clientThread = new Thread(client);
68 <            
69 <            clientThread.start();
70 <            data.start();
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 <        } catch (Exception e) {
67 <            System.err.println("ERROR START: " + e);
68 <            System.exit(1);
69 <        }  
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(Queue dataQueue) {
78 <        
79 <        _dataQueue = dataQueue;
80 <        _myQueue = _dataQueue.getQueue();
82 >    private Conient(JPanel data, JPanel control) {
83          // set up the Frame
84 <        setTitle("I-Scream Client");
85 <        //setSize(width, height);
84 <        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
85 <        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        _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
87   utton = new JButton("Connect");
88 <        
89 <        // set up the text area
90 <        _status.setEditable(false);
91 <        JScrollPane statusPane = new JScrollPane(_status);
102 <        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);
88 >        // set what happens when the X in the corner is clicked        
89 >        addWindowListener(new WindowAdapter() {
90 >            public void windowClosing(WindowEvent e) {System.exit(0);}
91 >        });
92  
93 <        //_tabbedPane.setSelectedIndex(0);
93 >        // add the control pane to the top border
94 >        getContentPane().add(control, "North");
95          
96 <        // build the frame
97 <        box.add(header);
98 <        box.add(main);
116 <        
117 <        getContentPane().add(box);
96 >        // create a scrollable pane for the data in the centre
97 >        JScrollPane scrollPane = new JScrollPane(data);
98 >        getContentPane().add(scrollPane, "Center");
99  
100 +        // setup the status panel        
101 +        JPanel bottom = new JPanel();
102 +        bottom.setLayout(new BorderLayout());
103 +        _messages.setEditable(false);
104 +        _messages.setRows(3);
105 +        JScrollPane messagesPane = new JScrollPane(_messages);
106 +        messagesPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
107 +        bottom.add(messagesPane, "Center");
108 +        JPanel statusPanel = new JPanel();
109 +        JPanel linkPanel = new JPanel();
110 +        linkPanel.setLayout(new GridLayout(2,1));
111 +        linkPanel.add(_controlStatus);
112 +        linkPanel.add(_dataStatus);
113 +        statusPanel.setLayout(new GridLayout(1,3));
114 +        statusPanel.add(linkPanel);
115 +        statusPanel.add(_queueStatus);
116 +        bottom.add(statusPanel, "South");
117 +
118 +        // add the status panel to the bottom border
119 +        getContentPane().add(bottom, "South");
120 +        
121          // show the window
122          show();
121        _status.insert("Running...\n",0);
123      }
124  
125   //---PUBLIC METHODS---
126  
126    public void run() {
127        HashMap hostList = new HashMap();
128        try {
129            while(true) {
130                
131                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);
163        }
164    }
165
127   //---PRIVATE METHODS---
128 +
129 + //---ACCESSOR/MUTATOR METHODS---
130 +
131 +    /**
132 +     * Sets the control link status.
133 +     *
134 +     * @param status the message
135 +     */
136 +    public static void setControlStatus(String status) {
137 +        _controlStatus.setText("Control Link: " + status);
138 +        _controlStatus.repaint();
139 +    }
140      
141 <    protected JPanel makeTextPanel(String text, java.awt.Component item) {
142 <        JPanel panel = new JPanel(false);
143 <        JLabel label = new JLabel(text);
144 <        label.setHorizontalAlignment(JLabel.RIGHT);
145 <        //item.setHorizontalAlignment(JLabel.LEFT);
146 <        panel.setLayout(new GridLayout(1, 2));
147 <        panel.add(label);
148 <        panel.add(item);
176 <        return panel;
141 >    /**
142 >     * Sets the data link status.
143 >     *
144 >     * @param status the message
145 >     */
146 >    public static void setDataStatus(String status) {
147 >        _dataStatus.setText("Data Link: " + status);
148 >        _dataStatus.repaint();
149      }
150  
151 +    /**
152 +     * Updates the queue status.
153 +     *
154 +     * @param currentQueue
155 +     * @param numElements
156 +     */
157 +    public static void setQueueStatus(int currentQueue, int numElements) {
158 +        _queueStatus.setText("Data Queue : " + currentQueue + " Packets Recieved : " + numElements);
159 +        _queueStatus.repaint();
160 +    }
161  
162 < //---ACCESSOR/MUTATOR METHODS---
162 >    /**
163 >     * Adds a system message to the messages list
164 >     *
165 >     * @param message the new message
166 >     */
167 >    public static void addMessage(String message) {
168 >        _messages.insert(message + "\n", 0);
169 >    }
170  
171   //---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;
172      
193    
173   //---STATIC ATTRIBUTES---
174      
175 +    /**
176 +     * Displays information about the data link
177 +     */
178 +    static JLabel _controlStatus = new JLabel("Control Link: Disconnected", JLabel.LEFT);
179 +    {
180 +        _controlStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
181 +    }
182 +    
183 +    /**
184 +     * Displays information about the data link
185 +     */
186 +    static JLabel _dataStatus = new JLabel("Data Link: Disconnected", JLabel.LEFT);
187 +    {
188 +        _dataStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
189 +    }
190 +    
191 +    /**
192 +     * Displays information about the inbound data queue.
193 +     */
194 +    static JLabel _queueStatus = new JLabel(" ", JLabel.LEFT);
195 +    {
196 +        _queueStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
197 +    }
198 +    
199 +    /**
200 +     * The place where system messages are written.
201 +     */
202 +    static JTextArea _messages = new JTextArea();
203 +    {
204 +        _messages.setLineWrap(true);
205 +    }
206   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines