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-2007 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: package org.netbeans.modules.cnd.discovery.wizard;
042:
043: import java.awt.Component;
044: import java.util.HashSet;
045: import java.util.Iterator;
046: import java.util.Set;
047: import javax.swing.event.ChangeEvent;
048: import javax.swing.event.ChangeListener;
049: import org.netbeans.modules.cnd.discovery.wizard.api.DiscoveryDescriptor;
050: import org.openide.WizardDescriptor;
051: import org.openide.util.HelpCtx;
052: import org.openide.util.NbBundle;
053:
054: /**
055: *
056: * @author Alexander Simon
057: */
058: public class SimpleConfigurationWizard implements
059: WizardDescriptor.Panel, ChangeListener {
060:
061: private DiscoveryDescriptor wizardDescriptor;
062: private SimpleConfigurationPanel component;
063: private String name;
064: private boolean inited = false;
065:
066: public SimpleConfigurationWizard() {
067: name = NbBundle.getMessage(SimpleConfigurationWizard.class,
068: "SimpleConfigurationName"); // NOI18N
069: }
070:
071: // Get the visual component for the panel. In this template, the component
072: // is kept separate. This can be more efficient: if the wizard is created
073: // but never displayed, or not all panels are displayed, it is better to
074: // create only those which really need to be visible.
075: public Component getComponent() {
076: if (component == null) {
077: component = new SimpleConfigurationPanel(this );
078: component.setName(name);
079: }
080: return component;
081: }
082:
083: public HelpCtx getHelp() {
084: return new HelpCtx(
085: DiscoveryWizardAction.HELP_CONTEXT_SIMPLE_CONFIGURATION);
086: }
087:
088: public boolean isValid() {
089: boolean valid = ((SimpleConfigurationPanel) getComponent())
090: .valid();
091: if (valid) {
092: wizardDescriptor.setMessage(""); // NOI18N
093: }
094: return valid;
095: }
096:
097: private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(
098: 1);
099:
100: public final void addChangeListener(ChangeListener l) {
101: synchronized (listeners) {
102: listeners.add(l);
103: }
104: }
105:
106: public final void removeChangeListener(ChangeListener l) {
107: synchronized (listeners) {
108: listeners.remove(l);
109: }
110: }
111:
112: protected final void fireChangeEvent() {
113: Iterator<ChangeListener> it;
114: synchronized (listeners) {
115: it = new HashSet<ChangeListener>(listeners).iterator();
116: }
117: ChangeEvent ev = new ChangeEvent(this );
118: while (it.hasNext()) {
119: it.next().stateChanged(ev);
120: }
121: }
122:
123: public void stateChanged(ChangeEvent e) {
124: fireChangeEvent();
125: }
126:
127: // You can use a settings object to keep track of state. Normally the
128: // settings object will be the WizardDescriptor, so you can use
129: // WizardDescriptor.getProperty & putProperty to store information entered
130: // by the user.
131: public void readSettings(Object settings) {
132: if (!inited) {
133: wizardDescriptor = DiscoveryWizardDescriptor
134: .adaptee(settings);
135: component.read(wizardDescriptor);
136: inited = true;
137: }
138: }
139:
140: public void storeSettings(Object settings) {
141: component.store(DiscoveryWizardDescriptor.adaptee(settings));
142: }
143: }
|