HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"JWizard"
Volume: 3 Issue: 9, p. 22

Download files assoicated with this article

	

Listing 1
 
private void setActive(Component comp, boolean enabled) 
{ 
comp.setVisible(enabled); 
comp.setEnabled(enabled); 
if (comp instanceof Container) 
{ 
Container cont = (Container)comp; 
int count = cont.getComponentCount(); 
for (int i = 0; i < count; i++) 
{ 
setActive(cont.getComponent(i), enabled); 
} 
} 
} 

public void show(Container parent, int index) 
{ 
synchronized (parent.getTreeLock()) 
{ 
checkLayout(parent); 
if (index < 0 || index > parent.getComponentCount() - 1) 
return; 
int ncomponents = parent.getComponentCount(); 
for (int i = 0 ; i < ncomponents ; i++) 
{ 
Component comp = parent.getComponent(i); 
if (comp.isVisible()) 
{ 
setActive(comp, false); 
comp = parent.getComponent(index); 
setActive(comp, true); 
parent.validate(); 
return; 
} 
} 
} 
} 

Listing 2
 
public void addPanel(String name, Component panel) 
{ 
if (index < 0) 
{ 
manager.setFirst(name); 
manager.setCurrent(name); 
} 
else 
{ 
manager.setPrevious(name, getName(index)); 
} 
add(name, panel); 
index++; 
} 

public void setPanel(String name) 
{ 
if (name == "") return; 
manager.setCurrent(name); 
layout.show(this, name); 
} 

Listing 3
 
public interface SequenceManager 
{ 
public String getFirst(); 
public void setFirst(String name); 

public String getCurrent(); 
public void setCurrent(String name); 

public String getNext(String name); 
public void setNext(String name, String next); 

public String getPrevious(String name); 
public void setPrevious(String name, String previous); 
} 

Listing 4
 
protected String first; 
protected String current; 
protected Hashtable next; 
protected Hashtable prev; 

public String getNext(String name) 
{ 
if (!next.containsKey(name)) return ""; 
return (String)next.get(name); 
} 

public void setNext(String name, String link) 
{ 
if (next.containsKey(name)) next.remove(name); 
if (prev.containsKey(link)) prev.remove(link); 
next.put(name, link); 
prev.put(link, name); 
} 

Listing 5
 
public interface DataCollectionModel 
{ 
public boolean hasValue(String name); 
public Object getValue(String name); 
public Object getValue(String name, Object def); 
public void setValue(String name, Object value); 
public void removeValue(String name); 
public void addChangeListener(ChangeListener listener); 
public void removeChangeListener(ChangeListener listener); 
} 

Listing 6.
 
public void addChangeListener(ChangeListener listener) 
{ 
listeners.addElement(listener); 
} 

public void fireChangeEvent() 
{ 
Vector list = (Vector)listeners.clone(); 
ChangeEvent event = new ChangeEvent(this); 
ChangeListener listener; 
for (int i = 0; i < list.size(); i++) 
{ 
listener = (ChangeListener)list.elementAt(i); 
listener.stateChanged(event); 
} 
} 

public void setValue(String name, Object value) 
{ 
put(name, value); 
fireChangeEvent(); 
} 
  

Listing 7
 
public interface WizardValidator 
{ 
public boolean canMoveForward(); 
public boolean canMoveBackward(); 
} 

Listing 8
 
protected boolean canMoveForward = false; 
protected boolean canMoveBackward = true; 

public WizardPanel(String name, String description) 
{ 
setLayout(new BorderLayout()); 

JPanel north = new JPanel(); 
north.setLayout(new BorderLayout()); 

if (name != null) 
{ 
JLabel title = new JLabel(name); 
title.setFont(new Font("Helvetica", Font.PLAIN, 24)); 
title.setBorder(new EdgeBorder(EdgeBorder.SOUTH)); 
north.add("North", title); 
} 

if (description != null) 
{ 
JTextArea explain = new JTextArea(description); 
explain.setFont(getFont()); 
explain.setBorder(new EmptyBorder(15, 2, 5, 15)); 
explain.setWrapStyleWord(true); 
explain.setEditable(false); 
explain.setLineWrap(true); 
explain.setOpaque(false); 
north.add("Center", explain); 
} 

add("North", north); 
} 

public boolean canMoveForward() 
{ 
return canMoveForward; 
} 

public boolean canMoveBackward() 
{ 
return canMoveBackward; 
} 

public DataCollectionModel getDataModel() 
{ 
return ((JWizard)getParent().getParent()).getModel(); 
} 

public SequenceManager getSequenceManager() 
{ 
return ((JWizard)getParent().getParent()).getManager(); 
} 

Listing 9.
 
public class JWizardTest extends JFrame 
{ 
public JWizardTest() 
{ 
super("JWizard Test"); 
setBounds(100, 100, 479, 357); 

JWizard wizard = new JWizard("JWizard.gif"); 
wizard.addPanel("info", new InformationPanel()); 
wizard.addPanel("favorites", new FavoritesPanel()); 
wizard.addPanel("java", new ResultPanel("Java", "100% Pure Genius!")); 
wizard.addPanel("cpp", new ResultPanel("C/C++", "You'll see...")); 
wizard.addPanel("pascal", new ResultPanel("Pascal", "Oh well...")); 
wizard.addPanel("smalltalk", new ResultPanel("SmallTalk", "Object Oriented")); 
wizard.addPanel("cobol", new ResultPanel("Cobol", "Year 2k problems?")); 
wizard.addPanel("fortran", new ResultPanel("Fortran", "Try Mathematica!")); 
wizard.setFirst(); 

getContentPane().setLayout(new BorderLayout()); 
getContentPane().add("Center", wizard); 
} 

public static void main(String[] args) 
{ 
JWizardTest wiz = new JWizardTest(); 
wiz.show(); 
} 
} 

}  
  
      
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.