samples/apifest1/infrastructure/testing-template/src/org/netbeans/apifest/testingtemplate/TestingTemplateWizardPanel.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:52:45 +0200
changeset 52 4257f4cf226b
permissions -rw-r--r--
Adding samples from API fest to the repository, including pieces of their code in the document, not just links
     1 package org.netbeans.apifest.testingtemplate;
     2 
     3 import java.awt.Component;
     4 import java.util.HashSet;
     5 import java.util.Iterator;
     6 import java.util.Set;
     7 import javax.swing.event.ChangeEvent;
     8 import javax.swing.event.ChangeListener;
     9 import org.openide.WizardDescriptor;
    10 import org.openide.WizardValidationException;
    11 import org.openide.util.HelpCtx;
    12 import org.openide.util.NbBundle;
    13 
    14 /**
    15  * Panel just asking for basic info.
    16  */
    17 public class TestingTemplateWizardPanel implements WizardDescriptor.Panel,
    18     WizardDescriptor.ValidatingPanel, WizardDescriptor.FinishablePanel {
    19     
    20     private WizardDescriptor wizardDescriptor;
    21     private TestingTemplatePanelVisual component;
    22     
    23     /** Creates a new instance of templateWizardPanel */
    24     public TestingTemplateWizardPanel() {
    25     }
    26     
    27     public Component getComponent() {
    28         if (component == null) {
    29             component = new TestingTemplatePanelVisual(this);
    30             component.setName(NbBundle.getMessage(TestingTemplateWizardPanel.class, "LBL_CreateProjectStep"));
    31         }
    32         return component;
    33     }
    34     
    35     public HelpCtx getHelp() {
    36         return new HelpCtx(TestingTemplateWizardPanel.class);
    37     }
    38     
    39     public boolean isValid() {
    40         getComponent();
    41         return component.valid(wizardDescriptor);
    42     }
    43     
    44     private final Set/*<ChangeListener>*/ listeners = new HashSet(1);
    45     public final void addChangeListener(ChangeListener l) {
    46         synchronized (listeners) {
    47             listeners.add(l);
    48         }
    49     }
    50     public final void removeChangeListener(ChangeListener l) {
    51         synchronized (listeners) {
    52             listeners.remove(l);
    53         }
    54     }
    55     protected final void fireChangeEvent() {
    56         Iterator it;
    57         synchronized (listeners) {
    58             it = new HashSet(listeners).iterator();
    59         }
    60         ChangeEvent ev = new ChangeEvent(this);
    61         while (it.hasNext()) {
    62             ((ChangeListener) it.next()).stateChanged(ev);
    63         }
    64     }
    65     
    66     public void readSettings(Object settings) {
    67         wizardDescriptor = (WizardDescriptor) settings;
    68         component.read(wizardDescriptor);
    69     }
    70     
    71     public void storeSettings(Object settings) {
    72         WizardDescriptor d = (WizardDescriptor) settings;
    73         component.store(d);
    74     }
    75     
    76     public boolean isFinishPanel() {
    77         return true;
    78     }
    79     
    80     public void validate() throws WizardValidationException {
    81         getComponent();
    82         component.validate(wizardDescriptor);
    83     }
    84     
    85 }