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.13 by ajm, Mon Jan 22 12:48:38 2001 UTC vs.
Revision 1.33 by tdb, Sat May 18 18:15:56 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   //---PACKAGE DECLARATION---
21 + package uk.org.iscream.cms.conient;
22  
23   //---IMPORTS---
24   import javax.swing.*;
# Line 7 | Line 27 | import java.awt.*;
27   import java.awt.event.*;
28  
29   /**
30 < * Root for the SwingClient...starts the whole show off...
30 > * This is the main class of the Conient client.
31   *
32 + * This sets up the control panel, the data panel
33 + * and its own display.
34 + *
35   * @author  $Author$
36   * @version $Id$
37   */
38 < public class SwingClient extends JFrame {
38 > public class Conient extends JFrame {
39  
40   //---FINAL ATTRIBUTES---
41  
# Line 20 | Line 43 | public class SwingClient extends JFrame {
43       * The current CVS revision of this class
44       */
45      public final String REVISION = "$Revision$";
46 <        
47 <    private final int width = 600;
48 <    private final int height = 600;
46 >
47 >    /**
48 >     * The initial width of the window
49 >     */        
50 >    private final int DEFAULT_WIDTH = 700;
51      
52 <    // the well known port
53 <    public static final int PORT = 4510;
52 >    /**
53 >     * The initial height of the window
54 >     */
55 >    private final int DEFAULT_HEIGHT = 600;
56      
57 +    /**
58 +     * The default configuration fle
59 +     * This can be specified on the command line
60 +     */
61 +    public static final String DEFAULT_CONFIG_FILE = "./etc/default.conf";
62 +    
63 +    /**
64 +     * The time in seconds to display the splash
65 +     * screen for
66 +     */
67 +    public static final int DISPLAY_SPLASH_TIME_SECONDS = 3;
68 +    
69   //---STATIC METHODS---
70  
71 +    /**
72 +     * The first method that is called.
73 +     * Sets up the various panels
74 +     *
75 +     * @param args the command line arguments
76 +     */
77      public static void main(String[] args) {
78          // get the host from the command line if they gave it
79          String host = null;
80 +        String configFile = DEFAULT_CONFIG_FILE;
81          if (args.length == 1) {
82 <            host = args[0];
82 >            configFile = args[0];
83          }
84 +
85 +        // start the configuration system
86 +        Configuration.initialise(configFile);
87  
88          // the data display panel
89          DataPanel data = new DataPanel();
# Line 43 | Line 92 | public class SwingClient extends JFrame {
92          ControlPanel control = new ControlPanel(data);
93          
94          // the main frame (passed the two panels)
95 <        SwingClient client = new SwingClient(data, control);
96 <        SwingClient.addMessage("Client started");
95 >        Conient client = new Conient(data, control);
96 >        conientFrame = (Frame) client;
97 >        Conient.addMessage("Conient {an i-scream Client} (c) 2001 The i-scream Project (http://www.i-scream.org.uk)");
98 >
99 >        Conient.addMessage("Conient ready.");
100 >        
101      }
49
102      
103 +    /**
104 +     * A static accessor, allowing components of the system
105 +     * to get hold of the root frame of the system.
106 +     *
107 +     * see conientFrame attribute for details.
108 +     *
109 +     * @return the root Conient frame
110 +     */
111 +    public static Frame getFrame() {
112 +        return conientFrame;
113 +    }
114 +    
115   //---CONSTRUCTORS---
116  
117      /**
118       * Creates a new Swing Client Frame
119       */
120 <    private SwingClient(JPanel data, JPanel control) {
120 >    private Conient(JSplitPane data, ControlPanel control) {
121          // set up the Frame
122 <        super("I-Scream Client");
122 >        super("Conient {an i-scream Client}");
123 >        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
124 >        setJMenuBar(control.getMenuBar());
125          
126 <        setSize(width, height);
126 >        // set what happens when the X in the corner is clicked        
127          addWindowListener(new WindowAdapter() {
128              public void windowClosing(WindowEvent e) {System.exit(0);}
129          });
130  
131 <        
66 <        // build the frame
131 >        // add the control pane to the top border
132          getContentPane().add(control, "North");
133 <        getContentPane().add(data, "Center");
134 <        
133 >        // add the data pane to the centre        
134 >        getContentPane().add(data);
135 >
136 >        // setup the status panel        
137          JPanel bottom = new JPanel();
138          bottom.setLayout(new BorderLayout());
139          _messages.setEditable(false);
140          _messages.setRows(3);
141          JScrollPane messagesPane = new JScrollPane(_messages);
142          messagesPane.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Messages "));
76
143          bottom.add(messagesPane, "Center");
144          JPanel statusPanel = new JPanel();
145          JPanel linkPanel = new JPanel();
146 <        linkPanel.setLayout(new GridLayout(2,1));
146 >        linkPanel.setLayout(new GridLayout(1,2));
147          linkPanel.add(_controlStatus);
148          linkPanel.add(_dataStatus);
149 <        statusPanel.setLayout(new GridLayout(1,3));
149 >        statusPanel.setLayout(new GridLayout(2,1));
150          statusPanel.add(linkPanel);
151          statusPanel.add(_queueStatus);
86        
152          bottom.add(statusPanel, "South");
153 +
154 +        // add the status panel to the bottom border
155          getContentPane().add(bottom, "South");
156          
157 <        // show the window
157 >        // a nice icon for the window
158 >        setIconImage((new ImageIcon("./resources/server.gif")).getImage());
159 >
160 >        // and just because we can, a silly splash screen
161 >        // of the dudes that did this funky jibble
162 >        Splash splash = new Splash();
163 >        splash.show();
164 >        // wait
165 >        try {
166 >            Thread.sleep(DISPLAY_SPLASH_TIME_SECONDS * 1000);
167 >        } catch (InterruptedException e) {
168 >            // don't do anything, we don't care
169 >        }
170 >        //loose the window
171 >        splash.dispose();
172 >        splash = null;        
173 >        // show the main window
174          show();
175      }
176  
# Line 97 | Line 180 | public class SwingClient extends JFrame {
180  
181   //---ACCESSOR/MUTATOR METHODS---
182  
183 +    /**
184 +     * Sets the control link status.
185 +     *
186 +     * @param status the message
187 +     */
188      public static void setControlStatus(String status) {
189          _controlStatus.setText("Control Link: " + status);
190          _controlStatus.repaint();
191      }
192      
193 +    /**
194 +     * Sets the data link status.
195 +     *
196 +     * @param status the message
197 +     */
198      public static void setDataStatus(String status) {
199          _dataStatus.setText("Data Link: " + status);
200          _dataStatus.repaint();
201      }
202  
203 +    /**
204 +     * Updates the queue status.
205 +     *
206 +     * @param currentQueue
207 +     * @param numElements
208 +     */
209      public static void setQueueStatus(int currentQueue, int numElements) {
210          _queueStatus.setText("Data Queue : " + currentQueue + " Packets Recieved : " + numElements);
211          _queueStatus.repaint();
212      }
213  
214 +    /**
215 +     * Adds a system message to the messages list
216 +     *
217 +     * @param message the new message
218 +     */
219      public static void addMessage(String message) {
220          _messages.insert(message + "\n", 0);
221      }
222  
223   //---ATTRIBUTES---
224      
121    ImageIcon _serverIcon = new ImageIcon("server.gif");
122    JLabel _serverCountLabel;
123    int _serverCount = 0;
124    
225   //---STATIC ATTRIBUTES---
226      
227 +    /**
228 +     * Displays information about the data link
229 +     */
230      static JLabel _controlStatus = new JLabel("Control Link: Disconnected", JLabel.LEFT);
231      {
232          _controlStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
233      }
234      
235 +    /**
236 +     * Displays information about the data link
237 +     */
238      static JLabel _dataStatus = new JLabel("Data Link: Disconnected", JLabel.LEFT);
239      {
240          _dataStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
241      }
242      
243 +    /**
244 +     * Displays information about the inbound data queue.
245 +     */
246      static JLabel _queueStatus = new JLabel(" ", JLabel.LEFT);
247      {
248          _queueStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
249      }
250 +    
251 +    /**
252 +     * The place where system messages are written.
253 +     */
254      static JTextArea _messages = new JTextArea();
255 +    {
256 +        _messages.setLineWrap(true);
257 +    }
258 +    
259 +    /**
260 +     * Holds a reference to the root frame for Conient
261 +     * This is only used by dialogs (specifically the configurationn
262 +     * dialog) so that it can be modal, please use the accessor.
263 +     */
264 +    private static Frame conientFrame;
265 +    
266 + //---INNER CLASSES----
267 +
268 +    /**
269 +     * An inner class to display a splash screen
270 +     */
271 +    private class Splash extends JWindow {
272 +        
273 +        /**
274 +         * Constructs a new splash screen
275 +         */
276 +        public Splash() {
277 +            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
278 +            JPanel splash = new JPanel();
279 +            splash.setBackground(Color.black);
280 +            JLabel image = new JLabel((new ImageIcon("./resources/i-scream-splash.gif")));
281 +            splash.add(image);
282 +            setContentPane(splash);
283 +            Dimension screen = getToolkit().getScreenSize();
284 +            pack();
285 +            setLocation((screen.width - getSize().width) / 2,
286 +                        (screen.height - getSize().height) / 2);
287 +            
288 +            
289 +        }
290 +    }
291   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines