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.12 by ajm, Mon Jan 22 05:11:40 2001 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines