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.35
Committed: Fri Jan 31 17:05:50 2003 UTC (21 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.34: +4 -4 lines
Log Message:
The images (from the resources directory) are now inside the JAR file.
Thanks Pete for pointing out how to do this ;)

File Contents

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