KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > dom > events > AbstractEvent


1 /*
2
3    Copyright 2000,2002-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.dom.events;
19
20 import org.w3c.dom.events.Event JavaDoc;
21 import org.w3c.dom.events.EventTarget JavaDoc;
22
23 /**
24  * The abstract <code>Event</code> root class.
25  *
26  * @author <a HREF="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
27  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
28  * @version $Id: AbstractEvent.java,v 1.9 2005/02/22 09:12:59 cam Exp $
29  */

30 public abstract class AbstractEvent implements Event JavaDoc {
31     /**
32      * The event type.
33      */

34     protected String JavaDoc type;
35
36     /**
37      * Whether this event is bubbling.
38      */

39     protected boolean isBubbling;
40
41     /**
42      * Whether this event is cancelable.
43      */

44     protected boolean cancelable;
45
46     /**
47      * The EventTarget whose EventListeners are currently being processed.
48      */

49     protected EventTarget JavaDoc currentTarget;
50
51     /**
52      * The target of this event.
53      */

54     protected EventTarget JavaDoc target;
55
56     /**
57      * The event phase.
58      */

59     protected short eventPhase;
60
61     /**
62      * The time the event was created.
63      */

64     protected long timeStamp = System.currentTimeMillis();
65
66     /**
67      * Whether the event propagation must be stopped.
68      */

69     protected boolean stopPropagation = false;
70
71     /**
72      * Whether the default action must be processed.
73      */

74     protected boolean preventDefault = false;
75
76     /**
77      * DOM: The <code>type</code> property represents the event name
78      * as a string property. The string must be an XML name.
79      */

80     public String JavaDoc getType() {
81     return type;
82     }
83
84     /**
85      * DOM: The <code>target</code> property indicates the
86      * <code>EventTarget</code> whose <code>EventListeners</code> are
87      * currently being processed.
88      */

89     public EventTarget JavaDoc getCurrentTarget() {
90     return currentTarget;
91     }
92
93     /**
94      * DOM: The <code>target</code> property indicates the
95      * <code>EventTarget</code> to which the event was originally
96      * dispatched.
97      */

98     public EventTarget JavaDoc getTarget() {
99     return target;
100     }
101
102     /**
103      * DOM: The <code>eventPhase</code> property indicates which phase
104      * of event flow is currently being evaluated.
105      */

106     public short getEventPhase() {
107     return eventPhase;
108     }
109
110     /**
111      * DOM: The <code>bubbles</code> property indicates whether or not
112      * an event is a bubbling event. If the event can bubble the
113      * value is true, else the value is false.
114      */

115     public boolean getBubbles() {
116     return isBubbling;
117     }
118
119     /**
120      * DOM: The <code>cancelable</code> property indicates whether or
121      * not an event can have its default action prevented. If the
122      * default action can be prevented the value is true, else the
123      * value is false.
124      */

125     public boolean getCancelable() {
126     return cancelable;
127     }
128
129     /**
130      * DOM: Used to specify the time (in milliseconds relative to the
131      * epoch) at
132      * which the event was created. Due to the fact that some systems may not
133      * provide this information the value of <code>timeStamp</code> may be
134      * returned. Examples of epoch time are the time of the system start or
135      * 0:0:0 UTC 1st January 1970.
136      */

137     public long getTimeStamp() {
138     return timeStamp;
139     }
140
141     /**
142      * DOM: The <code>stopPropagation</code> method is used prevent
143      * further propagation of an event during event flow. If this
144      * method is called by any <code>EventListener</code> the event
145      * will cease propagating through the tree. The event will
146      * complete dispatch to all listeners on the current
147      * <code>EventTarget</code> before event flow stops. This method
148      * may be used during any stage of event flow.
149      */

150     public void stopPropagation() {
151     this.stopPropagation = true;
152     }
153
154     /**
155      * DOM: If an event is cancelable, the <code>preventDefault</code>
156      * method is used to signify that the event is to be canceled,
157      * meaning any default action normally taken by the implementation
158      * as a result of the event will not occur. If, during any stage
159      * of event flow, the <code>preventDefault</code> method is called
160      * the event is canceled. Any default action associated with the
161      * event will not occur. Calling this method for a non-cancelable
162      * event has no effect. Once <code>preventDefault</code> has been
163      * called it will remain in effect throughout the remainder of the
164      * event's propagation. This method may be used during any stage
165      * of event flow.
166      */

167     public void preventDefault() {
168     this.preventDefault = true;
169     }
170
171     /**
172      * DOM: The <code>initEvent</code> method is used to initialize the
173      * value of interface. This method may only be called before the
174      * <code>Event</code> has been dispatched via the
175      * <code>dispatchEvent</code> method, though it may be called multiple
176      * times during that phase if necessary. If called multiple times the
177      * final invocation takes precedence. If called from a subclass of
178      * <code>Event</code> interface only the values specified in the
179      * <code>initEvent</code> method are modified, all other attributes are
180      * left unchanged.
181      * @param eventTypeArg Specifies the event type. This type may be any
182      * event type currently defined in this specification or a new event
183      * type.. The string must be an XML name . Any new event type must
184      * not begin with any upper, lower, or mixed case version of the
185      * string "DOM". This prefix is reserved for future DOM event sets.
186      * @param canBubbleArg Specifies whether or not the event can bubble.
187      * @param cancelableArg Specifies whether or not the event's default
188      * action can be prevented.
189      */

190     public void initEvent(String JavaDoc eventTypeArg,
191               boolean canBubbleArg,
192               boolean cancelableArg) {
193     this.type = eventTypeArg;
194     this.isBubbling = canBubbleArg;
195     this.cancelable = cancelableArg;
196     }
197
198     boolean getPreventDefault() {
199     return preventDefault;
200     }
201
202     boolean getStopPropagation() {
203     return stopPropagation;
204     }
205
206     void setEventPhase(short eventPhase) {
207     this.eventPhase = eventPhase;
208     }
209
210     void stopPropagation(boolean state) {
211     this.stopPropagation = state;
212     }
213
214     void preventDefault(boolean state) {
215     this.preventDefault = state;
216     }
217
218     void setCurrentTarget(EventTarget JavaDoc currentTarget) {
219     this.currentTarget = currentTarget;
220     }
221
222     void setTarget(EventTarget JavaDoc target) {
223     this.target = target;
224     }
225
226     public static boolean getEventPreventDefault(Event JavaDoc evt) {
227         AbstractEvent ae = (AbstractEvent)evt;
228         return ae.getPreventDefault();
229     }
230 }
231
Popular Tags