| /************************************************************** |
| * |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| * |
| *************************************************************/ |
| |
| /* |
| * InstallationPathIterator.java |
| * |
| * Created on February 12, 2003 |
| */ |
| |
| package org.openoffice.netbeans.modules.office.wizard; |
| |
| import java.io.IOException; |
| import java.io.ObjectInputStream; |
| import java.util.HashSet; |
| import java.util.Iterator; |
| import java.util.NoSuchElementException; |
| import java.util.Set; |
| import javax.swing.event.ChangeEvent; |
| 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 tomaso |
| */ |
| public class InstallationPathIterator implements WizardDescriptor.Iterator { |
| |
| // You should define what panels you want to use here: |
| |
| protected WizardDescriptor.Panel[] createPanels() { |
| return new WizardDescriptor.Panel[] { |
| new SelectPathPanel() |
| }; |
| } |
| |
| // And the list of step names: |
| |
| protected String[] createSteps() { |
| return new String[] { |
| "Select OpenOffice.org Installation" |
| }; |
| } |
| |
| // --- 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(InstallationPathIterator.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 listeners = new HashSet(1); // Set<ChangeListener> |
| 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 it; |
| synchronized (listeners) { |
| it = new HashSet(listeners).iterator(); |
| } |
| ChangeEvent ev = new ChangeEvent(this); |
| while (it.hasNext()) { |
| ((ChangeListener)it.next()).stateChanged(ev); |
| } |
| } |
| private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { |
| in.defaultReadObject(); |
| listeners = new HashSet(1); |
| } |
| */ |
| |
| } |