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.12 by ajm, Mon Jan 22 05:11:40 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 28 | 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)) {
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);
62 <        }  
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(DataReader data) {
71 <        _data = data;
66 >    private SwingClient(JPanel data, JPanel control) {
67          // set up the Frame
68 <        setTitle("I-Scream Client");
68 >        super("I-Scream Client");
69 >        
70          setSize(width, height);
71 <        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
72 <        Box box = Box.createVerticalBox();
71 >        addWindowListener(new WindowAdapter() {
72 >            public void windowClosing(WindowEvent e) {System.exit(0);}
73 >        });
74  
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);
75          
87        //_tabbedPane.setSelectedIndex(0);
88        
76          // build the frame
77 <        box.add(header);
78 <        box.add(_tabbedPane);
79 <        box.add(_status);
80 <        getContentPane().add(box);
77 >        getContentPane().add(control, "North");
78 >        getContentPane().add(data, "Center");
79 >        
80 >        JPanel bottom = new JPanel();
81 >        bottom.setLayout(new BorderLayout());
82 >        _messages.setEditable(false);
83 >        _messages.setRows(3);
84 >        JScrollPane messagesPane = new JScrollPane(_messages);
85 >        messagesPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
86  
87 +        bottom.add(messagesPane, "Center");
88 +        JPanel statusPanel = new JPanel();
89 +        JPanel linkPanel = new JPanel();
90 +        linkPanel.setLayout(new GridLayout(2,1));
91 +        linkPanel.add(_controlStatus);
92 +        linkPanel.add(_dataStatus);
93 +        statusPanel.setLayout(new GridLayout(1,3));
94 +        statusPanel.add(linkPanel);
95 +        statusPanel.add(_queueStatus);
96 +        
97 +        bottom.add(statusPanel, "South");
98 +        getContentPane().add(bottom, "South");
99 +        
100          // show the window
101          show();
97        _status.setText("Running...");
102      }
103  
104   //---PUBLIC METHODS---
105  
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
106   //---PRIVATE METHODS---
107 +
108 + //---ACCESSOR/MUTATOR METHODS---
109 +
110 +    public static void setControlStatus(String status) {
111 +        _controlStatus.setText("Control Link: " + status);
112 +        _controlStatus.repaint();
113 +    }
114      
115 <    protected JPanel makeTextPanel(String text, Component item) {
116 <        JPanel panel = new JPanel(false);
117 <        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;
115 >    public static void setDataStatus(String status) {
116 >        _dataStatus.setText("Data Link: " + status);
117 >        _dataStatus.repaint();
118      }
119  
120 +    public static void setQueueStatus(int currentQueue, int numElements) {
121 +        _queueStatus.setText("Data Queue : " + currentQueue + " Packets Recieved : " + numElements);
122 +        _queueStatus.repaint();
123 +    }
124  
125 < //---ACCESSOR/MUTATOR METHODS---
126 <
125 >    public static void addMessage(String message) {
126 >        _messages.insert(message + "\n", 0);
127 >    }
128   //---ATTRIBUTES---
129  
130 <    HostDisplayPanel host;
131 <    JTabbedPane _tabbedPane = new JTabbedPane();
132 <    DataReader _data;
133 <    JLabel _status = new JLabel();
130 >    static JLabel _controlStatus = new JLabel("Control Link: Disconnected", JLabel.LEFT);
131 >    {
132 >        _controlStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
133 >    }
134 >    
135 >    static JLabel _dataStatus = new JLabel("Data Link: Disconnected", JLabel.LEFT);
136 >    {
137 >        _dataStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
138 >    }
139 >    
140 >    static JLabel _queueStatus = new JLabel("-", JLabel.LEFT);
141 >    {
142 >        _queueStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
143 >    }
144 >    
145      ImageIcon _serverIcon = new ImageIcon("server.gif");
146 +    JLabel _serverCountLabel;
147 +    int _serverCount = 0;
148 +    static JTextArea _messages = new JTextArea();
149      
150   //---STATIC ATTRIBUTES---
151      
152 < }
152 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines