package textbender.o.rhinohide.events; // Copyright 2006-2007, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import netscape.javascript.JSObject; import org.w3c.dom.events.*; import textbender.g.lang.ThreadSafe; import textbender.o.rhinohide.*; /** An event target implemented as an overlay of a JavaScript event target. *

* Note: If in-memory caching is in effect, * listeners should probably be removed, during page exit. * Caching will persist JavaScript-side listener registrations; * but not (apparently) the Java-side listeners. *

* * @see Firefox in-memory caching */ public @ThreadSafe class RhiEventTarget extends Rhinohide implements EventTarget { /** Constructs a RhiEventTarget. * * @param window global object * @param jsObject bridge to underlying JavaScript event target, * per {@linkplain Rhinohide#jsObject() jsObject}() * * @return event target, or null if jsObject is null */ public static RhiEventTarget wrapEventTarget( RhiWindow window, JSObject jsObject ) { if( jsObject == null ) return null; return new RhiEventTarget( window, jsObject ); } protected RhiEventTarget( RhiWindow window, JSObject jsObject ) { super( window, jsObject ); } protected RhiEventTarget( JSObject jsObject ) { super( jsObject ); } // for RhiWindow // - E v e n t - T a r g e t ---------------------------------------------------------- public void addEventListener( String type, EventListener listener, boolean useCapture ) { if( !( listener instanceof Relay )) throw new IllegalArgumentException( "listener not instance of " + Relay.class ); Relay relay = (Relay)listener; // assert ThreadSafe.U.isThreadSafe( relay, "addTo", RhiEventTarget.class, String.class, Boolean.TYPE ); ///// works only for public methods relay.addTo( RhiEventTarget.this, type, useCapture ); } /** Not yet coded. * * @throws UnsupportedOperationException */ public final boolean dispatchEvent( Event e ) throws EventException { throw new UnsupportedOperationException(); } public void removeEventListener( String type, EventListener listener, boolean useCapture ) { if( !( listener instanceof Relay )) throw new IllegalArgumentException( "listener not instance of " + Relay.class ); Relay relay = (Relay)listener; // assert ThreadSafe.U.isThreadSafe( relay, "removeFrom", RhiEventTarget.class, String.class, Boolean.TYPE ); ///// works only for public methods relay.removeFrom( RhiEventTarget.this, type, useCapture ); } }