package textbender.o.rhinohide.events; // Copyright 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 textbender.g.lang.ThreadSafe; import textbender.o.rhinohide.RhiWindow; /** A synchronous relay, based on an intermediate JavaScript listener/relay, * from which events are pulled. * (Pulled, to work around bugs of {@linkplain RelayS RelayS}.) */ public abstract class RelaySIP extends RelaySI { /** Constructs a RelaySIP. */ public RelaySIP() { super( /*dummyFlag*/false ); dispatchAdaptor = new DispatchPuller(); // cannot pass to super() as parameter, cannot construct till after super() } // - E v e n t - R e l a y - S I ------------------------------------------------------ @ThreadSafe @Override JSObject createJSORelay_orNull( RhiWindow window ) { return (JSObject)window.relayFactorySIP().call( "createRelay" ); } /** Implementation of {@linkplain RelaySI#rhiRelay rhiRelay} listener, * expressed as a script fragment. * [This will later be made private.] */ public static final String HANDLE_EVENT_SCRIPT = "" + " relay.handleEvent = function( e ) \n" + " { \n" + " relay.latestEvent = e; \n" + " relay.dispatchAdaptor.handleEvent(); \n" + " }; \n" ; // ==================================================================================== /** Relay adaptor that pulls events from the JavaScript side, * and wraps each as a proper Java {@linkplain org.w3c.dom.events.Event Event}. * [This is implementation, made public only for technical reasons.] */ public final class DispatchPuller // must not be private, or dispatch fails { public @ThreadSafe void handleEvent() { JSObject eventJS = (JSObject)rhiRelay.getMemberV( "latestEvent" ); // System.out.println( "ERSIP.DP event: " + eventJS ); RelaySIP.this.handleEvent ( RhiEvent.wrapEvent( rhiRelay.window(), eventJS, /*isAsync*/false )); } } }