Module: JRubyFX
- Includes:
- FXImports, Utils::CommonUtils
- Included in:
- Application, Controller, DSL
- Defined in:
- lib/jrubyfx/fxml_module.rb,
lib/jrubyfx/dsl.rb,
lib/jrubyfx_tasks.rb,
lib/jrubyfx/version.rb,
lib/jrubyfx/jfx_imports.rb,
lib/jrubyfx/utils/common_utils.rb,
lib/jrubyfx/utils/common_converters.rb
Overview
JRubyFX - Write JavaFX and FXML in Ruby Copyright © 2013 The JRubyFX Team
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Defined Under Namespace
Modules: DSL, FXImports, Tasks, Utils Classes: Application, Controller
Constant Summary collapse
- VERSION =
Current gem version. Used in rake task.
'0.9.1'
Constants included from FXImports
FXImports::JFX_CLASS_HIERARCHY
Instance Method Summary collapse
-
#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.
-
#run_later(&block) ⇒ Object
call-seq: run_later { block }.
-
#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.
Methods included from Utils::CommonUtils
#attempt_conversion, #populate_properties, #split_args_from_properties
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/fxml_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/fxml_module.rb', line 61 def run_later(&block) 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
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jrubyfx/fxml_module.rb', line 42 def with(obj, properties = {}, &block) 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 |