org.pietschy.wizard
Class PanelWizardStep

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byorg.pietschy.wizard.PanelWizardStep
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, WizardStep

public class PanelWizardStep
extends javax.swing.JPanel
implements WizardStep

This is a base class for JPanel based wizard steps. Subclasses override the methods init(org.pietschy.wizard.WizardModel), prepare(), applyState().

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

An example is shown below.

    public class MyWizardStep
    extends PanelWizardStep
    {
       private MyModel model;
       private JCheckBox agreeCheckbox;
       private JTextArea license;

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

          // build and layout the components..
          agreeCheckbox = new JCheckBox("Agree");
          license = new JTextArea();
          setLayout(...);
          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()
       {
          // read the model and configure the panel
       }

       public void applyState()
       throws InvalidStateException
       {
          // load a progress bar of some kind..
          ...

          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..
             ......
             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();
       }
    }
 

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, 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 org.pietschy.wizard.WizardStep
_ID_
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PanelWizardStep()
          A default constructor make this class JavaBean compatible.
PanelWizardStep(java.lang.String name, java.lang.String summary)
          Creates a new step with the specified name and summary.
PanelWizardStep(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 applyState()
          This method is called whenever the user presses next while this step is active.
 javax.swing.Icon getIcon()
          Gets the Icon that represents this step.
 java.lang.String getSummary()
          Gets the summary of this step.
 java.awt.Component getView()
          Returns 'this'.
 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 prepare()
          Called to prepare this step to display.
 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 setSummary(java.lang.String summary)
          Sets this steps summary.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.pietschy.wizard.WizardStep
addPropertyChangeListener, addPropertyChangeListener, getName, getPreferredSize, removePropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

PanelWizardStep

public PanelWizardStep()
A default constructor make this class JavaBean compatible.


PanelWizardStep

public PanelWizardStep(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.

PanelWizardStep

public PanelWizardStep(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

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 this steps summary. 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 'this'.

Specified by:
getView in interface WizardStep
Returns:
this panel.

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 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.

prepare

public void prepare()
Called to prepare this step to display. Subclasses should query the model and configure their view appropriately.

This method will be called whenever the step is to be displayed, regardless of whether the user pressed next or previous.

Specified by:
prepare in interface WizardStep

applyState

public void applyState()
                throws InvalidStateException
This method is called whenever the user presses next while this step is active.

If this method will take a long time to complete, subclasses should consider executing the work and a separate thread and displaying some kind of progress indicator.

This method will only be called if WizardModel.isNextAvailable() and isComplete() return true.

Specified by:
applyState in interface WizardStep
Throws:
InvalidStateException - if an error occurs and the wizard can't progress to the next step. By default the message of this exception will be displayed to the user. If you wish to prevent this behaviour please ensure InvalidStateException.setShowUser(boolean) is called with a value of false.

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


Copyright © 2004 Andrew Pietsch.