KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > tool > service > swing > ui > MainWindow


1 package org.apache.axis.tool.service.swing.ui;
2
3 import java.awt.HeadlessException JavaDoc;
4 import java.awt.Toolkit JavaDoc;
5 import java.awt.event.ActionEvent JavaDoc;
6 import java.awt.event.ActionListener JavaDoc;
7
8 import javax.swing.JButton JavaDoc;
9 import javax.swing.JFrame JavaDoc;
10 import javax.swing.JOptionPane JavaDoc;
11 import javax.swing.JPanel JavaDoc;
12
13 import org.apache.axis.tool.service.bean.WizardBean;
14 import org.apache.axis.tool.service.control.Controller;
15 import org.apache.axis.tool.service.control.ProcessException;
16
17 /*
18  * Copyright 2004,2005 The Apache Software Foundation.
19  *
20  * Licensed under the Apache License, Version 2.0 (the "License");
21  * you may not use this file except in compliance with the License.
22  * You may obtain a copy of the License at
23  *
24  * http://www.apache.org/licenses/LICENSE-2.0
25  *
26  * Unless required by applicable law or agreed to in writing, software
27  * distributed under the License is distributed on an "AS IS" BASIS,
28  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29  * See the License for the specific language governing permissions and
30  * limitations under the License.
31  */

32
33 public class MainWindow extends JFrame JavaDoc {
34
35     private JPanel JavaDoc wizardPaneContainer;
36     private JButton JavaDoc nextButton;
37     private JButton JavaDoc previousButton;
38     private JButton JavaDoc cancelButton;
39     private JButton JavaDoc finishButton;
40     private int currentPage;
41     private WizardPane currentWizardPane;
42
43     private static final int PAGE_1=1;
44     private static final int PAGE_2=2;
45     private static final int PAGE_3=3;
46     //private static final int PAGE_4=4;
47

48
49     private WizardBean wizardBean = new WizardBean();
50
51     public MainWindow() throws HeadlessException JavaDoc {
52         super("Axis 2 - Service Jar Builder");
53         init();
54
55     }
56
57     private void init(){
58         this.getContentPane().setLayout(null);
59
60         this.setBounds((int)Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2 - 400/2,
61                 (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()/2 - 360/2,
62                 400,360);
63         this.setResizable(false);
64         this.setDefaultCloseOperation(EXIT_ON_CLOSE);
65
66         int hgap = 5;
67         int vgap = 5;
68         int bWidth = 80;
69         int bHeight = 20;
70
71         this.wizardPaneContainer = new JPanel JavaDoc(null);
72         this.getContentPane().add(this.wizardPaneContainer);
73         this.wizardPaneContainer.setBounds(0,0,400,300);
74
75         this.previousButton = new JButton JavaDoc("Previous");
76         this.getContentPane().add(this.previousButton);
77         this.previousButton.setBounds(hgap,300+vgap,bWidth,bHeight);
78         this.previousButton.addActionListener(new ActionListener JavaDoc(){
79             public void actionPerformed(ActionEvent JavaDoc e) {
80                 moveBackWard();
81             }
82
83         });
84 //
85
this.nextButton= new JButton JavaDoc("Next");
86         this.getContentPane().add(this.nextButton);
87         this.nextButton.setBounds(hgap +bWidth + hgap,300 + vgap,bWidth,bHeight);
88         this.nextButton.addActionListener(new ActionListener JavaDoc(){
89             public void actionPerformed(ActionEvent JavaDoc e) {
90                 moveForward();
91             }
92         });
93
94         this.cancelButton= new JButton JavaDoc("Close");
95         this.getContentPane().add(this.cancelButton) ;
96         this.cancelButton.setBounds(hgap + (bWidth + hgap)*2,300 + vgap,bWidth,bHeight);
97         this.cancelButton.addActionListener(new ActionListener JavaDoc(){
98             public void actionPerformed(ActionEvent JavaDoc e) {
99                 if (confirmExit())
100                     System.exit(0);
101             }
102         });
103
104         this.finishButton= new JButton JavaDoc("Finish");
105         this.getContentPane().add(this.finishButton) ;
106         this.finishButton.setBounds(hgap + (bWidth + hgap)*3,300 + vgap,bWidth,bHeight);
107         this.finishButton.addActionListener(new ActionListener JavaDoc(){
108             public void actionPerformed(ActionEvent JavaDoc e) {
109                 processFinish();
110             }
111         });
112
113
114
115         this.currentPage = PAGE_1;
116         moveToPage(currentPage); //add the first page as default
117
}
118
119     private void showErrorMessage(){
120        JOptionPane.showMessageDialog(this,"Required Value Not set!!!","Error",JOptionPane.ERROR_MESSAGE);
121     }
122
123     private void showErrorMessage(String JavaDoc message){
124        JOptionPane.showMessageDialog(this,message,"Error",JOptionPane.ERROR_MESSAGE);
125     }
126
127     private void showSuccessMessage(String JavaDoc message){
128        JOptionPane.showMessageDialog(this,message,"Error",JOptionPane.INFORMATION_MESSAGE);
129     }
130
131     private boolean confirmExit(){
132         int returnType = JOptionPane.showOptionDialog(this,
133                 "Are you sure you want to exit?",
134                 "Exit service builder",
135                 JOptionPane.YES_NO_OPTION,
136                 JOptionPane.WARNING_MESSAGE,
137                 null,null,null);
138         return (returnType==JOptionPane.YES_OPTION);
139     }
140
141     private void moveForward(){
142         if (currentWizardPane.validateValues()){
143             this.currentPage ++;
144             moveToPage(this.currentPage);
145         }else{
146             showErrorMessage();
147         }
148     }
149
150     private void moveBackWard(){
151             this.currentPage --;
152             moveToPage(this.currentPage);
153
154     }
155
156     private void moveToPage(int page){
157         switch(page){
158             case PAGE_1:
159                 processPage(new WizardPane1(this.wizardBean, this),false,true,false);
160                 break;
161             case PAGE_2:
162                 processPage(new WizardPane2(this.wizardBean, this),true,true,false);
163                 break;
164             case PAGE_3:
165                 processPage(new WizardPane3(this.wizardBean, this),true,false,true);
166                 break;
167             default:
168                 return;
169         }
170     }
171     private void processFinish(){
172         if (currentWizardPane.validateValues()){
173             try {
174                 new Controller().process(wizardBean);
175                 showSuccessMessage(" jar file creation successful! ");
176             } catch (ProcessException e) {
177                 showErrorMessage(e.getMessage());
178             } catch (Exception JavaDoc e) {
179                 showErrorMessage("Unknown Error! " +e.getMessage() );
180             }
181         }else{
182             showErrorMessage();
183         }
184     }
185
186     private void processPage(WizardPane pane,boolean prevButtonState,boolean nextButtonState,boolean finishButtonState){
187         this.wizardPaneContainer.removeAll();
188         currentWizardPane = pane;
189         this.wizardPaneContainer.add(pane);
190         this.previousButton.setEnabled(prevButtonState);
191         this.nextButton.setEnabled(nextButtonState);
192         this.finishButton.setEnabled(finishButtonState);
193         this.repaint();
194     }
195
196
197     public static void main(String JavaDoc[] args) {
198         new MainWindow().show();
199     }
200
201
202 }
203
Popular Tags