import java.awt.Component; import java.util.*; import javax.swing.*; import javax.swing.JLabel; import javax.swing.event.ChangeListener; import org.openide.WizardDescriptor; import org.openide.util.*; import org.openide.util.HelpCtx; public class WizardDescTest { /** Creates a new instance of WizardDescTest */ public WizardDescTest() { } static MyWizardDescriptor wd; /** * @param args the command line arguments */ public static void main(String[] args) { WizardDescriptor.Panel panels[] = new WizardDescriptor.Panel[2]; panels[0] = new Panel("first panel"); panels[1] = new Panel("second panel"); wd = new MyWizardDescriptor(panels); wd.addPropertyChangeListener(new Listener()); java.awt.Dialog d = org.openide.TopManager.getDefault().createDialog(wd); d.show(); } public static class MyWizardDescriptor extends WizardDescriptor { Object realValue; private MyWizardDescriptor () { super (new WizardDescriptor.Panel[] {}); } public MyWizardDescriptor (WizardDescriptor.Panel[] panels) { super (panels); } public void setValue (Object obj) { setRealValue (obj); super.setValue (obj); } public void setRealValue (Object obj) { realValue = obj; } public Object getRealValue () { return realValue; } } public static class Panel implements WizardDescriptor.Panel, WizardDescriptor.FinishPanel { private String text; public Panel(String text) { this.text = text; } public Component getComponent() { return new JLabel(text); } public void addChangeListener(ChangeListener l) { } public HelpCtx getHelp() { return null; } public boolean isValid() { return true; } public void readSettings(Object settings) { System.err.println("readSettings of panel: "+text); System.out.println("CURRENT VALUE: " + handleValue (wd.getValue ())); System.out.println("FUTURE VALUE: " + handleValue (wd.getRealValue ())); System.out.println(""); } public void removeChangeListener(ChangeListener l) { //System.out.println("!!! removeChangeListener !!!"); } public void storeSettings(Object settings) { System.err.println("storeSettings of panel: "+text); System.out.println("CURRENT VALUE: " + handleValue (wd.getValue ())); System.out.println("FUTURE VALUE: " + handleValue (wd.getRealValue ())); System.out.println(""); } } public static class Listener implements java.beans.PropertyChangeListener { public void propertyChange(java.beans.PropertyChangeEvent propertyChangeEvent) { if (WizardDescriptor.PROP_VALUE.equals(propertyChangeEvent.getPropertyName ())) { System.out.println("### VALUE: " + handleValue (wd.getValue ())); } } } public static String handleValue (Object val) { if (val == null) return "NULL"; if (val instanceof String) return (String) val; if (WizardDescriptor.FINISH_OPTION.equals (val)) return "FINISH_OPTION"; if (WizardDescriptor.CANCEL_OPTION.equals (val)) return "CANCEL_OPTION"; if (WizardDescriptor.CLOSED_OPTION.equals (val)) return "CLOSED_OPTION"; if (val instanceof JButton) { JButton butt = (JButton) val; ResourceBundle b = NbBundle.getBundle ("org.openide.Bundle"); // NOI18N if (b.getString ("CTL_NEXT").equals (butt.getText ())) return "NEXT_OPTION"; if (b.getString ("CTL_PREVIOUS").equals (butt.getText ())) return "NEXT_PREVIOUS"; if (b.getString ("CTL_FINISH").equals (butt.getText ())) return "FINISH_OPTION"; if (b.getString ("CTL_CANCEL").equals (butt.getText ())) return "CANCEL_OPTION"; } return "UNKNOWN OPTION: " + val; } }