org.pietschy.wizard
Class AbstractWizardStep

java.lang.Object
  extended byorg.pietschy.wizard.AbstractWizardStep
All Implemented Interfaces:
WizardStep
Direct Known Subclasses:
WizardPaneStep

public abstract class AbstractWizardStep
extends java.lang.Object
implements WizardStep

This is the base class for all non panel related wizard steps. Subclasses must implement the abstract methods init(org.pietschy.wizard.WizardModel), WizardStep.prepare(), WizardStep.applyState() and WizardStep.getPreferredSize(). In addition an appropriate UI must be installed by calling setView(java.awt.Component).

The Wizard listens to property change events from the step and will update accordingly when ever setView(java.awt.Component), setComplete(boolean) or setBusy(boolean) is called.

An example is shown below.

    public class MyWizardStep
    extends WizardStep
    {
       private MyModel model;
       private JPanel mainView;
       private JCheckBox agreeCheckbox;
       private JTextArea license;

       public MyWizardStep()
       {
          super("My First Step", "A summary of the first step");

          // build and layout the components..
          mainView = new JPanel();
          agreeCheckbox = new JCheckBox("Agree");
          license = new JTextArea();
          mainView.setLayout(...);
          mainView.add(agreeCheckbox);
          ...

          // listen to changes in the state..
          agreeCheckbox.addItemListener(new ItemListener()
          {
             public void itemSelected(ItemEvent e)
             {
                // only continue if they agree
                MyWizardStep.this.setComplete(agreeCheckbox.isSelected());
             }
          });
       }

       public void init(WizardModel model)
       {
          this.model = (MyModel) model;
       }

       public void prepare()
       {
          // load our view...
          setView(mainView);
       }

       public void applyState()
       throws InvalidStateException
       {
          // display a progress bar of some kind..
          setView(myProgressView);

          setBusy(true);
          try
          {
             // do some work on another thread.. see Foxtrot
             ...
          }
          finally
          {
             setBusy(false);
          }

          // if error then throw an exception
          if (!ok)
          {
             // restore our original view..
             setView(mainView)
             throw new InvalidStateException("That didn't work!");
          }

          // this isn't really meaningful as we refuse to continue
          // while the checkbox is un-checked.
          model.setAcceptsLicense(agreeCheckbox.isSelected());
       }

       public void getPreferredSize()
       {
          // use the size of our main view...
          return mainView.getPreferredSize();
       }
    }
 


Field Summary
 
Fields inherited from interface org.pietschy.wizard.WizardStep
_ID_
 
Constructor Summary
AbstractWizardStep(java.lang.String name, java.lang.String summary)
          Creates a new step with the specified name and summary.
AbstractWizardStep(java.lang.String name, java.lang.String summary, javax.swing.Icon icon)
          Creates a new step with the specified name and summary.
 
Method Summary
 void abortBusy()
          Called by the wizard if the user presses cancel while the step is in a busy state.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
           
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
           
 javax.swing.Icon getIcon()
          Gets the Icon that represents this step.
 java.lang.String getName()
          Gets the name of this step.
 java.lang.String getSummary()
          Gets the summary of this step.
 java.awt.Component getView()
          Returns the current view this step is displaying.
abstract  void init(WizardModel model)
          Called to initialize the step.
 boolean isBusy()
          Checks if the current task is busy.
 boolean isComplete()
          Checks if this step is compete.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
           
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
           
 void setBusy(boolean busy)
          Sets the busy state of this wizard step.
 void setComplete(boolean complete)
          Marks this step as compete.
 void setIcon(javax.swing.Icon icon)
          Sets the Icon that represents this step.
 void setName(java.lang.String name)
          Sets the name of this step.
 void setSummary(java.lang.String summary)
          Sets the summary of this step.
protected  void setView(java.awt.Component component)
          Sets the current view this step is displaying.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.pietschy.wizard.WizardStep
applyState, getPreferredSize, prepare
 

Constructor Detail

AbstractWizardStep

public AbstractWizardStep(java.lang.String name,
                          java.lang.String summary)
Creates a new step with the specified name and summary. The name and summary are displayed in the wizard title block while this step is active.

Parameters:
name - the name of this step.
summary - a brief summary of this step or some usage guidelines.

AbstractWizardStep

public AbstractWizardStep(java.lang.String name,
                          java.lang.String summary,
                          javax.swing.Icon icon)
Creates a new step with the specified name and summary. The name and summary are displayed in the wizard title block while this step is active.

Parameters:
name - the name of this step.
summary - a brief summary of this step or some usage guidelines.
Method Detail

getName

public java.lang.String getName()
Gets the name of this step. This will be displayed in the title of the wizard while this step is active.

Specified by:
getName in interface WizardStep
Returns:
the name of this step.

setName

public void setName(java.lang.String name)
Sets the name of this step. This will be displayed in the title of the wizard while this step is active.

Parameters:
name - the name of this step.

getSummary

public java.lang.String getSummary()
Gets the summary of this step. This will be displayed in the title of the wizard while this step is active. The summary is typically an overview of the step or some usage guidelines for the user.

Specified by:
getSummary in interface WizardStep
Returns:
the summary of this step.

setSummary

public void setSummary(java.lang.String summary)
Sets the summary of this step. This will be displayed in the title of the wizard while this step is active. The summary is typically an overview of the step or some usage guidelines for the user.

Parameters:
summary - the summary of this step.

getIcon

public javax.swing.Icon getIcon()
Gets the Icon that represents this step.

Specified by:
getIcon in interface WizardStep
Returns:
the Icon that represents this step, or null if the step doesn't have an icon.

setIcon

public void setIcon(javax.swing.Icon icon)
Sets the Icon that represents this step.

Parameters:
icon - the Icon that represents this step, or null if the step doesn't have an icon.

getView

public java.awt.Component getView()
Returns the current view this step is displaying. This component will be displayed in the main section of the wizard with this step is active. This may changed at any time by calling setView(java.awt.Component) and the wizard will update accordingly.

Specified by:
getView in interface WizardStep
Returns:
the current view of the step.
See Also:
setView(java.awt.Component)

setView

protected void setView(java.awt.Component component)
Sets the current view this step is displaying. This component will be displayed in the main section of the wizard with this step is active. This method may changed at any time and the wizard will update accordingly.

Parameters:
component - the current view of the step.

isComplete

public boolean isComplete()
Checks if this step is compete. This method should return true if the wizard can proceed to the next step. This property is bound and changes can be made at anytime by calling setComplete(boolean) .

Specified by:
isComplete in interface WizardStep
Returns:
true if the wizard can proceed from this step, false otherwise.
See Also:
setComplete(boolean)

setComplete

public void setComplete(boolean complete)
Marks this step as compete. The wizard will not be able to proceed from this step until this property is configured to true.

Parameters:
complete - true to allow the wizard to proceed, false otherwise.
See Also:
isComplete()

isBusy

public boolean isBusy()
Checks if the current task is busy. This usually indicates that the step is performing a time consuming task on a background thread.

Specified by:
isBusy in interface WizardStep
Returns:
true if step is busy performing a background operation, false otherwise.
See Also:
WizardStep.abortBusy()

setBusy

public void setBusy(boolean busy)
Sets the busy state of this wizard step. This should usually be set when a time consuming task is being performed on a background thread. The Wizard responds by disabling the various buttons appropriately.

Wizard steps that go into a busy state must also implement abortBusy() to cancel any inprogress operation.

Parameters:
busy - true to mark the step as busy and disable further user action, false to return the wizard to its normal state.

init

public abstract void init(WizardModel model)
Called to initialize the step. This method will be called when the wizard is first initialising.

Specified by:
init in interface WizardStep
Parameters:
model - the model to which the step belongs.

abortBusy

public void abortBusy()
Called by the wizard if the user presses cancel while the step is in a busy state. Steps that are never busy need not override this method.

Specified by:
abortBusy in interface WizardStep

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Specified by:
addPropertyChangeListener in interface WizardStep

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Specified by:
removePropertyChangeListener in interface WizardStep

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener listener)
Specified by:
addPropertyChangeListener in interface WizardStep

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyName,
                                         java.beans.PropertyChangeListener listener)
Specified by:
removePropertyChangeListener in interface WizardStep


Copyright © 2004 Andrew Pietsch.