KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > multiServer > launch > LaunchFrame


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  */

22 package org.enhydra.multiServer.launch;
23
24 // Kernel imports
25
import org.enhydra.multiServer.kernel.Kernel;
26
27 // Standard mports
28
import java.awt.*;
29 import java.awt.event.*;
30 import java.beans.*;
31 import javax.swing.*;
32 import javax.swing.event.*;
33
34 //
35
public class LaunchFrame extends JFrame {
36     private BorderLayout layoutRoot;
37     private LaunchPanel launchPanel;
38     private GridBagLayout layoutMain;
39     private JMenuBar menuBar;
40     private JMenu menuFile;
41     private JMenuItem menuStart;
42     private JMenuItem menuStop;
43     private JMenuItem menuGotoAdmin;
44     private JMenuItem menuExit;
45     private JMenu menuView;
46     private JRadioButtonMenuItem menuMessages;
47     private JRadioButtonMenuItem menuSettings;
48     private JMenu menuHelp;
49     private JMenuItem menuAdminHelp;
50     private JMenuItem menuAbout;
51
52     public LaunchFrame() {
53         try {
54             jbInit();
55             pmInit();
56         } catch (Exception JavaDoc e) {
57             e.printStackTrace();
58         }
59     }
60
61     protected void initPaths() {
62         launchPanel.initPaths();
63     }
64
65     protected LaunchApp getApp() {
66         return LaunchApp.app;
67     }
68
69     protected void clearAll() {
70         setVisible(false);
71         removeAll();
72         dispose();
73     }
74
75     protected void refreshStatus(String JavaDoc status, String JavaDoc message,
76                                  boolean starting) {
77         launchPanel.refreshStatus(status, message, starting);
78         if (starting) {
79             menuStart.setEnabled(false);
80             menuStop.setEnabled(true);
81             menuGotoAdmin.setEnabled(false);
82         } else if (Kernel.getKernel() == null) {
83             menuStart.setEnabled(true);
84             menuStop.setEnabled(false);
85             menuGotoAdmin.setEnabled(false);
86         } else if (getApp().isServerRunning()) {
87             menuStart.setEnabled(false);
88             menuStop.setEnabled(true);
89             menuGotoAdmin.setEnabled(true);
90         } else {
91             menuStart.setEnabled(true);
92             menuStop.setEnabled(true);
93             menuGotoAdmin.setEnabled(false);
94         }
95     }
96
97     private void pmInit() {
98         ButtonGroup group = new ButtonGroup();
99
100         group.add(menuMessages);
101         group.add(menuSettings);
102
103         //
104
}
105
106     public void show() {
107         pack();
108         setSize((int) (getSize().width * 0.8),
109                 (int) (getSize().height * 0.8));
110         setLocation(SwingUtil.getCenteringPoint(getSize()));
111         super.show();
112     }
113
114     protected void processWindowEvent(java.awt.event.WindowEvent JavaDoc e) {
115         if (e.getID() == java.awt.event.WindowEvent.WINDOW_CLOSING) {
116             exit();
117         }
118     }
119
120     private void jbInit() throws Exception JavaDoc {
121         launchPanel =
122             (LaunchPanel) Beans.instantiate(getClass().getClassLoader(),
123                                             LaunchPanel.class.getName());
124         menuBar = (JMenuBar) Beans.instantiate(getClass().getClassLoader(),
125                                                JMenuBar.class.getName());
126         menuFile = (JMenu) Beans.instantiate(getClass().getClassLoader(),
127                                              JMenu.class.getName());
128         menuStart = (JMenuItem) Beans.instantiate(getClass().getClassLoader(),
129                                                   JMenuItem.class.getName());
130         menuStop = (JMenuItem) Beans.instantiate(getClass().getClassLoader(),
131                                                  JMenuItem.class.getName());
132         menuGotoAdmin =
133             (JMenuItem) Beans.instantiate(getClass().getClassLoader(),
134                                           JMenuItem.class.getName());
135         menuView = (JMenu) Beans.instantiate(getClass().getClassLoader(),
136                                              JMenu.class.getName());
137         menuMessages =
138             (JRadioButtonMenuItem) Beans.instantiate(getClass().getClassLoader(),
139                 JRadioButtonMenuItem.class.getName());
140         menuSettings =
141             (JRadioButtonMenuItem) Beans.instantiate(getClass().getClassLoader(),
142                 JRadioButtonMenuItem.class.getName());
143         menuExit = (JMenuItem) Beans.instantiate(getClass().getClassLoader(),
144                                                  JMenuItem.class.getName());
145         menuHelp = (JMenu) Beans.instantiate(getClass().getClassLoader(),
146                                              JMenu.class.getName());
147         menuAdminHelp =
148             (JMenuItem) Beans.instantiate(getClass().getClassLoader(),
149                                           JMenuItem.class.getName());
150         menuAbout = (JMenuItem) Beans.instantiate(getClass().getClassLoader(),
151                                                   JMenuItem.class.getName());
152         layoutRoot =
153             (BorderLayout) Beans.instantiate(getClass().getClassLoader(),
154                                              BorderLayout.class.getName());
155         menuBar.add(menuFile);
156         menuBar.add(menuView);
157         menuBar.add(menuHelp);
158         menuFile.setMnemonic('F');
159         menuFile.setText("File");
160         menuFile.add(menuStart);
161         menuFile.add(menuStop);
162         menuFile.addSeparator();
163         menuFile.add(menuGotoAdmin);
164         menuFile.addSeparator();
165         menuFile.add(menuExit);
166         menuStart.setMnemonic('S');
167         menuStart.setText("Start Server");
168         menuStart.addActionListener(new ActionListener() {
169             public void actionPerformed(ActionEvent e) {
170                 launchPanel.startServer();
171             }
172
173         });
174         menuStop.setEnabled(false);
175         menuStop.setMnemonic('d');
176         menuStop.setText("Shutdown Server");
177         menuStop.addActionListener(new ActionListener() {
178             public void actionPerformed(ActionEvent e) {
179                 launchPanel.stopServer();
180             }
181
182         });
183         menuGotoAdmin.setEnabled(false);
184         menuGotoAdmin.setMnemonic('A');
185         menuGotoAdmin.setText("Go to Admin Servlet");
186         menuGotoAdmin.addActionListener(new ActionListener() {
187             public void actionPerformed(ActionEvent e) {
188                 launchPanel.gotoAdmin();
189             }
190
191         });
192         menuExit.setMnemonic('X');
193         menuExit.setText("Exit");
194         menuExit.addActionListener(new ActionListener() {
195             public void actionPerformed(ActionEvent e) {
196                 exit();
197             }
198
199         });
200         menuHelp.setMnemonic('H');
201         menuHelp.setText("Help");
202         menuAbout.setMnemonic('A');
203         menuAbout.setText("About...");
204         menuAbout.addActionListener(new ActionListener() {
205             public void actionPerformed(ActionEvent e) {
206                 showAboutBox();
207             }
208
209         });
210         menuAdminHelp.setMnemonic('L');
211         menuAdminHelp.setText("Admin Login");
212         menuAdminHelp.addActionListener(new ActionListener() {
213             public void actionPerformed(ActionEvent e) {
214                 adminHelp();
215             }
216
217         });
218         menuView.setMnemonic('V');
219         menuView.setText("View");
220         menuView.add(menuMessages);
221         menuView.add(menuSettings);
222         menuView.addMenuListener(new MenuListener() {
223             public void menuCanceled(MenuEvent e) {}
224
225             public void menuDeselected(MenuEvent e) {}
226
227             public void menuSelected(MenuEvent e) {
228                 if (launchPanel.isMessageTabSelected()) {
229                     menuMessages.setSelected(true);
230                     menuSettings.setSelected(false);
231                 } else {
232                     menuMessages.setSelected(false);
233                     menuSettings.setSelected(true);
234                 }
235             }
236
237         });
238         menuMessages.setSelected(true);
239         menuMessages.setText("Messages");
240         menuMessages.setAccelerator(javax.swing.KeyStroke.getKeyStroke(77,
241                 java.awt.event.KeyEvent.CTRL_MASK, false));
242         menuMessages.addItemListener(new ItemListener() {
243             public void itemStateChanged(ItemEvent e) {
244                 if (e.getStateChange() == ItemEvent.SELECTED) {
245                     launchPanel.viewMessages();
246                 }
247             }
248
249         });
250         menuSettings.setText("Settings");
251         menuSettings.setAccelerator(javax.swing.KeyStroke.getKeyStroke(83,
252                 java.awt.event.KeyEvent.CTRL_MASK, false));
253         menuSettings.addItemListener(new ItemListener() {
254             public void itemStateChanged(ItemEvent e) {
255                 if (e.getStateChange() == ItemEvent.SELECTED) {
256                     launchPanel.viewSettings();
257                 }
258             }
259
260         });
261         menuHelp.add(menuAdminHelp);
262         menuHelp.add(menuAbout);
263         this.setTitle("Enhydra Launch Utility");
264         this.setJMenuBar(menuBar);
265         this.getContentPane().setLayout(layoutRoot);
266         this.getContentPane().add(launchPanel, BorderLayout.CENTER);
267     }
268
269     private void exit() {
270         getApp().exit();
271     }
272
273     private void showAboutBox() {
274         AboutBox about = new AboutBox(this);
275
276         about.setTitleText(getTitle());
277         about.setTextAreaText("Enhydra 4.0");
278         about.setSmallText("Copyright (c) 2000, Lutris Technologies, All Rights Reserved.");
279         about.show();
280     }
281
282     private void adminHelp() {
283         JOptionPane.showMessageDialog(this,
284                                       "Default login for the Admin Servlet\n\n"
285                                       + " User Name: admin\n"
286                                       + " Password: enhydra\n\n",
287                                       "Admin Login Help",
288                                       JOptionPane.INFORMATION_MESSAGE);
289     }
290
291 }
292
Popular Tags