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.projectimport.j2seimport.ui;
043:
044: import java.util.ArrayList;
045: import java.util.Iterator;
046: import java.util.List;
047: import javax.swing.JComponent;
048: import javax.swing.JPanel;
049: import javax.swing.event.ChangeEvent;
050: import javax.swing.event.ChangeListener;
051: import org.openide.WizardDescriptor;
052: import org.openide.util.NbBundle;
053:
054: /**
055: *
056: * @author Radek Matous
057: */
058: public abstract class BasicPanel extends JPanel {
059: private BasicWizardPanel wiardPanel;
060: private boolean isOK = false;
061:
062: public abstract int getPanelIndex();
063:
064: public abstract String getPanelDescription();
065:
066: protected abstract void storeWizardData(WizardData data);
067:
068: protected abstract void readWizardData(WizardData data);
069:
070: public abstract void validateContent()
071: throws org.openide.WizardValidationException;
072:
073: public String getName() {
074: return getPanelDescription();
075: }
076:
077: public final boolean isOK() {
078: return isOK;
079: }
080:
081: public final void setValid(boolean valid) {
082: boolean fire = (isOK() != valid);
083: isOK = valid;
084: if (fire) {
085: wiardPanel.fireChange();
086: }
087: }
088:
089: public final WizardDescriptor.Panel getWizardPanel() {
090: if (wiardPanel == null) {
091: initPanel();
092: wiardPanel = new BasicWizardPanel();
093: }
094: return wiardPanel;
095: }
096:
097: final void initPanel() {
098: putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); // NOI18N
099: putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE); // NOI18N
100: putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE); // NOI18N
101: putClientProperty("WizardPanel_contentSelectedIndex", // NOI18N
102: new Integer(getPanelIndex()));
103: putClientProperty("WizardPanel_contentData", new String[] { // NOI18N
104: getPanelDescription() });
105: setPreferredSize(new java.awt.Dimension(500, 380));
106: }
107:
108: public static class WizardData {
109: private ErrorMessages errorMessages;
110:
111: public final void setErrorMessages(ErrorMessages errorMessages) {
112: this .errorMessages = errorMessages;
113: }
114:
115: public final ErrorMessages getErrorMessages() {
116: return errorMessages;
117: }
118: }
119:
120: public interface ErrorMessages {
121: void setError(String message);
122: }
123:
124: private class BasicWizardPanel implements WizardDescriptor.Panel,
125: WizardDescriptor.ValidatingPanel {
126:
127: /** Registered ChangeListeners */
128: private List changeListeners;
129:
130: /** Creates a new instance of BasicWizardPanel */
131: public BasicWizardPanel() {
132: }
133:
134: public void addChangeListener(ChangeListener l) {
135: if (changeListeners == null) {
136: changeListeners = new ArrayList(2);
137: }
138: changeListeners.add(l);
139: }
140:
141: public void removeChangeListener(ChangeListener l) {
142: if (changeListeners != null) {
143: if (changeListeners.remove(l)
144: && changeListeners.isEmpty()) {
145: changeListeners = null;
146: }
147: }
148: }
149:
150: public void fireChange() {
151: if (changeListeners != null) {
152: ChangeEvent e = new ChangeEvent(this );
153: for (Iterator i = changeListeners.iterator(); i
154: .hasNext();) {
155: ((ChangeListener) i.next()).stateChanged(e);
156: }
157: }
158: }
159:
160: public final void storeSettings(Object settings) {
161: BasicPanel.this
162: .storeWizardData((BasicPanel.WizardData) settings);
163: }
164:
165: public final void readSettings(Object settings) {
166: BasicPanel.this
167: .readWizardData((BasicPanel.WizardData) settings);
168: }
169:
170: public org.openide.util.HelpCtx getHelp() {
171: return null;
172: }
173:
174: public java.awt.Component getComponent() {
175: return BasicPanel.this ;
176: }
177:
178: public boolean isValid() {
179: return BasicPanel.this .isOK();
180: }
181:
182: public void validate()
183: throws org.openide.WizardValidationException {
184: BasicPanel.this.validateContent();
185: }
186: }
187:
188: }
|