KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > base > tool > WizardFrame


1 /*
2  * Created on Jul 19, 2005
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package org.enhydra.base.tool;
8
9 import javax.swing.JFrame JavaDoc;
10
11 import javax.swing.JPanel JavaDoc;
12 import java.awt.BorderLayout JavaDoc;
13
14 import javax.swing.JButton JavaDoc;
15 import java.awt.Toolkit JavaDoc;
16 import java.awt.event.ActionEvent JavaDoc;
17 import java.awt.event.ActionListener JavaDoc;
18 import java.io.BufferedReader JavaDoc;
19 import java.io.File JavaDoc;
20 import java.io.FileInputStream JavaDoc;
21 import java.io.FileOutputStream JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.io.InputStreamReader JavaDoc;
25 import java.util.Properties JavaDoc;
26
27 import javax.swing.AbstractAction JavaDoc;
28
29 import javax.swing.JTabbedPane JavaDoc;
30
31 /**
32  * @author slobodan
33  *
34  * TODO To change the template for this generated type comment go to Window -
35  * Preferences - Java - Code Style - Code Templates
36  */

37 public class WizardFrame extends JFrame JavaDoc {
38
39     private javax.swing.JPanel JavaDoc jContentPane = null;
40
41     private JPanel JavaDoc backPanel = null;
42
43     private JPanel JavaDoc buttonPanell = null;
44
45     private JButton JavaDoc configureButton = null;
46
47     private JButton JavaDoc closeButton = null;
48
49     private JPanel JavaDoc settingPanel = null;
50
51     private String JavaDoc enhydraDir = null;
52
53     private JTabbedPane JavaDoc tabBase = null;
54
55     private ConnectorConfigurationPanel connectorPanel = null;
56
57     private AdaptorConfigurationPanel adaptorPanel = null;
58
59     private ServerShutdownConfigurationPanel serverPanel = null;
60
61     private AuthenticationConfigurationPanel authenticationPanel = null;
62
63     private EnhydraBasePanel enhydraBasePanel = null;
64
65     private JavaConfigurationPanel javaPanel = null;
66
67     private OutputPanel outputPanel = null;
68
69     // configuration properties
70
private String JavaDoc httpenabled = "on";
71
72     private String JavaDoc sslenabled = "on";
73
74     private String JavaDoc ajpenabled = "on";
75
76     private String JavaDoc directorenabled = "on";
77
78     private String JavaDoc httpport = "8080";
79
80     private String JavaDoc sslport = "8443";
81
82     private String JavaDoc ajpport = "9009";
83
84     private String JavaDoc directorport = "9003";
85
86     private String JavaDoc httpadaptorenabled = "on";
87
88     private String JavaDoc rmiadaptorenabled = "on";
89
90     private String JavaDoc httpadaptorport = "9050";
91
92     private String JavaDoc rmiadaptorport = "1099";
93
94     private String JavaDoc serverport = "8005";
95
96     private String JavaDoc servershutdown = "SHUTDOWN";
97
98     private String JavaDoc authmode = "none";
99
100     private String JavaDoc username = "admin";
101
102     private String JavaDoc password = "enhydra";
103
104     private String JavaDoc servicename = "Enhydra";
105
106     private String JavaDoc basedir = "";
107
108     private String JavaDoc jdkdir = "";
109
110     private Properties JavaDoc props = null;
111
112     private String JavaDoc basePropertyFile = "base.properties";
113
114     private String JavaDoc enhydraPropertyFile = "build.properties";
115
116     private String JavaDoc propertyFileName = "";
117
118     /**
119      * This is the default constructor
120      */

121     public WizardFrame(String JavaDoc enhydraDir) {
122         super();
123         this.enhydraDir = enhydraDir;
124         initialize();
125     }
126
127     /**
128      * This is the default constructor
129      */

130     public WizardFrame() {
131         super();
132         this.enhydraDir = null;
133         initialize();
134     }
135
136     private void loadProperties() {
137         props = new Properties JavaDoc();
138         File JavaDoc propertyFile = null;
139         FileInputStream JavaDoc propertyFileIS = null;
140         try {
141             propertyFile = new File JavaDoc(this.enhydraDir + File.separator
142                     + basePropertyFile);
143             if (propertyFile.exists()) {
144                 propertyFileIS = new FileInputStream JavaDoc(propertyFile);
145                 props.load(propertyFileIS);
146                 propertyFileName = basePropertyFile;
147             } else {
148                 propertyFile = new File JavaDoc(this.enhydraDir + File.separator
149                         + enhydraPropertyFile);
150                 if (propertyFile.exists()) {
151                     propertyFileIS = new FileInputStream JavaDoc(propertyFile);
152                     props.load(propertyFileIS);
153                     propertyFileName = enhydraPropertyFile;
154                 }
155             }
156         } catch (Exception JavaDoc ex) {
157             System.out
158                     .println("Unable to properly initialize property values!");
159         } finally {
160             try {
161                 if (propertyFileIS != null)
162                     propertyFileIS.close();
163             } catch (IOException JavaDoc ex) {
164                 System.out
165                         .println("Unable to close property file input stream!");
166             }
167         }
168
169         if (props != null) {
170             // configuration properties
171
if (props.containsKey("httpenabled"))
172                 httpenabled = props.getProperty("httpenabled");
173             if (props.containsKey("httpport"))
174                 httpport = props.getProperty("httpport");
175             if (props.containsKey("sslenabled"))
176                 sslenabled = props.getProperty("sslenabled");
177             if (props.containsKey("ajpenabled"))
178                 ajpenabled = props.getProperty("ajpenabled");
179             if (props.containsKey("directorenabled"))
180                 directorenabled = props.getProperty("directorenabled");
181             if (props.containsKey("sslport"))
182                 sslport = props.getProperty("sslport");
183             if (props.containsKey("ajpport"))
184                 ajpport = props.getProperty("ajpport");
185             if (props.containsKey("directorport"))
186                 directorport = props.getProperty("directorport");
187             if (props.containsKey("httpadaptorenabled"))
188                 httpadaptorenabled = props.getProperty("httpadaptorenabled");
189             if (props.containsKey("rmiadaptorenabled"))
190                 rmiadaptorenabled = props.getProperty("rmiadaptorenabled");
191             if (props.containsKey("httpadaptorport"))
192                 httpadaptorport = props.getProperty("httpadaptorport");
193             if (props.containsKey("rmiadaptorport"))
194                 rmiadaptorport = props.getProperty("rmiadaptorport");
195             if (props.containsKey("serverport"))
196                 serverport = props.getProperty("serverport");
197             if (props.containsKey("servershutdown"))
198                 servershutdown = props.getProperty("servershutdown");
199             if (props.containsKey("authmode"))
200                 authmode = props.getProperty("authmode");
201             if (props.containsKey("username"))
202                 username = props.getProperty("username");
203             if (props.containsKey("password"))
204                 password = props.getProperty("password");
205             if (props.containsKey("servicename")
206                     && basePropertyFile.equals(propertyFileName))
207                 servicename = props.getProperty("servicename");
208             if (props.containsKey("base.dir")
209                     && basePropertyFile.equals(propertyFileName))
210                 basedir = props.getProperty("base.dir");
211             if (props.containsKey("jdk.dir"))
212                 jdkdir = props.getProperty("jdk.dir");
213         }
214     }
215
216     private void saveProperties() {
217         setProperties();
218
219         if (props == null) {
220             props = new Properties JavaDoc();
221         }
222         // configuration properties
223
props.setProperty("httpenabled", httpenabled);
224         props.setProperty("httpport", httpport);
225         props.setProperty("sslenabled", sslenabled);
226         props.setProperty("ajpenabled", ajpenabled);
227         props.setProperty("directorenabled", directorenabled);
228         props.setProperty("sslport", sslport);
229         props.setProperty("ajpport", ajpport);
230         props.setProperty("directorport", directorport);
231         props.setProperty("httpadaptorenabled", httpadaptorenabled);
232         props.setProperty("rmiadaptorenabled", rmiadaptorenabled);
233         props.setProperty("httpadaptorport", httpadaptorport);
234         props.setProperty("rmiadaptorport", rmiadaptorport);
235         props.setProperty("serverport", serverport);
236         props.setProperty("servershutdown", servershutdown);
237         props.setProperty("authmode", authmode);
238         props.setProperty("username", username);
239         props.setProperty("password", password);
240         props.setProperty("jdk.dir", jdkdir);
241
242         propertyFileName = enhydraPropertyFile;
243         if (enhydraBasePanel != null && enhydraBasePanel.getBaseChecked()) {
244             propertyFileName = basePropertyFile;
245             props.setProperty("servicename", servicename);
246             props.setProperty("base.dir", basedir);
247         }
248
249         File JavaDoc propertyFile = null;
250         FileOutputStream JavaDoc propertyFileOS = null;
251
252         try {
253             propertyFile = new File JavaDoc(this.enhydraDir + File.separator
254                     + propertyFileName);
255             if (!propertyFile.exists()) {
256                 propertyFile.createNewFile();
257             }
258             propertyFileOS = new FileOutputStream JavaDoc(propertyFile);
259             props
260                     .store(propertyFileOS,
261                             "Created by Enhydra Configuration Tool");
262         } catch (Exception JavaDoc ex) {
263             System.out.println("Unable to save property values!");
264         } finally {
265             try {
266                 if (propertyFileOS != null)
267                     propertyFileOS.close();
268             } catch (IOException JavaDoc ex) {
269                 System.out
270                         .println("Unable to close property file output stream!");
271             }
272         }
273     }
274
275     private void setProperties() {
276         if (connectorPanel.getHttpChecked()) {
277             httpenabled = "on";
278             httpport = connectorPanel.getHttpPort();
279         } else {
280             httpenabled = "off";
281         }
282
283         if (connectorPanel.getSslHttpChecked()) {
284             sslenabled = "on";
285             sslport = connectorPanel.getSslHttpPort();
286         } else {
287             sslenabled = "off";
288         }
289
290         if (connectorPanel.getAjpChecked()) {
291             ajpenabled = "on";
292             ajpport = connectorPanel.getAjpPort();
293         } else {
294             ajpenabled = "off";
295         }
296
297         if (connectorPanel.getDirectorChecked()) {
298             directorenabled = "on";
299             directorport = connectorPanel.getDirectorPort();
300         } else {
301             directorenabled = "off";
302         }
303
304         if (adaptorPanel.getHttpChecked()) {
305             httpadaptorenabled = "on";
306             httpadaptorport = adaptorPanel.getHttpPort();
307         } else {
308             httpadaptorenabled = "off";
309         }
310
311         authmode = adaptorPanel.getComboSelection();
312
313         if (adaptorPanel.getRmiChecked()) {
314             rmiadaptorenabled = "on";
315             rmiadaptorport = adaptorPanel.getRmiPort();
316         } else {
317             rmiadaptorenabled = "off";
318         }
319
320         serverport = serverPanel.getServerPort();
321         servershutdown = serverPanel.getServerString();
322
323         username = authenticationPanel.getUserName();
324         password = authenticationPanel.getPassword();
325
326         jdkdir = javaPanel.getJavaPath();
327
328         if (enhydraBasePanel.getBaseChecked()) {
329             servicename = enhydraBasePanel.getServiceName();
330             basedir = enhydraBasePanel.getBasePath();
331             propertyFileName = basePropertyFile;
332         } else {
333             basedir = "";
334             servicename = "";
335             propertyFileName = enhydraPropertyFile;
336         }
337     }
338
339     /**
340      * This method initializes this
341      *
342      * @return void
343      */

344     private void initialize() {
345         loadProperties();
346
347         this.setSize(350, 250);
348
349         int width = Toolkit.getDefaultToolkit().getScreenSize().width / 2 - 175;
350         int height = Toolkit.getDefaultToolkit().getScreenSize().height / 2 - 125;
351
352         this.setLocation(width, height);
353         this.setResizable(false);
354         this
355                 .setIconImage(Toolkit.getDefaultToolkit().getImage(
356                         getClass().getResource(
357                                 "/org/enhydra/base/tool/largeicon.gif")));
358         this.setName("wizardFrame");
359         this.setTitle("Enhydra Configurator");
360         this.setContentPane(getJContentPane());
361
362         connectorPanel = new ConnectorConfigurationPanel();
363         if ("on".equals(httpenabled))
364             connectorPanel.setHttpChecked(true);
365         else
366             connectorPanel.setHttpChecked(false);
367         connectorPanel.setHttpPort(httpport);
368         if ("on".equals(sslenabled))
369             connectorPanel.setSslHttpChecked(true);
370         else
371             connectorPanel.setSslHttpChecked(false);
372         connectorPanel.setSslHttpPort(sslport);
373         if ("on".equals(ajpenabled))
374             connectorPanel.setAjpChecked(true);
375         else
376             connectorPanel.setAjpChecked(false);
377         connectorPanel.setAjpPort(ajpport);
378         if ("on".equals(directorenabled))
379             connectorPanel.setDirectorChecked(true);
380         else
381             connectorPanel.setDirectorChecked(false);
382         connectorPanel.setDirectorPort(directorport);
383         getTabBase().addTab("Connectors", connectorPanel);
384
385         adaptorPanel = new AdaptorConfigurationPanel();
386         if ("on".equals(httpadaptorenabled))
387             adaptorPanel.setHttpChecked(true);
388         else
389             adaptorPanel.setHttpChecked(false);
390         adaptorPanel.setHttpPort(httpadaptorport);
391         if ("on".equals(rmiadaptorenabled))
392             adaptorPanel.setRmiChecked(true);
393         else
394             adaptorPanel.setRmiChecked(false);
395         adaptorPanel.setRmiPort(rmiadaptorport);
396
397         adaptorPanel.setComboSelection(authmode);
398
399         getTabBase().addTab("Adaptors", adaptorPanel);
400
401         serverPanel = new ServerShutdownConfigurationPanel();
402         serverPanel.setServerPort(serverport);
403         serverPanel.setServerString(servershutdown);
404         getTabBase().addTab("Server Shutdown", serverPanel);
405
406         authenticationPanel = new AuthenticationConfigurationPanel();
407         authenticationPanel.setPassword(password);
408         authenticationPanel.setUserName(username);
409         getTabBase().addTab("Administrator", authenticationPanel);
410
411         javaPanel = new JavaConfigurationPanel();
412         javaPanel.setJavaPath(jdkdir);
413         getTabBase().addTab("Java", javaPanel);
414
415         enhydraBasePanel = new EnhydraBasePanel();
416         enhydraBasePanel.setBaseChecked(!("".equals(basedir)));
417         enhydraBasePanel.setServiceName(servicename);
418         enhydraBasePanel.setBasePath(basedir);
419         getTabBase().addTab("Enhydra Base", enhydraBasePanel);
420
421         outputPanel = new OutputPanel();
422         getTabBase().addTab("Output", outputPanel);
423
424         this.setVisible(true);
425     }
426
427     /**
428      * This method initializes jContentPane
429      *
430      * @return javax.swing.JPanel
431      */

432     private javax.swing.JPanel JavaDoc getJContentPane() {
433         if (jContentPane == null) {
434             jContentPane = new javax.swing.JPanel JavaDoc();
435             jContentPane.setLayout(new java.awt.BorderLayout JavaDoc());
436             jContentPane.add(getBackPanel(), java.awt.BorderLayout.CENTER);
437         }
438         return jContentPane;
439     }
440
441     /**
442      * This method initializes jPanel
443      *
444      * @return javax.swing.JPanel
445      */

446     private JPanel JavaDoc getBackPanel() {
447         if (backPanel == null) {
448             backPanel = new JPanel JavaDoc();
449             backPanel.setLayout(new BorderLayout JavaDoc());
450             backPanel.add(getButtonPanell(), java.awt.BorderLayout.SOUTH);
451             backPanel.add(getSettingPanel(), java.awt.BorderLayout.CENTER);
452         }
453         return backPanel;
454     }
455
456     /**
457      * This method initializes jPanel1
458      *
459      * @return javax.swing.JPanel
460      */

461     private JPanel JavaDoc getButtonPanell() {
462         if (buttonPanell == null) {
463             buttonPanell = new JPanel JavaDoc();
464             buttonPanell.setPreferredSize(new java.awt.Dimension JavaDoc(10, 35));
465             buttonPanell.setBorder(javax.swing.BorderFactory
466                     .createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
467             buttonPanell.add(getConfigureButton(), null);
468             buttonPanell.add(getCloseButton(), null);
469         }
470         return buttonPanell;
471     }
472
473     /**
474      * This method initializes jButton
475      *
476      * @return javax.swing.JButton
477      */

478     private JButton JavaDoc getConfigureButton() {
479         if (configureButton == null) {
480             configureButton = new JButton JavaDoc();
481             configureButton.setPreferredSize(new java.awt.Dimension JavaDoc(100, 20));
482             configureButton.setText("Configure");
483             configureButton.setSelected(true);
484             configureButton.setToolTipText("Generate Enhydra Base Directory");
485             configureButton.setName("configureButton");
486             configureButton.addActionListener(new CustomActionListener());
487         }
488         return configureButton;
489     }
490
491     /**
492      * This method initializes jButton1
493      *
494      * @return javax.swing.JButton
495      */

496     private JButton JavaDoc getCloseButton() {
497         if (closeButton == null) {
498             closeButton = new JButton JavaDoc();
499             closeButton.setPreferredSize(new java.awt.Dimension JavaDoc(100, 20));
500             closeButton.setText("Close");
501             closeButton.setToolTipText("Close Enhydra Base Generator Dialog");
502             closeButton.setName("closeButton");
503             closeButton.addActionListener(new CustomActionListener());
504         }
505         return closeButton;
506     }
507
508     /**
509      * This method initializes jPanel
510      *
511      * @return javax.swing.JPanel
512      */

513     private JPanel JavaDoc getSettingPanel() {
514         if (settingPanel == null) {
515
516             settingPanel = new JPanel JavaDoc();
517             settingPanel.setLayout(new BorderLayout JavaDoc());
518             settingPanel.setPreferredSize(new java.awt.Dimension JavaDoc(300, 35));
519             settingPanel.add(getTabBase(), java.awt.BorderLayout.CENTER);
520         }
521         return settingPanel;
522     }
523
524     private class CustomAction extends AbstractAction JavaDoc {
525         public void actionPerformed(ActionEvent JavaDoc ae) {
526             String JavaDoc command = ae.getActionCommand();
527             if ("Close".equals(command)) {
528                 System.exit(0);
529             } else if ("Configure".equals(command)) {
530                 getTabBase().setSelectedComponent(enhydraBasePanel);
531                 if (enhydraBasePanel.checkEntries()) {
532                     getTabBase().setSelectedComponent(adaptorPanel);
533                     if (adaptorPanel.checkEntries()) {
534                         getTabBase().setSelectedComponent(connectorPanel);
535                         if (connectorPanel.checkEntries()) {
536                             getTabBase().setSelectedComponent(serverPanel);
537                             if (serverPanel.checkEntries()) {
538                                 getTabBase().setSelectedComponent(
539                                         authenticationPanel);
540                                 if (authenticationPanel.checkEntries()) {
541                                     getTabBase()
542                                             .setSelectedComponent(javaPanel);
543                                     if (javaPanel.checkEntries()) {
544                                         getTabBase().setSelectedComponent(
545                                                 outputPanel);
546
547                                         new Thread JavaDoc() {
548                                             public void run() {
549                                                 saveProperties();
550                                                 executeConfiguration();
551                                             }
552                                         }.start();
553                                     }
554                                 }
555                             }
556                         }
557                     }
558                 }
559             }
560         }
561     }
562
563     private int executeConfiguration() {
564         outputPanel.clearText();
565         File JavaDoc root = new File JavaDoc(enhydraDir);
566         
567         String JavaDoc executable = "configure";
568         if (enhydraBasePanel != null && enhydraBasePanel.getBaseChecked()) {
569             executable = "configureBase";
570         }
571         if ('/' != File.separatorChar) {
572             executable = executable + ".bat";
573         }
574         
575         String JavaDoc execLine = enhydraDir + File.separator + executable;
576
577         execLine = execLine + " -jdk.dir " + jdkdir;
578
579         if (enhydraBasePanel != null && enhydraBasePanel.getBaseChecked()) {
580             execLine = execLine + " -base.dir " + basedir;
581         }
582
583         InputStream JavaDoc inputStream = null;
584         BufferedReader JavaDoc bufferedReader = null;
585
586         try {
587             Process JavaDoc process = Runtime.getRuntime().exec(execLine, null, root);
588
589             inputStream = process.getInputStream();
590             bufferedReader = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(
591                     inputStream));
592
593             String JavaDoc s = null;
594             while ((s = bufferedReader.readLine()) != null) {
595                 outputPanel.appendTextLine(s);
596                 s = null;
597             }
598
599             process.waitFor();
600             return process.exitValue();
601         } catch (Exception JavaDoc ex) {
602             System.out.println("Unable to execute configuration process!");
603             return -1;
604         } finally {
605             try {
606                 if (inputStream != null)
607                     inputStream.close();
608                 if (bufferedReader != null)
609                     bufferedReader.close();
610             } catch (Exception JavaDoc exc) {
611                 System.out.println("Unable to close process stream!");
612             }
613         }
614     }
615
616     private class CustomActionListener implements ActionListener JavaDoc {
617
618         protected AbstractAction JavaDoc action;
619
620         public CustomActionListener() {
621             action = new CustomAction();
622         }
623
624         public void actionPerformed(ActionEvent JavaDoc e) {
625             action.actionPerformed(e);
626         }
627     }
628
629     public void setEnhydraDir(String JavaDoc enhydraDir) {
630         this.enhydraDir = enhydraDir;
631     }
632
633     public String JavaDoc getEnhydraDir() {
634         return enhydraDir;
635     }
636
637     /**
638      * This method initializes jTabbedPane
639      *
640      * @return javax.swing.JTabbedPane
641      */

642     private JTabbedPane JavaDoc getTabBase() {
643         if (tabBase == null) {
644             tabBase = new JTabbedPane JavaDoc();
645             tabBase.setName("tabBase");
646         }
647         return tabBase;
648     }
649 }
Popular Tags