1 6 7 package com.memoire.vainstall.gui; 8 9 import java.awt.*; 10 import java.awt.event.ActionListener ; 11 import java.awt.event.ActionEvent ; 12 import javax.swing.*; 13 import javax.swing.border.*; 14 import com.memoire.vainstall.VAStep; 15 import com.memoire.vainstall.VAWizardInterface; 16 import com.memoire.vainstall.VAGlobals; 17 import com.memoire.vainstall.VAWelcomeStep; 18 import com.memoire.vainstall.VALanguageStep; 19 20 24 25 public class VAWizard 26 extends JDialog 27 implements VAWizardInterface, ActionListener 28 { 29 private static VAWizard UNIQUE_WIZARD=null; 30 JButton btNext_, btBack_, btCancel_; 31 VAPanel panel_; 32 JPanel pnNav_; 33 34 protected VAWizard() 35 { 36 super(); 37 init(); 38 } 39 40 protected void init() 41 { 42 super.setTitle(VAGlobals.i18n("UI_Title")); 43 super.setDefaultCloseOperation(HIDE_ON_CLOSE); 44 setModal(true); 45 46 Container cp=getContentPane(); 47 cp.setLayout(new BorderLayout()); 48 cp.setBackground(Color.red); 49 50 pnNav_=new JPanel(); 51 pnNav_.setLayout(new FlowLayout(FlowLayout.RIGHT)); 52 pnNav_.setBorder(new CompoundBorder(new EtchedBorder(), 53 new EmptyBorder(new Insets(5, 5, 5, 5)))); 54 btNext_=new JButton(VAGlobals.i18n("UI_Next")); 55 btBack_=new JButton(VAGlobals.i18n("UI_Back")); 56 btCancel_=new JButton(VAGlobals.i18n("UI_Cancel")); 57 pnNav_.add(btCancel_); 58 pnNav_.add(btBack_); 59 pnNav_.add(btNext_); 60 btNext_.addActionListener(this); 61 btBack_.addActionListener(this); 62 btCancel_.addActionListener(this); 63 64 panel_=new VAPanel(); 65 Dimension d=VAImagePanel.IMAGE_PANEL.getPreferredSize(); 66 panel_.setPreferredSize(new Dimension(d.width+400, d.height)); 68 cp.add(BorderLayout.CENTER, panel_); 69 cp.add(BorderLayout.SOUTH, pnNav_); 70 pack(); 71 setResizable(false); 72 73 Dimension dimScreen=Toolkit.getDefaultToolkit().getScreenSize(); 75 this.setLocation((dimScreen.width-this.getSize().width)/2, 76 (dimScreen.height-this.getSize().height)/2); 77 } 78 79 public static VAWizardInterface createWizard() 80 { 81 if( UNIQUE_WIZARD==null ) UNIQUE_WIZARD=new VAWizard(); 82 else UNIQUE_WIZARD.init(); 83 return UNIQUE_WIZARD; 84 } 85 86 public void setStep(VAStep step) 87 { 88 panel_=(VAPanel)step; 89 Container pnContent=getContentPane(); 90 pnContent.removeAll(); 91 panel_.setBorder(new CompoundBorder(new EtchedBorder(), 93 new EmptyBorder(new Insets(5, 5, 5, 5)))); 94 pnContent.add(BorderLayout.CENTER, panel_); 95 96 if(step instanceof VAWelcomeStep || 99 step instanceof VALanguageStep) { 100 btNext_.setText(VAGlobals.i18n("UI_Next")); 101 btBack_.setText(VAGlobals.i18n("UI_Back")); 102 btCancel_.setText(VAGlobals.i18n("UI_Cancel")); 103 doLayout(); 104 validate(); 105 } 106 107 pnContent.add(BorderLayout.SOUTH, pnNav_); 108 pnContent.doLayout(); 109 invalidate(); 110 pnContent.validate(); 111 Dimension size=getSize(); 114 } 117 118 public VAPanel getPanel() { return panel_; } 119 120 public void setActionEnabled(int actions) 121 { 122 btCancel_.setEnabled((actions&CANCEL)==CANCEL); 123 btBack_.setEnabled((actions&BACK)==BACK); 124 btNext_.setEnabled(((actions&NEXT)==NEXT)||((actions&FINISH)==FINISH)); 125 if( (actions&FINISH)==FINISH ) { 126 btNext_.setText(VAGlobals.i18n("UI_Finish")); 127 } 128 } 129 130 public void actionPerformed(ActionEvent e) 131 { 132 Object SRC=e.getSource(); 133 if( SRC==btCancel_ ) dispose(true); 134 else 135 if( SRC==btBack_ ) panel_.backAction(); 136 else 137 if( SRC==btNext_ ) 138 { 139 Runnable runner = new Runnable () { 161 public void run() { 162 panel_.nextAction(); 163 } 164 }; 165 new Thread (runner).start(); 166 } 167 } 168 169 public void hide(boolean question) 170 { 171 if( question ) { 172 int res=JOptionPane.showConfirmDialog( 173 this, 174 VAGlobals.i18n("UI_AbortQuestion"), 175 VAGlobals.i18n("UI_Finish"), 176 JOptionPane.YES_NO_OPTION, 177 JOptionPane.QUESTION_MESSAGE); 178 if( res==JOptionPane.YES_OPTION ) { 179 panel_.cancelAction(); 180 } 181 } else super.hide(); 182 } 183 184 public void dispose() 185 { 186 hide(true); 187 } 188 189 public void dispose(boolean confirm) 190 { 191 hide(confirm); 192 } 193 194 public void show() 195 { 196 super.show(); 197 } 198 199 public void hide() 200 { 201 hide(true); 202 } 203 } 204 | Popular Tags |