jrubyfx 1.2.0-java → 2.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +21 -10
- data/lib/jrubyfx/application.rb +2 -2
- data/lib/jrubyfx/controller.rb +62 -31
- data/lib/jrubyfx/core_ext/exts.yml +9 -1
- data/lib/jrubyfx/core_ext/observable_value.rb +20 -2
- data/lib/jrubyfx/core_ext/precompiled.rb +1185 -175
- data/lib/jrubyfx/dsl.rb +3 -0
- data/lib/jrubyfx/dsl_map.rb +486 -9
- data/lib/jrubyfx/fxml_helper.rb +134 -0
- data/lib/jrubyfx/imports.rb +498 -26
- data/lib/jrubyfx/module.rb +28 -0
- data/lib/jrubyfx/part_imports.rb +63 -52
- data/lib/jrubyfx/utils.rb +6 -1
- data/lib/jrubyfx/version.rb +1 -1
- data/lib/jrubyfx.rb +6 -5
- data/lib/jrubyfx_tasks.rb +3 -1
- metadata +4 -19
- data/lib/jrubyfx/java_fx_impl.rb +0 -137
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2663b39ced8255fd70b6666efcf58ad87133d4a385f5f01dc8fd6d9797ebf298
|
4
|
+
data.tar.gz: ec875fdd53ca592f9023004b83595d902d8dd74a680a2b3830df71a744369b4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dee292568c4247cff866bccffab39a1f2ee1928c95c776649540a459a3edb5f3d4b90ae49a17b50906f38e96a24f4ca0d0ecf3235d3d6c1ce702c606fefb2170
|
7
|
+
data.tar.gz: f3e259057d479843db42ed9e9582a2e3acbd64fa214221a639dbc6d965fa86f456e3e4b96e0e734971a1c4989829d335600457ec9be61b7dd373675535d61c6b
|
data/README.md
CHANGED
@@ -1,24 +1,34 @@
|
|
1
1
|
JRubyFX
|
2
2
|
=======
|
3
|
-
JRubyFX is a pure ruby wrapper for JavaFX 2.2+ with FXML support
|
3
|
+
JRubyFX is a pure ruby wrapper for JavaFX 2.2+ with FXML support. Currently supported: Java 8+, JRuby 9.3+.
|
4
4
|
|
5
5
|
Status
|
6
6
|
------
|
7
|
-
JRubyFX master should be usable in its current form and able to run
|
8
|
-
|
7
|
+
JRubyFX master should be usable in its current form and able to run most FXML apps.
|
8
|
+
As of JRubyFX 2.0, the Java FXML Loader is used. This requires JRuby 9.3+.
|
9
|
+
Please see the [JRubyFX github wiki](https://github.com/jruby/jrubyfx/wiki/) for upgrading from 1.x.
|
9
10
|
|
10
11
|
Install
|
11
12
|
-----
|
13
|
+
|
14
|
+
For JRuby 9.3.4+:
|
15
|
+
|
12
16
|
```text
|
13
17
|
gem install jrubyfx
|
14
18
|
```
|
19
|
+
For older JRuby versions:
|
20
|
+
|
21
|
+
```text
|
22
|
+
gem install jrubyfx -v 1.2
|
23
|
+
```
|
24
|
+
|
25
|
+
If you are using Java 9+, additionally append the contents of `module-opens.txt` to `bin/.jruby.java_opts` in your jruby install. If you fail to do this, you may get inscruitable "method X not found, did you mean X?" errors.
|
15
26
|
|
16
27
|
Manual Build and Install
|
17
28
|
-----
|
18
|
-
Build is done using rake/gem/bundler/rdoc. You need JRuby
|
29
|
+
Build is done using rake/gem/bundler/rdoc. You need JRuby >= 9.3.4.0, Java >= 8 with JavaFX 11 modules installed (only required for `reflect` task). Building native application packages requires JDK 8+.
|
19
30
|
|
20
31
|
```text
|
21
|
-
gem install jrubyfx-fxmlloader
|
22
32
|
rake install
|
23
33
|
```
|
24
34
|
Once the gem is installed, just run a ruby file that uses it normally.
|
@@ -26,7 +36,11 @@ Once the gem is installed, just run a ruby file that uses it normally.
|
|
26
36
|
**NOTE:** If you don't have JRuby installed as the `ruby` command, use `jruby -S rake` instead of `rake`. If
|
27
37
|
you are using RVM, this does not apply to you (though make sure you `rvm use jruby`).
|
28
38
|
|
29
|
-
**If you are reporting bugs or encountering fxml issues:** please
|
39
|
+
**If you are reporting bugs or encountering fxml issues:** please ensure you are using JRubyFX 2.0. Prior version relied on a ported fxml parser and had many known issues.
|
40
|
+
|
41
|
+
Updating the Imports
|
42
|
+
--------------
|
43
|
+
JRubyFX currently uses the 11-based classes for the default imports (part_imports.rb). In the future, this list may change. See `gen_tree.rb` for a script to help automate finding the classes to import.
|
30
44
|
|
31
45
|
Creating a Jar
|
32
46
|
--------------
|
@@ -94,16 +108,13 @@ If you want rdoc, run `rake rdoc`. Please note that there are lots of generated
|
|
94
108
|
|
95
109
|
Issues
|
96
110
|
------
|
97
|
-
* Use JRubyFX-FxmlLoader's FxmlLoader instead of javafx.fxml.FXMLLoader for maximum Ruby support.
|
98
|
-
* FXML support in master for very complex documents is untested. Report bugs against JRubyFX-FxmlLoader with the FXML file if it fails.
|
99
|
-
* You must use the provided JavaFXImpl::Launcher to launch the app (aka: call _yourFXApplicationClass_.launch())
|
100
111
|
* Errors loading JavaFX are bugs. Please report if you encounter this issue, tell us your platform, OS, and version of JRuby
|
101
112
|
* Jarify command needs the `jar` executable in your path.
|
102
113
|
* Any other difficulties are bugs. Please report them
|
103
114
|
|
104
115
|
Contact
|
105
116
|
-------
|
106
|
-
Find us in #jruby on
|
117
|
+
Find us in #jruby on matrix.
|
107
118
|
|
108
119
|
License
|
109
120
|
-------
|
data/lib/jrubyfx/application.rb
CHANGED
@@ -36,7 +36,7 @@ class JRubyFX::Application < Java.javafx.application.Application
|
|
36
36
|
#
|
37
37
|
# When called on a subclass, this is effectively our main method.
|
38
38
|
def self.launch(*args)
|
39
|
-
#
|
40
|
-
|
39
|
+
# Note: object args are no longer allowed
|
40
|
+
Java.javafx.application.Application.launch(self.become_java!, args.map(&:to_s).to_java(:string))
|
41
41
|
end
|
42
42
|
end
|
data/lib/jrubyfx/controller.rb
CHANGED
@@ -16,19 +16,16 @@ limitations under the License.
|
|
16
16
|
=end
|
17
17
|
|
18
18
|
require 'jrubyfx/utils/string_utils'
|
19
|
-
|
20
|
-
|
21
|
-
require 'jrubyfx-fxmlloader'
|
22
|
-
rescue LoadError
|
23
|
-
# no fxmlloader, ignore it
|
24
|
-
end
|
19
|
+
require 'jrubyfx/fxml_helper'
|
20
|
+
require 'jruby/core_ext'
|
25
21
|
|
26
22
|
# Special methods for fxml loading
|
27
23
|
module Kernel
|
28
24
|
@@jrubyfx_res_dir = {}
|
29
25
|
@@jrubyfx_fxml_res_cl = nil
|
30
|
-
def fxml_root(value=nil, jar_value=nil,
|
31
|
-
@@jrubyfx_fxml_res_cl =
|
26
|
+
def fxml_root(value=nil, jar_value=nil, get_resources: nil, fxml_class_loader: nil)
|
27
|
+
@@jrubyfx_fxml_res_cl = get_resources if get_resources
|
28
|
+
@@jrubyfx_fxml_main_cl = fxml_class_loader if fxml_class_loader
|
32
29
|
if value or jar_value
|
33
30
|
@@jrubyfx_fxml_dir = (JRubyFX::Application.in_jar? and jar_value) ? jar_value : File.expand_path(value)
|
34
31
|
else
|
@@ -45,6 +42,9 @@ module Kernel
|
|
45
42
|
def get_fxml_resource_class_loader
|
46
43
|
@@jrubyfx_fxml_res_cl || JRuby.runtime.jruby_class_loader.method("get_resource")
|
47
44
|
end
|
45
|
+
def get_fxml_classes_class_loader
|
46
|
+
@@jrubyfx_fxml_main_cl ||= JRubyFX::PolyglotClassLoader.new
|
47
|
+
end
|
48
48
|
def resource_url(type, relative_path)
|
49
49
|
if JRubyFX::Application.in_jar?
|
50
50
|
get_fxml_resource_class_loader.call("#{resource_root(type)}/#{relative_path}")
|
@@ -77,6 +77,10 @@ module JRubyFX::Controller
|
|
77
77
|
base.extend(ClassMethods)
|
78
78
|
base.extend(JRubyFX::FXMLClassUtils) if defined? JRubyFX::FXMLClassUtils
|
79
79
|
base.extend(JRubyFX::FXImports)
|
80
|
+
base.configure_java_class ctor_name: "java_ctor" do
|
81
|
+
dispatch :initialize, :fx_initialize # we want to load our code before calling user code
|
82
|
+
# un-exclude "initialize"
|
83
|
+
end
|
80
84
|
# register ourselves as a control. overridable with custom_fxml_control
|
81
85
|
register_type base if base.is_a? Class
|
82
86
|
end
|
@@ -113,11 +117,20 @@ module JRubyFX::Controller
|
|
113
117
|
def load_into(stage, settings={})
|
114
118
|
# Inherit from default settings
|
115
119
|
settings = DEFAULT_SETTINGS.merge({root_dir: (self.instance_variable_get("@fxml_root_dir") || fxml_root),
|
116
|
-
|
120
|
+
get_resources: get_fxml_resource_class_loader,
|
121
|
+
fxml_class_loader: get_fxml_classes_class_loader,
|
117
122
|
filename: self.instance_variable_get("@filename")}).merge settings
|
118
|
-
|
119
|
-
|
120
|
-
|
123
|
+
|
124
|
+
raise "JRubyFX 1.x style class loader argument passed into 'load_into'. Replace 'class_loader' with either 'get_resources' (likely) or 'fxml_class_loader' (less likely)" if settings.has_key? :class_loader
|
125
|
+
|
126
|
+
unless @built
|
127
|
+
## Use the temporary loader to reformat AController
|
128
|
+
JRubyFX::FxmlHelper.transform self, Controller.get_fxml_location(settings[:root_dir], settings[:filename], settings[:get_resources])
|
129
|
+
|
130
|
+
# Custom controls don't always need to be pure java, but oh well...
|
131
|
+
become_java!
|
132
|
+
@built = true
|
133
|
+
end
|
121
134
|
|
122
135
|
# like new, without initialize
|
123
136
|
ctrl = allocate
|
@@ -126,7 +139,7 @@ module JRubyFX::Controller
|
|
126
139
|
ctrl.stage = stage
|
127
140
|
|
128
141
|
# load the FXML file
|
129
|
-
root = Controller.get_fxml_loader(settings[:filename], ctrl, settings[:root_dir], settings[:
|
142
|
+
root = Controller.get_fxml_loader(settings[:filename], ctrl, settings[:root_dir], settings[:get_resources], settings[:fxml_class_loader]).load
|
130
143
|
|
131
144
|
# Unless the FXML root node is a scene, wrap that node in a scene
|
132
145
|
if root.is_a? Scene
|
@@ -148,14 +161,24 @@ module JRubyFX::Controller
|
|
148
161
|
if @preparsed && @preparsed.length > 0
|
149
162
|
return @preparsed.pop.finish_initialization(*args, &block)
|
150
163
|
end
|
164
|
+
|
165
|
+
settings = DEFAULT_SETTINGS.merge({root_dir: @fxml_root_dir || fxml_root, get_resources: get_fxml_resource_class_loader,
|
166
|
+
fxml_class_loader: get_fxml_classes_class_loader, filename: @filename})
|
167
|
+
|
151
168
|
# Custom controls don't always need to be pure java, but oh well...
|
152
|
-
|
169
|
+
if @filename && !@built
|
170
|
+
@built = true # TODO: move later if no new :bake call
|
171
|
+
## Use the temporary loader to reformat AController
|
172
|
+
JRubyFX::FxmlHelper.transform self, Controller.get_fxml_location(settings[:root_dir], settings[:filename], settings[:get_resources])
|
173
|
+
|
174
|
+
# Custom controls don't always need to be pure java, but oh well...
|
175
|
+
become_java!
|
176
|
+
end
|
153
177
|
|
154
178
|
# like new, without initialize
|
155
179
|
ctrl = allocate
|
156
180
|
|
157
|
-
ctrl.initialize_controller(
|
158
|
-
filename: @filename}),
|
181
|
+
ctrl.initialize_controller(settings,
|
159
182
|
*args, &block) if @filename
|
160
183
|
|
161
184
|
# return the controller
|
@@ -232,17 +255,22 @@ module JRubyFX::Controller
|
|
232
255
|
end
|
233
256
|
end
|
234
257
|
end
|
258
|
+
|
259
|
+
# java initialize is redirected to here
|
260
|
+
def fx_initialize()
|
261
|
+
# Do nothing, as we already control initialization
|
262
|
+
end
|
235
263
|
|
236
264
|
#default java ctor, override for arguments
|
237
|
-
def java_ctor(
|
238
|
-
|
265
|
+
def java_ctor(*initialize_arguments)
|
266
|
+
super()
|
239
267
|
end
|
240
268
|
|
241
269
|
# Initialize all controllers
|
242
270
|
def initialize_controller(options={}, *args, &block)
|
243
|
-
|
271
|
+
|
244
272
|
# JRuby complains loudly (probably broken behavior) if we don't call the ctor
|
245
|
-
|
273
|
+
__jallocate!() # TODO: args? TODO: non-java controllers?*args) # TODO: remove
|
246
274
|
|
247
275
|
# load the FXML file with the current control as the root
|
248
276
|
load_fxml options[:filename], options[:root_dir]
|
@@ -254,14 +282,14 @@ module JRubyFX::Controller
|
|
254
282
|
def pre_initialize_controller(options={})
|
255
283
|
|
256
284
|
# JRuby complains loudly (probably broken behavior) if we don't call the ctor
|
257
|
-
java_ctor self.class.
|
285
|
+
java_ctor self.class.instance_method(:__jallocate!).bind(self), [] #TODO: do we need to call this now with []?
|
258
286
|
|
259
287
|
# load the FXML file with the current control as the root
|
260
288
|
load_fxml options[:filename], options[:root_dir]
|
261
289
|
end
|
262
290
|
|
263
291
|
def load_fxml(filename, root_dir=nil)
|
264
|
-
fx = Controller.get_fxml_loader(filename, self, root_dir || @fxml_root_dir || fxml_root, get_fxml_resource_class_loader)
|
292
|
+
fx = Controller.get_fxml_loader(filename, self, root_dir || @fxml_root_dir || fxml_root, get_fxml_resource_class_loader, get_fxml_classes_class_loader)
|
265
293
|
fx.root = self
|
266
294
|
fx.load
|
267
295
|
end
|
@@ -273,7 +301,7 @@ module JRubyFX::Controller
|
|
273
301
|
self.scene = self unless @scene
|
274
302
|
|
275
303
|
# Everything is ready, call initialize
|
276
|
-
if private_methods.include? :initialize
|
304
|
+
if private_methods.include? :initialize or methods.include? :initialize
|
277
305
|
self.send :initialize, *args, &block
|
278
306
|
end
|
279
307
|
|
@@ -306,11 +334,14 @@ module JRubyFX::Controller
|
|
306
334
|
def self.load_fxml_only(filename, stage, settings={})
|
307
335
|
# Inherit from default settings
|
308
336
|
settings = DEFAULT_SETTINGS.merge({root_dir: fxml_root,
|
309
|
-
|
337
|
+
get_resources: get_fxml_resource_class_loader,
|
338
|
+
fxml_class_loader: get_fxml_classes_class_loader,
|
310
339
|
filename: filename}).merge settings
|
311
|
-
|
340
|
+
|
341
|
+
raise "JRubyFX 1.x style class loader argument passed into 'load_fxml_only'. Replace 'class_loader' with either 'get_resources' (likely) or 'fxml_class_loader' (less likely)" if settings.has_key? :class_loader
|
342
|
+
|
312
343
|
# load the FXML file
|
313
|
-
root = Controller.get_fxml_loader(settings[:filename], nil, settings[:root_dir], settings[:
|
344
|
+
root = Controller.get_fxml_loader(settings[:filename], nil, settings[:root_dir], settings[:get_resources], settings[:fxml_class_loader]).load
|
314
345
|
|
315
346
|
# TODO: de-duplicate this code
|
316
347
|
|
@@ -343,15 +374,15 @@ module JRubyFX::Controller
|
|
343
374
|
# === Equivalent Java
|
344
375
|
# Parent root = FXMLLoader.load(getClass().getResource("Demo.fxml"));
|
345
376
|
#
|
346
|
-
def self.get_fxml_loader(filename, controller = nil, root_dir = nil,
|
347
|
-
fx =
|
348
|
-
|
377
|
+
def self.get_fxml_loader(filename, controller = nil, root_dir = nil, get_resources = JRuby.runtime.jruby_class_loader.method("get_resource"), fxml_class_loader=nil)
|
378
|
+
fx = javafx.fxml.FXMLLoader.new(get_fxml_location(root_dir, filename, get_resources))
|
379
|
+
fx.class_loader = fxml_class_loader unless fxml_class_loader.nil?
|
349
380
|
# we must set this here for JFX to call our events
|
350
381
|
fx.controller = controller
|
351
382
|
fx
|
352
383
|
end
|
353
384
|
|
354
|
-
def self.get_fxml_location(root_dir, filename,
|
385
|
+
def self.get_fxml_location(root_dir, filename, get_resources)
|
355
386
|
if JRubyFX::Application.in_jar? and filename.match(/^[^.\/]/)
|
356
387
|
# If we are in a jar file, use the class loader to get the file from the jar (like java)
|
357
388
|
# TODO: should just be able to use URLs
|
@@ -362,7 +393,7 @@ module JRubyFX::Controller
|
|
362
393
|
# we want to point to a folder inside the jar, otherwise to a filesystem's one. According to this we format and
|
363
394
|
# feed the right path to the class loader.
|
364
395
|
|
365
|
-
location =
|
396
|
+
location = get_resources.call(File.join(root_dir, filename))
|
366
397
|
|
367
398
|
# fall back if not found
|
368
399
|
return location if location
|
@@ -16,6 +16,9 @@
|
|
16
16
|
"Java::JavafxSceneControl::TreeItem":
|
17
17
|
method_missing: "Java::JavafxSceneControl::TreeItem"
|
18
18
|
add: get_children
|
19
|
+
"Java::JavafxSceneControl::TreeTableView":
|
20
|
+
method_missing: "Java::JavafxSceneControl::TreeItem"
|
21
|
+
add: get_children
|
19
22
|
"Java::JavafxSceneControl::TableView":
|
20
23
|
method_missing: "Java::JavafxSceneControl::TableColumn"
|
21
24
|
add: get_columns
|
@@ -39,6 +42,8 @@
|
|
39
42
|
"Java::JavafxAnimation::Timeline":
|
40
43
|
method_missing: "Java::JavafxAnimation::KeyFrame"
|
41
44
|
add: key_frames
|
45
|
+
"Java::JavafxSceneLayout::BackgroundFill":
|
46
|
+
new_converter: [[color, none, none]]
|
42
47
|
"Java::JavafxSceneShape::Path":
|
43
48
|
add: elements
|
44
49
|
rotate: []
|
@@ -51,7 +56,10 @@
|
|
51
56
|
logical_children: panes
|
52
57
|
"Java::JavafxSceneShape::Circle":
|
53
58
|
new_converter: [[], [none], [none, color], [none, none, none], [none, none, none, color]]
|
59
|
+
"Java::JavafxSceneShape::Rectangle":
|
60
|
+
new_converter: [[], [none, none], [none, none, none, none], [none, none, color]]
|
54
61
|
"Java::JavafxScenePaint::Stop":
|
55
62
|
new_converter: [[none, color]]
|
56
63
|
"Java::JavafxSceneShape::Shape":
|
57
|
-
getter_setter: fill
|
64
|
+
getter_setter: fill
|
65
|
+
|
@@ -131,6 +131,24 @@ module Java::javafx::collections::ObservableMap
|
|
131
131
|
# stores the listeners.
|
132
132
|
end
|
133
133
|
|
134
|
+
module Java::javafx::beans::binding::NumberExpression
|
135
|
+
def - x
|
136
|
+
subtract x
|
137
|
+
end
|
138
|
+
def / x
|
139
|
+
divide x
|
140
|
+
end
|
141
|
+
def * x
|
142
|
+
multiply x
|
143
|
+
end
|
144
|
+
def + x
|
145
|
+
add x
|
146
|
+
end
|
147
|
+
def -@ x
|
148
|
+
negate x
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
134
152
|
class Class
|
135
153
|
def property_writer(*symbol_names)
|
136
154
|
symbol_names.each do |symbol_name|
|
@@ -147,8 +165,8 @@ class Class
|
|
147
165
|
end
|
148
166
|
end
|
149
167
|
def property_accessor(*symbol_names)
|
150
|
-
property_reader
|
151
|
-
property_writer
|
168
|
+
property_reader(*symbol_names)
|
169
|
+
property_writer(*symbol_names)
|
152
170
|
symbol_names.each do |symbol_name|
|
153
171
|
send(:define_method, symbol_name.id2name + "_property") do
|
154
172
|
instance_variable_get("@#{symbol_name}")
|