1 package org.apache.axis.tool.service.swing.ui; 2 3 import java.awt.HeadlessException ; 4 import java.awt.Toolkit ; 5 import java.awt.event.ActionEvent ; 6 import java.awt.event.ActionListener ; 7 8 import javax.swing.JButton ; 9 import javax.swing.JFrame ; 10 import javax.swing.JOptionPane ; 11 import javax.swing.JPanel ; 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 32 33 public class MainWindow extends JFrame { 34 35 private JPanel wizardPaneContainer; 36 private JButton nextButton; 37 private JButton previousButton; 38 private JButton cancelButton; 39 private JButton 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 48 49 private WizardBean wizardBean = new WizardBean(); 50 51 public MainWindow() throws HeadlessException { 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 (null); 72 this.getContentPane().add(this.wizardPaneContainer); 73 this.wizardPaneContainer.setBounds(0,0,400,300); 74 75 this.previousButton = new JButton ("Previous"); 76 this.getContentPane().add(this.previousButton); 77 this.previousButton.setBounds(hgap,300+vgap,bWidth,bHeight); 78 this.previousButton.addActionListener(new ActionListener (){ 79 public void actionPerformed(ActionEvent e) { 80 moveBackWard(); 81 } 82 83 }); 84 this.nextButton= new JButton ("Next"); 86 this.getContentPane().add(this.nextButton); 87 this.nextButton.setBounds(hgap +bWidth + hgap,300 + vgap,bWidth,bHeight); 88 this.nextButton.addActionListener(new ActionListener (){ 89 public void actionPerformed(ActionEvent e) { 90 moveForward(); 91 } 92 }); 93 94 this.cancelButton= new JButton ("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 (){ 98 public void actionPerformed(ActionEvent e) { 99 if (confirmExit()) 100 System.exit(0); 101 } 102 }); 103 104 this.finishButton= new JButton ("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 (){ 108 public void actionPerformed(ActionEvent e) { 109 processFinish(); 110 } 111 }); 112 113 114 115 this.currentPage = PAGE_1; 116 moveToPage(currentPage); } 118 119 private void showErrorMessage(){ 120 JOptionPane.showMessageDialog(this,"Required Value Not set!!!","Error",JOptionPane.ERROR_MESSAGE); 121 } 122 123 private void showErrorMessage(String message){ 124 JOptionPane.showMessageDialog(this,message,"Error",JOptionPane.ERROR_MESSAGE); 125 } 126 127 private void showSuccessMessage(String 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 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 [] args) { 198 new MainWindow().show(); 199 } 200 201 202 } 203 | Popular Tags |