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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines