protected class GenericNativeWindow.NativeWindowEventDispatcher extends Object implements InvocationHandler
NativeWindowEventDispatcher
implements a custom
layer to handle native window events as defined in
NativeWindowListener
.
Basically, this class provides its own private implementation of a
NativeWindowListener
, which is implemented as a
import java.lang.reflect.Proxy
object. This is due to the
the actual native event interface, which is specified by the generic
parameter E
, being known only at runtime. Furthermore, this
class itself is also the proxy's InvocationHandler
.
Each invocation of any of the event handler methods is then forwarded to
all registered event listeners. Between the invocation and forwarding, a
new NativeWindowEvent
object is created, including the
parameters passed from the native side, which is in turn passed to the
registered listeners.
Modifier and Type | Field and Description |
---|---|
protected GenericNativeWindow.EventInvocationCache |
eventInvocationCache
This
HashMap derived cache provides fast mapping between
the name of an event method invoked on the native event interface and
the corresponding method to be invoked on a registered
NativeWindowListener together with the event id. |
protected List<NativeWindowListener> |
listeners
Stores all listeners that have registered to receive native window
events.
|
protected Class<E> |
nativeEventInterface
The native COM event interface.
|
protected E |
nativeEventProxy
A reference to the proxy object receiving native COM events.
|
Constructor and Description |
---|
NativeWindowEventDispatcher(Class<E> eventInterface)
Create a
NativeWindowEventDispatcher object. |
Modifier and Type | Method and Description |
---|---|
void |
addNativeWindowListener(NativeWindowListener listener)
Adds the specified native window listener to receive window events
from the underlying native window.
|
NativeWindowListener[] |
getNativeWindowListeners()
Returns an array of all the native window listeners registered on
this
GenericNativeWindow instance. |
Object |
invoke(Object proxy,
Method method,
Object[] args)
The
InvocationHandler implementation. |
boolean |
isNativeWindowListener(NativeWindowListener listener)
Indicates whether the specified native window listener
listener is registered on this
GenericNativeWindow instance. |
void |
removeNativeWindowListener(NativeWindowListener listener)
Removes the specified native window listener, so that it no longer
receives window events from the underlying native window.
|
protected List<NativeWindowListener> listeners
protected GenericNativeWindow.EventInvocationCache eventInvocationCache
HashMap
derived cache provides fast mapping between
the name of an event method invoked on the native event interface and
the corresponding method to be invoked on a registered
NativeWindowListener
together with the event id.protected Class<E extends ComEventListener> nativeEventInterface
addComEventListener
. Since native registering is done
lazily after the first NativeWindowListener
has
registered, the native event interface is kept in this field.protected E extends ComEventListener nativeEventProxy
public void addNativeWindowListener(NativeWindowListener listener)
listener
is
null
, no exception is thrown and no action is performed.listener
- the native window listener to be addedremoveNativeWindowListener(com.datagis.com4j.NativeWindowListener)
,
getNativeWindowListeners()
,
NativeWindowListener
,
NativeWindowAdapter
public void removeNativeWindowListener(NativeWindowListener listener)
null
or was not
previously added to this GenericNativeWindow
instance.listener
- the native window listener to be removedaddNativeWindowListener(com.datagis.com4j.NativeWindowListener)
,
getNativeWindowListeners()
,
NativeWindowListener
,
NativeWindowAdapter
public NativeWindowListener[] getNativeWindowListeners()
GenericNativeWindow
instance.NativeWindowListener
s or an empty array if no native window listeners are
currently registeredaddNativeWindowListener(com.datagis.com4j.NativeWindowListener)
,
removeNativeWindowListener(com.datagis.com4j.NativeWindowListener)
public boolean isNativeWindowListener(NativeWindowListener listener)
listener
is registered on this
GenericNativeWindow
instance.listener
- the native window listener to testtrue
if the specified native window listener
listener
is registered with this
GenericNativeWindow
instance; false
otherwise.addNativeWindowListener(com.datagis.com4j.NativeWindowListener)
,
removeNativeWindowListener(com.datagis.com4j.NativeWindowListener)
,
getNativeWindowListeners()
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
InvocationHandler
implementation. Invoked each time,
a method on nativeEventProxy
is invoked.invoke
in interface InvocationHandler
proxy
- the proxy instance that the method was invoked onmethod
- the Method
instance corresponding to the
interface method invoked on the proxy instanceargs
- an array of objects containing the values of the arguments
passed in the method invocation on the proxy instance, or
null
if interface method takes no argumentsThrowable
- the exception to throw from the method invocation on the
proxy instanceInvocationHandler
,
Proxy
Copyright © 2009 - 2016 DataGis. All Rights Reserved.