home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Source.bin
/
Wizard.java
< prev
next >
Wrap
Text File
|
1998-10-25
|
43KB
|
1,610 lines
package symantec.itools.awt;
import java.io.FileWriter;
import java.io.IOException;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.util.Vector;
import java.util.Enumeration;
import java.util.ResourceBundle;
/**
* The Wizard component provides services to create wizards.
* It maintains a list of pages and uses the services of a
* WizardController to define its behavior.
*
* @see WizardController
* @see SimpleWizardController
*/
public class Wizard extends Panel implements WizardInterface, java.io.Serializable
{
/**
* Constructs a Wizard.
*/
public Wizard()
{
//debug("Wizard");
// Add a GridBagLayout to the Panel base class
GridBagLayout gridBagLayout;
gridBagLayout = new GridBagLayout();
super.setLayout(gridBagLayout);
// The first panel will contain the pages
panel1 = new Panel();
panel1.setLayout(null);
GridBagConstraints gbc;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(0, 0, 0, 0);
((GridBagLayout)super.getLayout()).setConstraints(panel1, gbc);
super.addImpl(panel1, null, -1);
// Horizontal line
horizontalLine1 = new symantec.itools.awt.shape.HorizontalLine();
try {
horizontalLine1.setBevelStyle(symantec.itools.awt.shape.HorizontalLine.BEVEL_LOWERED);
}
catch(java.beans.PropertyVetoException e) { }
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.weightx = 1.0;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(0, 0, 0, 0);
((GridBagLayout)super.getLayout()).setConstraints(horizontalLine1, gbc);
super.addImpl(horizontalLine1, null, -1);
// The second panel contains the navigation buttons and associated panels
panel2 = new Panel();
panel2.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 2;
gbc.weightx = 1.0;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(2, 2, 2, 2);
((GridBagLayout)super.getLayout()).setConstraints(panel2, gbc);
super.addImpl(panel2, null, -1);
// Navigation buttons and associated panels
panel3 = new Panel();
panel3.setLayout(new GridLayout());
previousButton = new Button();
previousButton.setActionCommand("button");
previousButton.setLabel(PREVIOUS_LABEL);
previousButton.setEnabled(false);
panel3.add(previousButton);
nextButton = new Button();
nextButton.setActionCommand("button");
nextButton.setLabel(NEXT_LABEL);
nextButton.setEnabled(false);
panel3.add(nextButton);
finishButton = new Button();
finishButton.setActionCommand("button");
finishButton.setLabel(FINISH_LABEL);
finishButton.setEnabled(false);
panel3.add(finishButton);
panel4 = new Panel();
panel4.setLayout(new GridLayout(1, 2, 6, 0));
cancelButton = new Button();
cancelButton.setActionCommand("button");
cancelButton.setLabel(CANCEL_LABEL);
if (!ignoreDesignTime && java.beans.Beans.isDesignTime())
cancelButton.setEnabled(false);
helpButton = new Button();
helpButton.setActionCommand("button");
helpButton.setLabel(HELP_LABEL);
if (!ignoreDesignTime && java.beans.Beans.isDesignTime())
helpButton.setEnabled(false);
// Select the button order
if (newButtonOrder) {
panel2.add(panel4);
panel2.add(panel3);
panel4.add(helpButton);
panel4.add(cancelButton);
} else {
panel2.add(panel3);
panel2.add(panel4);
panel4.add(cancelButton);
panel4.add(helpButton);
}
// Other objects
vPages = new Vector();
actionListeners = new Vector();
controller = new SimpleWizardController(this);
}
/**
* Set the wizard starting page. This has to be called before any
* page is added.
*/
public void setFirstPageIndex(int index)
{
if (index >= 0)
firstPageIndex = index;
}
/**
* Tell the wizard to ignore the value of java.beans.Beans.isDesignTime().
*/
public void setIgnoreDesignTime(boolean ignore)
{
ignoreDesignTime = ignore;
}
public boolean getIgnoreDesignTime()
{
return ignoreDesignTime;
}
/**
* Sets a customized WizardController.
* This should be done once before actually using the Wizard
* and after all pages have been added. If no customized
* WizardController is set, a default SimpleWizardController
* is used.
*
* @see #getWizardController
*/
public void setWizardController(WizardController controller)
{
WizardController oldController = this.controller;
this.controller = controller;
if (controllerPrepared)
{
oldController.doCancel();
controllerPrepared = false;
initiateController(firstPageIndex);
}
// Set the buttons status
updateButtonsState();
}
/**
* Initiates the WizardController.
* Begins the WizardController life cycle and shows the
* first page.
*/
private void initiateController(int index)
{
//debug("initiateController: " + index);
Component comp = getComponentAt(index);
if (!controllerPrepared)
{
// Prepare the controller
if (controller instanceof SimpleWizardController)
((SimpleWizardController)controller).doPrepare(index);
else
controller.doPrepare();
controllerPrepared = true;
// Prepare the new page
controller.resetChainInfo();
controller.preparePage(comp, WizardController.NEXT);
// Show the new page
showPage(comp);
curIndex = index;
controller.pageShown(comp);
}
}
/**
* Restarts the wizard after usage.
* The WizardController life cycle will be reset and the
* first page will be shown again.
*/
public void restart()
{
if (controllerPrepared)
{
controller.doCancel();
controllerPrepared = false;
}
initiateController(firstPageIndex);
}
/**
* Get the current WizardController.
*
* @see #setWizardController
*/
public WizardController getWizardController()
{
return controller;
}
/**
* Returns the zero-relative index of the currently selected page.
* @return the currently selected page or -1 if none are shown
*/
public int getSelectedIndex()
{
//debug("getSelectedIndex");
return curIndex;
}
/**
* Replaces a page at the index specified.
* @param index the zero-relative index of the page to change
* @param comp the new component
* @see #getComponentAt
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @exception ArrayIndexOutOfBoundsException
* if the index is invalid
* @exception IllegalArgumentException
* if the component is null
*/
public void setComponentAt(int index, Component comp) throws PropertyVetoException
{
//debug("setComponentAt");
if (!isIndexValid(index))
throw new ArrayIndexOutOfBoundsException();
if (comp == null)
throw new IllegalArgumentException();
Component oldPage = getComponentAt(index);
vetos.fireVetoableChange("ComponentAt", oldPage, comp);
vPages.setElementAt(comp, index);
if (index == curIndex)
{
hidePage();
showPage(comp);
}
changes.firePropertyChange("ComponentAt", oldPage, comp);
}
/**
* Gets the component for the page at the given index.
* @param index zero-relative index of the page
* @return returns the component associated with the page
* @exception ArrayIndexOutOfBoundsException
* if the index is invalid
* @see #setComponentAt
*/
public Component getComponentAt(int index)
{
//debug("getComponentAt");
if (!isIndexValid(index))
throw new ArrayIndexOutOfBoundsException();
return (Component)vPages.elementAt(index);
}
/**
* Shows or hides the Help button depending on the value of the parameter.
*
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #isHelpButtonVisible
*/
public void setHelpButtonVisible(boolean visible) throws PropertyVetoException
{
if (visible == helpButtonVisible)
return;
Boolean oldvalue = new Boolean(helpButtonVisible);
Boolean newvalue = new Boolean(visible);
vetos.fireVetoableChange("HelpButtonVisible", oldvalue, newvalue);
if (visible && !helpButtonVisible)
{
panel4.add(helpButton);
helpButtonVisible = true;
}
else if (!visible && helpButtonVisible)
{
panel4.remove(helpButton);
helpButtonVisible = false;
}
changes.firePropertyChange("HelpButtonVisible", oldvalue, newvalue);
}
/**
* Determines whether the Help button is visible.
*
* @see #setHelpButtonVisible
*/
public boolean isHelpButtonVisible()
{
return helpButtonVisible;
}
/**
* Sets a combined Next/Finish button or two buttons depending on the
* value of the parameter.
*
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #isCombinedButton
*/
public void setCombinedButton(boolean combined) throws PropertyVetoException
{
if (combined == combinedButton)
return;
Boolean oldvalue = new Boolean(combinedButton);
Boolean newvalue = new Boolean(combined);
vetos.fireVetoableChange("combinedButton", oldvalue, newvalue);
if (combined && !combinedButton)
{
panel3.remove(finishButton);
combinedButton = true;
}
else if (!combined && combinedButton)
{
panel3.add(finishButton);
combinedButton = false;
}
changes.firePropertyChange("combinedButton", oldvalue, newvalue);
}
/**
* Determines whether there is a combined Next/Finish button.
*
* @see #setCombinedButton
*/
public boolean isCombinedButton()
{
return combinedButton;
}
/**
* Sets the buttons alignment of the navigation buttons.
*
* @param align
* Wizard.LEFT, Wizard.CENTER or Wizard.RIGHT
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @exception IllegalArgumentException
* if the parameter is invalid
* @see #getButtonsAlignment
*/
public void setButtonsAlignment(int align) throws PropertyVetoException
{
if ((align != LEFT) && (align != CENTER) && (align != RIGHT))
throw new IllegalArgumentException();
Integer oldvalue = new Integer(getButtonsAlignment());
Integer newvalue = new Integer(align);
vetos.fireVetoableChange("buttonsAlignment", oldvalue, newvalue);
((FlowLayout)panel2.getLayout()).setAlignment(align);
panel2.invalidate();
//panel2.doLayout();
changes.firePropertyChange("buttonsAlignment", oldvalue, newvalue);
}
/**
* Gets the buttons alignment of the navigation buttons.
*
* @see #setButtonsAlignment
*/
public int getButtonsAlignment()
{
return ((FlowLayout)panel2.getLayout()).getAlignment();
}
/**
* Gets the index for a specific page.
* @param comp the page to get the index of
* @return the zero-relative index of the page or -1 if it is not found
* @exception IllegalArgumentException
* if the component is null
*/
public int getPageIndex(Component comp)
{
//debug("getPageIndex");
if (comp == null)
throw new IllegalArgumentException();
return vPages.indexOf(comp);
}
/**
* Show and select the page at the given index.
* The page is activated, ready for user input.
* @param index zero-relative index of the page to select
*/
private void showPageAt(int index)
{
//debug("showPageAt: " + index);
// Check index
if (!isIndexValid(index))
return;
if (index != curIndex)
{
hidePage();
showPage(getComponentAt(index));
curIndex = index;
}
}
/**
* Hides the current component component.
* This is a low-level method.
* @param comp the Component to add and show
*/
private void hidePage()
{
//debug("hidePage");
if (userComponent != null)
{
userComponent.setVisible(false);
userComponent = null;
}
}
/**
* Adds the component to the base panel and shows it.
* This is a low-level method used by showPageAt and
* setComponentAt only.
* @param comp the Component to add and show
*/
private void showPage(Component comp)
{
//debug("showPage");
// Register the new component
userComponent = comp;
if (userComponent != null)
{
// Add the component to the panel1 only if it has not already be done
Component[] comps = panel1.getComponents();
int l = comps.length;
int x;
for (x = 0; x < l; x++)
{
if (comps[x] == userComponent)
break;
}
if (x == l) {
panel1.add(userComponent, -1);
//debug("showPage: adding component " + comp);
}
// Show and request focus...
userComponent.setVisible(true);
userComponent.requestFocus();
//userComponent.invalidate();
validate();
}
}
/**
* Check if the specified index is in a valid range.
* @param index the index to test
*/
private boolean isIndexValid(int index)
{
return ((index >=0) && (index < getPageCount())) ? true : false;
}
/**
* Removes a page and its associated component at the given index.
* The currently active page cannot be removed.
* @param index zero-relative index of the page
* @exception ArrayIndexOutOfBoundsException
* if the index is invalid
*/
public void removePageAt(int index)
{
//debug("removePageAt: " + index);
if (!isIndexValid(index))
throw new ArrayIndexOutOfBoundsException();
int oldSize = getPageCount();
// Check if the current page will be removed
if (index == curIndex)
{
if (getPageCount() == 1)
{
// It is the last remaining page
if (userComponent != null)
userComponent.setVisible(false);
curIndex = -1;
if (controllerPrepared)
{
controller.doCancel();
controllerPrepared = false;
}
}
else if (curIndex == (getPageCount() - 1))
{
// It is the last page index
showPageAt(curIndex - 1);
}
else
{
showPageAt(curIndex + 1);
}
}
// Remove everything
Component p = getComponentAt(index);
panel1.remove(p);
vPages.removeElementAt(index);
// Update current index
if ((curIndex != -1) && (index < curIndex))
curIndex--;
updateButtonsState();
int newSize = getPageCount();
changes.firePropertyChange("PageCount", new Integer(oldSize), new Integer(newSize));
}
/**
* Removes all pages and their associated components, clearing
* the Wizard entirely.
*/
public void removeAllPages()
{
//debug("removeAllPages");
if (userComponent != null)
userComponent.setVisible(false);
userComponent = null;
vPages = new Vector();
curIndex = -1;
if (controllerPrepared)
{
controller.doCancel();
controllerPrepared = false;
}
panel1.removeAll();
updateButtonsState();
}
/**
* Gets the number of pages in the Wizard.
* @return the number of pages currently in the Wizard
*/
public int getPageCount()
{
//debug("getPageCount: " + vPages.size());
return vPages.size();
}
/**
* Adds a listener for all event changes.
* @param listener the listener to add.
* @see #removePropertyChangeListener
*/
public void addPropertyChangeListener(PropertyChangeListener listener)
{
//debug("addPropertyChangeListener");
changes.addPropertyChangeListener(listener);
}
/**
* Removes a listener for all event changes.
* @param listener the listener to remove.
* @see #addPropertyChangeListener
*/
public void removePropertyChangeListener(PropertyChangeListener listener)
{
//debug("removePropertyChangeListener");
changes.removePropertyChangeListener(listener);
}
/**
* Adds a vetoable listener for all event changes.
* @param listener the listener to add.
* @see #removeVetoableChangeListener
*/
public void addVetoableChangeListener(VetoableChangeListener listener)
{
//debug("addVetoableChangeListener");
vetos.addVetoableChangeListener(listener);
}
/**
* Removes a vetoable listener for all event changes.
* @param listener the listener to remove.
* @see #addVetoableChangeListener
*/
public void removeVetoableChangeListener(VetoableChangeListener listener)
{
//debug("removeVetoableChangeListener");
vetos.removeVetoableChangeListener(listener);
}
/**
* Adds the specified action listener to receive action events from
* the Finish button.
*
* @see #removeActionListener
*/
public void addActionListener(ActionListener l)
{
actionListeners.addElement(l);
}
/**
* Removes the specified action listener so that it no longer receives
* action events from the Finish button.
*
* @see #addActionListener
*/
public void removeActionListener(ActionListener l)
{
actionListeners.removeElement(l);
}
/**
* Fires an action event to all registered listeners.
*
* @see #addActionListener
* @see #removeActionListener
*/
private void fireActionEvent(String command)
{
ActionEvent event = new ActionEvent(this, 0, command);
for (Enumeration e = actionListeners.elements(); e.hasMoreElements();)
{
ActionListener l = (ActionListener)e.nextElement();
l.actionPerformed(event);
}
}
// Methods overriding Container methods
/**
* Adds the specified component to this container at the specified
* index. This method also notifies the layout manager to add
* the component to this container's layout using the specified
* constraints object.
* <p>
* This is the method to override if a program needs to track
* every add request to a container. An overriding method should
* usually include a call to the superclass's version of the method:
* <p>
* <blockquote>
* <code>super.addImpl(comp, constraints, index)</code>
* </blockquote>
* <p>
* @param comp the component to be added.
* @param constraints an object expressing layout contraints
* for this component.
* @param index the position in the container's list at which to
* insert the component, where <code>-1</code>
* means insert at the end.
* @see java.awt.Container#add(java.awt.Component)
* @see java.awt.Container#add(java.awt.Component, int)
* @see java.awt.Container#add(java.awt.Component, java.lang.Object)
* @see java.awt.LayoutManager
* @since JDK1.1
*/
protected void addImpl(Component comp, Object constraints, int index)
{
//debug("addImpl: " + comp + ", " + constraints + ", " + index);
if (comp == null)
throw new IllegalArgumentException();
int oldSize = getPageCount();
int index1;
// Add page and label
if (index == -1)
{
index1 = getPageCount();
vPages.addElement(comp);
}
else
{
index1 = index;
vPages.insertElementAt(comp, index1);
}
// Update current index
if ((curIndex != -1) && (index1 <= curIndex))
curIndex++;
// Try to show the new page
if (!ignoreDesignTime && java.beans.Beans.isDesignTime())
{
// Show the pages as they are added
showPageAt(index1);
}
else if (!controllerPrepared)//curIndex == -1
{
// Show the first page only
if (index1 == firstPageIndex)
initiateController(firstPageIndex);
}
// Set the buttons status
updateButtonsState();
// Fire the page count change
int newSize = getPageCount();
changes.firePropertyChange("PageCount", new Integer(oldSize), new Integer(newSize));
}
/**
* Removes the specified component from this container.
* This is a standard Java AWT method which gets called to remove
* a component from a container. When this happens the component's
* removeNotify() will also get called to indicate component
* removal.
*
* @param comp the component to remove
* @see java.awt.Component#add
*/
public void remove(Component comp)
{
//debug("remove");
if (comp == null)
return;
removePageAt(getPageIndex(comp));
}
/**
* Removes the component, specified by <code>index</code>, from
* this container.
* This is a standard Java AWT method which gets called to remove
* a component from a container. When this happens the component's
* removeNotify() will also get called to indicate component
* removal.
*
* @param comp the component to remove
* @see java.awt.Component#add
*/
public void remove(int index)
{
//debug("remove");
removePageAt(index);
}
/**
* Tells this component that it has been added to a container.
* This is a standard Java AWT method which gets called by the AWT when
* this component is added to a container. Typically, it is used to
* create this component's peer.
*
* It has been overridden here to hook-up event listeners.
*
* @see #removeNotify
*/
public void addNotify()
{
//debug("addNotify");
super.addNotify();
// Hook up listeners
if ((mouse == null) && !ignoreDesignTime && java.beans.Beans.isDesignTime())
{
mouse = new Mouse();
addMouseListener(mouse);
}
if (action == null)
{
action = new Action();
previousButton.addActionListener(action);
nextButton.addActionListener(action);
finishButton.addActionListener(action);
cancelButton.addActionListener(action);
helpButton.addActionListener(action);
}
}
/**
* Tells this component that it is being removed from a container.
* This is a standard Java AWT method which gets called by the AWT when
* this component is removed from a container. Typically, it is used to
* destroy the peers of this component and all its subcomponents.
*
* It has been overridden here to unhook event listeners.
*
* @see #addNotify
*/
public void removeNotify()
{
//debug("removeNotify");
//Unhook listeners
if (mouse != null)
{
removeMouseListener(mouse);
mouse = null;
}
if (action != null)
{
previousButton.removeActionListener(action);
nextButton.removeActionListener(action);
finishButton.removeActionListener(action);
cancelButton.removeActionListener(action);
helpButton.removeActionListener(action);
action = null;
}
super.removeNotify();
}
/**
* Takes no action.
* This is a standard Java AWT method which gets called to specify
* which layout manager should be used to layout the components in
* standard containers.
*
* Since layout managers CANNOT BE USED with this container the standard
* setLayout has been OVERRIDDEN for this container and does nothing.
*
* @param mgr the layout manager to use to layout this container's components
* (IGNORED)
* @see java.awt.Container#getLayout
**/
public void setLayout(LayoutManager mgr)
{
//debug("setLayout");
}
public LayoutManager getLayout()
{
//debug("getLayout");
return null;
}
/**
* Handles the laying out of components within this component.
* This is a standard Java AWT method which gets called by the AWT
* when this component is validated with the validate() method.
*
* @see java.awt.Container#validate
*/
public void doLayout()
{
//debug("doLayout");
super.doLayout();
if (userComponent != null)
{
Rectangle r = panel1.getBounds();
//if ((r.width != 0) && (r.height != 0))
userComponent.setBounds(0, 0, r.width, r.height);
//userComponent.invalidate();
//userComponent.validate();
}
}
/**
* Sets the background color of this component.
*/
public void setBackground(Color color)
{
super.setBackground(color);
// Why has this to be done?
panel1.setBackground(color);
panel2.setBackground(color);
panel3.setBackground(color);
panel4.setBackground(color);
}
// Inner classes
/**
* This is the Mouse Event handling innerclass. It handles mouse events
* at design time only.
*/
class Mouse extends MouseAdapter implements java.io.Serializable
{
public void mousePressed(MouseEvent e)
{
//System.err.println("Before mouse click...");
//System.err.println("Mouse click: " + e.getPoint().x + ", " + e.getPoint().y);
Component c = getComponentAt(e.getPoint());
//System.err.println(" class: " + c.getClass().getName());
if (c == panel2)
{
e.translatePoint(-panel2.getLocation().x, -panel2.getLocation().y);
c = panel2.getComponentAt(e.getPoint());
//System.err.println(" panel2: " + e.getPoint());
if (c == panel3)
{
e.translatePoint(-panel3.getLocation().x, -panel3.getLocation().y);
c = panel3.getComponentAt(e.getPoint());
//System.err.println(" panel3: " + e.getPoint());
if (c == previousButton)
goPrevious();
else if (c == nextButton)
goNext();
else
;//System.err.println("none");
}
else if (c == panel4)
{
e.translatePoint(-panel4.getLocation().x, -panel4.getLocation().y);
c = panel4.getComponentAt(e.getPoint());
System.err.println(" panel4: " + e.getPoint());
if (c == cancelButton)
;//System.err.println("cancel");
else if (c == helpButton)
;//System.err.println("help");
else
;//System.err.println("none");
}
else
{
//System.err.println("none");
}
}
}
}
/**
* This is the Action Event handling innerclass.
*/
class Action implements ActionListener, java.io.Serializable
{
public void actionPerformed(ActionEvent e)
{
Object o = e.getSource();
if (o == previousButton)
goPrevious();
else if ((o == nextButton) && (!combinedButton || !controller.isFinishEnabled()))
goNext();
else if ((o == finishButton) || ((o == nextButton) && combinedButton && controller.isFinishEnabled()))
doFinish();
else if (o == cancelButton)
doCancel();
else if (o == helpButton)
doHelp();
}
}
/**
* Performs the actions needed when the Finish button is pressed.
*
* @see #doCancel
* @see #doHelp
*/
public void doFinish()
{
//debug("doFinish");
Component source = (curIndex != -1) ? getComponentAt(curIndex) : null;
if (source == null)
return;
if (controller.validatePage(source, null, WizardController.FINISH))
{
controller.doFinish();
controllerPrepared = false;
fireActionEvent("Finish");
}
}
/**
* Performs the actions needed when the Cancel button is pressed.
*
* @see #doFinish
* @see #doHelp
*/
public void doCancel()
{
//debug("doCancel");
Component source = (curIndex != -1) ? getComponentAt(curIndex) : null;
if (source == null)
return;
if (controller.validatePage(source, null, WizardController.CANCEL))
{
controller.doCancel();
controllerPrepared = false;
fireActionEvent("Cancel");
}
}
/**
* Performs the actions needed when the Help button is pressed.
*
* @see #doFinish
* @see #doCancel
*/
public void doHelp()
{
//debug("doHelp");
Component source = (curIndex != -1) ? getComponentAt(curIndex) : null;
if (source == null)
return;
if (controller.validatePage(source, null, WizardController.HELP))
{
controller.doHelp();
fireActionEvent("Help");
}
}
// Implementation of the WizardInterface interface
/**
* Sets the index of the page to show when goPrevious is called.
*
* @see #setNextPageIndex
* @see #goPrevious
* @see WizardController
* @see SimpleWizardController
*/
public void setPreviousPageIndex(int index)
{
//debug("setPreviousPageIndex");
controller.setPreviousPageIndex(index);
}
/**
* Sets the index of the page to show when goNext is called.
*
* @see #setPreviousPageIndex
* @see #goNext
* @see WizardController
* @see SimpleWizardController
*/
public void setNextPageIndex(int index)
{
//debug("setNextPageIndex");
controller.setNextPageIndex(index);
}
/**
* Sets the page to show when goPrevious is called.
*
* @see #setNextPageIndex
* @see #goPrevious
* @see WizardController
* @see SimpleWizardController
*/
public void setPreviousPage(Component comp)
{
controller.setPreviousPage(comp);
}
/**
* Sets the page to show when goNext is called.
*
* @see #setPreviousPageIndex
* @see #goNext
* @see WizardController
* @see SimpleWizardController
*/
public void setNextPage(Component comp)
{
controller.setNextPage(comp);
}
/**
* Go to the previous page.
* If a page has been selected with setPreviousPage it will be used.
* If a page index has been selected with setPreviousPageIndex it will be
* used unless a page has been specified. The chain information will be
* reset.
*
* @see #goNext
* @see #setPreviousPage
* @see #setPreviousPageIndex
*/
public void goPrevious()
{
//debug("goPrevious");
// Determines the source and target
Component source = (curIndex != -1) ? getComponentAt(curIndex) : null;
Component target = controller.getPreviousPage();
//if (target == null)
// return;
int index = getPageIndex(target);
// Validate the current page and continue if validation succeeded
if (curIndex != -1)
{
if (!controller.validatePage(source, target, WizardController.PREVIOUS))
return;
}
// Determines the real target and continue if the new target is valid
target = controller.getPreviousPage();
if (target == null)
return;
index = getPageIndex(target);
// Hide the current page
if (curIndex != -1)
{
hidePage();
controller.pageHidden(source);
}
// Prepare the controller if needed
/*
if (!controllerPrepared)
{
controller.doPrepare();
controllerPrepared = true;
}
*/
// Prepare the new page
controller.resetChainInfo();
controller.preparePage(target, WizardController.PREVIOUS);
// Show the new page
showPage(target);
curIndex = index;
controller.pageShown(target);
// Set state information
updateButtonsState();
}
/**
* Go to the next page.
* If a page has been selected with setNextPage it will be used.
* If a page index has been selected with setNextPageIndex it will be
* used unless a page has been specified. The chain information will be
* reset.
*
* @see #goPrevious
* @see #setNextPage
* @see #setNextPageIndex
*/
public void goNext()
{
//debug("goNext");
// Determines the source and target
Component source = (curIndex != -1) ? getComponentAt(curIndex) : null;
Component target = controller.getNextPage();
//if (target == null)
// return;
int index = getPageIndex(target);
// Validate the current page and continue if validation succeeded
if (curIndex != -1)
{
if (!controller.validatePage(source, target, WizardController.NEXT))
return;
}
// Determines the real target and continue if the new target is valid
target = controller.getNextPage();
if (target == null)
return;
index = getPageIndex(target);
// Hide the current page
if (curIndex != -1)
{
hidePage();
controller.pageHidden(source);
}
// Prepare the new page
controller.resetChainInfo();
controller.preparePage(target, WizardController.NEXT);
// Show the new page
showPage(target);
curIndex = index;
controller.pageShown(target);
// Set state information
updateButtonsState();
}
/**
* Sets a default status for the Previous, Next and Finish buttons.
*
* @see #setPreviousEnabled
* @see #setNextEnabled
* @see #setFinishEnabled
* @see #setCancelEnabled
* @see #setHelpEnabled
*/
public void updateButtonsState()
{
//debug("updateButtonsState");
previousButton.setEnabled(controller.isPreviousEnabled());
if (combinedButton)
{
updateCombinedButton();
}
else
{
nextButton.setEnabled(controller.isNextEnabled());
finishButton.setEnabled(controller.isFinishEnabled());
}
cancelButton.setEnabled(controller.isCancelEnabled());
helpButton.setEnabled(controller.isHelpEnabled());
}
private void updateCombinedButton()
{
String ntext = NEXT_LABEL;
boolean nstatus = true;
boolean nextEnabled = controller.isNextEnabled();
boolean finishEnabled = controller.isFinishEnabled();
if (!nextEnabled && !finishEnabled)
nstatus = false;
else if (!nextEnabled && finishEnabled)
ntext = FINISH_LABEL;
nextButton.setLabel(ntext);
nextButton.setEnabled(nstatus);
}
/**
* Enables or disables the Previous button.
* @param status <code>true</code> to enable the button
*
* @see #setNextEnabled
* @see #setFinishEnabled
* @see #setCancelEnabled
* @see #setHelpEnabled
*/
public void setPreviousEnabled(boolean status)
{
controller.setPreviousEnabled(status);
//previousButton.setEnabled(status);
}
/**
* Enables or disables the Next button.
* @param status <code>true</code> to enable the button
*
* @see #setPreviousEnabled
* @see #setFinishEnabled
* @see #setCancelEnabled
* @see #setHelpEnabled
*/
public void setNextEnabled(boolean status)
{
controller.setNextEnabled(status);
}
/**
* Enables or disables the Finish button.
* @param status <code>true</code> to enable the button
*
* @see #setPreviousEnabled
* @see #setNextEnabled
* @see #setCancelEnabled
* @see #setHelpEnabled
*/
public void setFinishEnabled(boolean status)
{
controller.setFinishEnabled(status);
}
/**
* Enables or disables the Cancel button.
* @param status <code>true</code> to enable the button
*
* @see #setPreviousEnabled
* @see #setNextEnabled
* @see #setFinishEnabled
* @see #setHelpEnabled
*/
public void setCancelEnabled(boolean status)
{
controller.setCancelEnabled(status);
}
/**
* Enables or disables the Help button.
* @param status <code>true</code> to enable the button
*
* @see #setPreviousEnabled
* @see #setNextEnabled
* @see #setFinishEnabled
* @see #setCancelEnabled
*/
public void setHelpEnabled(boolean status)
{
controller.setHelpEnabled(status);
}
/**
* Return the Previous button component.
*/
public Button getPreviousButton()
{
return previousButton;
}
/**
* Return the Next button component.
*/
public Button getNextButton()
{
return nextButton;
}
/**
* Return the Finish button component.
*/
public Button getFinishButton()
{
return finishButton;
}
/**
* Return the Cancel button component.
*/
public Button getCancelButton()
{
return cancelButton;
}
/**
* Return the Help button component.
*/
public Button getHelpButton()
{
return helpButton;
}
/**
* Set the button order for all instances of Wizard.
* This should be called before instanciating a Wizard.
*/
public static void setAlternativeButtonOrder(boolean order)
{
newButtonOrder = order;
}
/**
* Get the button order for all instances of Wizard.
*/
public static boolean getAlternativeButtonOrder()
{
return newButtonOrder;
}
// Member variables
private WizardController controller;
private boolean controllerPrepared = false;
private boolean ignoreDesignTime = false;
private VetoableChangeSupport vetos = new VetoableChangeSupport(this);
private PropertyChangeSupport changes = new PropertyChangeSupport(this);
private Vector vPages;
private int firstPageIndex = 0;
private int curIndex = -1;
private Component userComponent = null;
private Action action;
private Mouse mouse;
/**
* The panel that contains the pages.
*/
protected Panel panel1;
/**
* The horizontal line separating the pages from the navigation buttons.
*/
protected symantec.itools.awt.shape.HorizontalLine horizontalLine1;
/**
* The top-level panel below the horizontal line.
*/
protected Panel panel2;
/**
* The panel that contains the navigation (Back,Next,Finish) buttons.
*/
protected Panel panel3;
/**
* The panel that contains the Cancel and Help buttons.
*/
protected Panel panel4;
/**
* The Back button.
*/
protected Button previousButton;
/**
* The Next button.
*/
protected Button nextButton;
/**
* The Finish button.
*/
protected Button finishButton;
/**
* The Cancel button.
*/
protected Button cancelButton;
/**
* The Help button.
*/
protected Button helpButton;
private boolean helpButtonVisible = true;
private boolean combinedButton = false;
private Vector actionListeners;
/**
* The text used for the Back button.
*/
protected static String PREVIOUS_LABEL;
/**
* The text used for the Next button.
*/
protected static String NEXT_LABEL;
/**
* The text used for the Finish button.
*/
protected static String FINISH_LABEL;
/**
* The text used for the Cancel button.
*/
protected static String CANCEL_LABEL;
/**
* The text used for the Help button.
*/
protected static String HELP_LABEL;
/**
* The resources.
*/
static {
ResourceBundle res = ResourceBundle.getBundle("symantec.itools.resources.ResBundle");
PREVIOUS_LABEL = res.getString("wizard_label_previous");
NEXT_LABEL = res.getString("wizard_label_next");
FINISH_LABEL = res.getString("wizard_label_finish");
CANCEL_LABEL = res.getString("wizard_label_cancel");
HELP_LABEL = res.getString("wizard_label_help");
}
/**
* Constant value indicating a layout aligned to the left.
*/
public final static int LEFT = FlowLayout.LEFT;
/**
* Constant value indicating a layout centered.
*/
public final static int CENTER = FlowLayout.CENTER;
/**
* Constant value indicating a layout aligned to the right.
*/
public final static int RIGHT = FlowLayout.RIGHT;
/**
* The button order for all instances of wizards.
*/
protected static boolean newButtonOrder = false;
// Debug
/*
private void debug(String s) {
fdebug("Wizard: " + s);
}
protected void fdebug(String s) {
if (false)
{
try {
FileWriter fw = new FileWriter("d:\\temp\\w.log", true);
fw.write(s + "\n");
fw.close();
} catch(IOException e) {
throw new RuntimeException("IOException caught in fdebug: " + e.getMessage());
}
}
if (true)
System.err.println(s);
}
*/
}