home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 November
/
Chip_1998-11_cd.bin
/
tema
/
Cafe
/
Source.bin
/
Wizard.java
< prev
next >
Wrap
Text File
|
1998-03-18
|
46KB
|
1,727 lines
/*
* Wizard.java
*/
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;
/**
* 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.add(panel1);
// 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.add(horizontalLine1);
// 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(0, 0, 0, 0);
((GridBagLayout)super.getLayout()).setConstraints(panel2, gbc);
super.add(panel2);
// Navigation buttons and associated panels
panel3 = new Panel();
panel3.setLayout(new GridLayout());
panel2.add(panel3);
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));
panel2.add(panel4);
cancelButton = new Button();
cancelButton.setActionCommand("button");
cancelButton.setLabel(CANCEL_LABEL);
if (java.beans.Beans.isDesignTime())
cancelButton.setEnabled(false);
panel4.add(cancelButton);
helpButton = new Button();
helpButton.setActionCommand("button");
helpButton.setLabel(HELP_LABEL);
if (java.beans.Beans.isDesignTime())
helpButton.setEnabled(false);
panel4.add(helpButton);
// Other objects
vPages = new Vector();
actionListeners = new Vector();
controller = new SimpleWizardController(this);
}
/**
* 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(userComponent);
}
// Set the buttons status
updateButtonsState();
}
/**
* Initiates the WizardController.
* Begins the WizardController life cycle and shows the
* first page.
*/
private void initiateController(Component comp)
{
if (!controllerPrepared)
{
// Prepare the controller
controller.doPrepare();
controllerPrepared = true;
// Prepare the new page
controller.resetChainInfo();
controller.preparePage(comp, WizardController.NEXT);
// Show the new page
showPage(comp);
curIndex = 0;
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(getComponentAt(0));
}
/**
* Get the current WizardController.
*
* @see #setWizardController
*/
public WizardController getWizardController()
{
return controller;
}
/**
* Selects the specified page and shows it.
* @param index the zero-relative index of the page to select
* @see #getSelectedIndex
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @exception ArrayIndexOutOfBoundsException
* if the index is invalid
*/
/*
public synchronized void setSelectedIndex(int index) throws PropertyVetoException
{
//debug("setSelectedIndex");
// Property has been made read-only.
// To FIX: Just ignore an invalid index. Should test isDesignTime.
//if (!isIndexValid(index))
// throw new ArrayIndexOutOfBoundsException();
if ((isIndexValid(index)) && (index != curIndex))
{
Integer oldindex = new Integer(curIndex);
Integer newindex = new Integer(index);
vetos.fireVetoableChange("SelectedIndex", oldindex, newindex);
showPageAt(index);
//resetChainInfo();
updateButtonsState();
changes.firePropertyChange("SelectedIndex", oldindex, newindex);
}
}
*/
/**
* 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;
}
/**
* Go to the page which has the given name.
*
* @see #getCurrentPageName
*/
/*
public synchronized void setCurrentPageByName(String name)
{
int current = curIndex;
int count = getPageCount();
String s;
for (int i = 0; i < count; i++)
{
if (getLabel(i).equals(name))
{
showPageAt(i);
resetChainInfo();
updateButtonsState();
return;
}
}
}
*/
/**
* Gets the name of the current page.
*
* @see #setCurrentPageByName
*/
/*
public String getCurrentPageName()
{
return getLabel(curIndex);
}
*/
/**
* Sets the page labels associated with the page positions.
* Note that the pages do not need to have been added yet for
* this method to work.
* @param labels an array of page labels for the page positions
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @see #getLabels
*/
/*
public synchronized void setLabels(String[] labels) throws PropertyVetoException
{
//debug("setLabels");
String[] oldValue = this.labels;
vetos.fireVetoableChange("Labels", oldValue, labels);
this.labels = labels;
changes.firePropertyChange("Labels", oldValue, labels);
}
*/
/**
* Gets the current page labels associated with the page positions.
* @return an array of page labels for the page positions
* @see #setLabels
*/
/*
public String[] getLabels()
{
return labels;
}
*/
/**
* Changes the label of the page at the specified index.
* @param index the zero-relative index of the page
* @param label the new label for the specified page
* @exception PropertyVetoException
* if the specified property value is unacceptable
* @exception ArrayIndexOutOfBoundsException
* if the index is invalid
* @see #getLabel
*/
/*
public synchronized void setLabel(int index, String label) throws PropertyVetoException
{
//debug("setLabel");
if (!isIndexValid(index))
throw new ArrayIndexOutOfBoundsException();
String oldValue = getLabel(index);
vetos.fireVetoableChange("Label", oldValue, label);
// Increase the size of the array if needed
if ((labels == null) || (labels.length < (index + 1)))
{
String[] oldLabels = labels;
labels = new String[index + 1];
if (oldLabels != null)
for (int i = 0; i < oldLabels.length; i++)
labels[i] = oldLabels[i];
}
// Set the new value
labels[index] = label;
changes.firePropertyChange("Label", oldValue, label);
}
*/
/**
* Gets the label of the page at the specified index.
* @param index the zero-relative index of the page
* @return the page label
* @exception ArrayIndexOutOfBoundsException
* if the index is invalid
* @see #setLabel
*/
/*
public synchronized String getLabel(int index)
{
if (!isIndexValid(index))
throw new ArrayIndexOutOfBoundsException();
if ((labels != null) && (index < labels.length) && (labels[index] != null))
return labels[index];
else
return "";
}
*/
/**
* 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 synchronized 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 synchronized 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 synchronized 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 synchronized 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 synchronized 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 synchronized 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.hide();
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);
// Show and request focus...
userComponent.show();
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 synchronized 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.hide();
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);
//vLabels.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 synchronized void removeAllPages()
{
//debug("removeAllPages");
if (userComponent != null)
userComponent.hide();
userComponent = null;
vPages = new Vector();
//vLabels = 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 a component to the end of this container.
* This is a standard Java AWT method which gets called to add a
* component to a container. The specified component is added to
* the end of this container.
*
* @param comp the component to add
* @return the added component
* @see #remove
*/
public Component add(Component comp)
{
//debug("add");
return add(comp,-1);
}
/**
* Adds a component to the end of this container.
* This is a standard Java AWT method which gets called to add a
* component to a container. Typically, the specified component is added to
* this container at the given zero-relative position index. A
* position index of -1 would append the component to the end.
* <p>
* It is overridden so that it only appends to the internal panel.
*
* @param comp the component to add
* @param pos the zero-relative index at which to add the component or -1
* for end
* @return the added component
* @exception IllegalArgumentException
* if the component is null
* @see #remove
*/
public synchronized Component add(Component comp, int pos)
{
//debug("add: " + pos);
if (comp == null)
throw new IllegalArgumentException();
int oldSize = getPageCount();
int index;
// Add page and label
if (pos == -1)
{
index = getPageCount();
vPages.addElement(comp);
//vLabels.addElement("");
}
else
{
index = pos;
vPages.insertElementAt(comp, index);
//vLabels.insertElementAt("", index);
}
// Update current index
if ((curIndex != -1) && (index <= curIndex))
curIndex++;
// Try to show the new page
if (java.beans.Beans.isDesignTime())
{
// Show the pages as they are added
showPageAt(index);
}
else if (!controllerPrepared)//curIndex == -1
{
// Show the first page only
initiateController(comp);
}
// Set the buttons status
updateButtonsState();
// Fire the page count change
int newSize = getPageCount();
changes.firePropertyChange("PageCount", new Integer(oldSize), new Integer(newSize));
return comp;
}
/**
* Takes no action.
* This is a standard Java AWT method which gets called to add a
* component to a container.
* It is overridden here to do nothing, so the user cannot change the way
* this container works.
*
* @param name the positioning directive for the layout manager (IGNORED)
* @param comp the component to add (IGNORED)
* @return the component parameter
*/
public Component add(String name, Component comp)
{
//debug("add");
return comp;
}
/**
* 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 #add
*/
public synchronized void remove(Component comp)
{
//debug("remove");
if (comp == null)
return;
removePageAt(getPageIndex(comp));
}
/**
* Returns the recommended dimensions to properly display this component.
* This is a standard Java AWT method which gets called to determine
* the recommended size of this component.
* <p>
* The returned size is large enough to display the biggest page component
* at its preferred size.
*
* @see #getMinimumSize
*/
public Dimension getPreferredSize()
{
//debug("getPreferredSize");
return super.getPreferredSize();
/*
Dimension p = size();
Dimension m = getMinimumSize();
return new Dimension(Math.max(p.width, m.width), Math.max(p.height, m.height));
*/
}
/**
* Returns the minimum dimensions to properly display this component.
* This is a standard Java AWT method which gets called to determine
* the minimum size of this component.
* <p>
*
* @see #getPreferredSize
*/
public Dimension getMinimumSize()
{
//debug("getMinimumSize");
return super.getMinimumSize();
//return new Dimension(20, 40);
}
/**
* 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 synchronized void addNotify()
{
//debug("addNotify");
super.addNotify();
// Hook up listeners
if ((mouse == null) && 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 synchronized 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 layout()
{
//debug("layout");
super.layout();
Rectangle r = panel1.getBounds();
if (userComponent != null)
{
userComponent.setBounds(0, 0, r.width, r.height);
//userComponent.invalidate();
//userComponent.validate();
}
}
// 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 synchronized 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 synchronized 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 controller if needed
/*
if (!controllerPrepared)
{
controller.doPrepare();
controllerPrepared = true;
}
*/
// 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 synchronized void updateButtonsState()
{
//debug("updateButtonsState");
/*
setPreviousEnabled(controller.isPreviousEnabled());
setNextEnabled(controller.isNextEnabled());
setFinishEnabled(controller.isFinishEnabled());
setCancelEnabled(controller.isCancelEnabled());
setHelpEnabled(controller.isHelpEnabled());
*/
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);
/*
nextEnabled = status;
if (combinedButton)
updateCombinedButton();
else
nextButton.setEnabled(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);
/*
finishEnabled = status;
if (combinedButton)
updateCombinedButton();
else
finishButton.setEnabled(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);
//cancelButton.setEnabled(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);
//helpButton.setEnabled(status);
}
// Member variables
private WizardController controller;
private boolean controllerPrepared = false;
private VetoableChangeSupport vetos = new VetoableChangeSupport(this);
private PropertyChangeSupport changes = new PropertyChangeSupport(this);
private Vector vPages;
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 boolean nextEnabled = false;
//private boolean finishEnabled = false;
private Vector actionListeners;
/**
* The text used for the Back button.
*/
protected final static String PREVIOUS_LABEL = "< Back";
/**
* The text used for the Next button.
*/
protected final static String NEXT_LABEL = "Next >";
/**
* The text used for the Finish button.
*/
protected final static String FINISH_LABEL = "Finish";
/**
* The text used for the Cancel button.
*/
protected final static String CANCEL_LABEL = "Cancel";
/**
* The text used for the Help button.
*/
protected final static String HELP_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;
// 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 (false)
System.err.println(s);
}
*/
}