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.4 by ajm, Mon Jan 15 00:12:31 2001 UTC vs.
Revision 1.13 by ajm, Mon Jan 22 12:48:38 2001 UTC

# Line 3 | Line 3
3   //---IMPORTS---
4   import javax.swing.*;
5   import javax.swing.border.*;
6 import java.awt.Color;
7
6   import java.awt.*;
7   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;
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 28 | 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 = 300;
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 = args[0];
35 <            int port = 4510;
36 <            Socket socket = new Socket(host, port);
37 <            BufferedReader inBound = new BufferedReader(new InputStreamReader(socket.getInputStream()));
38 <            PrintWriter outBound = new PrintWriter(socket.getOutputStream());
39 <            DataReader data = new DataReader(inBound);
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 >        // the data display panel
40 >        DataPanel data = new DataPanel();
41          
42 <            SwingClient cli = new SwingClient(data);
43 <            Thread cliThread = new Thread(cli);
44 <            cliThread.start();
45 <        } catch (Exception e) {
46 <            System.err.println("ERROR START: " + e);
47 <        }  
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(DataReader data) {
60 <        _data = data;
56 >    private SwingClient(JPanel data, JPanel control) {
57          // set up the Frame
58 <        setTitle("I-Scream Client");
58 >        super("I-Scream Client");
59 >        
60          setSize(width, height);
61 <        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
62 <        Box box = Box.createVerticalBox();
61 >        addWindowListener(new WindowAdapter() {
62 >            public void windowClosing(WindowEvent e) {System.exit(0);}
63 >        });
64  
67        // create the i-scream logo at the top
68        JLabel iscream = new JLabel(new ImageIcon("i-scream.gif"));
69        JLabel comment = new JLabel("   I-Scream Client");
70        comment.setForeground( new Color(0, 0, 102));
71        Box header = Box.createHorizontalBox();
72        header.add(comment);
73        header.add(Box.createHorizontalGlue());
74        header.add(iscream);
65          
66 +        // build the frame
67 +        getContentPane().add(control, "North");
68 +        getContentPane().add(data, "Center");
69          
70 +        JPanel bottom = new JPanel();
71 +        bottom.setLayout(new BorderLayout());
72 +        _messages.setEditable(false);
73 +        _messages.setRows(3);
74 +        JScrollPane messagesPane = new JScrollPane(_messages);
75 +        messagesPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
76 +
77 +        bottom.add(messagesPane, "Center");
78 +        JPanel statusPanel = new JPanel();
79 +        JPanel linkPanel = new JPanel();
80 +        linkPanel.setLayout(new GridLayout(2,1));
81 +        linkPanel.add(_controlStatus);
82 +        linkPanel.add(_dataStatus);
83 +        statusPanel.setLayout(new GridLayout(1,3));
84 +        statusPanel.add(linkPanel);
85 +        statusPanel.add(_queueStatus);
86          
87 <        //_tabbedPane.setSelectedIndex(0);
87 >        bottom.add(statusPanel, "South");
88 >        getContentPane().add(bottom, "South");
89          
80        // build the frame
81        box.add(header);
82        box.add(_tabbedPane);
83        box.add(_status);
84        getContentPane().add(box);
85
90          // show the window
91          show();
88        _status.setText("Running...");
92      }
93  
94   //---PUBLIC METHODS---
95  
93    public void run() {
94        HashMap hostList = new HashMap();
95        try {
96        _data.start();
97        while(true) {
98            synchronized (_data) {
99                _data.wait();
100            }
101            String xml = _data.getXML();
102            if (xml == null) {
103                _status.setText("No XML to update...");
104            } else {
105            
106            // Get a string without any null characters in it.
107            //  -- maybe String.trim() would be better here ?
108            if (xml.indexOf(0) != -1) {
109                xml = xml.substring(0, xml.indexOf(0));
110            }
111            else {
112                xml = xml.substring(0, xml.length());
113            }
114            
115            // Use XMLPacketMaker to make an XMLPacket object.
116            XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
117            XMLPacket packet = xmlPacketMaker.createXMLPacket();
118            String hostName = packet.getParam("packet.attributes.machine_name");
119            if(!hostList.containsKey(hostName)) {
120                host = new HostDisplayPanel();      
121                _tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName);
122                hostList.put(hostName, host);
123                _status.setText("New Host added: " + hostName);
124            }
125            ((HostDisplayPanel) hostList.get(hostName)).updateHost(packet);
126            }
127        }
128        } catch (Exception e) {
129            System.err.println("ERROR RUN: " + e);
130        }
131    }
132
96   //---PRIVATE METHODS---
97 +
98 + //---ACCESSOR/MUTATOR METHODS---
99 +
100 +    public static void setControlStatus(String status) {
101 +        _controlStatus.setText("Control Link: " + status);
102 +        _controlStatus.repaint();
103 +    }
104      
105 <    protected JPanel makeTextPanel(String text, Component item) {
106 <        JPanel panel = new JPanel(false);
107 <        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);
143 <        return panel;
105 >    public static void setDataStatus(String status) {
106 >        _dataStatus.setText("Data Link: " + status);
107 >        _dataStatus.repaint();
108      }
109  
110 +    public static void setQueueStatus(int currentQueue, int numElements) {
111 +        _queueStatus.setText("Data Queue : " + currentQueue + " Packets Recieved : " + numElements);
112 +        _queueStatus.repaint();
113 +    }
114  
115 < //---ACCESSOR/MUTATOR METHODS---
115 >    public static void addMessage(String message) {
116 >        _messages.insert(message + "\n", 0);
117 >    }
118  
119   //---ATTRIBUTES---
150    HostDisplayPanel host;
151    JTabbedPane _tabbedPane = new JTabbedPane();
152
153    JLabel _machine_name = new JLabel();
154    JLabel _ip = new JLabel();
155    JLabel _date = new JLabel();
156    JLabel _seq_no = new JLabel();
120      
121 <    JLabel _sTime = new JLabel();
121 >    ImageIcon _serverIcon = new ImageIcon("server.gif");
122 >    JLabel _serverCountLabel;
123 >    int _serverCount = 0;
124      
125 <    JLabel _load_load1 = new JLabel();
161 <    JLabel _load_load5 = new JLabel();
162 <    JLabel _load_load15 = new JLabel();
125 > //---STATIC ATTRIBUTES---
126      
127 <    JLabel _processes_total = new JLabel();
165 <    JLabel _processes_sleeping = new JLabel();
166 <    JLabel _processes_zombie = new JLabel();
167 <    JLabel _processes_stopped = new JLabel();
168 <    
169 <    int min = 0;
170 <    int max = 100;
171 <    JProgressBar _cpu_idle = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
127 >    static JLabel _controlStatus = new JLabel("Control Link: Disconnected", JLabel.LEFT);
128      {
129 <        _cpu_idle.setStringPainted(true);
129 >        _controlStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
130      }
131 <    JProgressBar _cpu_user = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
131 >    
132 >    static JLabel _dataStatus = new JLabel("Data Link: Disconnected", JLabel.LEFT);
133      {
134 <        _cpu_user.setStringPainted(true);
134 >        _dataStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
135      }
136 <    JProgressBar _cpu_kernel = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
136 >    
137 >    static JLabel _queueStatus = new JLabel(" ", JLabel.LEFT);
138      {
139 <        _cpu_kernel.setStringPainted(true);
139 >        _queueStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
140      }
141 <    JProgressBar _cpu_iowait = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
142 <    {
185 <        _cpu_iowait.setStringPainted(true);
186 <    }
187 <    JProgressBar _cpu_swap = new JProgressBar(JProgressBar.HORIZONTAL, min, max);
188 <    {
189 <        _cpu_swap.setStringPainted(true);
190 <    }
191 <    
192 <    JLabel _memory_real = new JLabel();
193 <    JLabel _memory_free = new JLabel();
194 <    JLabel _memory_swapinuse = new JLabel();
195 <    JLabel _memory_swapfree = new JLabel();
196 <    DataReader _data;
197 <    JLabel _status = new JLabel();
198 <    ImageIcon _serverIcon = new ImageIcon("server.gif");
199 <    
200 < //---STATIC ATTRIBUTES---
201 <    
202 < }
141 >    static JTextArea _messages = new JTextArea();
142 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines