jrubyfx 0.9.2-java → 1.0.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +19 -17
- data/bin/jrubyfx-generator +28 -11
- data/lib/jrubyfx.rb +8 -4
- data/lib/jrubyfx/{fxml_application.rb → application.rb} +0 -2
- data/lib/jrubyfx/controller.rb +307 -0
- data/lib/jrubyfx/core_ext/border_pane.rb +0 -1
- data/lib/jrubyfx/core_ext/duration.rb +1 -1
- data/lib/jrubyfx/core_ext/exts.yml +53 -0
- data/lib/jrubyfx/core_ext/image_view.rb +1 -0
- data/lib/jrubyfx/core_ext/observable_value.rb +69 -2
- data/lib/jrubyfx/core_ext/path.rb +0 -6
- data/lib/jrubyfx/core_ext/precompiled.rb +501 -0
- data/lib/jrubyfx/core_ext/stage.rb +12 -0
- data/lib/jrubyfx/core_ext/table_view.rb +0 -4
- data/lib/jrubyfx/core_ext/timeline.rb +3 -7
- data/lib/jrubyfx/dsl.rb +168 -150
- data/lib/jrubyfx/dsl_map.rb +267 -0
- data/lib/jrubyfx/imports.rb +64 -0
- data/lib/jrubyfx/java_fx_impl.rb +0 -1
- data/lib/jrubyfx/module.rb +172 -0
- data/lib/jrubyfx/{jfx_imports.rb → part_imports.rb} +17 -9
- data/lib/jrubyfx/utils.rb +13 -4
- data/lib/jrubyfx/utils/common_converters.rb +45 -13
- data/lib/jrubyfx/utils/common_utils.rb +1 -1
- data/lib/jrubyfx/version.rb +1 -1
- data/lib/jrubyfx_tasks.rb +9 -1
- metadata +69 -55
- data/lib/jrubyfx/core_ext/circle.rb +0 -26
- data/lib/jrubyfx/core_ext/drag_event.rb~ +0 -32
- data/lib/jrubyfx/core_ext/image_view.rb~ +0 -24
- data/lib/jrubyfx/core_ext/labeled.rb +0 -24
- data/lib/jrubyfx/core_ext/menu.rb +0 -25
- data/lib/jrubyfx/core_ext/menu.rb~ +0 -26
- data/lib/jrubyfx/core_ext/menu_bar.rb +0 -25
- data/lib/jrubyfx/core_ext/menu_bar.rb~ +0 -24
- data/lib/jrubyfx/core_ext/menu_item.rb +0 -22
- data/lib/jrubyfx/core_ext/node.rb +0 -26
- data/lib/jrubyfx/core_ext/parallel_transition.rb +0 -28
- data/lib/jrubyfx/core_ext/parent.rb +0 -28
- data/lib/jrubyfx/core_ext/scene.rb +0 -29
- data/lib/jrubyfx/core_ext/shape.rb +0 -29
- data/lib/jrubyfx/core_ext/stop.rb +0 -31
- data/lib/jrubyfx/core_ext/tree_item.rb +0 -25
- data/lib/jrubyfx/core_ext/tree_item.rb~ +0 -25
- data/lib/jrubyfx/core_ext/tree_view.rb~ +0 -33
- data/lib/jrubyfx/fxml_controller.rb +0 -325
- data/lib/jrubyfx/fxml_module.rb +0 -98
@@ -1,33 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
JRubyFX - Write JavaFX and FXML in Ruby
|
3
|
-
Copyright (C) 2013 The JRubyFX Team
|
4
|
-
|
5
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
you may not use this file except in compliance with the License.
|
7
|
-
You may obtain a copy of the License at
|
8
|
-
|
9
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
|
11
|
-
Unless required by applicable law or agreed to in writing, software
|
12
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
See the License for the specific language governing permissions and
|
15
|
-
limitations under the License.
|
16
|
-
=end
|
17
|
-
require 'jrubyfx/dsl'
|
18
|
-
|
19
|
-
# JRubyFX DSL extensions for JavaFX TableViews
|
20
|
-
class Java::javafx::scene::control::TreeView
|
21
|
-
include JRubyFX::DSL
|
22
|
-
extend JRubyFX::Utils::CommonConverters
|
23
|
-
|
24
|
-
include_add
|
25
|
-
|
26
|
-
##
|
27
|
-
# Make sure we add any nested TreeItem's to this one
|
28
|
-
def method_missing(name, *args, &block)
|
29
|
-
super.tap do |obj|
|
30
|
-
add(obj) if obj.kind_of? TreeItem
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,325 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
JRubyFX - Write JavaFX and FXML in Ruby
|
3
|
-
Copyright (C) 2013 The JRubyFX Team
|
4
|
-
|
5
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
you may not use this file except in compliance with the License.
|
7
|
-
You may obtain a copy of the License at
|
8
|
-
|
9
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
|
11
|
-
Unless required by applicable law or agreed to in writing, software
|
12
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
See the License for the specific language governing permissions and
|
15
|
-
limitations under the License.
|
16
|
-
=end
|
17
|
-
|
18
|
-
require 'jrubyfx'
|
19
|
-
|
20
|
-
# Inherit from this class for FXML controllers
|
21
|
-
class JRubyFX::Controller
|
22
|
-
include JRubyFX
|
23
|
-
include JRubyFX::DSL
|
24
|
-
java_import 'java.net.URL'
|
25
|
-
java_import 'javafx.fxml.FXMLLoader'
|
26
|
-
|
27
|
-
# Controllers usually need access to the stage.
|
28
|
-
attr_accessor :stage
|
29
|
-
|
30
|
-
##
|
31
|
-
# call-seq:
|
32
|
-
# fx_handler(callback) { |event_info| block } => Method
|
33
|
-
# fx_handler(callback, EventType) { |event_info| block } => Method
|
34
|
-
# fx_type_handler(callback) { |event_info| block } => Method
|
35
|
-
#
|
36
|
-
# Registers a function of name `name` for a FXML defined event with the body in the block
|
37
|
-
# Note: there are overrides for most of the default types, so you should never
|
38
|
-
# need to manually specify the `type` argument unless you have custom events.
|
39
|
-
# The overrides are in the format fx_*_handler where * is the event type (ex:
|
40
|
-
# fx_key_handler for KeyEvent).
|
41
|
-
# === Overloads
|
42
|
-
# * fx_key_handler is for KeyEvent
|
43
|
-
# * fx_mouse_handler is for MouseEvent
|
44
|
-
# * fx_touch_handler is for TouchEvent
|
45
|
-
# * fx_gesture_handler is for GestureEvent
|
46
|
-
# * fx_context_handler is for ContextMenuEvent
|
47
|
-
# * fx_context_menu_handler is for ContextMenuEvent
|
48
|
-
# * fx_drag_handler is for DragEvent
|
49
|
-
# * fx_ime_handler is for InputMethodEvent
|
50
|
-
# * fx_input_method_handler is for InputMethodEvent
|
51
|
-
# * fx_window_handler is for WindowEvent
|
52
|
-
# * fx_action_handler is for ActionEvent
|
53
|
-
# * fx_generic_handler is for Event
|
54
|
-
#
|
55
|
-
# === Examples
|
56
|
-
# fx_handler :click do
|
57
|
-
# puts "button clicked"
|
58
|
-
# end
|
59
|
-
#
|
60
|
-
# fx_mouse_handler :moved do |event|
|
61
|
-
# puts "Mouse Moved"
|
62
|
-
# p event
|
63
|
-
# end
|
64
|
-
#
|
65
|
-
# fx_key_handler :keypress do
|
66
|
-
# puts "Key Pressed"
|
67
|
-
# end
|
68
|
-
#
|
69
|
-
# === Equivalent Java
|
70
|
-
# @FXML
|
71
|
-
# private void click(ActionEvent event) {
|
72
|
-
# System.out.println("button clicked");
|
73
|
-
# }
|
74
|
-
#
|
75
|
-
# @FXML
|
76
|
-
# private void moved(MouseEvent event) {
|
77
|
-
# System.out.println("Mouse Moved");
|
78
|
-
# }
|
79
|
-
#
|
80
|
-
# @FXML
|
81
|
-
# private void keypress(KeyEvent event) {
|
82
|
-
# System.out.println("Key Pressed");
|
83
|
-
# }
|
84
|
-
#
|
85
|
-
def self.fx_handler(names, type=ActionEvent, &block)
|
86
|
-
[names].flatten.each do |name|
|
87
|
-
class_eval do
|
88
|
-
#must define this way so block executes in class scope, not static scope
|
89
|
-
define_method(name, block)
|
90
|
-
#the first arg is the return type, the rest are params
|
91
|
-
add_method_signature name, [Void::TYPE, type]
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# Get the singleton class, and add special overloads as fx_EVENT_handler
|
97
|
-
# This funky syntax allows us to define methods on self (like define_method("self.method"),
|
98
|
-
# except that does not work)
|
99
|
-
class << self
|
100
|
-
include JRubyFX::FXImports
|
101
|
-
{:key => KeyEvent,
|
102
|
-
:mouse => MouseEvent,
|
103
|
-
:touch => TouchEvent,
|
104
|
-
:gesture => GestureEvent,
|
105
|
-
:context => ContextMenuEvent,
|
106
|
-
:context_menu => ContextMenuEvent,
|
107
|
-
:drag => DragEvent,
|
108
|
-
:ime => InputMethodEvent,
|
109
|
-
:input_method => InputMethodEvent,
|
110
|
-
:window => WindowEvent,
|
111
|
-
:action => ActionEvent,
|
112
|
-
:generic => Event}.each do |method, klass|
|
113
|
-
#instance_eval on the self instance so that these are defined as class methods
|
114
|
-
self.instance_eval do
|
115
|
-
# define the handy overloads that just pass our arguments in
|
116
|
-
define_method("fx_#{method}_handler") do |name, &block|
|
117
|
-
fx_handler(name, klass, &block)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
# When FXMLLoader detects a method called initialze taking 0 args, then it calls it
|
124
|
-
# We don't want this, as ruby new calls initialize
|
125
|
-
# Override new to avoid calling initialize
|
126
|
-
def self.new(*args, &block)
|
127
|
-
obj = self.allocate
|
128
|
-
obj.send(:initialize_ruby, *args, &block) if defined? obj.initialize_ruby
|
129
|
-
obj
|
130
|
-
end
|
131
|
-
|
132
|
-
# this is the default initialize that the FXML loader will call
|
133
|
-
def initialize()
|
134
|
-
end
|
135
|
-
# this is the default initialized method so we can always call it
|
136
|
-
def initialize_fxml(*args)
|
137
|
-
self.send(:initialize_fxml_warn, *args) if defined? initialize_fxml_warn
|
138
|
-
end
|
139
|
-
alias_method :initialize_orig, :initialize
|
140
|
-
|
141
|
-
# When initialize is defined, rename it to initialized, and restore
|
142
|
-
# initialize to default so java does not double call us
|
143
|
-
def self.method_added(name)
|
144
|
-
if name == :initialize && !@in_alias
|
145
|
-
puts <<WARNIT
|
146
|
-
*****************************************************************************
|
147
|
-
*****************************************************************************
|
148
|
-
** WARNING! WARNING! WARNING! WARNING! **
|
149
|
-
** WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! **
|
150
|
-
** WARNING! WARNING! WARNING! WARNING! **
|
151
|
-
*****************************************************************************
|
152
|
-
** **
|
153
|
-
** You probably meant to define `initialize_fxml` instead of `initialize` **
|
154
|
-
** `initialize` is ambiguous in JavaFX controllers as FXMLLoader will call **
|
155
|
-
** it if it has 0 arguments in addition to it being ruby's constructor. **
|
156
|
-
** If you need access to FXML elements (defined with `fx_id :myEltId`), **
|
157
|
-
** then use `initialize_fxml`. If you need the ruby constructor, which **
|
158
|
-
** does not have access to FXML yet, use `initialize_ruby` instead **
|
159
|
-
** **
|
160
|
-
** Assuming you wanted `initialize_fxml` for this run **
|
161
|
-
** **
|
162
|
-
*****************************************************************************
|
163
|
-
** WARNING! WARNING! WARNING! WARNING! **
|
164
|
-
** WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! **
|
165
|
-
** WARNING! WARNING! WARNING! WARNING! **
|
166
|
-
*****************************************************************************
|
167
|
-
*****************************************************************************
|
168
|
-
WARNIT
|
169
|
-
@in_alias = true
|
170
|
-
alias_method :initialize_fxml_warn, :initialize
|
171
|
-
alias_method :initialize, :initialize_orig
|
172
|
-
@in_alias = false
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
# FXML linked variable names by subclass
|
177
|
-
@@fxml_linked_args = {}
|
178
|
-
|
179
|
-
##
|
180
|
-
# call-seq:
|
181
|
-
# fx_id :name, ...
|
182
|
-
#
|
183
|
-
# Register one or more variable names to bind to a fx:id in the FXML file.
|
184
|
-
# === Example
|
185
|
-
# fx_id :myVar
|
186
|
-
#
|
187
|
-
# === Equivalent Java
|
188
|
-
# @FXML
|
189
|
-
# private ClassName myVar;
|
190
|
-
#
|
191
|
-
def self.fx_id(*name)
|
192
|
-
# we must distinguish between subclasses, hence self.
|
193
|
-
(@@fxml_linked_args[self] ||= []).concat(name)
|
194
|
-
end
|
195
|
-
|
196
|
-
##
|
197
|
-
# call-seq:
|
198
|
-
# fx_id_optional :name, ...
|
199
|
-
#
|
200
|
-
# Register one or more variable name to bind to a fx:id in the FXML file if it exists.
|
201
|
-
# If the name cannot be found, don't complain.
|
202
|
-
# === Example
|
203
|
-
# fx_id_optional :myVar
|
204
|
-
#
|
205
|
-
# === Equivalent Java
|
206
|
-
# @FXML
|
207
|
-
# private ClassName myVar;
|
208
|
-
#
|
209
|
-
def self.fx_id_optional(*names)
|
210
|
-
fx_id *names.map {|i| {i => :quiet} }
|
211
|
-
end
|
212
|
-
|
213
|
-
##
|
214
|
-
# Set scene object (setter), and update fxml-injected values. If you are manually
|
215
|
-
# loading FXML, you MUST call this to link `fx_id` specified names.
|
216
|
-
def scene=(s)
|
217
|
-
@scene = s
|
218
|
-
(@@fxml_linked_args[self.class] ||= []).each do |name|
|
219
|
-
quiet = false
|
220
|
-
# you can specify name => [quiet/verbose], so we need to check for that
|
221
|
-
if name.is_a? Hash
|
222
|
-
quiet = name.values[0] == :quiet
|
223
|
-
name = name.keys[0]
|
224
|
-
end
|
225
|
-
# set each instance variable from the lookup on the scene
|
226
|
-
val = s.lookup("##{name}")
|
227
|
-
if val == nil && !quiet
|
228
|
-
puts "[WARNING] fx_id not found: #{name}. Is id set to a different value than fx:id? (if this is expected, use fx_id_optional)"
|
229
|
-
end
|
230
|
-
instance_variable_set("@#{name}".to_sym, val)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
##
|
235
|
-
# Return the scene object (getter)
|
236
|
-
def scene()
|
237
|
-
@scene
|
238
|
-
end
|
239
|
-
|
240
|
-
##
|
241
|
-
# Magic self-java-ifying new call. (Creates a Java instance)
|
242
|
-
def self.new_java(*args)
|
243
|
-
self.become_java!
|
244
|
-
self.new(*args)
|
245
|
-
end
|
246
|
-
|
247
|
-
##
|
248
|
-
# Load given fxml file onto the given stage. `settings` is an optional hash of:
|
249
|
-
# * :initialize => [array of arguments to pass to the initialize function]
|
250
|
-
# * :width => Default width of the Scene
|
251
|
-
# * :height => Default height of the Scene
|
252
|
-
# * :fill => Fill color of the Scene's background
|
253
|
-
# * :depth_buffer => JavaFX Scene DepthBuffer argument (look it up)
|
254
|
-
# * :relative_to => number of calls back, or filename. `filename` is evaluated
|
255
|
-
# as being relative to this. Default is relative to caller (1)
|
256
|
-
# Returns a scene, either a new one, or the FXML root if its a Scene.
|
257
|
-
# === Examples
|
258
|
-
#
|
259
|
-
# controller = MyFXController.load_fxml("Demo.fxml", stage)
|
260
|
-
#
|
261
|
-
# === Equivalent Java
|
262
|
-
# Parent root = FXMLLoader.load(getClass().getResource("Demo.fxml"));
|
263
|
-
# Scene scene = new Scene(root);
|
264
|
-
# stage.setScene(scene);
|
265
|
-
# controller = root.getController();
|
266
|
-
#
|
267
|
-
def self.load_fxml(filename, stage, settings={})
|
268
|
-
# Create our class as a java class with any arguments it wants
|
269
|
-
ctrl = self.new_java *settings[:initialize_ruby].to_a
|
270
|
-
# save the stage so we can reference it if needed later
|
271
|
-
ctrl.stage = stage
|
272
|
-
# load the FXML file
|
273
|
-
parent = load_fxml_resource(filename, ctrl, settings[:relative_to] || 1)
|
274
|
-
# set the controller and stage scene, so that all the fx_id variables are hooked up
|
275
|
-
ctrl.scene = stage.scene = if parent.is_a? Scene
|
276
|
-
parent
|
277
|
-
elsif settings.has_key? :fill
|
278
|
-
Scene.new(parent, settings[:width] || -1, settings[:height] || -1, settings[:fill] || Color::WHITE)
|
279
|
-
else
|
280
|
-
Scene.new(parent, settings[:width] || -1, settings[:height] || -1, settings[:depth_buffer] || settings[:depthBuffer] || false)
|
281
|
-
end
|
282
|
-
# instead of using the initializable interface, roll our own so we don't have to deal with java.
|
283
|
-
ctrl.initialize_fxml(*settings[:initialize_fxml].to_a)
|
284
|
-
# return the controller. If they want the new scene, they can call the scene() method on it
|
285
|
-
return ctrl
|
286
|
-
end
|
287
|
-
|
288
|
-
##
|
289
|
-
# call-seq:
|
290
|
-
# load_fxml_resource(filename) => Parent
|
291
|
-
# load_fxml_resource(filename, controller_instance) => Parent
|
292
|
-
# load_fxml_resource(filename, controller_instance, relative_to) => Parent
|
293
|
-
#
|
294
|
-
# Load a FXML file given a filename and a controller and return the root element
|
295
|
-
# relative_to can be a file that this should be relative to, or an index
|
296
|
-
# of the caller number. If you are calling this from a function, pass 0
|
297
|
-
# as you are the immediate caller of this function.
|
298
|
-
# === Examples
|
299
|
-
# root = JRubyFX::Controller.load_fxml_resource("Demo.fxml")
|
300
|
-
#
|
301
|
-
# root = JRubyFX::Controller.load_fxml_resource("Demo.fxml", my_controller)
|
302
|
-
#
|
303
|
-
# === Equivalent Java
|
304
|
-
# Parent root = FXMLLoader.load(getClass().getResource("Demo.fxml"));
|
305
|
-
#
|
306
|
-
def self.load_fxml_resource(filename, ctrlr=nil, relative_to=0)
|
307
|
-
fx = FXMLLoader.new()
|
308
|
-
fx.location = if JRubyFX::Application.in_jar?
|
309
|
-
# If we are in a jar file, use the class loader to get the file from the jar (like java)
|
310
|
-
JRuby.runtime.jruby_class_loader.get_resource(filename)
|
311
|
-
else
|
312
|
-
if relative_to.is_a? Fixnum or relative_to == nil
|
313
|
-
# caller[0] returns a string like so:
|
314
|
-
# "/home/user/.rvm/rubies/jruby-1.7.1/lib/ruby/1.9/irb/workspace.rb:80:in `eval'"
|
315
|
-
# and then we use a regex to filter out the filename
|
316
|
-
relative_to = caller[relative_to||0][/(.*):[0-9]+:in /, 1] # the 1 is the first match, aka everything up to the :
|
317
|
-
end
|
318
|
-
# If we are in the normal filesystem, create a normal file url path relative to the main file
|
319
|
-
URL.new(URL.new("file:"), "#{File.dirname(relative_to)}/#{filename}")
|
320
|
-
end
|
321
|
-
# we must set this here for JFX to call our events
|
322
|
-
fx.controller = ctrlr
|
323
|
-
return fx.load()
|
324
|
-
end
|
325
|
-
end
|
data/lib/jrubyfx/fxml_module.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
=begin
|
2
|
-
JRubyFX - Write JavaFX and FXML in Ruby
|
3
|
-
Copyright (C) 2013 The JRubyFX Team
|
4
|
-
|
5
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
you may not use this file except in compliance with the License.
|
7
|
-
You may obtain a copy of the License at
|
8
|
-
|
9
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
|
11
|
-
Unless required by applicable law or agreed to in writing, software
|
12
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
See the License for the specific language governing permissions and
|
15
|
-
limitations under the License.
|
16
|
-
=end
|
17
|
-
|
18
|
-
require 'jrubyfx'
|
19
|
-
require 'jrubyfx/utils/common_utils'
|
20
|
-
|
21
|
-
# This module contains useful methods for defining JavaFX code. Include it in your
|
22
|
-
# class to use it, and the JRubyFX::FXImports. JRubyFX::Application and JRubyFX::Controller already include it.
|
23
|
-
module JRubyFX
|
24
|
-
include JRubyFX::FXImports
|
25
|
-
include JRubyFX::Utils::CommonUtils
|
26
|
-
|
27
|
-
##
|
28
|
-
# call-seq:
|
29
|
-
# with(obj, hash) => obj
|
30
|
-
# with(obj) { block } => obj
|
31
|
-
# with(obj, hash) { block }=> obj
|
32
|
-
#
|
33
|
-
# Set properties (e.g. setters) on the passed in object plus also invoke
|
34
|
-
# any block passed against this object.
|
35
|
-
# === Examples
|
36
|
-
#
|
37
|
-
# with(grid, vgap: 2, hgap: 2) do
|
38
|
-
# set_pref_size(500, 400)
|
39
|
-
# children << location << go << view
|
40
|
-
# end
|
41
|
-
#
|
42
|
-
def with(obj, properties = {}, &block)
|
43
|
-
populate_properties(obj, properties)
|
44
|
-
|
45
|
-
if block_given?
|
46
|
-
# cache the proxy - http://wiki.jruby.org/Persistence
|
47
|
-
obj.class.__persistent__ = true if obj.class.ancestors.include? JavaProxy
|
48
|
-
obj.extend(JRubyFX)
|
49
|
-
obj.instance_eval(&block)
|
50
|
-
end
|
51
|
-
|
52
|
-
obj
|
53
|
-
end
|
54
|
-
|
55
|
-
##
|
56
|
-
# call-seq:
|
57
|
-
# run_later { block }
|
58
|
-
#
|
59
|
-
# Convenience method so anything can safely schedule to run on JavaFX
|
60
|
-
# main thread.
|
61
|
-
def run_later(&block)
|
62
|
-
Platform.run_later &block
|
63
|
-
end
|
64
|
-
|
65
|
-
##
|
66
|
-
# call-seq:
|
67
|
-
# build(class) => obj
|
68
|
-
# build(class, hash) => obj
|
69
|
-
# build(class) { block } => obj
|
70
|
-
# build(class, hash) { block } => obj
|
71
|
-
#
|
72
|
-
# Create "build" a new JavaFX instance with the provided class and
|
73
|
-
# set properties (e.g. setters) on that new instance plus also invoke
|
74
|
-
# any block passed against this new instance. This also can build a proc
|
75
|
-
# or lambda form in which case the return value of the block will be what
|
76
|
-
# is used to set the additional properties on.
|
77
|
-
# === Examples
|
78
|
-
#
|
79
|
-
# grid = build(GridPane, vgap: 2, hgap: 2) do
|
80
|
-
# set_pref_size(500, 400)
|
81
|
-
# children << location << go << view
|
82
|
-
# end
|
83
|
-
#
|
84
|
-
# build(proc { Foo.new }, vgap: 2, hgap: 2)
|
85
|
-
#
|
86
|
-
def build(klass, *args, &block)
|
87
|
-
args, properties = split_args_from_properties(*args)
|
88
|
-
|
89
|
-
obj = if klass.kind_of? Proc
|
90
|
-
klass.call(*args)
|
91
|
-
else
|
92
|
-
klass.new(*attempt_conversion(klass, :new, *args))
|
93
|
-
end
|
94
|
-
|
95
|
-
with(obj, properties, &block)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|