/
EventRegistrationImpl.java
287 lines (228 loc) · 8.61 KB
/
EventRegistrationImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is RaptorCanvas.
*
* The Initial Developer of the Original Code is Kirk Baker and
* Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are
* Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All
* Rights Reserved.
*
* Contributor(s): Ed Burns <edburns@acm.org>
*/
package org.mozilla.webclient.impl.wrapper_native;
import org.mozilla.util.Assert;
import org.mozilla.util.Log;
import org.mozilla.util.ParameterCheck;
import org.mozilla.webclient.BrowserControl;
import org.mozilla.webclient.EventRegistration2;
import org.mozilla.webclient.impl.WrapperFactory;
import org.mozilla.webclient.DocumentLoadEvent;
import org.mozilla.webclient.DocumentLoadListener;
import org.mozilla.webclient.NewWindowEvent;
import org.mozilla.webclient.NewWindowListener;
import java.awt.event.MouseListener;
import org.mozilla.webclient.WebclientEvent;
import org.mozilla.webclient.WebclientEventListener;
import org.mozilla.webclient.UnimplementedException;
public class EventRegistrationImpl extends ImplObjectNative implements EventRegistration2
{
//
// Constants
//
//
// Class Variables
//
//
// Instance Variables
//
// Attribute Instance Variables
// Relationship Instance Variables
/**
* the Java thread for processing events, owned by WrapperFactoryImpl
*/
// PENDING: Currently we rely on NativeEventThread logic to maintain the
// list of listeners to add and to add them in a threadsafe manner. In
// webclient 2.0, we're going to maintain the list of listeners ourself,
// in this class, and use the Runnable trick to make sure they get added
// on the right thread.
private NativeEventThread nativeEventThread = null;
//
// Constructors and Initializers
//
public EventRegistrationImpl(WrapperFactory yourFactory,
BrowserControl yourBrowserControl)
{
super(yourFactory, yourBrowserControl);
// pull out the NativeEventThread from the WrapperFactory
nativeEventThread = NativeEventThread.instance;
}
public void delete()
{
nativeEventThread = null;
super.delete();
}
//
// Class methods
//
//
// General Methods
//
//
// Methods from EventRegistration
//
/**
* We create a WCEventListenerWrapper containing the user passed
* DocumentLoadListener, and the string obtained from
* DocumentLoadListener.class.getName();
*/
public void addDocumentLoadListener(DocumentLoadListener listener)
{
ParameterCheck.nonNull(listener);
getWrapperFactory().verifyInitialized();
Assert.assert_it(-1 != getNativeBrowserControl());
Assert.assert_it(null != nativeEventThread);
ParameterCheck.nonNull(listener);
WCEventListenerWrapper listenerWrapper =
new WCEventListenerWrapper(listener,
DocumentLoadListener.class.getName());
if (null == listenerWrapper) {
throw new NullPointerException("Can't instantiate WCEventListenerWrapper, out of memory.");
}
synchronized(getBrowserControl()) {
// PENDING nativeEventThread.addListener(listenerWrapper);
}
}
public void removeDocumentLoadListener(DocumentLoadListener listener)
{
ParameterCheck.nonNull(listener);
getWrapperFactory().verifyInitialized();
Assert.assert_it(-1 != getNativeBrowserControl());
Assert.assert_it(null != nativeEventThread);
ParameterCheck.nonNull(listener);
WCEventListenerWrapper listenerWrapper =
new WCEventListenerWrapper(listener,
DocumentLoadListener.class.getName());
if (null == listenerWrapper) {
throw new NullPointerException("Can't instantiate WCEventListenerWrapper, out of memory.");
}
synchronized(getBrowserControl()) {
// PENDING nativeEventThread.removeListener(listenerWrapper);
}
}
public void addMouseListener(MouseListener listener)
{
ParameterCheck.nonNull(listener);
getWrapperFactory().verifyInitialized();
Assert.assert_it(-1 != getNativeBrowserControl());
Assert.assert_it(null != nativeEventThread);
ParameterCheck.nonNull(listener);
// We have to wrap the user provided java.awt.event.MouseListener
// instance in a custom WebclientEventListener subclass that also
// implements java.awt.event.MouseListener. See WCMouseListener for
// more information.
WCMouseListenerImpl mouseListenerWrapper =
new WCMouseListenerImpl(listener);
if (null == mouseListenerWrapper) {
throw new NullPointerException("Can't instantiate WCMouseListenerImpl, out of memory.");
}
WCEventListenerWrapper listenerWrapper =
new WCEventListenerWrapper(mouseListenerWrapper,
MouseListener.class.getName());
if (null == listenerWrapper) {
throw new NullPointerException("Can't instantiate WCEventListenerWrapper, out of memory.");
}
synchronized(getBrowserControl()) {
// PENDING nativeEventThread.addListener(listenerWrapper);
}
}
public void removeMouseListener(MouseListener listener)
{
ParameterCheck.nonNull(listener);
getWrapperFactory().verifyInitialized();
Assert.assert_it(-1 != getNativeBrowserControl());
Assert.assert_it(null != nativeEventThread);
ParameterCheck.nonNull(listener);
WCMouseListenerImpl mouseListenerWrapper =
new WCMouseListenerImpl(listener);
if (null == mouseListenerWrapper) {
throw new NullPointerException("Can't instantiate WCMouseListenerImpl, out of memory.");
}
WCEventListenerWrapper listenerWrapper =
new WCEventListenerWrapper(mouseListenerWrapper,
MouseListener.class.getName());
if (null == listenerWrapper) {
throw new NullPointerException("Can't instantiate WCEventListenerWrapper, out of memory.");
}
synchronized(getBrowserControl()) {
// PENDING nativeEventThread.removeListener(listenerWrapper);
}
}
public void addNewWindowListener(NewWindowListener listener)
{
ParameterCheck.nonNull(listener);
getWrapperFactory().verifyInitialized();
Assert.assert_it(-1 != getNativeBrowserControl());
Assert.assert_it(null != nativeEventThread);
ParameterCheck.nonNull(listener);
WCEventListenerWrapper listenerWrapper =
new WCEventListenerWrapper(listener,
NewWindowListener.class.getName());
if (null == listenerWrapper) {
throw new NullPointerException("Can't instantiate WCEventListenerWrapper, out of memory.");
}
synchronized(getBrowserControl()) {
// PENDING nativeEventThread.addListener(listenerWrapper);
}
}
public void removeNewWindowListener(NewWindowListener listener)
{
ParameterCheck.nonNull(listener);
getWrapperFactory().verifyInitialized();
Assert.assert_it(-1 != getNativeBrowserControl());
Assert.assert_it(null != nativeEventThread);
ParameterCheck.nonNull(listener);
WCEventListenerWrapper listenerWrapper =
new WCEventListenerWrapper(listener,
NewWindowListener.class.getName());
if (null == listenerWrapper) {
throw new NullPointerException("Can't instantiate WCEventListenerWrapper, out of memory.");
}
synchronized(getBrowserControl()) {
// PENDING nativeEventThread.removeListener(listenerWrapper);
}
}
// ----VERTIGO_TEST_START
//
// Test methods
//
public static void main(String [] args)
{
Assert.setEnabled(true);
Log.setApplicationName("EventRegistrationImpl");
Log.setApplicationVersion("0.0");
Log.setApplicationVersionDate("$Id: EventRegistrationImpl.java,v 1.5 2004/04/17 21:25:11 edburns%acm.org Exp $");
try {
org.mozilla.webclient.BrowserControlFactory.setAppData(args[0]);
org.mozilla.webclient.BrowserControl control =
org.mozilla.webclient.BrowserControlFactory.newBrowserControl();
Assert.assert_it(control != null);
EventRegistration2 wc = (EventRegistration2)
control.queryInterface(org.mozilla.webclient.BrowserControl.WINDOW_CONTROL_NAME);
Assert.assert_it(wc != null);
}
catch (Exception e) {
System.out.println("got exception: " + e.getMessage());
}
}
// ----VERTIGO_TEST_END
} // end of class EventRegistrationImpl