KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > dom > events > EventImpl


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

16 package org.apache.xerces.dom.events;
17
18 import org.w3c.dom.events.Event JavaDoc;
19 import org.w3c.dom.events.EventTarget JavaDoc;
20
21 /**
22  * EventImpl is an implementation of the basic "generic" DOM Level 2 Event
23  * object. It may be subclassed by more specialized event sets.
24  * Note that in our implementation, events are re-dispatchable (dispatch
25  * clears the stopPropagation and preventDefault flags before it starts);
26  * I believe that is the DOM's intent but I don't see an explicit statement
27  * to this effect.
28  *
29  * @xerces.internal
30  *
31  * @version $Id: EventImpl.java,v 1.10 2004/10/06 15:25:33 mrglavas Exp $
32  */

33 public class EventImpl implements Event JavaDoc
34 {
35     public String JavaDoc type=null;
36     public EventTarget JavaDoc target;
37     public EventTarget JavaDoc currentTarget;
38     public short eventPhase;
39     public boolean initialized=false, bubbles=true, cancelable=false;
40     public boolean stopPropagation=false, preventDefault=false;
41      
42     protected long timeStamp = System.currentTimeMillis();
43
44     /** The DOM doesn't deal with constructors, so instead we have an
45         initializer call to set most of the read-only fields. The
46         others are set, and reset, by the event subsystem during dispatch.
47         <p>
48         Note that init() -- and the subclass-specific initWhatever() calls --
49         may be reinvoked. At least one initialization is required; repeated
50         initializations overwrite the event with new values of their
51         parameters.
52     */

53     public void initEvent(String JavaDoc eventTypeArg, boolean canBubbleArg,
54                         boolean cancelableArg)
55     {
56             type=eventTypeArg;
57             bubbles=canBubbleArg;
58             cancelable=cancelableArg;
59             
60             initialized=true;
61     }
62     
63     /** @return true iff this Event is of a class and type which supports
64         bubbling. In the generic case, this is True.
65         */

66     public boolean getBubbles()
67     {
68         return bubbles;
69     }
70
71     /** @return true iff this Event is of a class and type which (a) has a
72         Default Behavior in this DOM, and (b)allows cancellation (blocking)
73         of that behavior. In the generic case, this is False.
74         */

75     public boolean getCancelable()
76     {
77         return cancelable;
78     }
79
80     /** @return the Node (EventTarget) whose EventListeners are currently
81         being processed. During capture and bubble phases, this may not be
82         the target node. */

83     public EventTarget JavaDoc getCurrentTarget()
84     {
85         return currentTarget;
86     }
87
88     /** @return the current processing phase for this event --
89         CAPTURING_PHASE, AT_TARGET, BUBBLING_PHASE. (There may be
90         an internal DEFAULT_PHASE as well, but the users won't see it.) */

91     public short getEventPhase()
92     {
93         return eventPhase;
94     }
95
96     /** @return the EventTarget (Node) to which the event was originally
97         dispatched.
98         */

99     public EventTarget JavaDoc getTarget()
100     {
101         return target;
102     }
103
104     /** @return event name as a string
105     */

106     public String JavaDoc getType()
107     {
108         return type;
109     }
110
111     public long getTimeStamp() {
112     return timeStamp;
113     }
114
115     /** Causes exit from in-progress event dispatch before the next
116         currentTarget is selected. Replaces the preventBubble() and
117         preventCapture() methods which were present in early drafts;
118         they may be reintroduced in future levels of the DOM. */

119     public void stopPropagation()
120     {
121         stopPropagation=true;
122     }
123
124     /** Prevents any default processing built into the target node from
125         occurring.
126       */

127     public void preventDefault()
128     {
129         preventDefault=true;
130     }
131
132 }
133
Popular Tags