KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > Event


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;
21
22 import java.util.*;
23 import java.beans.EventSetDescriptor JavaDoc;
24 import java.lang.reflect.Method JavaDoc;
25
26 /**
27  * Represents one event of a component. Holds handlers attached to the event.
28  *
29  * @author Tomas Pavek
30  */

31
32 public class Event {
33
34     private static String JavaDoc[] NO_HANDLERS = {};
35
36     private RADComponent component;
37     private EventSetDescriptor JavaDoc eventSetDescriptor;
38     private Method JavaDoc listenerMethod;
39     private boolean inCEDL; // CEDL - common event dispatching listener
40
private List eventHandlers;
41
42     Event(RADComponent component,
43           EventSetDescriptor JavaDoc eventSetDescriptor,
44           Method JavaDoc listenerMethod)
45     {
46         this.component = component;
47         this.eventSetDescriptor = eventSetDescriptor;
48         this.listenerMethod = listenerMethod;
49     }
50
51     // --------
52

53     public String JavaDoc getName() {
54         return listenerMethod.getName();
55     }
56
57     public String JavaDoc getId() {
58         return FormEvents.getEventIdName(listenerMethod);
59     }
60
61     public final RADComponent getComponent() {
62         return component;
63     }
64
65     public final EventSetDescriptor JavaDoc getEventSetDescriptor() {
66         return eventSetDescriptor;
67     }
68
69     public final Method JavaDoc getListenerMethod() {
70         return listenerMethod;
71     }
72
73     public boolean hasEventHandlers() {
74         return eventHandlers != null && eventHandlers.size() > 0;
75     }
76
77     public boolean hasEventHandler(String JavaDoc handler) {
78         return eventHandlers != null ? eventHandlers.contains(handler) : false;
79     }
80
81     public String JavaDoc[] getEventHandlers() {
82         if (eventHandlers == null || eventHandlers.size() == 0)
83             return NO_HANDLERS;
84
85         String JavaDoc[] handlerNames = new String JavaDoc[eventHandlers.size()];
86         eventHandlers.toArray(handlerNames);
87         return handlerNames;
88     }
89
90     // CEDL - common event dispatching listener
91
public final boolean isInCEDL() {
92         return inCEDL;
93     }
94
95     // --------
96

97     void setInCEDL(boolean isIn) {
98         inCEDL = isIn;
99     }
100
101     boolean addEventHandler(String JavaDoc handlerName) {
102         if (eventHandlers == null)
103             eventHandlers = new ArrayList(1);
104         else if (eventHandlers.contains(handlerName))
105             return false;
106
107         eventHandlers.add(handlerName);
108         return true;
109     }
110
111     boolean removeEventHandler(String JavaDoc handlerName) {
112         return eventHandlers != null && eventHandlers.remove(handlerName);
113     }
114
115     boolean renameEventHandler(String JavaDoc oldHandlerName, String JavaDoc newHandlerName) {
116         if (eventHandlers == null)
117             return false;
118         int index = eventHandlers.indexOf(oldHandlerName);
119         if (index < 0 || eventHandlers.contains(newHandlerName))
120             return false;
121
122         eventHandlers.set(index, newHandlerName);
123         return true;
124     }
125
126     List getEventHandlerList() {
127         return eventHandlers;
128     }
129 }
130
Popular Tags