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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8a064999e484e03f5884810d6e550fc45dc5a004
4
- data.tar.gz: 65024687422bb89e24e05a79b90856591961f3e2
2
+ SHA256:
3
+ metadata.gz: 2663b39ced8255fd70b6666efcf58ad87133d4a385f5f01dc8fd6d9797ebf298
4
+ data.tar.gz: ec875fdd53ca592f9023004b83595d902d8dd74a680a2b3830df71a744369b4c
5
5
  SHA512:
6
- metadata.gz: 03c78c8e191648d7cbe82f13db565b1ca0552e4870940bbc9bbd58153165b16aed5d5dcc4e328151b0ed149267678d86c1972f63c219b5f051abb7dbbd976081
7
- data.tar.gz: 0fdad3b966bec08eb468cec0d412ca9e9eb02db40e34e6ea6cbe1c3fc7e61ae907ae482a7231cd651fb5ef367f8a62c0c086a2a8190a072fe463118bc643637d
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 simple FXML apps if used properly (see Issues).
8
- FXML syntax in master/1.0 is very different from 0.9 series. Please see the [JRubyFX github wiki](https://github.com/jruby/jrubyfx/wiki/) for more details.
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 >1.7.4 (in 1.9 mode), Java >1.6 with JavaFX 2.2, but Java 7 is recommended. Building native application packages requires JDK 8.
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 install [master jrubyfx-fxmlloader](https://github.com/byteit101/JRubyFX-FXMLLoader/) instead of from rubygems
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 freenode.
117
+ Find us in #jruby on matrix.
107
118
 
108
119
  License
109
120
  -------
@@ -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
- #call our custom launcher to avoid a java shim
40
- JavaFXImpl::Launcher.launch_app(self, *args)
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
@@ -16,19 +16,16 @@ limitations under the License.
16
16
  =end
17
17
 
18
18
  require 'jrubyfx/utils/string_utils'
19
- # If fxmlloader is installed, require it here
20
- begin
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, class_loader = nil)
31
- @@jrubyfx_fxml_res_cl = class_loader if class_loader
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
- class_loader: (get_fxml_resource_class_loader),
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
- # Custom controls don't always need to be pure java, but oh well...
120
- become_java!
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[:class_loader]).load
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
- become_java! if @filename
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(DEFAULT_SETTINGS.merge({root_dir: @fxml_root_dir || fxml_root,
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(ctor, initialize_arguments)
238
- ctor.call
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
- java_ctor self.class.superclass.instance_method(:initialize).bind(self), args
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.superclass.instance_method(:initialize).bind(self), [] #TODO: do we need to call this now with []?
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
- class_loader: get_fxml_resource_class_loader,
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[:class_loader]).load
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, class_loader = JRuby.runtime.jruby_class_loader.method("get_resource"))
347
- fx = FxmlLoader.new
348
- fx.location = get_fxml_location(root_dir, filename, class_loader)
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, class_loader)
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 = class_loader.call(File.join(root_dir, filename))
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 *symbol_names
151
- property_writer *symbol_names
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}")