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.14 by tdb, Mon Jan 22 19:35:36 2001 UTC

# Line 3 | Line 3
3   //---IMPORTS---
4   import javax.swing.*;
5   import javax.swing.border.*;
6 import java.awt.Color;
7 import uk.ac.ukc.iscream.util.*;
8
6   import java.awt.*;
7   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.*;
8  
9   /**
10 < * NASTY AND BASIC, PLEASE DON'T COMPLAIN
10 > * Root for the SwingClient...starts the whole show off...
11   *
12   * @author  $Author$
13   * @version $Id$
14   */
15 < public class SwingClient extends JFrame implements Runnable {
15 > public class SwingClient extends JFrame {
16  
17   //---FINAL ATTRIBUTES---
18  
# Line 30 | Line 20 | public class SwingClient extends JFrame implements Run
20       * The current CVS revision of this class
21       */
22      public final String REVISION = "$Revision$";
23 +        
24 +    private final int width = 600;
25 +    private final int height = 600;
26      
27 <    private final int width = 400;
28 <    private final int height = 700;
27 >    // the well known port
28 >    public static final int PORT = 4510;
29      
30   //---STATIC METHODS---
31  
32      public static void main(String[] args) {
33 <        try {
34 <            String host = null;
35 <            if (args.length != 1) {
36 <                Object response = null;
37 <                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());
33 >        // get the host from the command line if they gave it
34 >        String host = null;
35 >        if (args.length == 1) {
36 >            host = args[0];
37 >        }
38  
39 <            Queue dataQueue = new Queue();
40 <            DataReader data = new DataReader(inBound, dataQueue);
39 >        // the data display panel
40 >        DataPanel data = new DataPanel();
41          
42 <            SwingClient client = new SwingClient(dataQueue);
43 <            Thread clientThread = new Thread(client);
44 <            
45 <            clientThread.start();
46 <            data.start();
47 <
66 <        } catch (Exception e) {
67 <            System.err.println("ERROR START: " + e);
68 <            System.exit(1);
69 <        }  
42 >        // the control panel
43 >        ControlPanel control = new ControlPanel(data);
44 >        
45 >        // the main frame (passed the two panels)
46 >        SwingClient client = new SwingClient(data, control);
47 >        SwingClient.addMessage("Client started");
48      }
49 +
50      
51   //---CONSTRUCTORS---
52  
53      /**
54 <     * Creates a new Swing Client.
54 >     * Creates a new Swing Client Frame
55       */
56 <    public SwingClient(Queue dataQueue) {
78 <        
79 <        _dataQueue = dataQueue;
80 <        _myQueue = _dataQueue.getQueue();
56 >    private SwingClient(JPanel data, JPanel control) {
57          // set up the Frame
58 <        setTitle("I-Scream Client");
59 <        //setSize(width, height);
60 <        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
61 <        Box box = Box.createVerticalBox();
58 >        super("I-Scream Client");
59 >        
60 >        setSize(width, height);
61 >        addWindowListener(new WindowAdapter() {
62 >            public void windowClosing(WindowEvent e) {System.exit(0);}
63 >        });
64  
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
65   utton = new JButton("Connect");
66 +        getContentPane().add(control, "North");
67          
68 <        // set up the text area
69 <        _status.setEditable(false);
101 <        JScrollPane statusPane = new JScrollPane(_status);
102 <        statusPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
68 >        JScrollPane scrollPane = new JScrollPane(data);
69 >        getContentPane().add(scrollPane, "Center");
70          
71 <        Box controlPane = Box.createVerticalBox();
72 <        controlPane.add(button);
73 <        //controlPane.add(Box.createVerticalGlue());
74 <        controlPane.add(statusPane);
75 <        main.add(controlPane);
76 <        main.add(_tabbedPane);
71 >        
72 >        JPanel bottom = new JPanel();
73 >        bottom.setLayout(new BorderLayout());
74 >        _messages.setEditable(false);
75 >        _messages.setRows(3);
76 >        JScrollPane messagesPane = new JScrollPane(_messages);
77 >        messagesPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
78  
79 <        //_tabbedPane.setSelectedIndex(0);
79 >        bottom.add(messagesPane, "Center");
80 >        JPanel statusPanel = new JPanel();
81 >        JPanel linkPanel = new JPanel();
82 >        linkPanel.setLayout(new GridLayout(2,1));
83 >        linkPanel.add(_controlStatus);
84 >        linkPanel.add(_dataStatus);
85 >        statusPanel.setLayout(new GridLayout(1,3));
86 >        statusPanel.add(linkPanel);
87 >        statusPanel.add(_queueStatus);
88          
89 <        // build the frame
90 <        box.add(header);
115 <        box.add(main);
89 >        bottom.add(statusPanel, "South");
90 >        getContentPane().add(bottom, "South");
91          
117        getContentPane().add(box);
118
92          // show the window
93          show();
121        _status.insert("Running...\n",0);
94      }
95  
96   //---PUBLIC METHODS---
97  
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
98   //---PRIVATE METHODS---
99 +
100 + //---ACCESSOR/MUTATOR METHODS---
101 +
102 +    public static void setControlStatus(String status) {
103 +        _controlStatus.setText("Control Link: " + status);
104 +        _controlStatus.repaint();
105 +    }
106      
107 <    protected JPanel makeTextPanel(String text, java.awt.Component item) {
108 <        JPanel panel = new JPanel(false);
109 <        JLabel label = new JLabel(text);
171 <        label.setHorizontalAlignment(JLabel.RIGHT);
172 <        //item.setHorizontalAlignment(JLabel.LEFT);
173 <        panel.setLayout(new GridLayout(1, 2));
174 <        panel.add(label);
175 <        panel.add(item);
176 <        return panel;
107 >    public static void setDataStatus(String status) {
108 >        _dataStatus.setText("Data Link: " + status);
109 >        _dataStatus.repaint();
110      }
111  
112 +    public static void setQueueStatus(int currentQueue, int numElements) {
113 +        _queueStatus.setText("Data Queue : " + currentQueue + " Packets Recieved : " + numElements);
114 +        _queueStatus.repaint();
115 +    }
116  
117 < //---ACCESSOR/MUTATOR METHODS---
117 >    public static void addMessage(String message) {
118 >        _messages.insert(message + "\n", 0);
119 >    }
120  
121   //---ATTRIBUTES---
122 <
184 <    HostDisplayPanel host;
185 <    JTabbedPane _tabbedPane = new JTabbedPane();
186 <    Queue _dataQueue;
187 <    int _myQueue;
188 <    JTextArea _status = new JTextArea();
122 >    
123      ImageIcon _serverIcon = new ImageIcon("server.gif");
124      JLabel _serverCountLabel;
125      int _serverCount = 0;
126      
193    
127   //---STATIC ATTRIBUTES---
128      
129 +    static JLabel _controlStatus = new JLabel("Control Link: Disconnected", JLabel.LEFT);
130 +    {
131 +        _controlStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
132 +    }
133 +    
134 +    static JLabel _dataStatus = new JLabel("Data Link: Disconnected", JLabel.LEFT);
135 +    {
136 +        _dataStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
137 +    }
138 +    
139 +    static JLabel _queueStatus = new JLabel(" ", JLabel.LEFT);
140 +    {
141 +        _queueStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
142 +    }
143 +    static JTextArea _messages = new JTextArea();
144   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines