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.7 by ajm, Mon Jan 15 03:26:26 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
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 = 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)) {
38 <                    response = JOptionPane.showInputDialog(null, "Please enter the name of a server running the I-Scream client interface:", "I-Scream Server", JOptionPane.INFORMATION_MESSAGE);
39 <                }
40 <                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);
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 client = new SwingClient(data);
43 <            Thread clientThread = new Thread(client);
44 <            clientThread.start();
45 <        } catch (Exception e) {
46 <            System.err.println("ERROR START: " + e);
47 <            System.exit(1);
62 <        }  
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) {
71 <        _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  
65 <        // create the i-scream logo at the top
79 <        JLabel iscream = new JLabel(new ImageIcon("i-scream.gif"));
80 <        _serverCountLabel = new JLabel("   Monitoring 0 hosts...");
81 <        _serverCountLabel.setForeground( new Color(0, 0, 102));
82 <        Box header = Box.createHorizontalBox();
83 <        header.add(_serverCountLabel);
84 <        header.add(Box.createHorizontalGlue());
85 <        header.add(iscream);
65 >        getContentPane().add(control, "North");
66          
67 <        //_tabbedPane.setSelectedIndex(0);
67 >        JScrollPane scrollPane = new JScrollPane(data);
68 >        getContentPane().add(scrollPane, "Center");
69          
70 <        // build the frame
71 <        box.add(header);
72 <        box.add(_tabbedPane);
73 <        box.add(_status);
74 <        getContentPane().add(box);
70 >        
71 >        JPanel bottom = new JPanel();
72 >        bottom.setLayout(new BorderLayout());
73 >        _messages.setEditable(false);
74 >        _messages.setRows(3);
75 >        JScrollPane messagesPane = new JScrollPane(_messages);
76 >        messagesPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
77  
78 +        bottom.add(messagesPane, "Center");
79 +        JPanel statusPanel = new JPanel();
80 +        JPanel linkPanel = new JPanel();
81 +        linkPanel.setLayout(new GridLayout(2,1));
82 +        linkPanel.add(_controlStatus);
83 +        linkPanel.add(_dataStatus);
84 +        statusPanel.setLayout(new GridLayout(1,3));
85 +        statusPanel.add(linkPanel);
86 +        statusPanel.add(_queueStatus);
87 +        
88 +        bottom.add(statusPanel, "South");
89 +        getContentPane().add(bottom, "South");
90 +        
91          // show the window
92          show();
97        _status.setText("Running...");
93      }
94  
95   //---PUBLIC METHODS---
96  
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                    // shouldn't really happen...but not sure
113                    _status.setText("No XML to update...");
114                } else {
115                    _status.setText("Got inbound data...handling");
116                    // Get a string without any null characters in it.
117                    //  -- maybe String.trim() would be better ?
118                    if (xml.indexOf(0) != -1) {
119                        xml = xml.substring(0, xml.indexOf(0));
120                    }
121                    else {
122                        xml = xml.substring(0, xml.length());
123                    }
124                    
125                    // Use XMLPacketMaker to make an XMLPacket object.
126                    XMLPacketMaker xmlPacketMaker = new XMLPacketMaker(xml);
127                    XMLPacket packet = xmlPacketMaker.createXMLPacket();
128                    String hostName = packet.getParam("packet.attributes.machine_name");
129                    if(!hostList.containsKey(hostName)) {
130                        _serverCount++;
131                        _serverCountLabel.setText("   Monitoring " + _serverCount + " hosts...");
132                        host = new HostDisplayPanel();      
133                        _tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName);
134                        hostList.put(hostName, host);
135                        _status.setText("New Host added: " + hostName);
136                    }
137                    ((HostDisplayPanel) hostList.get(hostName)).updateHost(packet);
138                }
139            }
140        } catch (Exception e) {
141            System.err.println("ERROR RUN: " + e);
142        }
143    }
144
97   //---PRIVATE METHODS---
98 +
99 + //---ACCESSOR/MUTATOR METHODS---
100 +
101 +    public static void setControlStatus(String status) {
102 +        _controlStatus.setText("Control Link: " + status);
103 +        _controlStatus.repaint();
104 +    }
105      
106 <    protected JPanel makeTextPanel(String text, Component item) {
107 <        JPanel panel = new JPanel(false);
108 <        JLabel label = new JLabel(text);
150 <        label.setHorizontalAlignment(JLabel.RIGHT);
151 <        //item.setHorizontalAlignment(JLabel.LEFT);
152 <        panel.setLayout(new GridLayout(1, 2));
153 <        panel.add(label);
154 <        panel.add(item);
155 <        return panel;
106 >    public static void setDataStatus(String status) {
107 >        _dataStatus.setText("Data Link: " + status);
108 >        _dataStatus.repaint();
109      }
110  
111 +    public static void setQueueStatus(int currentQueue, int numElements) {
112 +        _queueStatus.setText("Data Queue : " + currentQueue + " Packets Recieved : " + numElements);
113 +        _queueStatus.repaint();
114 +    }
115  
116 < //---ACCESSOR/MUTATOR METHODS---
116 >    public static void addMessage(String message) {
117 >        _messages.insert(message + "\n", 0);
118 >    }
119  
120   //---ATTRIBUTES---
121 <
163 <    HostDisplayPanel host;
164 <    JTabbedPane _tabbedPane = new JTabbedPane();
165 <    DataReader _data;
166 <    JLabel _status = new JLabel();
121 >    
122      ImageIcon _serverIcon = new ImageIcon("server.gif");
123      JLabel _serverCountLabel;
124      int _serverCount = 0;
125      
126   //---STATIC ATTRIBUTES---
127      
128 < }
128 >    static JLabel _controlStatus = new JLabel("Control Link: Disconnected", JLabel.LEFT);
129 >    {
130 >        _controlStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
131 >    }
132 >    
133 >    static JLabel _dataStatus = new JLabel("Data Link: Disconnected", JLabel.LEFT);
134 >    {
135 >        _dataStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
136 >    }
137 >    
138 >    static JLabel _queueStatus = new JLabel(" ", JLabel.LEFT);
139 >    {
140 >        _queueStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
141 >    }
142 >    static JTextArea _messages = new JTextArea();
143 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines