001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.mobility.cldcplatform.wizard;
043:
044: import org.openide.WizardDescriptor;
045: import org.netbeans.modules.mobility.cldcplatform.*;
046:
047: import javax.swing.event.ChangeListener;
048: import javax.swing.event.ChangeEvent;
049: import javax.swing.*;
050: import java.util.*;
051: import java.io.IOException;
052: import org.openide.util.NbBundle;
053:
054: /**
055: * @author David Kaspar
056: */
057: public class InstallerIterator implements
058: WizardDescriptor.InstantiatingIterator {
059:
060: private static InstallerIterator INSTANCE;
061:
062: ArrayList<ChangeListener> listeners = new ArrayList<ChangeListener>();
063: int current;
064: private WizardDescriptor.FinishablePanel[] panels;
065: private WizardDescriptor wizardDescriptor;
066:
067: public static synchronized InstallerIterator getDefault() {
068: if (INSTANCE == null)
069: INSTANCE = new InstallerIterator();
070: return INSTANCE;
071: }
072:
073: public void addChangeListener(final ChangeListener changeListener) {
074: listeners.add(changeListener);
075: }
076:
077: public void removeChangeListener(final ChangeListener changeListener) {
078: listeners.remove(changeListener);
079: }
080:
081: public void fireChanged() {
082: final ChangeEvent e = new ChangeEvent(this );
083: for (final ChangeListener l : listeners)
084: l.stateChanged(e);
085: }
086:
087: public WizardDescriptor.Panel current() {
088: return panels[current];
089: }
090:
091: public String name() {
092: return NbBundle.getMessage(InstallerIterator.class,
093: "Title_InstallIterator_Add_Mobile_Platforms"); //NOI18N
094: }
095:
096: public boolean hasNext() {
097: return current < panels.length - 1 && current().isValid();
098: }
099:
100: public boolean hasPrevious() {
101: return current > 0;
102: }
103:
104: public void nextPanel() {
105: assert hasNext();
106: current++;
107: }
108:
109: public void previousPanel() {
110: assert hasPrevious();
111: current--;
112: }
113:
114: public void initialize(final WizardDescriptor wizardDescriptor) {
115: this .wizardDescriptor = wizardDescriptor;
116: current = 0;
117: panels = new WizardDescriptor.FinishablePanel[] {
118: new FindWizardPanel(), new DetectWizardPanel(), };
119: String[] strs = new String[panels.length];
120: for (int i = 0; i < strs.length; i++)
121: strs[i] = panels[i].getComponent().getName();
122: ((JComponent) panels[0].getComponent()).putClientProperty(
123: "WizardPanel_contentData", strs); // NOI18N
124: }
125:
126: public void uninitialize(@SuppressWarnings("unused")
127: final WizardDescriptor wizardDescriptor) {
128: panels = null;
129: }
130:
131: public Set<J2MEPlatform> instantiate() throws IOException {
132: final J2MEPlatform[] platforms = (J2MEPlatform[]) wizardDescriptor
133: .getProperty(DetectPanel.PROP_PLATFORMS);
134: final HashSet<J2MEPlatform> set = new HashSet<J2MEPlatform>();
135: for (int i = 0; i < platforms.length; i++) {
136: final J2MEPlatform platform = platforms[i];
137: J2MEPlatform.createPlatform(platform);
138: set.add(platform);
139: }
140: return set;
141: }
142:
143: }
|