KickJava   Java API By Example, From Geeks To Geeks.

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


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 imports
28
import java.awt.*;
29 import java.awt.event.*;
30 import java.beans.*;
31 import java.io.File JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.text.DateFormat JavaDoc;
34 import java.util.Date JavaDoc;
35 import javax.swing.border.*;
36 import javax.swing.*;
37 import javax.swing.filechooser.FileFilter JavaDoc;
38
39 //
40
public class LaunchPanel extends JPanel {
41     private GridBagLayout layoutMain;
42     private JToolBar toolBar;
43     private JButton buttonStart;
44     private JButton buttonStop;
45     private JButton buttonAdmin;
46     private ConfPanel confPanel;
47     private OutputPanel outputPanel;
48     private JPanel panelStatus;
49     private JLabel labelStatus;
50     private JTabbedPane tabPane;
51     private GridBagLayout layoutStatus;
52
53     public LaunchPanel() {
54         try {
55             jbInit();
56             pmInit();
57         } catch (Exception JavaDoc ex) {
58             ex.printStackTrace();
59         }
60     }
61
62     protected void initPaths() {
63         confPanel.initPaths();
64     }
65
66     protected void refreshStatus(String JavaDoc status, String JavaDoc message,
67                                  boolean starting) {
68         Date JavaDoc nowDate = new Date JavaDoc(System.currentTimeMillis());
69         String JavaDoc now = DateFormat.getDateTimeInstance().format(nowDate);
70
71         if (getApp() != null) {
72             labelStatus.setText(status + " at " + now);
73             if ((message != null) && (message.trim().length() > 0)
74                     && (outputPanel != null)) {
75                 outputPanel.appendMessage(message);
76                 outputPanel.appendMessage("\n");
77             }
78             if (starting) {
79                 tabPane.setSelectedIndex(0);
80                 buttonStart.setEnabled(false);
81                 buttonStop.setEnabled(true);
82                 buttonAdmin.setEnabled(false);
83             } else if (Kernel.getKernel() == null) {
84                 buttonStart.setEnabled(true);
85                 buttonStop.setEnabled(false);
86                 buttonAdmin.setEnabled(false);
87             } else if (getApp().isServerRunning()) {
88                 buttonStart.setEnabled(false);
89                 buttonStop.setEnabled(true);
90                 buttonAdmin.setEnabled(true);
91             } else {
92                 buttonStart.setEnabled(true);
93                 buttonStop.setEnabled(true);
94                 buttonAdmin.setEnabled(false);
95             }
96         }
97     }
98
99     protected void startServer() {
100         getApp().startServer();
101     }
102
103     protected void stopServer() {
104         int choice =
105             JOptionPane.showConfirmDialog(this,
106                                           "Shutting down the server will also close the \n"
107                                           + "launcher application. Continue with shutdown?",
108                                           "Enhydra Launcher",
109                                           JOptionPane.OK_CANCEL_OPTION,
110                                           JOptionPane.QUESTION_MESSAGE);
111
112         if (choice == JOptionPane.OK_OPTION) {
113             getApp().stopServer();
114         }
115     }
116
117     protected void gotoAdmin() {
118         if (!getApp().isServerRunning()) {
119             int result =
120                 JOptionPane.showConfirmDialog(getTopLevelAncestor(),
121                                               "The Enhydra server is required to use the Admin servlet \n"
122                                               + "and it may not have been started. Do you want to continue?",
123                                               "Go to Admin Servlet",
124                                               JOptionPane.YES_NO_OPTION);
125
126             if (result == JOptionPane.NO_OPTION) {
127                 return;
128             }
129         }
130         if (getApp().getBrowser() == null) {
131             confPanel.selectBrowser();
132             getApp().storeAppProperties();
133         }
134         if (getApp().getBrowser() != null) {
135             StringBuffer JavaDoc cmd = new StringBuffer JavaDoc();
136             cmd.append(getApp().getBrowser());
137             cmd.append(" ");
138             cmd.append("http://localhost:8001");
139             try {
140                 Runtime.getRuntime().exec(cmd.toString());
141             } catch (IOException JavaDoc e) {
142                 e.printStackTrace();
143             }
144         }
145     }
146
147     protected void viewMessages() {
148         tabPane.setSelectedIndex(0);
149     }
150
151     protected void viewSettings() {
152         tabPane.setSelectedIndex(1);
153         confPanel.firstFocus();
154     }
155
156     protected boolean isMessageTabSelected() {
157         return (tabPane.getSelectedIndex() == 0);
158     }
159
160     private void pmInit() {
161         Border borderText = null;
162         Border borderStatus = null;
163
164         borderText = BorderFactory.createBevelBorder(1);
165         borderStatus = BorderFactory.createLoweredBevelBorder();
166         panelStatus.setBorder(borderStatus);
167         ImageIcon start =
168             new ImageIcon(ClassLoader.getSystemResource("org/enhydra/multiServer/launch/media/start.gif"));
169         ImageIcon stop =
170             new ImageIcon(ClassLoader.getSystemResource("org/enhydra/multiServer/launch/media/stop.gif"));
171         ImageIcon admin =
172             new ImageIcon(ClassLoader.getSystemResource("org/enhydra/multiServer/launch/media/admin.gif"));
173
174         buttonStart.setIcon(start);
175         buttonStart.setText(new String JavaDoc());
176         buttonStop.setIcon(stop);
177         buttonStop.setText(new String JavaDoc());
178         buttonAdmin.setIcon(admin);
179         buttonAdmin.setText(new String JavaDoc());
180         labelStatus.setText(new String JavaDoc());
181         outputPanel.initCapture();
182     }
183
184     private void jbInit() throws Exception JavaDoc {
185         layoutMain =
186             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
187                                               GridBagLayout.class.getName());
188         toolBar = (JToolBar) Beans.instantiate(getClass().getClassLoader(),
189                                                JToolBar.class.getName());
190         buttonStart = (JButton) Beans.instantiate(getClass().getClassLoader(),
191                                                   JButton.class.getName());
192         buttonStop = (JButton) Beans.instantiate(getClass().getClassLoader(),
193                                                  JButton.class.getName());
194         buttonAdmin = (JButton) Beans.instantiate(getClass().getClassLoader(),
195                                                   JButton.class.getName());
196         confPanel = (ConfPanel) Beans.instantiate(getClass().getClassLoader(),
197                                                   ConfPanel.class.getName());
198         outputPanel =
199             (OutputPanel) Beans.instantiate(getClass().getClassLoader(),
200                                             OutputPanel.class.getName());
201         panelStatus = (JPanel) Beans.instantiate(getClass().getClassLoader(),
202                                                  JPanel.class.getName());
203         labelStatus = (JLabel) Beans.instantiate(getClass().getClassLoader(),
204                                                  JLabel.class.getName());
205         tabPane =
206             (JTabbedPane) Beans.instantiate(getClass().getClassLoader(),
207                                             JTabbedPane.class.getName());
208         layoutStatus =
209             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
210                                               GridBagLayout.class.getName());
211         buttonStart.setRequestFocusEnabled(false);
212         buttonStart.setToolTipText("Start Server");
213         buttonStart.setBorderPainted(false);
214         buttonStart.setFocusPainted(false);
215         buttonStart.setText("->");
216         buttonStart.addActionListener(new java.awt.event.ActionListener JavaDoc() {
217             public void actionPerformed(ActionEvent e) {
218                 startServer();
219             }
220
221         });
222         buttonStop.setEnabled(false);
223         buttonStop.setRequestFocusEnabled(false);
224         buttonStop.setToolTipText("Shutdown Server");
225         buttonStop.setBorderPainted(false);
226         buttonStop.setFocusPainted(false);
227         buttonStop.setText("X");
228         buttonStop.addActionListener(new java.awt.event.ActionListener JavaDoc() {
229             public void actionPerformed(ActionEvent e) {
230                 stopServer();
231             }
232
233         });
234         buttonAdmin.setEnabled(false);
235         buttonAdmin.setRequestFocusEnabled(false);
236         buttonAdmin.setToolTipText("Go to Admin Servlet");
237         buttonAdmin.setBorderPainted(false);
238         buttonAdmin.setFocusPainted(false);
239         buttonAdmin.setText("A");
240         buttonAdmin.addActionListener(new ActionListener() {
241             public void actionPerformed(ActionEvent e) {
242                 gotoAdmin();
243             }
244
245         });
246
247         // toolbar
248
toolBar.setFloatable(false);
249         toolBar.add(buttonStart, null);
250         toolBar.add(buttonStop, null);
251         toolBar.add(buttonAdmin, null);
252
253         // tab
254
tabPane.addTab("Messages", outputPanel);
255         tabPane.addTab("Settings", confPanel);
256         labelStatus.setText("Status");
257         panelStatus.setLayout(layoutStatus);
258         panelStatus.add(labelStatus,
259                         new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1,
260                                                GridBagConstraints.CENTER,
261                                                GridBagConstraints.HORIZONTAL,
262                                                new Insets(1, 5, 1, 5), 100,
263                                                22));
264         this.setLayout(layoutMain);
265         this.add(toolBar,
266                  new GridBagConstraints(0, 0, GridBagConstraints.REMAINDER,
267                                         1, 0.1, 0.1,
268                                         GridBagConstraints.NORTH,
269                                         GridBagConstraints.HORIZONTAL,
270                                         new Insets(5, 5, 5, 5), 0, 0));
271         this.add(tabPane,
272                  new GridBagConstraints(0, 0, 1, 1, 0.5, 0.5,
273                                         GridBagConstraints.CENTER,
274                                         GridBagConstraints.BOTH,
275                                         new Insets(50, 4, 5, 4), 300, 50));
276         this.add(panelStatus,
277                  new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1,
278                                         GridBagConstraints.SOUTH,
279                                         GridBagConstraints.HORIZONTAL,
280                                         new Insets(2, 5, 2, 5), 0, 0));
281     }
282
283     private LaunchApp getApp() {
284         return LaunchApp.app;
285     }
286
287 }
288
Popular Tags