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.8 by ajm, Sat Jan 20 16:06:53 2001 UTC

# Line 4 | Line 4
4   import javax.swing.*;
5   import javax.swing.border.*;
6   import java.awt.Color;
7 + import uk.ac.ukc.iscream.util.*;
8  
9   import java.awt.*;
10   import java.awt.event.*;
# Line 13 | Line 14 | import java.util.Date;
14   import java.text.DateFormat;
15   import java.util.Locale;
16   import java.util.HashMap;
17 + import javax.swing.border.*;
18  
19   /**
20   * NASTY AND BASIC, PLEASE DON'T COMPLAIN
# Line 51 | Line 53 | public class SwingClient extends JFrame implements Run
53              Socket socket = new Socket(host, port);
54              BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream()));
55              PrintWriter outBound = new PrintWriter(socket.getOutputStream());
56 <            DataReader data = new DataReader(inBound);
56 >
57 >            Queue dataQueue = new Queue();
58 >            DataReader data = new DataReader(inBound, dataQueue);
59          
60 <            SwingClient client = new SwingClient(data);
60 >            SwingClient client = new SwingClient(dataQueue);
61              Thread clientThread = new Thread(client);
62 +            
63              clientThread.start();
64 +            data.start();
65 +
66          } catch (Exception e) {
67              System.err.println("ERROR START: " + e);
68              System.exit(1);
# Line 67 | Line 74 | public class SwingClient extends JFrame implements Run
74      /**
75       * Creates a new Swing Client.
76       */
77 <    public SwingClient(DataReader data) {
78 <        _data = data;
77 >    public SwingClient(Queue dataQueue) {
78 >        
79 >        _dataQueue = dataQueue;
80 >        _myQueue = _dataQueue.getQueue();
81          // set up the Frame
82          setTitle("I-Scream Client");
83 <        setSize(width, height);
83 >        //setSize(width, height);
84          setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
85          Box box = Box.createVerticalBox();
86  
87          // create the i-scream logo at the top
88          JLabel iscream = new JLabel(new ImageIcon("i-scream.gif"));
89 <        JLabel comment = new JLabel("   I-Scream Client");
90 <        comment.setForeground( new Color(0, 0, 102));
89 >        _serverCountLabel = new JLabel("   Monitoring 0 hosts...");
90 >        _serverCountLabel.setForeground( new Color(0, 0, 102));
91          Box header = Box.createHorizontalBox();
92 <        header.add(comment);
92 >        header.add(_serverCountLabel);
93          header.add(Box.createHorizontalGlue());
94          header.add(iscream);
95 +        Box main = Box.createHorizontalBox();
96 +        JButton
97   utton = new JButton("Connect");
98          
99 +        // set up the text area
100 +        _status.setEditable(false);
101 +        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);
110 +
111          //_tabbedPane.setSelectedIndex(0);
112          
113          // build the frame
114          box.add(header);
115 <        box.add(_tabbedPane);
116 <        box.add(_status);
115 >        box.add(main);
116 >        
117          getContentPane().add(box);
118  
119          // show the window
120          show();
121 <        _status.setText("Running...");
121 >        _status.insert("Running...\n",0);
122      }
123  
124   //---PUBLIC METHODS---
# Line 102 | Line 125 | public class SwingClient extends JFrame implements Run
125      public void run() {
126          HashMap hostList = new HashMap();
127          try {
128 <        _data.start();
129 <        while(true) {
130 <            synchronized (_data) {
131 <                _data.wait();
128 >            while(true) {
129 >                
130 >                String xml = (String) _dataQueue.get(_myQueue);
131 >                if (xml == null) {
132 >                    // shouldn't really happen...but not sure
133 >                    _status.insert("No XML to update...",0);
134 >                } else {
135 >                    
136 >                    // Get a string without any null characters in it.
137 >                    //  -- maybe String.trim() would be better ?
138 >                    if (xml.indexOf(0) != -1) {
139 >                        xml = xml.substring(0, xml.indexOf(0));
140 >                    }
141 >                    else {
142 >                        xml = xml.substring(0, xml.length());
143 >                    }
144 >                    
145 >                    // Use XMLPacketMaker to make an XMLPacket object.
146 >                    XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
147 >                    XMLPacket packet = xmlPacketMaker.createXMLPacket();
148 >                    String hostName = packet.getParam("packet.attributes.machine_name");
149 >                    if(!hostList.containsKey(hostName)) {
150 >                        _serverCount++;
151 >                        _serverCountLabel.setText("   Monitoring " + _serverCount + " hosts...");
152 >                        host = new HostDisplayPanel();      
153 >                        _tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName);
154 >                        hostList.put(hostName, host);
155 >                        _status.insert("New Host added: " + hostName + "\n", 0);
156 >                    }
157 >                    ((HostDisplayPanel) hostList.get(hostName)).updateHost(packet);
158 >                }
159              }
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        }
160          } catch (Exception e) {
161              System.err.println("ERROR RUN: " + e);
162          }
# Line 141 | Line 164 | public class SwingClient extends JFrame implements Run
164  
165   //---PRIVATE METHODS---
166      
167 <    protected JPanel makeTextPanel(String text, Component item) {
167 >    protected JPanel makeTextPanel(String text, java.awt.Component item) {
168          JPanel panel = new JPanel(false);
169          JLabel label = new JLabel(text);
170          label.setHorizontalAlignment(JLabel.RIGHT);
# Line 159 | Line 182 | public class SwingClient extends JFrame implements Run
182  
183      HostDisplayPanel host;
184      JTabbedPane _tabbedPane = new JTabbedPane();
185 <    DataReader _data;
186 <    JLabel _status = new JLabel();
185 >    Queue _dataQueue;
186 >    int _myQueue;
187 >    JTextArea _status = new JTextArea();
188      ImageIcon _serverIcon = new ImageIcon("server.gif");
189 +    JLabel _serverCountLabel;
190 +    int _serverCount = 0;
191 +    
192      
193   //---STATIC ATTRIBUTES---
194      
195 < }
195 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines