home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
WizardController.java
< prev
next >
Wrap
Text File
|
1998-11-12
|
14KB
|
758 lines
package com.symantec.itools.frameworks.wizard;
import com.sun.java.swing.JPanel;
import java.awt.Image;
import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Vector;
import com.symantec.itools.swing.icons.ImageIcon;
/**
* @author Symantec Internet Tools Division
* @version 1.0
* @since VCafe 3.0
*/
public class WizardController
{
protected static final int NULL_PANEL = -2;
/**
* @since VCafe 3.0
*/
protected Wizard wizard;
/**
* @since VCafe 3.0
*/
protected Vector panels;
/**
* @since VCafe 3.0
*/
protected int currentPanelIndex;
/**
* @since VCafe 3.0
*/
protected JPanel currentPanel;
/**
* @since VCafe 3.0
*/
protected String title;
{
currentPanelIndex = -1;
panels = new Vector();
}
public WizardController()
{
}
public WizardController(Wizard w)
{
wizard = w;
wizard.setWizardController(this);
}
public void setWizard(Wizard w)
{
wizard = w;
wizard.setWizardController(this);
}
/**
* @since VCafe 3.0
*/
public void init()
{
if(panels.size() > 0)
{
currentPanelIndex = firstPanelIndex();
currentPanel = (JPanel)panels.elementAt(currentPanelIndex);
if(wizard != null)
{
if(currentPanelIndex > 0)
{
wizard.setBackEnabled(true);
}
else
{
wizard.setBackEnabled(false);
}
wizard.setCancelEnabled(true);
wizard.setHelpEnabled(true);
if(panels.size() > 1 + currentPanelIndex)
{
wizard.setNextEnabled(true);
wizard.setFinishEnabled(false);
}
else
{
wizard.setNextEnabled(false);
wizard.setFinishEnabled(true);
}
wizard.showPanel(currentPanel);
}
if(currentPanel instanceof WizardPage)
{
((WizardPage)currentPanel).entering();
}
}
else
{
if(wizard != null)
{
wizard.setBackEnabled(false);
wizard.setNextEnabled(false);
wizard.setCancelEnabled(true);
wizard.setHelpEnabled(true);
wizard.setFinishEnabled(true);
}
}
}
/**
* @param panel TODO
* @since VCafe 3.0
*/
public void addPanel(JPanel panel)
{
if(panel instanceof WizardPage)
{
((WizardPage)panel).setWizardController(this);
}
panels.addElement(panel);
}
/**
* @param panel TODO
* @param index TODO
* @since VCafe 3.0
*/
public boolean addPanel(JPanel panel, int index)
{
if(panel instanceof WizardPage)
{
((WizardPage)panel).setWizardController(this);
}
if(index < 0)
{
panels.addElement(panel);
}
else
{
panels.insertElementAt(panel, index);
}
return true;
}
/**
* @param panel TODO
* @since VCafe 3.0
*/
public boolean removePanel(JPanel panel)
{
return panels.removeElement(panel);
}
/**
* @param index TODO
* @since VCafe 3.0
*/
public boolean removePanel(int index)
{
if (index >= 0 && index < panels.size())
{
panels.removeElementAt(index);
return true;
}
else
return false;
}
/**
* @since VCafe 3.0
*/
public Wizard getWizard()
{
return wizard;
}
/**
* @since VCafe 3.0
*/
public void backPanel()
{
if(currentPanelIndex > 0)
{
currentPanelIndex = computePreviousPanelIndex(currentPanelIndex);
currentPanel = (JPanel)panels.elementAt(currentPanelIndex);
if(currentPanelIndex > 0 && wizard != null)
{
wizard.setBackEnabled(true);
}
}
if(wizard != null)
{
if(currentPanelIndex == 0)
{
wizard.setBackEnabled(false);
}
if(panels.size() > currentPanelIndex+1)
{
wizard.setNextEnabled(true);
}
wizard.setFinishEnabled(false);
wizard.showPanel(currentPanel);
}
if(currentPanel instanceof WizardPage)
{
((WizardPage)currentPanel).entering();
}
}
/**
* @since VCafe 3.0
*/
public void nextPanel()
{
if(!(currentPanel instanceof WizardPage) || (((WizardPage)currentPanel).exiting()))
{
currentPanelIndex = computeNextPanelIndex(currentPanelIndex);
if(wizard != null)
{
wizard.setBackEnabled(true);
}
if(currentPanelIndex < panels.size())
{
currentPanel = (JPanel)panels.elementAt(currentPanelIndex);
}
}
if(currentPanelIndex == panels.size() - 1)
{
if(wizard != null)
{
wizard.setBackEnabled(true);
wizard.setNextEnabled(false);
wizard.setFinishEnabled(true);
}
}
if(wizard != null)
{
wizard.showPanel(currentPanel);
}
if(currentPanel instanceof WizardPage)
{
((WizardPage)currentPanel).entering();
}
}
/**
* @since VCafe 3.0
*/
protected int firstPanelIndex()
{
return 0;
}
/**
* @param currentIndex TODO
* @since VCafe 3.0
*/
protected int computeNextPanelIndex(int currentIndex)
{
int max;
max = panels.size();
if(max > currentIndex + 1)
{
return currentIndex + 1;
}
return NULL_PANEL;
}
/**
* @param currentIndex TODO
* @since VCafe 3.0
*/
protected int computePreviousPanelIndex(int currentIndex)
{
if (currentIndex > 0)
{
return currentIndex - 1;
}
return NULL_PANEL;
}
/**
* @param goHere TODO
* @exception java.lang.ArrayIndexOutOfBoundsException
* @since VCafe 3.0
*/
protected int gotoPanel(JPanel goHere)
throws ArrayIndexOutOfBoundsException
{
int newIndex;
newIndex = panels.indexOf(goHere);
if((!(currentPanel instanceof WizardPage)) || (((WizardPage)currentPanel).exiting()))
{
currentPanelIndex = newIndex;
currentPanel = (JPanel)panels.elementAt(currentPanelIndex);
if(currentPanel instanceof WizardPage)
{
((WizardPage)currentPanel).entering();
}
if(wizard != null)
{
wizard.showPanel(currentPanel);
}
}
return newIndex;
}
/**
* @since VCafe 3.0
*/
public void finish()
{
if((!(currentPanel instanceof WizardPage)) || ((WizardPage)currentPanel).exiting())
{
for(Enumeration e = panels.elements(); e.hasMoreElements();)
{
JPanel panel;
panel = (JPanel)e.nextElement();
if(panel instanceof WizardPage)
{
((WizardPage)panel).finish();
}
}
}
}
/**
* @since VCafe 3.0
*/
public void cancel()
{
if((!(currentPanel instanceof WizardPage)) || (((WizardPage)currentPanel).exiting()))
{
for(Enumeration e = panels.elements(); e.hasMoreElements();)
{
JPanel panel;
panel = (JPanel)e.nextElement();
if(panel instanceof WizardPage)
{
((WizardPage)panel).cancel();
}
}
}
}
/**
* @since VCafe 3.0
*/
public void cancelWizard()
{
if(wizard != null)
{
wizard.cancel();
}
}
/**
* @since VCafe 3.0
*/
public void help()
{
}
/**
* @param str TODO
* @since VCafe 3.0
*/
public void setWizardTitle(String str)
{
title = str;
}
/**
* @since VCafe 3.0
*/
public String getWizardTitle()
{
return (title);
}
/**
* @param dataName TODO
* @since VCafe 3.0
*/
public Object getData(String dataName)
{
for(Enumeration e = panels.elements(); e.hasMoreElements();)
{
JPanel panel;
panel = (JPanel)e.nextElement();
if(panel instanceof WizardPage)
{
Object data;
data = ((WizardPage)panel).getData(dataName);
if(data != null)
{
return (data);
}
}
}
return (null);
}
/**
* @since VCafe 3.0
*/
public Vector getSummary()
{
Vector summaries;
summaries = new Vector();
for(Enumeration e = panels.elements(); e.hasMoreElements();)
{
JPanel panel;
panel = (JPanel)e.nextElement();
if(panel instanceof WizardSummaryPage)
{
Summary s;
s = ((WizardSummaryPage)panel).getSummary();
if(s != null)
{
summaries.addElement(s);
}
}
}
return (summaries);
}
public Vector getWizardSummary()
{
Vector summaries;
summaries = new Vector();
int max = panels.size();
for(int i = 0; i < max; i++)
{
JPanel panel;
panel = (JPanel)panels.elementAt(i);
if(panel instanceof WizardSummaryPage)
{
WizardSummary s;
s = ((WizardSummaryPage)panel).getWizardSummary();
if(s != null)
{
summaries.addElement(s);
}
}
}
return (summaries);
}
/**
* @param f TODO
* @since VCafe 3.0
*/
public void setBackEnabled(boolean f)
{
if(currentPanelIndex > 0 && wizard != null)
{
wizard.setBackEnabled(f);
}
}
/**
* @param f TODO
* @since VCafe 3.0
*/
public void setNextEnabled(boolean f)
{
if(currentPanelIndex < panels.size() && wizard != null)
{
wizard.setNextEnabled(f);
}
}
/**
* @param f TODO
* @since VCafe 3.0
*/
public void setFinishEnabled(boolean f)
{
if(wizard != null)
{
wizard.setFinishEnabled(f);
}
}
/**
* @param f TODO
* @since VCafe 3.0
*/
public void setCancelEnabled(boolean f)
{
if(wizard != null)
{
wizard.setCancelEnabled(f);
}
}
/**
* @param f TODO
* @since VCafe 3.0
*/
public void setHelpEnabled(boolean f)
{
if(wizard != null)
{
wizard.setHelpEnabled(f);
}
}
/**
* @since VCafe 3.0
*/
public boolean isBackEnabled()
{
if(wizard != null)
{
return (wizard.isBackEnabled());
}
return (false);
}
/**
* @since VCafe 3.0
*/
public boolean isNextEnabled()
{
if(wizard != null)
{
return (wizard.isNextEnabled());
}
return (false);
}
/**
* @since VCafe 3.0
*/
public boolean isFinishEnabled()
{
if(wizard != null)
{
return (wizard.isFinishEnabled());
}
return (false);
}
/**
* @since VCafe 3.0
*/
public boolean isCancelEnabled()
{
if(wizard != null)
{
return (wizard.isCancelEnabled());
}
return (false);
}
/**
* @since VCafe 3.0
*/
public boolean isHelpEnabled()
{
if(wizard != null)
{
return (wizard.isHelpEnabled());
}
return (false);
}
/**
* @since VCafe 3.0
*/
public void setBackFocus()
{
if(wizard != null)
{
wizard.setBackFocus();
}
}
/**
* @since VCafe 3.0
*/
public void setNextFocus()
{
if(wizard != null)
{
wizard.setNextFocus();
}
}
/**
* @since VCafe 3.0
*/
public void setFinishFocus()
{
if(wizard != null)
{
wizard.setFinishFocus();
}
}
/**
* @since VCafe 3.0
*/
public void setCancelFocus()
{
if(wizard != null)
{
wizard.setCancelFocus();
}
}
/**
* @since VCafe 3.0
*/
public void setHelpFocus()
{
if(wizard != null)
{
wizard.setHelpFocus();
}
}
public void setImage(Image image)
{
if(wizard != null)
{
wizard.setImage(image);
}
}
public void setImage(URL url)
{
if(wizard != null)
{
wizard.setImage(url);
}
}
public void setImage(InputStream stream)
throws IOException
{
if(wizard != null)
{
wizard.setImage(stream);
}
}
public void setImage(ImageIcon icon)
{
if(wizard != null)
{
wizard.setImage(icon);
}
}
}