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.15 by ajm, Wed Jan 24 03:09:43 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 SwingClient 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 i-scream server port
40 +     */
41 +    public static final int PORT = 4510;
42 +    
43   //---STATIC METHODS---
44  
45 +    /**
46 +     * The first method that is called.
47 +     * Sets up the various panels
48 +     *
49 +     * @param args the command line arguments
50 +     */
51      public static void main(String[] args) {
52 <        try {
53 <            String host = null;
54 <            if (args.length != 1) {
55 <                Object response = null;
56 <                while(!(response instanceof String)) {
45 <                    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 <            }
51 <
52 <            int port = 4510;
53 <            Socket socket = new Socket(host, port);
54 <            BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream()));
55 <            PrintWriter outBound = new PrintWriter(socket.getOutputStream());
52 >        // get the host from the command line if they gave it
53 >        String host = null;
54 >        if (args.length == 1) {
55 >            host = args[0];
56 >        }
57  
58 <            Queue dataQueue = new Queue();
59 <            DataReader data = new DataReader(inBound, dataQueue);
58 >        // the data display panel
59 >        DataPanel data = new DataPanel();
60          
61 <            SwingClient client = new SwingClient(dataQueue);
62 <            Thread clientThread = new Thread(client);
63 <            
64 <            clientThread.start();
65 <            data.start();
66 <
67 <        } catch (Exception e) {
67 <            System.err.println("ERROR START: " + e);
68 <            System.exit(1);
69 <        }  
61 >        // the control panel
62 >        ControlPanel control = new ControlPanel(data);
63 >        
64 >        // the main frame (passed the two panels)
65 >        SwingClient client = new SwingClient(data, control);
66 >        SwingClient.addMessage("Conient {an I-scream Client} © 2001 University of Kent & Project I-Scream");
67 >        SwingClient.addMessage("Conient ready.");
68      }
69 +
70      
71   //---CONSTRUCTORS---
72  
73      /**
74 <     * Creates a new Swing Client.
74 >     * Creates a new Swing Client Frame
75       */
76 <    public SwingClient(Queue dataQueue) {
78 <        
79 <        _dataQueue = dataQueue;
80 <        _myQueue = _dataQueue.getQueue();
76 >    private SwingClient(JPanel data, JPanel control) {
77          // set up the Frame
78 <        setTitle("I-Scream Client");
79 <        //setSize(width, height);
84 <        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
85 <        Box box = Box.createVerticalBox();
78 >        super("Conient {an I-scream Client}");
79 >        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
80  
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
81   utton = new JButton("Connect");
82 <        
83 <        // set up the text area
84 <        _status.setEditable(false);
85 <        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);
82 >        // set what happens when the X in the corner is clicked        
83 >        addWindowListener(new WindowAdapter() {
84 >            public void windowClosing(WindowEvent e) {System.exit(0);}
85 >        });
86  
87 <        //_tabbedPane.setSelectedIndex(0);
87 >        // add the control pane to the top border
88 >        getContentPane().add(control, "North");
89          
90 <        // build the frame
91 <        box.add(header);
92 <        box.add(main);
116 <        
117 <        getContentPane().add(box);
90 >        // create a scrollable pane for the data in the centre
91 >        JScrollPane scrollPane = new JScrollPane(data);
92 >        getContentPane().add(scrollPane, "Center");
93  
94 +        // setup the status panel        
95 +        JPanel bottom = new JPanel();
96 +        bottom.setLayout(new BorderLayout());
97 +        _messages.setEditable(false);
98 +        _messages.setRows(3);
99 +        JScrollPane messagesPane = new JScrollPane(_messages);
100 +        messagesPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
101 +        bottom.add(messagesPane, "Center");
102 +        JPanel statusPanel = new JPanel();
103 +        JPanel linkPanel = new JPanel();
104 +        linkPanel.setLayout(new GridLayout(2,1));
105 +        linkPanel.add(_controlStatus);
106 +        linkPanel.add(_dataStatus);
107 +        statusPanel.setLayout(new GridLayout(1,3));
108 +        statusPanel.add(linkPanel);
109 +        statusPanel.add(_queueStatus);
110 +        bottom.add(statusPanel, "South");
111 +
112 +        // add the status panel to the bottom border
113 +        getContentPane().add(bottom, "South");
114 +        
115          // show the window
116          show();
121        _status.insert("Running...\n",0);
117      }
118  
119   //---PUBLIC METHODS---
120  
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
121   //---PRIVATE METHODS---
122 +
123 + //---ACCESSOR/MUTATOR METHODS---
124 +
125 +    /**
126 +     * Sets the control link status.
127 +     *
128 +     * @param status the message
129 +     */
130 +    public static void setControlStatus(String status) {
131 +        _controlStatus.setText("Control Link: " + status);
132 +        _controlStatus.repaint();
133 +    }
134      
135 <    protected JPanel makeTextPanel(String text, java.awt.Component item) {
136 <        JPanel panel = new JPanel(false);
137 <        JLabel label = new JLabel(text);
138 <        label.setHorizontalAlignment(JLabel.RIGHT);
139 <        //item.setHorizontalAlignment(JLabel.LEFT);
140 <        panel.setLayout(new GridLayout(1, 2));
141 <        panel.add(label);
142 <        panel.add(item);
176 <        return panel;
135 >    /**
136 >     * Sets the data link status.
137 >     *
138 >     * @param status the message
139 >     */
140 >    public static void setDataStatus(String status) {
141 >        _dataStatus.setText("Data Link: " + status);
142 >        _dataStatus.repaint();
143      }
144  
145 +    /**
146 +     * Updates the queue status.
147 +     *
148 +     * @param currentQueue
149 +     * @param numElements
150 +     */
151 +    public static void setQueueStatus(int currentQueue, int numElements) {
152 +        _queueStatus.setText("Data Queue : " + currentQueue + " Packets Recieved : " + numElements);
153 +        _queueStatus.repaint();
154 +    }
155  
156 < //---ACCESSOR/MUTATOR METHODS---
156 >    /**
157 >     * Adds a system message to the messages list
158 >     *
159 >     * @param message the new message
160 >     */
161 >    public static void addMessage(String message) {
162 >        _messages.insert(message + "\n", 0);
163 >    }
164  
165   //---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;
166      
193    
167   //---STATIC ATTRIBUTES---
168      
169 +    /**
170 +     * Displays information about the data link
171 +     */
172 +    static JLabel _controlStatus = new JLabel("Control Link: Disconnected", JLabel.LEFT);
173 +    {
174 +        _controlStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
175 +    }
176 +    
177 +    /**
178 +     * Displays information about the data link
179 +     */
180 +    static JLabel _dataStatus = new JLabel("Data Link: Disconnected", JLabel.LEFT);
181 +    {
182 +        _dataStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
183 +    }
184 +    
185 +    /**
186 +     * Displays information about the inbound data queue.
187 +     */
188 +    static JLabel _queueStatus = new JLabel(" ", JLabel.LEFT);
189 +    {
190 +        _queueStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
191 +    }
192 +    
193 +    /**
194 +     * The place where system messages are written.
195 +     */
196 +    static JTextArea _messages = new JTextArea();
197   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines