|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container java.awt.Window java.awt.Dialog javax.swing.JDialog org.freixas.jwizard.JWizardDialog
public class JWizardDialog
This class creates a Wizard dialog.
I wrote this class because I couldn't find a good, free, easy-to-use, well-documented Java Wizard dialog. I hope this one is both flexible and easy-to-use.
A wizard is a dialog that leads a user through a procedure step-by-step. Some Wizards only gather information until the very last step, when they execute some tasks. Others will perform actions as they go.
To create a Wizard, you need two deal with two classes: JWizardDialog (this class) and JWizardPanel. The basic steps are:
Each JWizardPanel consists of a step title (which should be specific to each step) and a set of components which you layout as you wish. If possible, you should try to create and layout all panel components at construction time (so that the Wizard size can be accurately determined). If you need some dynamic layout, the method makingVisible() is called each time prior to making the JWizardPanel step visible.
The Wizard has four buttons which always appear, although they may at times be disabled. The buttons are Back, Next, Finish and Cancel. You can also add a Help button with addHelpButton().
When the buttons are pressed, they call the methods back(), next(), finish(), cancel() and help(), respectively. You can override any of these. The default finish() and cancel() methods call dispose(); when you override these, you would usually finish by calling super.finish() or super.cancel().
The default back(), next() and help() methods call equivalent methods in the current JWizardPanel. You would not normally override these methods, but the hooks are there if you need them.
In the JWizardPanel, the default back() and next() methods usally go to the previous or next panel. You can change the panel they go to by calling setBackPanel() or setNextPanel(), giving the index of the panel to go to. A value of -1 disables the corresponding button. Again, you can override these and then finish by calling super.back() or super.next(). The default help() method does nothing.
The Finish button is normally enabled only on the last step. If you allow an early exit from the Wizard, call setEarlyFinish() and the Finish button will be enabled.
The Cancel button is normally always enabled. To disable it on the last step, call disableCancelAtEnd().
Just prior to switching steps, switchToStep() is called in JWizardDialog. This method supplies the current and new step indices. The return value is the index of the panel which will actually be displayed. The default method returns the input value, but you can override this if you need special flow control in the JWizardDialog rather than the JWizardPanel.
When the dialog is displayed, it is normally centered over its parent. If there is no Frame parent, it is centered on the screen. You can disable this with disableCentering(), which must be called before the JWizardDialog is made visible.
That's about all there is to it.
JWizardPanel
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JDialog |
---|
JDialog.AccessibleJDialog |
Nested classes/interfaces inherited from class java.awt.Dialog |
---|
Dialog.AccessibleAWTDialog |
Nested classes/interfaces inherited from class java.awt.Window |
---|
Window.AccessibleAWTWindow |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary |
---|
Fields inherited from class javax.swing.JDialog |
---|
accessibleContext, rootPane, rootPaneCheckingEnabled |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface javax.swing.WindowConstants |
---|
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
JWizardDialog()
Creates a non-modal JWizardDialog without a title and without a specified Frame owner. |
|
JWizardDialog(Dialog owner)
Creates a non-modal JWizardDialog without a title with the specified Dialog as its owner. |
|
JWizardDialog(Dialog owner,
boolean modal)
Creates a modal or non-modal JWizardDialog without a title and with the specified owner Dialog. |
|
JWizardDialog(Dialog owner,
String title)
Creates a non-modal JWizardDialog with the specified title and with the specified owner frame. |
|
JWizardDialog(Dialog owner,
String title,
boolean modal)
Creates a modal or non-modal JWizardDialog with the specified title and the specified owner Dialog. |
|
JWizardDialog(Dialog owner,
String title,
boolean modal,
GraphicsConfiguration gc)
Creates a modal or non-modal JWizardDialog with the specified title, owner Dialog, and GraphicsConfiguration. |
|
JWizardDialog(Frame owner)
Creates a non-modal JWizardDialog without a title with the specified Frame as its owner. |
|
JWizardDialog(Frame owner,
boolean modal)
Creates a modal or non-modal JWizardDialog without a title and with the specified owner Frame. |
|
JWizardDialog(Frame owner,
String title)
Creates a non-modal JWizardDialog with the specified title and with the specified owner frame. |
|
JWizardDialog(Frame owner,
String title,
boolean modal)
Creates a modal or non-modal JWizardDialog with the specified title and the specified owner Frame. |
|
JWizardDialog(Frame owner,
String title,
boolean modal,
GraphicsConfiguration gc)
Creates a modal or non-modal JWizardDialog with the specified title, owner Frame, and GraphicsConfiguration. |
Method Summary | |
---|---|
void |
addHelpButton()
This adds a help button to the wizard. |
void |
addWizardPanel(JWizardPanel panel)
Add a panel representing a step in the wizard. |
protected void |
back()
Called when the Back button is pressed. |
protected void |
cancel()
Called when the Cancel button is pressed. |
void |
disableCancelAtEnd()
If this method is called, the Cancel button is disabled when on the last step. |
void |
disableCentering()
Don't center the dialog. |
protected void |
finish()
Called when the Finish button is pressed. |
int |
getCurrentStep()
Returns the current step being displayed by the wizard. |
int |
getLastStep()
Returns the last step displayed by the wizard. |
protected void |
help()
Called when the Help button is pressed. |
boolean |
isFinished()
Returns true if the wizard finished (the user pressed the Finish) button). |
protected void |
next()
Called when the Next button is pressed. |
void |
setEarlyFinish()
If this method is called, the Finish button is enabled immediately. |
void |
setWizardIcon(Icon icon)
Add an image which displays on the left side of the wizard. |
void |
show()
Deprecated. As of JDK version 1.1, replaced by setVisible(boolean). |
protected int |
switchToStep(int currentIndex,
int newIndex)
This method is called just prior to switching from one step to another (after any next() or back() method is called). |
Methods inherited from class java.awt.Dialog |
---|
addNotify, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setResizable, setTitle, setUndecorated |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public JWizardDialog() throws HeadlessException
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale().
HeadlessException
- If GraphicsEnvironment.isHeadless() returns true.public JWizardDialog(Frame owner) throws HeadlessException
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale().
owner
- The Frame owning the dialog.
HeadlessException
- If GraphicsEnvironment.isHeadless() returns true.public JWizardDialog(Frame owner, boolean modal) throws HeadlessException
owner
- The Frame owning the dialog.modal
- True for a modal dialog, false for one that allows
others windows to be active at the same time.
HeadlessException
- If GraphicsEnvironment.isHeadless() returns true.public JWizardDialog(Frame owner, String title) throws HeadlessException
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale().
owner
- The Frame owning the dialog.title
- The String to display in the dialog's title bar.
HeadlessException
- If GraphicsEnvironment.isHeadless() returns true.public JWizardDialog(Frame owner, String title, boolean modal) throws HeadlessException
NOTE: Any popup components (JComboBox, JPopupMenu, JMenuBar) created within a modal dialog will be forced to be lightweight.
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale().
owner
- The Frame owning the dialog.title
- The String to display in the dialog's title bar.modal
- True for a modal dialog, false for one that allows
others windows to be active at the same time.
HeadlessException
- If GraphicsEnvironment.isHeadless() returns true.public JWizardDialog(Frame owner, String title, boolean modal, GraphicsConfiguration gc) throws HeadlessException
NOTE: Any popup components (JComboBox, JPopupMenu, JMenuBar) created within a modal dialog will be forced to be lightweight.
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.
owner
- The Frame owning the dialog.title
- The String to display in the dialog's title bar.modal
- True for a modal dialog, false for one that allows
others windows to be active at the same time.gc
- The GraphicsConfiguration of the target screen device. If
gc is null, the same GraphicsConfiguration as the owning Frame
is used.
HeadlessException
- If GraphicsEnvironment.isHeadless() returns true.public JWizardDialog(Dialog owner) throws HeadlessException
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale().
owner
- The Dialog owning the dialog.
HeadlessException
- If GraphicsEnvironment.isHeadless() returns true.public JWizardDialog(Dialog owner, boolean modal) throws HeadlessException
owner
- The Dialog owning the dialog.modal
- True for a modal dialog, false for one that allows
others windows to be active at the same time.
HeadlessException
- If GraphicsEnvironment.isHeadless() returns true.public JWizardDialog(Dialog owner, String title) throws HeadlessException
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale().
owner
- The Dialog owning the dialog.title
- The String to display in the dialog's title bar.
HeadlessException
- If GraphicsEnvironment.isHeadless() returns true.public JWizardDialog(Dialog owner, String title, boolean modal) throws HeadlessException
NOTE: Any popup components (JComboBox, JPopupMenu, JMenuBar) created within a modal dialog will be forced to be lightweight.
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale().
owner
- The Dialog owning the dialog.title
- The String to display in the dialog's title bar.modal
- True for a modal dialog, false for one that allows
others windows to be active at the same time.
HeadlessException
- If GraphicsEnvironment.isHeadless() returns true.public JWizardDialog(Dialog owner, String title, boolean modal, GraphicsConfiguration gc) throws HeadlessException
NOTE: Any popup components (JComboBox, JPopupMenu, JMenuBar) created within a modal dialog will be forced to be lightweight.
This constructor sets the component's locale property to the value returned by JComponent.getDefaultLocale.
owner
- The Dialog owning the dialog.title
- The String to display in the dialog's title bar.modal
- True for a modal dialog, false for one that allows
others windows to be active at the same time.gc
- The GraphicsConfiguration of the target screen device. If
gc is null, the same GraphicsConfiguration as the owning Dialog
is used.
HeadlessException
- If GraphicsEnvironment.isHeadless() returns true.Method Detail |
---|
public void setWizardIcon(Icon icon)
icon
- The icon representing the image to display. If null, no
image is displayed.public void addWizardPanel(JWizardPanel panel)
panel
- The JWizardPanel to addpublic void addHelpButton()
help()
public void setEarlyFinish()
public boolean isFinished()
public void disableCancelAtEnd()
public void disableCentering()
public int getCurrentStep()
public int getLastStep()
public void show()
show
in class Dialog
protected void back()
JWizardPanel.back()
protected void next()
JWizardPanel.next()
protected void finish()
protected void cancel()
protected void help()
protected int switchToStep(int currentIndex, int newIndex)
currentIndex
- The index of the current JWizardPanel.newIndex
- The index of the JWizardPanel we are about to
display.
|
Copyright © 2004-2005 Antonio Freixas Licensed under the Artistic License |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |