Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JRubyFX For Web Developers

JRubyFX For Web Developers

JRubyFX is a DSL and set of wrappers for the Java UI toolkit JavaFX

Avatar for Neil Matatall

Neil Matatall

April 30, 2015
Tweet

More Decks by Neil Matatall

Other Decks in Technology

Transcript

  1. CSS .default-color0.chart-series-line { -fx-stroke: #CC0000; } .default-color1.chart-series-line { -fx-stroke: #FF6600;

    } .default-color2.chart-series-line { -fx-stroke: #FFCC00; } .default-color0.chart-line-symbol { -fx-background-color: #CC0000, white; } .default-color1.chart-line-symbol { -fx-background-color: #FF6600, white; } .default-color2.chart-line-symbol { -fx-background-color: #FFCC00, white; }
  2. Automaton require_relative '../lib/brakeman_pro' require 'lib/automaton.jar' java_import 'com.athaydes.automaton.FXer' java_import 'com.athaydes.automaton.FXApp' FXApp.start_app(

    BrakemanPro::Main.new ); fxer = FXer.get_user_with( FXApp.scene.root ) fxer.click_on("text:Add Group").wait_for_fx_events fxer.type("Yo mama").click_on("text:Save")
  3. Polish You can distribute apps as a jar or as

    a native application with various installers • deb/rpm • OSX Applications (bundles) / dmg / pkg • exe / msi for windows The JVM is included in the package.
  4. But inline event handlers are bad Prefer binding in controller

    code over on* attributes in fxml unless your component is tiny
  5. Custom Elements module BrakemanPro module Controls class CodeViewer < Java::javafx::scene::control::VBox

    include JRubyFX::Controller fxml "result_category_pane.fxml" … def update_code code @webview.get_engine.load_content(content, "text/html") end
  6. Controller class MainWindow include JRubyFX::Controller fxml "main.fxml" def some_function @main_pane.center

    = CodeViewer.new @split_pane.items.add(@code_viewer) @code_viewer.update_code(warning.location) end end
  7. Starting the app class Main < JRubyFX::Application def start(stage) title

    = "Brakeman Pro" with(stage, title: title, resizable: true) do fxml MainWindow show end end end
  8. Design Tip (follow at your own risk) • Make components

    as small as possible • Have each component belong to an object, or prefer composition over inheritance. depends. • If the object won’t change, bind properties • If the object will change, use a “repaint” strategy
  9. Performance Tips • Store “pages” in memory • Track “dirty

    regions” • Update on change (or bind) • The fewer elements, the faster the process • Perform (most) code in event handlers in a run_later
  10. What isn’t cool Exception in thread "JavaFX Application Thread" org.jruby.exceptions.RaiseException:

    (NoMethodError) undefined method `int' for RubyWrapperBeanAdapter:Class at RUBY.getConstantValue(.../jrubyfx-fxmlloader-0.4-java/lib/fxmlloader/rrba.rb:607) at RUBY.constructValue(.../jrubyfx-fxmlloader-0.4-java/lib/fxmlloader/real_elts.rb:85) at RUBY.processStartElement(.../jrubyfx-fxmlloader-0.4-java/lib/fxmlloader/value_elts.rb:62) at FxmlLoader.processStartElement(.../jrubyfx-fxmlloader-0.4-java/lib/jrubyfx-fxmlloader.rb:440) at RUBY.load(.../jrubyfx-fxmlloader-0.4-java/lib/jrubyfx-fxmlloader.rb:351) at RUBY.load_fxml(.../jrubyfx-1.1.1-java/lib/jrubyfx/controller.rb:266) at RUBY.initialize_controller(.../jrubyfx-1.1.1-java/lib/jrubyfx/controller.rb:248) at RUBY.new(.../jrubyfx-1.1.1-java/lib/jrubyfx/controller.rb:157) at RUBY.initialize(...brakeman-pro/lib/brakeman_pro/controller/details_controller.rb:12) <columnResizePolicy> <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" /> </columnResizePolicy>
  11. What isn’t cool I’ve yet to be able to use

    a release, always pointing to master Project activity is… bursty Java