KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > memoire > vainstall > gui > VAWizard


1 /**
2  * $RCSfile: VAWizard.java,v $
3  * @creation 01/02/00
4  * @modification $Date: 2004/02/02 20:57:58 $
5  */

6
7 package com.memoire.vainstall.gui;
8
9 import java.awt.*;
10 import java.awt.event.ActionListener JavaDoc;
11 import java.awt.event.ActionEvent JavaDoc;
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 /**
21  * @version $Id: VAWizard.java,v 1.9 2004/02/02 20:57:58 deniger Exp $
22  * @author Axel von Arnim
23  */

24
25 public class VAWizard
26        extends JDialog
27        implements VAWizardInterface, ActionListener JavaDoc
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 // System.out.println("image size: "+d.width+","+d.height);
67
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     // center dialog
74
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_.setPreferredSize(new Dimension(600,400));
92
panel_.setBorder(new CompoundBorder(new EtchedBorder(),
93                                         new EmptyBorder(new Insets(5, 5, 5, 5))));
94     pnContent.add(BorderLayout.CENTER, panel_);
95
96     // in case of language change we need to update the pnNav_ panel
97
// this is a hack due to the static way of handling language
98
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();
112
// setSize(new Dimension(size.width, size.height));
113
Dimension size=getSize();
114     //setSize(new Dimension(size.width+1, size.height+1));
115
//repaint();
116
}
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 JavaDoc e)
131   {
132     Object JavaDoc 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      // OSX Repaint
140
// Necessary for Mac OS X MRJ.
141
// On Mac OS X RepaintManger.currentManager().paintDirtyRegions()
142
// does not work. Hence, calls to VAInstallStep.details
143
// VAInstallStep.status and to the progess bar do not work
144
// on OS X (build 1.4.1_01-69.1 [late 2003] and for several
145
// builds before that one).
146
//
147
// A work around to the problem is to do work from a thread
148
// other than the event dispatch thread. Here, a new thread
149
// is launched. Associated with this, all calls to
150
// RepaintManager.currentManager().paintDirtyRegions()
151
// have been commented out. They have been labeled
152
// with "OSX Repaint - see VAWizard.java" so that the original mode
153
// of operation can be restored if Apple ever gets its act together.
154
// The modification works fine on Linux and Windows.
155
//
156
// Note that use of Runnable causes the class file VAWizard$1.class
157
// to be generated. It has been added to VAArchiver.java. If you
158
// eliminate the use of a new thread here, remove the entry from
159
// VAArchiver.java
160
Runnable JavaDoc runner = new Runnable JavaDoc() {
161     public void run() {
162             panel_.nextAction();
163     }
164      };
165      new Thread JavaDoc(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