001: /**
002: * $RCSfile: VAWizard.java,v $
003: * @creation 01/02/00
004: * @modification $Date: 2004/02/02 20:57:58 $
005: */package com.memoire.vainstall.gui;
006:
007: import java.awt.*;
008: import java.awt.event.ActionListener;
009: import java.awt.event.ActionEvent;
010: import javax.swing.*;
011: import javax.swing.border.*;
012: import com.memoire.vainstall.VAStep;
013: import com.memoire.vainstall.VAWizardInterface;
014: import com.memoire.vainstall.VAGlobals;
015: import com.memoire.vainstall.VAWelcomeStep;
016: import com.memoire.vainstall.VALanguageStep;
017:
018: /**
019: * @version $Id: VAWizard.java,v 1.9 2004/02/02 20:57:58 deniger Exp $
020: * @author Axel von Arnim
021: */
022:
023: public class VAWizard extends JDialog implements VAWizardInterface,
024: ActionListener {
025: private static VAWizard UNIQUE_WIZARD = null;
026: JButton btNext_, btBack_, btCancel_;
027: VAPanel panel_;
028: JPanel pnNav_;
029:
030: protected VAWizard() {
031: super ();
032: init();
033: }
034:
035: protected void init() {
036: super .setTitle(VAGlobals.i18n("UI_Title"));
037: super .setDefaultCloseOperation(HIDE_ON_CLOSE);
038: setModal(true);
039:
040: Container cp = getContentPane();
041: cp.setLayout(new BorderLayout());
042: cp.setBackground(Color.red);
043:
044: pnNav_ = new JPanel();
045: pnNav_.setLayout(new FlowLayout(FlowLayout.RIGHT));
046: pnNav_.setBorder(new CompoundBorder(new EtchedBorder(),
047: new EmptyBorder(new Insets(5, 5, 5, 5))));
048: btNext_ = new JButton(VAGlobals.i18n("UI_Next"));
049: btBack_ = new JButton(VAGlobals.i18n("UI_Back"));
050: btCancel_ = new JButton(VAGlobals.i18n("UI_Cancel"));
051: pnNav_.add(btCancel_);
052: pnNav_.add(btBack_);
053: pnNav_.add(btNext_);
054: btNext_.addActionListener(this );
055: btBack_.addActionListener(this );
056: btCancel_.addActionListener(this );
057:
058: panel_ = new VAPanel();
059: Dimension d = VAImagePanel.IMAGE_PANEL.getPreferredSize();
060: // System.out.println("image size: "+d.width+","+d.height);
061: panel_.setPreferredSize(new Dimension(d.width + 400, d.height));
062: cp.add(BorderLayout.CENTER, panel_);
063: cp.add(BorderLayout.SOUTH, pnNav_);
064: pack();
065: setResizable(false);
066:
067: // center dialog
068: Dimension dimScreen = Toolkit.getDefaultToolkit()
069: .getScreenSize();
070: this .setLocation((dimScreen.width - this .getSize().width) / 2,
071: (dimScreen.height - this .getSize().height) / 2);
072: }
073:
074: public static VAWizardInterface createWizard() {
075: if (UNIQUE_WIZARD == null)
076: UNIQUE_WIZARD = new VAWizard();
077: else
078: UNIQUE_WIZARD.init();
079: return UNIQUE_WIZARD;
080: }
081:
082: public void setStep(VAStep step) {
083: panel_ = (VAPanel) step;
084: Container pnContent = getContentPane();
085: pnContent.removeAll();
086: //panel_.setPreferredSize(new Dimension(600,400));
087: panel_.setBorder(new CompoundBorder(new EtchedBorder(),
088: new EmptyBorder(new Insets(5, 5, 5, 5))));
089: pnContent.add(BorderLayout.CENTER, panel_);
090:
091: // in case of language change we need to update the pnNav_ panel
092: // this is a hack due to the static way of handling language
093: if (step instanceof VAWelcomeStep
094: || step instanceof VALanguageStep) {
095: btNext_.setText(VAGlobals.i18n("UI_Next"));
096: btBack_.setText(VAGlobals.i18n("UI_Back"));
097: btCancel_.setText(VAGlobals.i18n("UI_Cancel"));
098: doLayout();
099: validate();
100: }
101:
102: pnContent.add(BorderLayout.SOUTH, pnNav_);
103: pnContent.doLayout();
104: invalidate();
105: pnContent.validate();
106: // Dimension size=getSize();
107: // setSize(new Dimension(size.width, size.height));
108: Dimension size = getSize();
109: //setSize(new Dimension(size.width+1, size.height+1));
110: //repaint();
111: }
112:
113: public VAPanel getPanel() {
114: return panel_;
115: }
116:
117: public void setActionEnabled(int actions) {
118: btCancel_.setEnabled((actions & CANCEL) == CANCEL);
119: btBack_.setEnabled((actions & BACK) == BACK);
120: btNext_.setEnabled(((actions & NEXT) == NEXT)
121: || ((actions & FINISH) == FINISH));
122: if ((actions & FINISH) == FINISH) {
123: btNext_.setText(VAGlobals.i18n("UI_Finish"));
124: }
125: }
126:
127: public void actionPerformed(ActionEvent e) {
128: Object src = e.getSource();
129: if (src == btCancel_)
130: dispose(true);
131: else if (src == btBack_)
132: panel_.backAction();
133: else if (src == btNext_) {
134: // OSX Repaint
135: // Necessary for Mac OS X MRJ.
136: // On Mac OS X RepaintManger.currentManager().paintDirtyRegions()
137: // does not work. Hence, calls to VAInstallStep.details
138: // VAInstallStep.status and to the progess bar do not work
139: // on OS X (build 1.4.1_01-69.1 [late 2003] and for several
140: // builds before that one).
141: //
142: // A work around to the problem is to do work from a thread
143: // other than the event dispatch thread. Here, a new thread
144: // is launched. Associated with this, all calls to
145: // RepaintManager.currentManager().paintDirtyRegions()
146: // have been commented out. They have been labeled
147: // with "OSX Repaint - see VAWizard.java" so that the original mode
148: // of operation can be restored if Apple ever gets its act together.
149: // The modification works fine on Linux and Windows.
150: //
151: // Note that use of Runnable causes the class file VAWizard$1.class
152: // to be generated. It has been added to VAArchiver.java. If you
153: // eliminate the use of a new thread here, remove the entry from
154: // VAArchiver.java
155: Runnable runner = new Runnable() {
156: public void run() {
157: panel_.nextAction();
158: }
159: };
160: new Thread(runner).start();
161: }
162: }
163:
164: public void hide(boolean question) {
165: if (question) {
166: int res = JOptionPane.showConfirmDialog(this , VAGlobals
167: .i18n("UI_AbortQuestion"), VAGlobals
168: .i18n("UI_Finish"), JOptionPane.YES_NO_OPTION,
169: JOptionPane.QUESTION_MESSAGE);
170: if (res == JOptionPane.YES_OPTION) {
171: panel_.cancelAction();
172: }
173: } else
174: super .hide();
175: }
176:
177: public void dispose() {
178: hide(true);
179: }
180:
181: public void dispose(boolean confirm) {
182: hide(confirm);
183: }
184:
185: public void show() {
186: super .show();
187: }
188:
189: public void hide() {
190: hide(true);
191: }
192: }
|