// Go through the list and check if the requested listener is already
// registered.
boolean found = false;
for (int i = 0; i < awtEventListeners.length; ++i)
{
AWTEventListenerProxy proxy = awtEventListeners[i];
if (proxy.getListener() == listener)
{
found = true;
// Modify the proxies event mask to include the new event mask.
AWTEventListenerProxy newProxy =
new AWTEventListenerProxy(proxy.getEventMask() | eventMask,
listener);
awtEventListeners[i] = newProxy;
break;
}
}
// If that listener was not found, then add it.
if (! found)
{
AWTEventListenerProxy proxy =
new AWTEventListenerProxy(eventMask, listener);
AWTEventListenerProxy[] newArray =
new AWTEventListenerProxy[awtEventListeners.length + 1];
System.arraycopy(awtEventListeners, 0, newArray, 0,
awtEventListeners.length);
newArray[newArray.length - 1] = proxy;