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 booleanblockedprotected intcurPageprotected java.util.LinkedList<WizardListener>listeners
-
Constructor Summary
Constructors Constructor Description AbstractWizardModel()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaboutToHide(int index, javax.swing.JComponent page)Called before the current page is hidden when switching pages.voidaboutToShow(int index, javax.swing.JComponent page)Called before a page is displayed.voidaddWizardListener(WizardListener li)Adds a listener that will receiveWizardEvents from the model.intbackward()Causes the model's internal representation to move to the previous page.booleancanFinish()Returnstrueif the wizard can be finished in its current state.booleancanGoBackward()Returnstrueif there is a page before the current page.booleancanGoForward()Returnstrueif there is a page after the current page.protected voidcheckPages()java.lang.Objectfinish()Completes the wizard, causing any relevant actions to take place.protected voidfireBlockStateChanged()protected voidfireFinished()protected voidfireHidingPage(int oldPage, javax.swing.JComponent page)protected voidfirePageChanged(int newPage, javax.swing.JComponent page)protected voidfirePageOrderChanged()protected voidfireReset()protected voidfireShowingPage(int newPage, javax.swing.JComponent page)intforward()Causes the model's internal representation to move to the next page.intgetCurrentPage()Returns the index of the current page.javax.swing.JComponentgetCurrentPageComponent()intgetPageCount()Returns the number of pages in the current set of pages.booleanisProgressBlocked()Returnstrueif progress is currently blocked.voidremoveWizardListener(WizardListener li)Removes a listener from the list of listeners so that it no longer receivesWizardEvents from the model.voidreset()Resets the model.voidsetCurrentPage(int index)Sets the current page of the internal model.voidsetProgressBlocked(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:WizardModelCalled 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:
aboutToHidein 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:WizardModelCalled 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:
aboutToShowin 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:WizardModelAdds a listener that will receiveWizardEvents from the model.- Specified by:
addWizardListenerin interfaceWizardModel- Parameters:
li- the listener to add
-
backward
public int backward()
Description copied from interface:WizardModelCauses the model's internal representation to move to the previous page.- Specified by:
backwardin interfaceWizardModel- Returns:
- the new page index
- See Also:
WizardModel.canGoBackward()
-
canFinish
public boolean canFinish()
Description copied from interface:WizardModelReturnstrueif the wizard can be finished in its current state. This method must always returnfalsewhen progress is blocked.- Specified by:
canFinishin interfaceWizardModel- Returns:
- whether the finish button should be enabled
- See Also:
WizardModel.isProgressBlocked()
-
canGoBackward
public boolean canGoBackward()
Description copied from interface:WizardModelReturnstrueif there is a page before the current page.- Specified by:
canGoBackwardin interfaceWizardModel- Returns:
- whether the previous button should be enabled
-
canGoForward
public boolean canGoForward()
Description copied from interface:WizardModelReturnstrueif there is a page after the current page. This method must always returnfalsewhen progress is blocked.- Specified by:
canGoForwardin 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:WizardModelCompletes the wizard, causing any relevant actions to take place. It may optionally return an arbitrary object to represent this result.- Specified by:
finishin 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:WizardModelCauses the model's internal representation to move to the next page.- Specified by:
forwardin interfaceWizardModel- Returns:
- the new page index
- See Also:
WizardModel.canGoForward()
-
getCurrentPage
public int getCurrentPage()
Description copied from interface:WizardModelReturns the index of the current page.- Specified by:
getCurrentPagein interfaceWizardModel- Returns:
- the index of the element in
WizardModel.getPageOrder()that represents the current page
-
getPageCount
public int getPageCount()
Description copied from interface:WizardModelReturns the number of pages in the current set of pages.- Specified by:
getPageCountin interfaceWizardModel- Returns:
- the number of pages in the wizard
-
isProgressBlocked
public boolean isProgressBlocked()
Description copied from interface:WizardModelReturnstrueif progress is currently blocked.- Specified by:
isProgressBlockedin interfaceWizardModel- Returns:
trueif the user is blocked from continuing
-
removeWizardListener
public void removeWizardListener(WizardListener li)
Description copied from interface:WizardModelRemoves a listener from the list of listeners so that it no longer receivesWizardEvents from the model.- Specified by:
removeWizardListenerin interfaceWizardModel- Parameters:
li- the listener to removes
-
reset
public void reset()
Description copied from interface:WizardModelResets 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:
resetin interfaceWizardModel
-
setCurrentPage
public void setCurrentPage(int index)
Description copied from interface:WizardModelSets the current page of the internal model.- Specified by:
setCurrentPagein interfaceWizardModel- Parameters:
index- the new page index
-
getCurrentPageComponent
public javax.swing.JComponent getCurrentPageComponent()
-
setProgressBlocked
public void setProgressBlocked(boolean block)
Description copied from interface:WizardModelSets 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:
setProgressBlockedin interfaceWizardModel- Parameters:
block- iftrue, prevents the user from going to the next page or finishing the dialog.
-
-