KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > wizard > ConnectionWizardPanel1


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.form.wizard;
21
22 import javax.swing.event.*;
23 import org.netbeans.modules.form.*;
24
25 /**
26  * The first panel of connection wizard - for selecting the activation event
27  * on the source component and handler for the event (where the connection code
28  * will be generated).
29  *
30  * @author Tomas Pavek
31  */

32
33 class ConnectionWizardPanel1 implements org.openide.WizardDescriptor.Panel {
34
35     private Event selectedEvent;
36
37     private RADComponent sourceComponent;
38
39     private EventListenerList listenerList;
40
41     private ConnectionPanel1 uiPanel;
42
43     // -------
44

45     ConnectionWizardPanel1(RADComponent source) {
46         sourceComponent = source;
47     }
48
49     RADComponent getSourceComponent() {
50         return sourceComponent;
51     }
52
53     Event getSelectedEvent() {
54         return selectedEvent;
55     }
56     String JavaDoc getEventName() {
57         return uiPanel != null ? uiPanel.getEventName() : null;
58     }
59
60     void setSelectedEvent(Event event) {
61         selectedEvent = event;
62         fireStateChanged();
63     }
64
65     boolean handlerAlreadyExists() {
66         if (uiPanel == null)
67             return false;
68
69         return selectedEvent != null
70                && selectedEvent.hasEventHandler(uiPanel.getEventName());
71     }
72
73     // ----------
74
// WizardDescriptor.Panel implementation
75

76     public java.awt.Component JavaDoc getComponent() {
77         if (uiPanel == null)
78             uiPanel = new ConnectionPanel1(this);
79         return uiPanel;
80     }
81
82     public org.openide.util.HelpCtx getHelp() {
83         return new org.openide.util.HelpCtx("gui.connecting.source"); // NOI18N
84
}
85
86     public boolean isValid() {
87         String JavaDoc eventName = uiPanel != null ? uiPanel.getEventName() : null;
88         return selectedEvent != null
89                && eventName != null && !"".equals(eventName)
90                && org.openide.util.Utilities.isJavaIdentifier(eventName);
91     }
92
93     public void readSettings(java.lang.Object JavaDoc settings) {
94     }
95
96     public void storeSettings(java.lang.Object JavaDoc settings) {
97     }
98
99     public void addChangeListener(ChangeListener listener) {
100         if (listenerList == null)
101             listenerList = new EventListenerList();
102         listenerList.add(ChangeListener.class, listener);
103     }
104
105     public void removeChangeListener(ChangeListener listener) {
106         if (listenerList != null)
107             listenerList.remove(ChangeListener.class, listener);
108     }
109
110     // -----
111

112     void fireStateChanged() {
113         if (listenerList == null)
114             return;
115
116         ChangeEvent e = null;
117         Object JavaDoc[] listeners = listenerList.getListenerList();
118         for (int i = listeners.length-2; i>=0; i-=2) {
119             if (listeners[i] == ChangeListener.class) {
120                 if (e == null)
121                     e = new ChangeEvent(this);
122                 ((ChangeListener)listeners[i+1]).stateChanged(e);
123             }
124         }
125     }
126 }
127
Popular Tags