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.6 by ajm, Mon Jan 15 03:15:06 2001 UTC vs.
Revision 1.9 by ajm, Sun Jan 21 03:30:00 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 20 | Line 22 | import java.util.HashMap;
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 29 | Line 31 | public class SwingClient extends JFrame implements Run
31       */
32      public final String REVISION = "$Revision$";
33      
34 <    private final int width = 400;
35 <    private final int height = 700;
34 >    private final int width = 600;
35 >    private final int height = 600;
36      
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)) {
48 <                    response = JOptionPane.showInputDialog(null, "Please enter the name of a server running the I-Scream client interface:", "I-Scream Server", JOptionPane.INFORMATION_MESSAGE);
49 <                }
50 <                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);
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 >        // the data display panel
50 >        DataPanel data = new DataPanel();
51          
52 <            SwingClient client = new SwingClient(data);
53 <            Thread clientThread = new Thread(client);
54 <            clientThread.start();
55 <        } catch (Exception e) {
56 <            System.err.println("ERROR START: " + e);
57 <            System.exit(1);
58 <        }  
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 >        SwingClient.setStatus("Disconnected");
59      }
60 +
61      
62   //---CONSTRUCTORS---
63  
64      /**
65 <     * Creates a new Swing Client.
65 >     * Creates a new Swing Client Frame
66       */
67 <    public SwingClient(DataReader data) {
71 <        _data = data;
67 >    private SwingClient(JPanel data, JPanel control) {
68          // set up the Frame
69 <        setTitle("I-Scream Client");
69 >        super("I-Scream Client");
70 >        
71          setSize(width, height);
72 <        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
73 <        Box box = Box.createVerticalBox();
72 >        addWindowListener(new WindowAdapter() {
73 >            public void windowClosing(WindowEvent e) {System.exit(0);}
74 >        });
75  
78        // create the i-scream logo at the top
79        JLabel iscream = new JLabel(new ImageIcon("i-scream.gif"));
80        JLabel comment = new JLabel("   I-Scream Client");
81        comment.setForeground( new Color(0, 0, 102));
82        Box header = Box.createHorizontalBox();
83        header.add(comment);
84        header.add(Box.createHorizontalGlue());
85        header.add(iscream);
76          
87        //_tabbedPane.setSelectedIndex(0);
88        
77          // build the frame
78 <        box.add(header);
79 <        box.add(_tabbedPane);
80 <        box.add(_status);
81 <        getContentPane().add(box);
78 >        getContentPane().add(control, "North");
79 >        getContentPane().add(data, "Center");
80 >        
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 +        bottom.add(_status, "South");
90 +        getContentPane().add(bottom, "South");
91 +        
92          // show the window
93          show();
97        _status.setText("Running...");
94      }
95  
96   //---PUBLIC METHODS---
97  
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 here ?
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                        host = new HostDisplayPanel();      
131                        _tabbedPane.addTab(hostName, _serverIcon, host, "Monitor " + hostName);
132                        hostList.put(hostName, host);
133                        _status.setText("New Host added: " + hostName);
134                    }
135                    ((HostDisplayPanel) hostList.get(hostName)).updateHost(packet);
136                }
137            }
138        } catch (Exception e) {
139            System.err.println("ERROR RUN: " + e);
140        }
141    }
142
98   //---PRIVATE METHODS---
144    
145    protected JPanel makeTextPanel(String text, Component item) {
146        JPanel panel = new JPanel(false);
147        JLabel label = new JLabel(text);
148        label.setHorizontalAlignment(JLabel.RIGHT);
149        //item.setHorizontalAlignment(JLabel.LEFT);
150        panel.setLayout(new GridLayout(1, 2));
151        panel.add(label);
152        panel.add(item);
153        return panel;
154    }
99  
156
100   //---ACCESSOR/MUTATOR METHODS---
101  
102 +    public static void setStatus(String status) {
103 +        _status.setText(status);
104 +        _status.repaint();
105 +    }
106 +
107 +    public static void addMessage(String message) {
108 +        _messages.insert(message + "\n", 0);
109 +    }
110   //---ATTRIBUTES---
111  
112 <    HostDisplayPanel host;
113 <    JTabbedPane _tabbedPane = new JTabbedPane();
114 <    DataReader _data;
115 <    JLabel _status = new JLabel();
112 >    static JLabel _status = new JLabel("Initialising", JLabel.LEFT);
113 >    {
114 >        _status.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
115 >    }      
116 >    
117      ImageIcon _serverIcon = new ImageIcon("server.gif");
118 +    JLabel _serverCountLabel;
119 +    int _serverCount = 0;
120 +    static JTextArea _messages = new JTextArea();
121      
122   //---STATIC ATTRIBUTES---
123      
124 < }
124 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines