Class: ScriptEventHandler
- Inherits:
-
Object
- Object
- ScriptEventHandler
- Includes:
- EventHandler
- Defined in:
- lib/fxmlloader/elts.rb
Instance Attribute Summary collapse
-
#script ⇒ Object
readonly
Returns the value of attribute script.
-
#scriptEngine ⇒ Object
readonly
Returns the value of attribute scriptEngine.
Instance Method Summary collapse
- #handle(event) ⇒ Object
-
#initialize(script, scriptEngine) ⇒ ScriptEventHandler
constructor
A new instance of ScriptEventHandler.
Constructor Details
#initialize(script, scriptEngine) ⇒ ScriptEventHandler
Returns a new instance of ScriptEventHandler.
534 535 536 537 |
# File 'lib/fxmlloader/elts.rb', line 534 def initialize(script, scriptEngine) @script = script; @scriptEngine = scriptEngine; end |
Instance Attribute Details
#script ⇒ Object (readonly)
Returns the value of attribute script.
533 534 535 |
# File 'lib/fxmlloader/elts.rb', line 533 def script @script end |
#scriptEngine ⇒ Object (readonly)
Returns the value of attribute scriptEngine.
533 534 535 |
# File 'lib/fxmlloader/elts.rb', line 533 def scriptEngine @scriptEngine end |
Instance Method Details
#handle(event) ⇒ Object
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
# File 'lib/fxmlloader/elts.rb', line 539 def handle(event) # Don't pollute the page namespace with values defined in the script engineBindings = @scriptEngine.getBindings(ScriptContext::ENGINE_SCOPE); #localBindings = @scriptEngine.createBindings(); # TODO: this causes errors with nashorn in jdk8 by creating a different kind of # script object that doesn't respect the magic nashorn.global object localBindings = Java::JavaxScript::SimpleBindings.new localBindings.put_all(engineBindings) localBindings.put(FXL::EVENT_KEY, event); @scriptEngine.setBindings(localBindings, ScriptContext::ENGINE_SCOPE); # Execute the script begin @scriptEngine.eval(@script); rescue ScriptException => exception raise exception end # Restore the original bindings @scriptEngine.setBindings(engineBindings, ScriptContext::ENGINE_SCOPE); end |