Module: Java::javafx::beans::value::ObservableValue

Defined in:
lib/jrubyfx/core_ext/observable_value.rb

Overview

JRubyFX DSL extensions for JavaFX ObservableValues

Instance Method Summary collapse

Instance Method Details

#add_change_listener(type = nil, &block) ⇒ Object

call-seq:

add_change_listener { |observable, old_value, new_value| block }
add_change_listener { |new_value| block }

Add a ruby block to call when the property changes changes



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/jrubyfx/core_ext/observable_value.rb', line 30

def add_change_listener(type=nil, &block)
  unless type
    type = :list if self.is_a? Java::javafx::collections::ObservableList
    type = :map if self.is_a? Java::javafx::collections::ObservableMap
  end
  if type == :list || type == :map
    super(&block)
  else
    old_verbose = $VERBOSE
    begin
      $VERBOSE = nil
      addListener(ChangeListener.impl {|name, x, y, z|
          if block.arity == 1
            block.call(z) # just call with new
          else
            block.call(x, y, z)
          end
        })
    ensure
      # always re-set to old value, even if block raises an exception
      $VERBOSE = old_verbose
    end
  end
end

#add_invalidation_listener(&block) ⇒ Object

call-seq:

add_invalidation_listener { |observable| block }

Add a ruby block to call when the property invalidates itself (bad property!)



61
62
63
64
65
66
67
68
69
70
# File 'lib/jrubyfx/core_ext/observable_value.rb', line 61

def add_invalidation_listener(&block)
    old_verbose = $VERBOSE
    begin
      $VERBOSE = nil
      addListener(InvalidationListener.impl {|name, change| block.call(change) })
    ensure
      # always re-set to old value, even if block raises an exception
      $VERBOSE = old_verbose
    end
end