Concepts
- A wizard is build of several screens.
- Previous and next screens decision is taken by the wizard class.
- Wizard data is stored in a Hashtable named data. It is accessible from Wizard and Screen class. Store and get options selected by the user here.
Wizard creation
- Create a class that extends Wizard. You have to implement getPreviousScreen(), getNextScreen() and finish() abstract methods.
- Displaying the wizard:
MyWizard wizard = new MyWizard(String sName,Class initial,
ImageIcon icon,Frame parentWindow,
Locale locale,int iHSize,int iVSize);
wizard.show();
- finish() method implements actions to be done at the end of the wizard
- getPreviousScreen() and getNextScreen() have to return previous or next screen class. Example:
public Class getNextScreen(Class screen) {
if (ActionSelectionPanel.class.equals(getCurrentScreen())){
String sAction = (String)data.get(KEY_ACTION);
if (ActionSelectionPanel.ACTION_CREATION.equals(sAction)){
return TypeSelectionPanel.class;
}
else if (ActionSelectionPanel.ACTION_DELETE.equals(sAction)){
return RemovePanel.class;
}
}
}
Screen creation
- For each wizard page, create a public Screen class. You have to implement initUI(), getDescription() and getName() abstract methods.
- getName() method should return the step name and getDescription() the step description (return null if no description needed).
- initUI() method contains graphical code for your screen. This method is automatically called from screen constructor so don't call it.
General use
- Set errors using the setProblem(String) method. The error will be displayed in red to the user at the bottom of the screen. When error is fixed, use a setProblem(null).
- Get and set wizard data using the data object available from wizard and screen classes.
- Use setCanFinish(true) method in a screen to set the fact that the screen is the last one (user can click on Finish button).
- By default, QDwizard keeps screens into memory so user can go previous or next and keep typed values. If you want to clear this cache, just make your screen(s) implement ClearPoint interface. When user will reach a screen that implements this interface, cache is cleaned up.
- The Screen class contains two empty methods onEnter() and onLeave() which are called by the wizard on entering and respectively before leaving the screen. You can override them if you want your screens to be notified on enter or leave. Note that this happens only in forwardmode, which means onEnter won't be called when you return to a screen via the previous button and onLeave won't be called when you leave the screen via the previous button.
- You can implement a cancel()method in your wizard, which will be called when the user presses the Cancel button.
Internationalization
- QDWizard supports at the moment following locales: English, French, German, Dutch, Spanish and Catalan. You can extend the i18n support for any locale xx by placing a qdwizard_xx.properties file in your classpath containing entries for Finish, Cancel, Previous and Next.