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
Revision: 1.33
Committed: Sat May 18 18:15:56 2002 UTC (22 years ago) by tdb
Branch: MAIN
Changes since 1.32: +22 -3 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# User Rev Content
1 tdb 1.33 /*
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 ajm 1.1 //---PACKAGE DECLARATION---
21 tdb 1.31 package uk.org.iscream.cms.conient;
22 ajm 1.1
23     //---IMPORTS---
24     import javax.swing.*;
25     import javax.swing.border.*;
26     import java.awt.*;
27     import java.awt.event.*;
28    
29     /**
30 ajm 1.15 * This is the main class of the Conient client.
31 ajm 1.1 *
32 ajm 1.15 * This sets up the control panel, the data panel
33     * and its own display.
34     *
35 tdb 1.33 * @author $Author: ajm $
36     * @version $Id: Conient.java,v 1.32 2002/02/14 16:50:10 ajm Exp $
37 ajm 1.1 */
38 ajm 1.16 public class Conient extends JFrame {
39 ajm 1.1
40     //---FINAL ATTRIBUTES---
41    
42     /**
43     * The current CVS revision of this class
44     */
45 tdb 1.33 public final String REVISION = "$Revision: 1.32 $";
46 ajm 1.15
47     /**
48     * The initial width of the window
49     */
50 ajm 1.27 private final int DEFAULT_WIDTH = 700;
51 ajm 1.15
52     /**
53     * The initial height of the window
54     */
55     private final int DEFAULT_HEIGHT = 600;
56 ajm 1.9
57 ajm 1.15 /**
58 ajm 1.19 * The default configuration fle
59     * This can be specified on the command line
60 ajm 1.15 */
61 ajm 1.19 public static final String DEFAULT_CONFIG_FILE = "./etc/default.conf";
62 ajm 1.1
63 ajm 1.22 /**
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 ajm 1.1 //---STATIC METHODS---
70    
71 ajm 1.15 /**
72     * The first method that is called.
73     * Sets up the various panels
74     *
75     * @param args the command line arguments
76     */
77 ajm 1.1 public static void main(String[] args) {
78 ajm 1.9 // get the host from the command line if they gave it
79     String host = null;
80 ajm 1.19 String configFile = DEFAULT_CONFIG_FILE;
81 ajm 1.9 if (args.length == 1) {
82 ajm 1.19 configFile = args[0];
83 ajm 1.9 }
84 ajm 1.19
85     // start the configuration system
86     Configuration.initialise(configFile);
87 ajm 1.8
88 ajm 1.9 // the data display panel
89     DataPanel data = new DataPanel();
90    
91     // the control panel
92     ControlPanel control = new ControlPanel(data);
93 ajm 1.1
94 ajm 1.9 // the main frame (passed the two panels)
95 ajm 1.16 Conient client = new Conient(data, control);
96 ajm 1.23 conientFrame = (Frame) client;
97 ajm 1.30 Conient.addMessage("Conient {an i-scream Client} (c) 2001 The i-scream Project (http://www.i-scream.org.uk)");
98 ajm 1.19
99 ajm 1.16 Conient.addMessage("Conient ready.");
100 ajm 1.22
101 ajm 1.1 }
102 ajm 1.23
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 ajm 1.1
115     //---CONSTRUCTORS---
116    
117     /**
118 ajm 1.9 * Creates a new Swing Client Frame
119 ajm 1.1 */
120 ajm 1.28 private Conient(JSplitPane data, ControlPanel control) {
121 ajm 1.9 // set up the Frame
122 ajm 1.17 super("Conient {an i-scream Client}");
123 ajm 1.15 setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
124 ajm 1.24 setJMenuBar(control.getMenuBar());
125    
126 ajm 1.15 // set what happens when the X in the corner is clicked
127 ajm 1.9 addWindowListener(new WindowAdapter() {
128     public void windowClosing(WindowEvent e) {System.exit(0);}
129     });
130 ajm 1.8
131 ajm 1.15 // add the control pane to the top border
132 tdb 1.14 getContentPane().add(control, "North");
133 ajm 1.28 // add the data pane to the centre
134     getContentPane().add(data);
135 ajm 1.15
136     // setup the status panel
137 ajm 1.9 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 "));
143     bottom.add(messagesPane, "Center");
144 ajm 1.11 JPanel statusPanel = new JPanel();
145 ajm 1.12 JPanel linkPanel = new JPanel();
146 ajm 1.20 linkPanel.setLayout(new GridLayout(1,2));
147 ajm 1.12 linkPanel.add(_controlStatus);
148     linkPanel.add(_dataStatus);
149 ajm 1.20 statusPanel.setLayout(new GridLayout(2,1));
150 ajm 1.12 statusPanel.add(linkPanel);
151 ajm 1.11 statusPanel.add(_queueStatus);
152     bottom.add(statusPanel, "South");
153 ajm 1.15
154     // add the status panel to the bottom border
155 ajm 1.9 getContentPane().add(bottom, "South");
156 ajm 1.8
157 ajm 1.21 // a nice icon for the window
158 ajm 1.25 setIconImage((new ImageIcon("./resources/server.gif")).getImage());
159 ajm 1.22
160     // and just because we can, a silly splash screen
161 ajm 1.32 // of the dudes that did this funky jibble
162 ajm 1.22 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 ajm 1.1 show();
175     }
176    
177     //---PUBLIC METHODS---
178    
179     //---PRIVATE METHODS---
180    
181 ajm 1.9 //---ACCESSOR/MUTATOR METHODS---
182 ajm 1.1
183 ajm 1.15 /**
184     * Sets the control link status.
185     *
186     * @param status the message
187     */
188 ajm 1.12 public static void setControlStatus(String status) {
189     _controlStatus.setText("Control Link: " + status);
190     _controlStatus.repaint();
191     }
192    
193 ajm 1.15 /**
194     * Sets the data link status.
195     *
196     * @param status the message
197     */
198 ajm 1.12 public static void setDataStatus(String status) {
199     _dataStatus.setText("Data Link: " + status);
200     _dataStatus.repaint();
201 ajm 1.9 }
202 ajm 1.1
203 ajm 1.15 /**
204     * Updates the queue status.
205     *
206     * @param currentQueue
207     * @param numElements
208     */
209 ajm 1.11 public static void setQueueStatus(int currentQueue, int numElements) {
210     _queueStatus.setText("Data Queue : " + currentQueue + " Packets Recieved : " + numElements);
211     _queueStatus.repaint();
212     }
213    
214 ajm 1.15 /**
215     * Adds a system message to the messages list
216     *
217     * @param message the new message
218     */
219 ajm 1.9 public static void addMessage(String message) {
220     _messages.insert(message + "\n", 0);
221     }
222 ajm 1.13
223 ajm 1.1 //---ATTRIBUTES---
224 ajm 1.13
225     //---STATIC ATTRIBUTES---
226    
227 ajm 1.15 /**
228     * Displays information about the data link
229     */
230 ajm 1.12 static JLabel _controlStatus = new JLabel("Control Link: Disconnected", JLabel.LEFT);
231 ajm 1.9 {
232 ajm 1.12 _controlStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
233 ajm 1.11 }
234    
235 ajm 1.15 /**
236     * Displays information about the data link
237     */
238 ajm 1.12 static JLabel _dataStatus = new JLabel("Data Link: Disconnected", JLabel.LEFT);
239 ajm 1.11 {
240 ajm 1.12 _dataStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
241 ajm 1.11 }
242    
243 ajm 1.15 /**
244     * Displays information about the inbound data queue.
245     */
246 ajm 1.13 static JLabel _queueStatus = new JLabel(" ", JLabel.LEFT);
247 ajm 1.11 {
248     _queueStatus.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
249     }
250 ajm 1.15
251     /**
252     * The place where system messages are written.
253     */
254 ajm 1.9 static JTextArea _messages = new JTextArea();
255 ajm 1.18 {
256     _messages.setLineWrap(true);
257 ajm 1.22 }
258 ajm 1.23
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 ajm 1.22
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 ajm 1.25 JLabel image = new JLabel((new ImageIcon("./resources/i-scream-splash.gif")));
281 ajm 1.22 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 ajm 1.18 }
291 ajm 1.8 }