com.sas.swing.visuals.wizard2
Class ButtonNavigationPanel

com.sas.swing.visuals.wizard2.ButtonNavigationPanel
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class ButtonNavigationPanel
implements java.awt.event.ActionListener

The ButtonNavigationPanel is a panel containing buttons designed to navigate through the pages of a Wizard object. The default constructor creates a panel with Back, Next, Cancel, and Help buttons, with the buttons justified to the right side of the container. Another constuctor is provided to create a ButtonNavigationPanel with custom buttons.

Two addButton methods are provided to add custom buttons, one allowing a button to be added at a specified index within the container. Buttons can be removed from the panel with the removeButton method, and access to buttons is achieved through the getButton method.

ButtonNavigationPanel uses a ButtonLayout layout manager, which allows the spacing between the buttons to be controlled, as well as the ability to justify the buttons to the left or right side. A constraint parameter is used by the ButtonLayout to specify the amount of space to place to the right of the buttons. This space can be specified as a fixed amount (in number of pixels), a percentage of the leftover space, and the remainder of leftover space. See class ButtonLayout for detailed information.

ButtonNavigationPanel implements the ActionListener interface, and handles the actionEvents generated by the buttons it contains. ActionEvents generated by buttons having action commands BACK_COMMAND and NEXT_FINISH_COMMAND call on the deck object to show previous and next pages respectively.

The action commands of other buttons firing ActionEvents are forwarded to the Wizard handleButtonCommand method for handling. If custom buttons are added to the ButtonNavigationPanel, then the Wizard handleButtonCommand method should be overridden to provide the desired functionality.

The enableButtons method is called to determine whether or not each button contained in the ButtonNavigationPanel object should be enabled, and set accordingly. It is internally called whenever a page in the wizard is shown, to correctly enable the buttons for that particular page. This method can also be called directly whenever the enabled state of a button requires change.

A button's enabled state is determined by calling the current page's isButtonEnabled method. The enableButtons method disables the "Back" button, having action command BACK_COMMAND, on the first page of the wizard. Also, on the last page of the wizard, the "Next" button, with action command NEXT_FINISH_COMMAND, is disabled if a custom "Finish" button, with an action command of FINISH_COMMAND is contained in the panel. Otherwise, if there is no custom "Finish" button, the text on the button with action command NEXT_FINISH_COMMAND is changed to "Finish".

See Also:
Wizard, ButtonLayout, Serialized Form

Field Summary
static java.lang.String ACTION_COMMAND
          The key used for storing the action command for a button defined by an Action.
static java.lang.String BACK_COMMAND
          The action command associated with the default "Back" button.
static java.lang.String CANCEL_COMMAND
          The action command associated with the default "Cancel" button.
protected  WizardPageDeck deck
          A WizardPageDeck object containing pages through which the buttons in this ButtonNavigationPanel control the navigation.
static java.lang.String FINISH_COMMAND
          The action command associated with a custom "Finish" button.
static java.lang.String HELP_COMMAND
          The action command associated with the default "Help" button.
protected  ButtonLayout layout
          The layout manager for this ButtonNavigationPanel
static java.lang.String NEXT_FINISH_COMMAND
          The action command associated with the default "Next" button.
static java.lang.String RB_KEY
           
 
Constructor Summary
ButtonNavigationPanel(WizardPageDeck deck)
          Creates a ButtonNavigationPanel with Back, Next, Cancel, and Help buttons, created from the corresponding Actions defined in the Wizard class.
ButtonNavigationPanel(WizardPageDeck deck, javax.swing.Action[] action, java.lang.Object[] constraint)
           
ButtonNavigationPanel(WizardPageDeck deck, java.lang.String[] buttonText, java.lang.String[] actionCommand, java.lang.Object[] constraint)
          Creates a right aligned ButtonNavigationPanel containing the specified buttons.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
          Handles ActionEvents fired from buttons in the ButtonNavigationPanel.
 void addButton(javax.swing.Action a, java.lang.Object constraint)
          Creates a new button attached to the specified Action object and appends it to the end of this container.
 void addButton(javax.swing.Action a, java.lang.Object constraint, int index)
          Creates a new button attached to the specified Action object and adds it to this container at the specified index.
 void addButton(java.lang.String buttonText, java.lang.String actionCommand, java.lang.Object constraint)
          Adds a button with the specified button text, action command, and spacing constraint to the end of this container
 void addButton(java.lang.String buttonText, java.lang.String actionCommand, java.lang.Object constraint, int index)
          Adds a button with the specified button text, action command, and spacing constraint at the specified index.
protected  javax.swing.JButton createButton(javax.swing.Action action)
           
protected  javax.swing.JButton createButton(java.lang.String buttonText, java.lang.String actionCommand)
          Factory method which creates a JButton to be used in the ButtonNavigationPanel.
 void createLayout()
          Creates the layout manager for this ButtonNavigationPanel.
 void createVisuals(javax.swing.Action[] action, java.lang.Object[] constraint)
           
 void createVisuals(java.lang.String[] buttonText, java.lang.String[] actionCommand, java.lang.Object[] constraint)
          Calls method createLayout to create the layout manager for the ButtonNavigationPanel.
 void enableButtons()
          Verifies the enabled state of each button for a page, and enables them accordingly.
 javax.swing.JButton getButton(java.lang.String actionCommand)
          Returns the button from the ButtonNavigationPanel with the specified action command.
 void removeButton(java.lang.String actionCommand)
          Removes the specified button from the ButtonNavigationPanel.
 

Field Detail

RB_KEY

public static final java.lang.String RB_KEY
See Also:
Constant Field Values

deck

protected WizardPageDeck deck
A WizardPageDeck object containing pages through which the buttons in this ButtonNavigationPanel control the navigation.


layout

protected ButtonLayout layout
The layout manager for this ButtonNavigationPanel


ACTION_COMMAND

public static final java.lang.String ACTION_COMMAND
The key used for storing the action command for a button defined by an Action.

See Also:
Constant Field Values

NEXT_FINISH_COMMAND

public static final java.lang.String NEXT_FINISH_COMMAND
The action command associated with the default "Next" button. The text on this button changes to "Finish" on the last page of the wizard if there is no custom "Finish" button, with action command FINISH_COMMAND contained in the ButtonNavigationPanel. If there is a custom "Finish" button, then text on the default "Next" button will remain "Next", but the button will be disabled.

See Also:
Constant Field Values

BACK_COMMAND

public static final java.lang.String BACK_COMMAND
The action command associated with the default "Back" button.

See Also:
Constant Field Values

CANCEL_COMMAND

public static final java.lang.String CANCEL_COMMAND
The action command associated with the default "Cancel" button.

See Also:
Constant Field Values

HELP_COMMAND

public static final java.lang.String HELP_COMMAND
The action command associated with the default "Help" button.

See Also:
Constant Field Values

FINISH_COMMAND

public static final java.lang.String FINISH_COMMAND
The action command associated with a custom "Finish" button.

See Also:
Constant Field Values
Constructor Detail

ButtonNavigationPanel

public ButtonNavigationPanel(WizardPageDeck deck,
                             java.lang.String[] buttonText,
                             java.lang.String[] actionCommand,
                             java.lang.Object[] constraint)
Creates a right aligned ButtonNavigationPanel containing the specified buttons.

Parameters:
deck - the WizardPageDeck object containing pages through which the buttons in this ButtonNavigationPanel control the navigation
buttonText - an array of Strings containing the text to be displayed on the buttons
actionCommand - an array of Strings containing the buttons' associated action commands
constraint - an array of Objects (Integer, Float, or String) specifying the amount of space to place to the right of the buttons

ButtonNavigationPanel

public ButtonNavigationPanel(WizardPageDeck deck)
Creates a ButtonNavigationPanel with Back, Next, Cancel, and Help buttons, created from the corresponding Actions defined in the Wizard class. The respective action commands associated with these buttons are BACK_COMMAND, NEXT_FINISH_COMMAND, CANCEL_COMMAND, and HELP_COMMAND. The buttons are right aligned within the panel.

Parameters:
deck - the WizardPageDeck object containing pages through which the buttons in this ButtonNavigationPanel control the navigation

ButtonNavigationPanel

public ButtonNavigationPanel(WizardPageDeck deck,
                             javax.swing.Action[] action,
                             java.lang.Object[] constraint)
Method Detail

addButton

public void addButton(java.lang.String buttonText,
                      java.lang.String actionCommand,
                      java.lang.Object constraint)
Adds a button with the specified button text, action command, and spacing constraint to the end of this container

Parameters:
buttonText - the text to be displayed on the button
actionCommand - the button's associated action command
constraint - an Integer, Float, or String object which specifies the amount of space to place to the right of the button
See Also:
ButtonLayout

addButton

public void addButton(java.lang.String buttonText,
                      java.lang.String actionCommand,
                      java.lang.Object constraint,
                      int index)
Adds a button with the specified button text, action command, and spacing constraint at the specified index.

Parameters:
buttonText - the text to be displayed on the button
actionCommand - the button's associated action command
constraint - an Integer, Float, or String object which specifies the amount of space to place to the right of the button
index - the position at which to insert the button, or -1 to insert the button at the end
See Also:
ButtonLayout

addButton

public void addButton(javax.swing.Action a,
                      java.lang.Object constraint)
Creates a new button attached to the specified Action object and appends it to the end of this container.

The action command for the button will be retrieved from the Action object through the key ACTION_COMMAND. If this value has not been set, then the action command will be set to Action.NAME.

Parameters:
a - the Action for the button to be added
constraint - an Integer, Float, or String object which specifies the amount of space to place to the right of the button
See Also:
Action

addButton

public void addButton(javax.swing.Action a,
                      java.lang.Object constraint,
                      int index)
Creates a new button attached to the specified Action object and adds it to this container at the specified index.

Parameters:
a - the Action for the button to be added
constraint - an Integer, Float, or String object which specifies the amount of space to place to the right of the button
index - the position at which to insert the button, or -1 to insert the button at the end
See Also:
Action

removeButton

public void removeButton(java.lang.String actionCommand)
Removes the specified button from the ButtonNavigationPanel.

Parameters:
actionCommand - the action command associated with the button to remove from the ButtonNavigationPanel

getButton

public javax.swing.JButton getButton(java.lang.String actionCommand)
Returns the button from the ButtonNavigationPanel with the specified action command.

Parameters:
actionCommand - the action command associated with the button to return
Returns:
the button with the specified action command or null if a button with specified action command was not found in the ButtonNavigationPanel

createButton

protected javax.swing.JButton createButton(java.lang.String buttonText,
                                           java.lang.String actionCommand)
Factory method which creates a JButton to be used in the ButtonNavigationPanel. This method also registers this ButtonNavigationPanel as the ActionListener for the button.


createButton

protected javax.swing.JButton createButton(javax.swing.Action action)

enableButtons

public void enableButtons()
Verifies the enabled state of each button for a page, and enables them accordingly. The button's state is determined by calling the current page's isButtonEnabled method.

If the first page of the wizard is being shown, then the button with the action command BACK_COMMAND is disabled.

If the last page is being shown, this method changes the text on the "Next" button with action command NEXT_FINISH_COMMAND to "Finish", only if a custom "Finish" button with action command FINISH_COMMAND is not contained in the panel. If there is a custom "Finish" button, then the button with action command NEXT_FINISH_COMMAND is disabled.

See Also:
WizardPageInterface.isButtonEnabled(java.lang.String)

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
Handles ActionEvents fired from buttons in the ButtonNavigationPanel. The previous page in the wizard path is shown when an ActionEvent is received from the button with the action command BACK_COMMAND. Likewise, the next page in the wizard path is shown when an ActionEvent is received from the button with the action command NEXT_FINISH_COMMAND. In either case, the current page's hidePage method is called and returns true before another page is shown. ActionEvents received from other buttons will be routed to the Wizard handleButtonCommand method for handling.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
event - the ActionEvent to be handled

createLayout

public void createLayout()
Creates the layout manager for this ButtonNavigationPanel. Called from method createVisuals. The layout manager used is the ButtonLayout, with the justification set to Orientations.RIGHT.

See Also:
ButtonLayout

createVisuals

public void createVisuals(java.lang.String[] buttonText,
                          java.lang.String[] actionCommand,
                          java.lang.Object[] constraint)
Calls method createLayout to create the layout manager for the ButtonNavigationPanel. Creates and adds the buttons specified by buttonText, actionCommand, and constraints to the ButtonNavigationPanel.

Parameters:
buttonText - an array of Strings specifying the text to be shown on the buttons
actionCommand - an array of Strings specifying the action commands for the buttons
constraints - an array of Objects specifying the spacing to place to the right of the buttons
See Also:
ButtonLayout, createLayout()

createVisuals

public void createVisuals(javax.swing.Action[] action,
                          java.lang.Object[] constraint)



Copyright © 2009 SAS Institute Inc. All Rights Reserved.