1 22 package org.enhydra.multiServer.launch; 23 24 import org.enhydra.multiServer.kernel.Kernel; 26 27 import java.awt.*; 29 import java.awt.event.*; 30 import java.beans.*; 31 import java.io.File ; 32 import java.io.IOException ; 33 import java.text.DateFormat ; 34 import java.util.Date ; 35 import javax.swing.border.*; 36 import javax.swing.*; 37 import javax.swing.filechooser.FileFilter ; 38 39 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 ex) { 58 ex.printStackTrace(); 59 } 60 } 61 62 protected void initPaths() { 63 confPanel.initPaths(); 64 } 65 66 protected void refreshStatus(String status, String message, 67 boolean starting) { 68 Date nowDate = new Date (System.currentTimeMillis()); 69 String 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 cmd = new StringBuffer (); 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 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 ()); 176 buttonStop.setIcon(stop); 177 buttonStop.setText(new String ()); 178 buttonAdmin.setIcon(admin); 179 buttonAdmin.setText(new String ()); 180 labelStatus.setText(new String ()); 181 outputPanel.initCapture(); 182 } 183 184 private void jbInit() throws Exception { 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 () { 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 () { 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.setFloatable(false); 249 toolBar.add(buttonStart, null); 250 toolBar.add(buttonStop, null); 251 toolBar.add(buttonAdmin, null); 252 253 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 |