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 javax.swing.JPanel;
045: import org.openide.WizardDescriptor;
046: import org.openide.util.NbBundle;
047:
048: /**
049: * @author Martin Krauskopf, Radek Matous
050: */
051: public abstract class BasicVisualPanel extends JPanel {
052:
053: private WizardDescriptor settings;
054:
055: protected BasicVisualPanel(final WizardDescriptor setting) {
056: this .settings = setting;
057: }
058:
059: public final WizardDescriptor getSettings() {
060: return settings;
061: }
062:
063: /**
064: * Set an error message and mark the panel as invalid.
065: */
066: protected final void setError(String message) {
067: if (message == null) {
068: throw new NullPointerException();
069: }
070: setMessage(message);
071: setValid(false);
072: }
073:
074: /**
075: * Set an warning message but mark the panel as valid.
076: */
077: protected final void setWarning(String message) {
078: if (message == null) {
079: throw new NullPointerException();
080: }
081: setMessage(message);
082: setValid(true);
083: }
084:
085: /**
086: * Mark the panel as invalid without any message.
087: * Use with restraint; generally {@link #setError} is better.
088: */
089: protected final void markInvalid() {
090: setMessage(null);
091: setValid(false);
092: }
093:
094: /**
095: * Mark the panel as valid and clear any error or warning message.
096: */
097: protected final void markValid() {
098: setMessage(null);
099: setValid(true);
100: }
101:
102: private final void setMessage(String message) {
103: settings.putProperty("WizardPanel_errorMessage", message); // NOI18N
104: }
105:
106: /**
107: * Sets this panel's validity and fires event to it's wrapper wizard panel.
108: * See {@link BasicWizardPanel#propertyChange} for what happens further.
109: */
110: private final void setValid(boolean valid) {
111: firePropertyChange("valid", null, Boolean.valueOf(valid)); // NOI18N
112: }
113: }
|