1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 /*
23  * InstallationPathIterator.java
24  *
25  * Created on February 12, 2003
26  */
27 
28 package org.openoffice.netbeans.modules.office.wizard;
29 
30 import java.io.IOException;
31 import java.io.ObjectInputStream;
32 import java.util.HashSet;
33 import java.util.Iterator;
34 import java.util.NoSuchElementException;
35 import java.util.Set;
36 import javax.swing.event.ChangeEvent;
37 import javax.swing.event.ChangeListener;
38 
39 import org.openide.WizardDescriptor;
40 import org.openide.util.NbBundle;
41 
42 /** A wizard iterator (sequence of panels).
43  * Used to create a wizard. Create one or more
44  * panels from template as needed too.
45  *
46  * @author tomaso
47  */
48 public class InstallationPathIterator implements WizardDescriptor.Iterator {
49 
50     // You should define what panels you want to use here:
51 
createPanels()52     protected WizardDescriptor.Panel[] createPanels() {
53         return new WizardDescriptor.Panel[] {
54             new SelectPathPanel()
55         };
56     }
57 
58     // And the list of step names:
59 
createSteps()60     protected String[] createSteps() {
61         return new String[] {
62             "Select OpenOffice.org Installation"
63         };
64     }
65 
66     // --- The rest probably does not need to be touched. ---
67 
68     // Keep track of the panels and selected panel:
69 
70     private transient int index = 0;
71     // Also package-accessible to descriptor:
getIndex()72     protected final int getIndex() {
73         return index;
74     }
75     private transient WizardDescriptor.Panel[] panels = null;
getPanels()76     protected final WizardDescriptor.Panel[] getPanels() {
77         if (panels == null) {
78             panels = createPanels();
79         }
80         return panels;
81     }
82 
83     // Also the list of steps in the left pane:
84 
85     private transient String[] steps = null;
86     // Also package-accessible to descriptor:
getSteps()87     protected final String[] getSteps() {
88         if (steps == null) {
89             steps = createSteps();
90         }
91         return steps;
92     }
93 
94     // --- WizardDescriptor.Iterator METHODS: ---
95     // Note that this is very similar to WizardDescriptor.Iterator, but with a
96     // few more options for customization. If you e.g. want to make panels appear
97     // or disappear dynamically, go ahead.
98 
name()99     public String name() {
100         return NbBundle.getMessage(InstallationPathIterator.class, "TITLE_x_of_y",
101         new Integer(index + 1), new Integer(getPanels().length));
102     }
103 
hasNext()104     public boolean hasNext() {
105         return index < getPanels().length - 1;
106     }
hasPrevious()107     public boolean hasPrevious() {
108         return index > 0;
109     }
nextPanel()110     public void nextPanel() {
111         if (!hasNext()) throw new NoSuchElementException();
112         index++;
113     }
previousPanel()114     public void previousPanel() {
115         if (!hasPrevious()) throw new NoSuchElementException();
116         index--;
117     }
current()118     public WizardDescriptor.Panel current() {
119         return getPanels()[index];
120     }
121 
122     // If nothing unusual changes in the middle of the wizard, simply:
addChangeListener(ChangeListener l)123     public final void addChangeListener(ChangeListener l) {}
removeChangeListener(ChangeListener l)124     public final void removeChangeListener(ChangeListener l) {}
125     // If something changes dynamically (besides moving between panels),
126     // e.g. the number of panels changes in response to user input, then
127     // uncomment the following and call when needed:
128     // fireChangeEvent();
129     /*
130     private transient Set listeners = new HashSet(1); // Set<ChangeListener>
131     public final void addChangeListener(ChangeListener l) {
132         synchronized (listeners) {
133             listeners.add(l);
134         }
135     }
136     public final void removeChangeListener(ChangeListener l) {
137         synchronized (listeners) {
138             listeners.remove(l);
139         }
140     }
141     protected final void fireChangeEvent() {
142         Iterator it;
143         synchronized (listeners) {
144             it = new HashSet(listeners).iterator();
145         }
146         ChangeEvent ev = new ChangeEvent(this);
147         while (it.hasNext()) {
148             ((ChangeListener)it.next()).stateChanged(ev);
149         }
150     }
151     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
152         in.defaultReadObject();
153         listeners = new HashSet(1);
154     }
155      */
156 
157 }
158