/*
 * __NAME__.java
 *
 * Created on __DATE__
 */

package Templates.API_Support.Window_System_API;

import java.util.NoSuchElementException;
import javax.swing.event.ChangeListener;

import org.openide.WizardDescriptor;
import org.openide.util.NbBundle;

/** A wizard iterator (sequence of panels).
 * Used to create a wizard. Create one or more
 * panels from template as needed too.
 *
 * @author __USER__
 */
public class __Sample_Wizard__Iterator implements WizardDescriptor.Iterator {

    // You should define what panels you want to use here:

    protected WizardDescriptor.Panel[] createPanels() {
        return new WizardDescriptor.Panel[] {
            /* --> EDIT ME <--
            new MyPanel1 (),
            new MyPanel2 ()
             */
        };
    }

    // And the list of step names:

    protected String[] createSteps() {
        return new String[] {
            /* --> EDIT ME <--
            NbBundle.getMessage(__NAME__.class, "LBL_step_1"),
            NbBundle.getMessage(__NAME__.class, "LBL_step_2")
             */
        };
    }

    // --- The rest probably does not need to be touched. ---

    // Keep track of the panels and selected panel:

    private transient int index = 0;
    // Also package-accessible to descriptor:
    protected final int getIndex() {
        return index;
    }
    private transient WizardDescriptor.Panel[] panels = null;
    protected final WizardDescriptor.Panel[] getPanels() {
        if (panels == null) {
            panels = createPanels();
        }
        return panels;
    }

    // Also the list of steps in the left pane:

    private transient String[] steps = null;
    // Also package-accessible to descriptor:
    protected final String[] getSteps() {
        if (steps == null) {
            steps = createSteps();
        }
        return steps;
    }

    // --- WizardDescriptor.Iterator METHODS: ---
    // Note that this is very similar to WizardDescriptor.Iterator, but with a
    // few more options for customization. If you e.g. want to make panels appear
    // or disappear dynamically, go ahead.

    public String name() {
        return NbBundle.getMessage(__NAME__.class, "TITLE_x_of_y",
            new Integer(index + 1), new Integer(getPanels().length));
    }

    public boolean hasNext() {
        return index < getPanels().length - 1;
    }
    public boolean hasPrevious() {
        return index > 0;
    }
    public void nextPanel() {
        if (!hasNext()) throw new NoSuchElementException();
        index++;
    }
    public void previousPanel() {
        if (!hasPrevious()) throw new NoSuchElementException();
        index--;
    }
    public WizardDescriptor.Panel current() {
        return getPanels()[index];
    }

    // If nothing unusual changes in the middle of the wizard, simply:
    public final void addChangeListener(ChangeListener l) {}
    public final void removeChangeListener(ChangeListener l) {}
    // If something changes dynamically (besides moving between panels),
    // e.g. the number of panels changes in response to user input, then
    // uncomment the following and call when needed:
    // fireChangeEvent();
    /*
    private transient Set<ChangeListener> listeners = new HashSet<ChangeListener>(1);
    public final void addChangeListener(ChangeListener l) {
        synchronized (listeners) {
            listeners.add(l);
        }
    }
    public final void removeChangeListener(ChangeListener l) {
        synchronized (listeners) {
            listeners.remove(l);
        }
    }
    protected final void fireChangeEvent() {
        Iterator<ChangeListener> it;
        synchronized (listeners) {
            it = new HashSet<ChangeListener>(listeners).iterator();
        }
        ChangeEvent ev = new ChangeEvent(this);
        while (it.hasNext()) {
            it.next().stateChanged(ev);
        }
    }
    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
        in.defaultReadObject();
        listeners = new HashSet<ChangeListener>(1);
    }
    */

}
