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.7 by ajm, Mon Jan 15 03:26:26 2001 UTC vs.
Revision 1.21 by ajm, Mon Feb 5 01:26:04 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   //---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);
44 <                }
45 <                host = (String) response;
46 <            } else {
47 <                host = args[0];
48 <            }
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);
62 <            BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream()));
63 <            PrintWriter outBound = new PrintWriter(socket.getOutputStream());
64 <            DataReader data = new DataReader(inBound);
60 >        // start the configuration system
61 >        Configuration.initialise(configFile);
62 >
63 >        // the data display panel
64 >        DataPanel data = new DataPanel();
65          
66 <            SwingClient client = new SwingClient(data);
67 <            Thread clientThread = new Thread(client);
68 <            clientThread.start();
69 <        } catch (Exception e) {
70 <            System.err.println("ERROR START: " + e);
71 <            System.exit(1);
72 <        }  
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 >        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(DataReader data) {
71 <        _data = data;
82 >    private Conient(JPanel data, JPanel control) {
83          // set up the Frame
84 <        setTitle("I-Scream Client");
85 <        setSize(width, height);
75 <        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
76 <        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());
85 <        header.add(iscream);
87 >        // set what happens when the X in the corner is clicked        
88 >        addWindowListener(new WindowAdapter() {
89 >            public void windowClosing(WindowEvent e) {System.exit(0);}
90 >        });
91 >
92 >        // add the control pane to the top border
93 >        getContentPane().add(control, "North");
94          
95 <        //_tabbedPane.setSelectedIndex(0);
96 <        
97 <        // build the frame
90 <        box.add(header);
91 <        box.add(_tabbedPane);
92 <        box.add(_status);
93 <        getContentPane().add(box);
95 >        // create a scrollable pane for the data in the centre
96 >        JScrollPane scrollPane = new JScrollPane(data);
97 >        getContentPane().add(scrollPane, "Center");
98  
99 +        // setup the status panel        
100 +        JPanel bottom = new JPanel();
101 +        bottom.setLayout(new BorderLayout());
102 +        _messages.setEditable(false);
103 +        _messages.setRows(3);
104 +        JScrollPane messagesPane = new JScrollPane(_messages);
105 +        messagesPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
106 +        bottom.add(messagesPane, "Center");
107 +        JPanel statusPanel = new JPanel();
108 +        JPanel linkPanel = new JPanel();
109 +        linkPanel.setLayout(new GridLayout(1,2));
110 +        linkPanel.add(_controlStatus);
111 +        linkPanel.add(_dataStatus);
112 +        statusPanel.setLayout(new GridLayout(2,1));
113 +        statusPanel.add(linkPanel);
114 +        statusPanel.add(_queueStatus);
115 +        bottom.add(statusPanel, "South");
116 +
117 +        // add the status panel to the bottom border
118 +        getContentPane().add(bottom, "South");
119 +        
120 +        // a nice icon for the window
121 +        setIconImage((new ImageIcon("./uk/ac/ukc/iscream/conient/server.gif")).getImage());
122          // show the window
123          show();
97        _status.setText("Running...");
124      }
125  
126   //---PUBLIC METHODS---
127  
102    public void run() {
103        HashMap hostList = new HashMap();
104        try {
105            _data.start();
106            while(true) {
107                synchronized (_data) {
108                    _data.wait();
109                }
110                String xml = _data.getXML();
111                if (xml == null) {
112                    // shouldn't really happen...but not sure
113                    _status.setText("No XML to update...");
114                } else {
115                    _status.setText("Got inbound data...handling");
116                    // Get a string without any null characters in it.
117                    //  -- maybe String.trim() would be better ?
118                    if (xml.indexOf(0) != -1) {
119                        xml = xml.substring(0, xml.indexOf(0));
120                    }
121                    else {
122                        xml = xml.substring(0, xml.length());
123                    }
124                    
125                    // Use XMLPacketMaker to make an XMLPacket object.
126                    XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
127                    XMLPacket packet = xmlPacketMaker.createXMLPacket();
128                    String hostName = packet.getParam("packet.attributes.machine_name");
129                    if(!hostList.containsKey(hostName)) {
130                        _serverCount++;
131                        _serverCountLabel.setText("   Monitoring " + _serverCount + " hosts...");
132                        host = new HostDisplayPanel();      
133                        _tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName);
134                        hostList.put(hostName, host);
135                        _status.setText("New Host added: " + hostName);
136                    }
137                    ((HostDisplayPanel) hostList.get(hostName)).updateHost(packet);
138                }
139            }
140        } catch (Exception e) {
141            System.err.println("ERROR RUN: " + e);
142        }
143    }
144
128   //---PRIVATE METHODS---
129 +
130 + //---ACCESSOR/MUTATOR METHODS---
131 +
132 +    /**
133 +     * Sets the control link status.
134 +     *
135 +     * @param status the message
136 +     */
137 +    public static void setControlStatus(String status) {
138 +        _controlStatus.setText("Control Link: " + status);
139 +        _controlStatus.repaint();
140 +    }
141      
142 <    protected JPanel makeTextPanel(String text, Component item) {
143 <        JPanel panel = new JPanel(false);
144 <        JLabel label = new JLabel(text);
145 <        label.setHorizontalAlignment(JLabel.RIGHT);
146 <        //item.setHorizontalAlignment(JLabel.LEFT);
147 <        panel.setLayout(new GridLayout(1, 2));
148 <        panel.add(label);
149 <        panel.add(item);
155 <        return panel;
142 >    /**
143 >     * Sets the data link status.
144 >     *
145 >     * @param status the message
146 >     */
147 >    public static void setDataStatus(String status) {
148 >        _dataStatus.setText("Data Link: " + status);
149 >        _dataStatus.repaint();
150      }
151  
152 +    /**
153 +     * Updates the queue status.
154 +     *
155 +     * @param currentQueue
156 +     * @param numElements
157 +     */
158 +    public static void setQueueStatus(int currentQueue, int numElements) {
159 +        _queueStatus.setText("Data Queue : " + currentQueue + " Packets Recieved : " + numElements);
160 +        _queueStatus.repaint();
161 +    }
162  
163 < //---ACCESSOR/MUTATOR METHODS---
163 >    /**
164 >     * Adds a system message to the messages list
165 >     *
166 >     * @param message the new message
167 >     */
168 >    public static void addMessage(String message) {
169 >        _messages.insert(message + "\n", 0);
170 >    }
171  
172   //---ATTRIBUTES---
162
163    HostDisplayPanel host;
164    JTabbedPane _tabbedPane = new JTabbedPane();
165    DataReader _data;
166    JLabel _status = new JLabel();
167    ImageIcon _serverIcon = new ImageIcon("server.gif");
168    JLabel _serverCountLabel;
169    int _serverCount = 0;
173      
174   //---STATIC ATTRIBUTES---
175      
176 < }
176 >    /**
177 >     * Displays information about the data link
178 >     */
179 >    static JLabel _controlStatus = new JLabel("Control Link: Disconnected", JLabel.LEFT);
180 >    {
181 >        _controlStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
182 >    }
183 >    
184 >    /**
185 >     * Displays information about the data link
186 >     */
187 >    static JLabel _dataStatus = new JLabel("Data Link: Disconnected", JLabel.LEFT);
188 >    {
189 >        _dataStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
190 >    }
191 >    
192 >    /**
193 >     * Displays information about the inbound data queue.
194 >     */
195 >    static JLabel _queueStatus = new JLabel(" ", JLabel.LEFT);
196 >    {
197 >        _queueStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
198 >    }
199 >    
200 >    /**
201 >     * The place where system messages are written.
202 >     */
203 >    static JTextArea _messages = new JTextArea();
204 >    {
205 >        _messages.setLineWrap(true);
206 >    }
207 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines