Class Wizard
- All Implemented Interfaces:
ActionListener
,ImageObserver
,MenuContainer
,Serializable
,EventListener
,Observer
,Accessible
JPanel
component. Typically you would not instantiate
a wizard directly, but instead you would create a WizardDialog
or
WizardFrame
, and then access the Wizard that is embedded inside of
those objects.
A Wizard should contain one or more steps. Steps are encapsulated in
WizardPane
objects. WizardPane's are panels on which you may
add instructions and input controls. You would not usually add components
directly to the panel, instead use the WizardPane
methods to control how specialized components are added to the panes.
The specialized controls include text input fields, combo boxes, lists,
file choosers, etc., and include the event handlers needed to
capture the input.
The first step (pane) in the process can be retrieved
from the Wizard using the getFirstStep()
method. Subsequent
steps are chained to each WizardPane, and are created using the
WizardPane.addNextStep()
method. Ultimately a wizard is
composed of a frame or dialog and a chain of WizardPanes.
Progress from step to step can be controlled through the use of
WizardCompletionTester
completion test handlers. These
test handlers can be assigned to each step, or to the component
as a whole. The test handlers will be called each time a control
is changed, and each time a pane is entered. A global test handler
will control the behaviour of the finish button. If the handler returns
true, the finish button will be enabled. If false, the finish button
will be disabled.
If a completetion test handler is assigned to a step, it will control the behaviour of the next button. If the test handler on the step returns true then the next button will be enabled. If false, the next button will be disabled. Step handlers are only invoked if the step is visible. If the final step is visible, the step handler will also control the behaviour of the finish button.
After configuring the steps, call start to activate the
wizard. The start2()
method will return with either
FINISHED
or CANCELLED
depending on the
method of termination.
After the wizard has terminated use the get() methods to extract
values. Alternatively, the translate(String)
method provides a
convenient way to interpolate values into a string.
You may optionally assign a task to be run when the finish button
on the wizard is clicked. The task is specified as an object that
implements the Runnable
interface. In this case the wizard
will display a interterminable JProgressBar
. If the obs parameter
is non-null, a determinate progress bar will be used instead.
- See Also:
WizardPane
,WizardFrame
,WizardDialog
, Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic boolean
static int
A constant result value indicating that the cancel button has been pressed.static boolean
static int
A constant result value indicating that the finish button has been pressed.static boolean
static boolean
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
The ActionListener interface is implemented in this class to catch the events generated by the navigation buttons on the main panel.boolean
getBoolean(String label)
Retrieve a boolean value from the wizard.boolean
getComponent(String var)
Get the current pane in this wizard.double
Retrieve a double value from the wizard.Retrieve a File value from the wizard.Return the initial step of the Wizardint
Retrieve an integer value from the wizard.int[]
getIntArray(String label)
Retrieve an attribute from the wizard.Get a reference to the parent window container for this Wizard.int
Get the status code.Retrieve a string value from the wizard.boolean
Test if the key is found in the dictionaryboolean
void
Set a data value in the wizard.removeItem(String label)
Remove a data value from the wizard.void
Request the window be closed.Reset the wizard with a new (blank) first step.void
setCloseWhenFinished(boolean state)
Set a flag so that the window will automatically close when the task is finished.void
Set a global conpletion test that will determine when the finish button is enabled.void
setContent(Component component)
Set the component inside the content pane.void
setCurrentPane(WizardPane pane)
Programatically set the current pane.void
setFinalTask(String label, Runnable task, Observable obs)
Set the task that will be executed when the finish button is clicked.setFirstStep(WizardPane step)
Set the wizard with a new first step.void
Set the default help associated with this wizard.void
setStatus(int status)
Set the status code.void
Set a status message to be displayed on the bottom of the wizard, just above the navigation buttons.boolean
void
start2()
Start the wizard.Translate a string by replacing all sequences of %var% with the value of variable 'var' taken from the attribute hash table.void
update(Observable object, Object arg)
Implements Observer interface to listen to progress messages from the final task.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
CANCELLED
public static final int CANCELLEDA constant result value indicating that the cancel button has been pressed.- See Also:
- Constant Field Values
-
FINISHED
public static final int FINISHEDA constant result value indicating that the finish button has been pressed.- See Also:
- Constant Field Values
-
ENTER
public static final boolean ENTER- See Also:
- Constant Field Values
-
LEAVE
public static final boolean LEAVE- See Also:
- Constant Field Values
-
FORWARD
public static final boolean FORWARD- See Also:
- Constant Field Values
-
BACKWARD
public static final boolean BACKWARD- See Also:
- Constant Field Values
-
-
Constructor Details
-
Wizard
The only constructor. Most applications should not instantiate this directly, but should instead useWizardDialog
orWizardFrame
.
-
-
Method Details
-
getParentWindow
Get a reference to the parent window container for this Wizard. -
getAppIcon
-
setContent
Set the component inside the content pane. Most applications will not use this method.- Parameters:
component
- The component to display inside of the wizard.
-
setFinalTask
Set the task that will be executed when the finish button is clicked.- Parameters:
label
- A String label to be displayed above the progress bar.task
- A object of type Runnable that will be invoked when the finish button is clicked.obs
- A object of type Observable that will emit progress notifications from the final task. This value may be null, in which case the progress bar will be indeterminant-style. The argument passed in the notification event shold be anInteger
in the range of 0 to 100.
-
setHelp
Set the default help associated with this wizard. The default help will be available on every pane, unless overridden by the custom help on an individual panel.- Parameters:
topic
- The help topic to display
-
setStatus
Set a status message to be displayed on the bottom of the wizard, just above the navigation buttons.- Parameters:
message
- The status message to display.
-
setStatusOk
public boolean setStatusOk() -
setCloseWhenFinished
public void setCloseWhenFinished(boolean state)Set a flag so that the window will automatically close when the task is finished. The default value is true. -
getCloseWhenFinished
public boolean getCloseWhenFinished() -
requestClose
public void requestClose()Request the window be closed. This will call the interrupt mechanism first. -
update
Implements Observer interface to listen to progress messages from the final task. If the final task has set anObservable
object, then this method will receive the notifications. The argument from the Observable is expected to be anInteger
object that ranges in value between 0 and 100. The progress bar will be set to the resulting value. -
setStatus
public void setStatus(int status) -
getStatus
public int getStatus() -
setCompletionTest
Set a global conpletion test that will determine when the finish button is enabled. If the value is null, then the finish button will be enabled when the last step is visible and the step completion handler (if not null) returns true. If non-null, the finish button will be enabled if the current step completion handler returns true and the global completion handler returns true. -
setCurrentPane
Programatically set the current pane. Do not automatically execute leave and entry actions. Caller is responsible to set up 'pane.prev' and 'currentPane.next' relationships. -
getCurrentPane
Get the current pane in this wizard. -
putItem
Set a data value in the wizard. Applications should generally not need to do this, but if they do they should take care. If you update a value that is being used by a control, the control will not update. -
removeItem
Remove a data value from the wizard. -
getItem
Retrieve an attribute from the wizard.- Parameters:
label
- A string label used as a key to retrieve a stored value from the wizard- Returns:
- An object reference to the stored value.
-
isDefined
Test if the key is found in the dictionary- Parameters:
label
- A string label used as a key to retrieve a stored value from the wizard
-
getComponent
-
isEnabled
-
getInt
Retrieve an integer value from the wizard.- Parameters:
label
- A string label used as a key to retrieve a stored value from the wizard- Returns:
- An int-valued interpretation of the stored object.
-
getDouble
Retrieve a double value from the wizard.- Parameters:
label
- A string label used as a key to retrieve a stored value from the wizard- Returns:
- A double-valued interpretation of the stored object.
-
getBoolean
Retrieve a boolean value from the wizard.- Parameters:
label
- A string label used as a key to retrieve a stored value from the wizard- Returns:
- A boolean-valued interpretation of the stored object.
-
getString
Retrieve a string value from the wizard.- Parameters:
label
- A string label used as a key to retrieve a stored value from the wizard- Returns:
- A string-valued interpretation of the stored object.
-
getFile
Retrieve a File value from the wizard.- Parameters:
label
- A string label used as a key to retrieve a stored value from the wizard- Returns:
- A file-valued interpretation of the stored object.
-
getIntArray
-
getFirstStep
Return the initial step of the Wizard- Returns:
- The first WizardPane object in the chain of steps for this wizard.
-
resetFirstStep
Reset the wizard with a new (blank) first step. All other steps are lost.- Returns:
- A new WizardPane object.
-
setFirstStep
Set the wizard with a new first step. The current first step (and all others that are chained to it) will be discarded.- Parameters:
step
- The step that is to be used as the first step in this wizard.- Returns:
- The reference to the first step.
-
start2
public void start2()Start the wizard. This will set the first pane, set up the navigation buttons, and show the the containing frame or dialog.If this is a dialog then this method will not return until the wizard has completed its actions and the window has been closed. If it is a frame then it will return right away.
The window will close upon the following conditions:
- the setCloseWhenFinished method has been set to true (default)
- the cancel or intterupt buttons have been pressed.
- the finish button has been clicked, and the final task (if any) has completed on a background thread.
Due to Swing threading rules this method must be invoked from the event dispatch thread.
-
actionPerformed
The ActionListener interface is implemented in this class to catch the events generated by the navigation buttons on the main panel.- Specified by:
actionPerformed
in interfaceActionListener
-
translate
Translate a string by replacing all sequences of %var% with the value of variable 'var' taken from the attribute hash table.If an attribute has not been defined then an empty string will be returned instead.
- Parameters:
command
- A String containing embedded substitution symbols. Each substitution symbol is of the form %var% where var is the label of the variable.- Returns:
- An interpolated string containing the results of the symbol substitution.
-