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.form.wizard;
043:
044: import javax.swing.event.*;
045: import org.netbeans.modules.form.*;
046:
047: /**
048: * The first panel of connection wizard - for selecting the activation event
049: * on the source component and handler for the event (where the connection code
050: * will be generated).
051: *
052: * @author Tomas Pavek
053: */
054:
055: class ConnectionWizardPanel1 implements
056: org.openide.WizardDescriptor.Panel {
057:
058: private Event selectedEvent;
059:
060: private RADComponent sourceComponent;
061:
062: private EventListenerList listenerList;
063:
064: private ConnectionPanel1 uiPanel;
065:
066: // -------
067:
068: ConnectionWizardPanel1(RADComponent source) {
069: sourceComponent = source;
070: }
071:
072: RADComponent getSourceComponent() {
073: return sourceComponent;
074: }
075:
076: Event getSelectedEvent() {
077: return selectedEvent;
078: }
079:
080: String getEventName() {
081: return uiPanel != null ? uiPanel.getEventName() : null;
082: }
083:
084: void setSelectedEvent(Event event) {
085: selectedEvent = event;
086: fireStateChanged();
087: }
088:
089: boolean handlerAlreadyExists() {
090: if (uiPanel == null)
091: return false;
092:
093: return selectedEvent != null
094: && selectedEvent
095: .hasEventHandler(uiPanel.getEventName());
096: }
097:
098: // ----------
099: // WizardDescriptor.Panel implementation
100:
101: public java.awt.Component getComponent() {
102: if (uiPanel == null)
103: uiPanel = new ConnectionPanel1(this );
104: return uiPanel;
105: }
106:
107: public org.openide.util.HelpCtx getHelp() {
108: return new org.openide.util.HelpCtx("gui.connecting.source"); // NOI18N
109: }
110:
111: public boolean isValid() {
112: String eventName = uiPanel != null ? uiPanel.getEventName()
113: : null;
114: return selectedEvent != null
115: && eventName != null
116: && !"".equals(eventName)
117: && org.openide.util.Utilities
118: .isJavaIdentifier(eventName);
119: }
120:
121: public void readSettings(java.lang.Object settings) {
122: }
123:
124: public void storeSettings(java.lang.Object settings) {
125: }
126:
127: public void addChangeListener(ChangeListener listener) {
128: if (listenerList == null)
129: listenerList = new EventListenerList();
130: listenerList.add(ChangeListener.class, listener);
131: }
132:
133: public void removeChangeListener(ChangeListener listener) {
134: if (listenerList != null)
135: listenerList.remove(ChangeListener.class, listener);
136: }
137:
138: // -----
139:
140: void fireStateChanged() {
141: if (listenerList == null)
142: return;
143:
144: ChangeEvent e = null;
145: Object[] listeners = listenerList.getListenerList();
146: for (int i = listeners.length - 2; i >= 0; i -= 2) {
147: if (listeners[i] == ChangeListener.class) {
148: if (e == null)
149: e = new ChangeEvent(this );
150: ((ChangeListener) listeners[i + 1]).stateChanged(e);
151: }
152: }
153: }
154: }
|