Module: JRubyFX

Includes:
FXImports, Utils::CommonUtils
Included in:
Application, DSL
Defined in:
lib/jrubyfx/module.rb,
lib/jrubyfx/dsl.rb,
lib/jrubyfx/utils.rb,
lib/jrubyfx_tasks.rb,
lib/jrubyfx/dsl_map.rb,
lib/jrubyfx/imports.rb,
lib/jrubyfx/version.rb,
lib/jrubyfx/dsl_control.rb,
lib/jrubyfx/part_imports.rb,
lib/jrubyfx/utils/common_utils.rb,
lib/jrubyfx/utils/common_converters.rb

Overview

Do NOT delete this or it will make RDOC associate the copyright header with JRubyFX module

Defined Under Namespace

Modules: Controller, DSL, DSLControl, FXImports, FXMLClassUtils, Tasks, Utils Classes: Application

Constant Summary collapse

VERSION =

Current gem version. Used in rake task.

'1.2.0'

Constants included from FXImports

FXImports::JFX_CLASS_HIERARCHY, FXImports::LOCAL_NAME_MAP

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::CommonUtils

#attempt_conversion, #populate_properties, #split_args_from_properties

Methods included from FXImports

#const_missing

Class Method Details

.included(mod) ⇒ Object



98
99
100
101
# File 'lib/jrubyfx/module.rb', line 98

def self.included(mod)
  mod.extend(JRubyFX::FXMLClassUtils)
  mod.extend(JRubyFX::FXImports)
end

.load_fx(force = false) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/jrubyfx/utils.rb', line 78

def self.load_fx(force=false)
  return if @already_loaded_fx and !force
  @already_loaded_fx = true
  java.util.concurrent.CountDownLatch.new(1).tap do |latch|
    com.sun.javafx.application.PlatformImpl.startup { latch.countDown }
    latch.await
  end
end

Instance Method Details

#build(klass, *args, &block) ⇒ Object

call-seq:

build(class) => obj
build(class, hash) => obj
build(class) { block } => obj
build(class, hash) { block } => obj

Create “build” a new JavaFX instance with the provided class and set properties (e.g. setters) on that new instance plus also invoke any block passed against this new instance. This also can build a proc or lambda form in which case the return value of the block will be what is used to set the additional properties on.

Examples

 grid = build(GridPane, vgap: 2, hgap: 2) do
   set_pref_size(500, 400)
   children << location << go << view
 end

build(proc { Foo.new }, vgap: 2, hgap: 2)


86
87
88
89
90
91
92
93
94
95
96
# File 'lib/jrubyfx/module.rb', line 86

def build(klass, *args, &block)
  args, properties = split_args_from_properties(*args)

  obj = if klass.kind_of? Proc
    klass.call(*args)
  else
    klass.new(*attempt_conversion(klass, :new, *args))
  end

  with(obj, properties, &block)
end

#run_later(&block) ⇒ Object

call-seq:

run_later { block }

Convenience method so anything can safely schedule to run on JavaFX main thread.



61
62
63
# File 'lib/jrubyfx/module.rb', line 61

def run_later(&block)
  Java::javafx.application.Platform.run_later &block
end

#with(obj, properties = {}, &block) ⇒ Object

call-seq:

with(obj, hash) => obj
with(obj) { block } => obj
with(obj, hash) { block }=> obj

Set properties (e.g. setters) on the passed in object plus also invoke any block passed against this object.

Examples

with(grid, vgap: 2, hgap: 2) do
  set_pref_size(500, 400)
  children << location << go << view
end


41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/jrubyfx/module.rb', line 41

def with(obj, properties = {}, &block)
  puts "Warning: calling 'with' on a nil object from #{caller[0]}" if obj.nil?
  populate_properties(obj, properties)

  if block_given?
    # cache the proxy - http://wiki.jruby.org/Persistence
    obj.class.__persistent__ = true if obj.class.ancestors.include? JavaProxy
    obj.extend(JRubyFX)
    obj.instance_eval(&block)
  end

  obj
end