KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lobobrowser > html > js > Event


1 /*
2     GNU LESSER GENERAL PUBLIC LICENSE
3     Copyright (C) 2006 The XAMJ Project
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13     Lesser General Public License for more details.
14
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19     Contact info: xamjadmin@users.sourceforge.net
20 */

21 package org.lobobrowser.html.js;
22
23 import org.w3c.dom.html2.*;
24 import java.awt.event.*;
25 import org.lobobrowser.js.*;
26
27 public class Event extends AbstractScriptableDelegate {
28     private boolean cancelBubble;
29     private HTMLElement fromElement, toElement;
30     private int leafX, leafY;
31     private boolean returnValue;
32     private HTMLElement srcElement;
33     private String JavaDoc type;
34     private final java.awt.event.InputEvent JavaDoc inputEvent;
35     
36     public Event(String JavaDoc type, HTMLElement srcElement, java.awt.event.InputEvent JavaDoc mouseEvent, int leafX, int leafY) {
37         this.type = type;
38         this.srcElement = srcElement;
39         this.leafX = leafX;
40         this.leafY = leafY;
41         this.inputEvent = mouseEvent;
42     }
43     
44     public Event(String JavaDoc type, HTMLElement srcElement, java.awt.event.KeyEvent JavaDoc keyEvent) {
45         this.type = type;
46         this.srcElement = srcElement;
47         this.inputEvent = keyEvent;
48     }
49
50     public boolean getAltKey() {
51         return this.inputEvent.isAltDown();
52     }
53     
54     public boolean getShiftKey() {
55         return this.inputEvent.isShiftDown();
56     }
57     
58     public boolean getCtrlKey() {
59         return this.inputEvent.isControlDown();
60     }
61     
62     public int getButton() {
63         InputEvent ie = this.inputEvent;
64         if(ie instanceof MouseEvent) {
65             return ((MouseEvent) ie).getButton();
66         }
67         else {
68             return 0;
69         }
70     }
71
72     public boolean isCancelBubble() {
73         return cancelBubble;
74     }
75
76     public void setCancelBubble(boolean cancelBubble) {
77         this.cancelBubble = cancelBubble;
78     }
79
80     public String JavaDoc getType() {
81         return type;
82     }
83
84     public void setType(String JavaDoc type) {
85         this.type = type;
86     }
87     
88     public int getClientX() {
89         InputEvent ie = this.inputEvent;
90         if(ie instanceof MouseEvent) {
91             return ((MouseEvent) ie).getX();
92         }
93         else {
94             return 0;
95         }
96     }
97     
98     public int getClientY() {
99         InputEvent ie = this.inputEvent;
100         if(ie instanceof MouseEvent) {
101             return ((MouseEvent) ie).getY();
102         }
103         else {
104             return 0;
105         }
106     }
107
108     public int getKeyCode() {
109         InputEvent ie = this.inputEvent;
110         if(ie instanceof KeyEvent) {
111             return ((KeyEvent) ie).getKeyCode();
112         }
113         else {
114             return 0;
115         }
116     }
117
118 // public int getOffsetX() {
119
// // Despite advertising that it returns an element-relative offset,
120
// // IE doesn't do this.
121
// //TODO: Must be relative to top viewport.
122
// return this.getClientX() - 2;
123
// }
124
//
125
// public int getOffsetY() {
126
// // Despite advertising that it returns an element-relative offset,
127
// // IE doesn't do this.
128
// //TODO: Must be relative to top viewport.
129
// return this.getClientY() - 2;
130
// }
131

132     public boolean isReturnValue() {
133         return returnValue;
134     }
135
136     public void setReturnValue(boolean returnValue) {
137         this.returnValue = returnValue;
138     }
139
140     public HTMLElement getSrcElement() {
141         return srcElement;
142     }
143
144     public void setSrcElement(HTMLElement srcElement) {
145         this.srcElement = srcElement;
146     }
147
148     public HTMLElement getFromElement() {
149         return fromElement;
150     }
151
152     public void setFromElement(HTMLElement fromElement) {
153         this.fromElement = fromElement;
154     }
155
156     public HTMLElement getToElement() {
157         return toElement;
158     }
159
160     public void setToElement(HTMLElement toElement) {
161         this.toElement = toElement;
162     }
163
164     public int getLeafX() {
165         return leafX;
166     }
167
168     public void setLeafX(int leafX) {
169         this.leafX = leafX;
170     }
171
172     public int getLeafY() {
173         return leafY;
174     }
175
176     public void setLeafY(int leafY) {
177         this.leafY = leafY;
178     }
179 }
180
Popular Tags