Package ca.cgjennings.ui.wizard
Class AbstractWizardModel
- java.lang.Object
-
- ca.cgjennings.ui.wizard.AbstractWizardModel
-
- All Implemented Interfaces:
WizardModel
- Direct Known Subclasses:
DefaultWizardModel
public abstract class AbstractWizardModel extends java.lang.Object implements WizardModel
An abstract base class for wizard models. This base class provides all the functionality required by a wizard model except forWizardModel.getPageOrder()
. Because the implementations of the other methods must callgetPageOrder()
, subclasses that do not represent the page order internally as an array should consider caching thegetPageOrder()
for performance reasons.- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
blocked
protected int
curPage
protected java.util.LinkedList<WizardListener>
listeners
-
Constructor Summary
Constructors Constructor Description AbstractWizardModel()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
aboutToHide(int index, javax.swing.JComponent page)
Called before the current page is hidden when switching pages.void
aboutToShow(int index, javax.swing.JComponent page)
Called before a page is displayed.void
addWizardListener(WizardListener li)
Adds a listener that will receiveWizardEvent
s from the model.int
backward()
Causes the model's internal representation to move to the previous page.boolean
canFinish()
Returnstrue
if the wizard can be finished in its current state.boolean
canGoBackward()
Returnstrue
if there is a page before the current page.boolean
canGoForward()
Returnstrue
if there is a page after the current page.protected void
checkPages()
java.lang.Object
finish()
Completes the wizard, causing any relevant actions to take place.protected void
fireBlockStateChanged()
protected void
fireFinished()
protected void
fireHidingPage(int oldPage, javax.swing.JComponent page)
protected void
firePageChanged(int newPage, javax.swing.JComponent page)
protected void
firePageOrderChanged()
protected void
fireReset()
protected void
fireShowingPage(int newPage, javax.swing.JComponent page)
int
forward()
Causes the model's internal representation to move to the next page.int
getCurrentPage()
Returns the index of the current page.javax.swing.JComponent
getCurrentPageComponent()
int
getPageCount()
Returns the number of pages in the current set of pages.boolean
isProgressBlocked()
Returnstrue
if progress is currently blocked.void
removeWizardListener(WizardListener li)
Removes a listener from the list of listeners so that it no longer receivesWizardEvent
s from the model.void
reset()
Resets the model.void
setCurrentPage(int index)
Sets the current page of the internal model.void
setProgressBlocked(boolean block)
Sets whether or not progress is blocked.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ca.cgjennings.ui.wizard.WizardModel
getPageOrder
-
-
-
-
Field Detail
-
blocked
protected boolean blocked
-
curPage
protected int curPage
-
listeners
protected java.util.LinkedList<WizardListener> listeners
-
-
Method Detail
-
aboutToHide
public void aboutToHide(int index, javax.swing.JComponent page)
Description copied from interface:WizardModel
Called before the current page is hidden when switching pages. After this is called, but beforeWizardModel.aboutToShow(int, javax.swing.JComponent)
is called,WizardModel.getPageOrder()
will be called to determine if the page order has changed.- Specified by:
aboutToHide
in interfaceWizardModel
- Parameters:
index
- the index of the currently displayed pagepage
- the page component that corresponds to the index- See Also:
WizardModel.aboutToShow(int, javax.swing.JComponent)
-
aboutToShow
public void aboutToShow(int index, javax.swing.JComponent page)
Description copied from interface:WizardModel
Called before a page is displayed. The following procedure describes how the model is consulted when moving to a new page:- User clicks next (or back).
-
WizardModel.aboutToHide(int, javax.swing.JComponent)
called for current page. -
WizardModel.forward()
(orWizardModel.backward()
) is called. -
WizardModel.getPageOrder()
andWizardModel.getCurrentPage()
called to determine which page to display. -
WizardModel.aboutToShow(int, javax.swing.JComponent)
called for new current page. - New page is displayed. Back, next, and finish buttons are updated to
enable them based on
WizardModel.canGoBackward()
and related methods.
- Specified by:
aboutToShow
in interfaceWizardModel
- Parameters:
index
- the index of the page to be shownpage
- the page component that corresponds to the index- See Also:
WizardModel.aboutToHide(int, javax.swing.JComponent)
-
addWizardListener
public void addWizardListener(WizardListener li)
Description copied from interface:WizardModel
Adds a listener that will receiveWizardEvent
s from the model.- Specified by:
addWizardListener
in interfaceWizardModel
- Parameters:
li
- the listener to add
-
backward
public int backward()
Description copied from interface:WizardModel
Causes the model's internal representation to move to the previous page.- Specified by:
backward
in interfaceWizardModel
- Returns:
- the new page index
- See Also:
WizardModel.canGoBackward()
-
canFinish
public boolean canFinish()
Description copied from interface:WizardModel
Returnstrue
if the wizard can be finished in its current state. This method must always returnfalse
when progress is blocked.- Specified by:
canFinish
in interfaceWizardModel
- Returns:
- whether the finish button should be enabled
- See Also:
WizardModel.isProgressBlocked()
-
canGoBackward
public boolean canGoBackward()
Description copied from interface:WizardModel
Returnstrue
if there is a page before the current page.- Specified by:
canGoBackward
in interfaceWizardModel
- Returns:
- whether the previous button should be enabled
-
canGoForward
public boolean canGoForward()
Description copied from interface:WizardModel
Returnstrue
if there is a page after the current page. This method must always returnfalse
when progress is blocked.- Specified by:
canGoForward
in interfaceWizardModel
- Returns:
- whether the next button should be enabled
- See Also:
WizardModel.isProgressBlocked()
-
checkPages
protected void checkPages()
-
finish
public java.lang.Object finish()
Description copied from interface:WizardModel
Completes the wizard, causing any relevant actions to take place. It may optionally return an arbitrary object to represent this result.- Specified by:
finish
in interfaceWizardModel
- Returns:
- an optional result, or
null
- See Also:
WizardModel.canFinish()
-
fireBlockStateChanged
protected void fireBlockStateChanged()
-
fireFinished
protected void fireFinished()
-
fireHidingPage
protected void fireHidingPage(int oldPage, javax.swing.JComponent page)
-
firePageChanged
protected void firePageChanged(int newPage, javax.swing.JComponent page)
-
firePageOrderChanged
protected void firePageOrderChanged()
-
fireReset
protected void fireReset()
-
fireShowingPage
protected void fireShowingPage(int newPage, javax.swing.JComponent page)
-
forward
public int forward()
Description copied from interface:WizardModel
Causes the model's internal representation to move to the next page.- Specified by:
forward
in interfaceWizardModel
- Returns:
- the new page index
- See Also:
WizardModel.canGoForward()
-
getCurrentPage
public int getCurrentPage()
Description copied from interface:WizardModel
Returns the index of the current page.- Specified by:
getCurrentPage
in interfaceWizardModel
- Returns:
- the index of the element in
WizardModel.getPageOrder()
that represents the current page
-
getPageCount
public int getPageCount()
Description copied from interface:WizardModel
Returns the number of pages in the current set of pages.- Specified by:
getPageCount
in interfaceWizardModel
- Returns:
- the number of pages in the wizard
-
isProgressBlocked
public boolean isProgressBlocked()
Description copied from interface:WizardModel
Returnstrue
if progress is currently blocked.- Specified by:
isProgressBlocked
in interfaceWizardModel
- Returns:
true
if the user is blocked from continuing
-
removeWizardListener
public void removeWizardListener(WizardListener li)
Description copied from interface:WizardModel
Removes a listener from the list of listeners so that it no longer receivesWizardEvent
s from the model.- Specified by:
removeWizardListener
in interfaceWizardModel
- Parameters:
li
- the listener to removes
-
reset
public void reset()
Description copied from interface:WizardModel
Resets the model. This is called when the model is installed in a dialog. It allows the model to be reused in multiple dialogs. This will reset the current page to its initial value and will typically reset the interface components that represent the wizard pages to an initial state. (Alternatively, any existing page components may be thrown out and a new set created.)- Specified by:
reset
in interfaceWizardModel
-
setCurrentPage
public void setCurrentPage(int index)
Description copied from interface:WizardModel
Sets the current page of the internal model.- Specified by:
setCurrentPage
in interfaceWizardModel
- Parameters:
index
- the new page index
-
getCurrentPageComponent
public javax.swing.JComponent getCurrentPageComponent()
-
setProgressBlocked
public void setProgressBlocked(boolean block)
Description copied from interface:WizardModel
Sets whether or not progress is blocked. When progress is blocked,WizardModel.canGoForward()
andWizardModel.canFinish()
must always returnfalse
. The progress blocking state can be cleared by calling this method with false, and is cleared automatically if the page changes. Blocking provides a mechanism for individual pages to prevent progress if they are missing required information.- Specified by:
setProgressBlocked
in interfaceWizardModel
- Parameters:
block
- iftrue
, prevents the user from going to the next page or finishing the dialog.
-
-