jrubyfx 0.9.1-java → 0.9.2-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 +18 -2
- data/bin/{rubyfx-generator → jrubyfx-generator} +3 -3
- data/bin/jrubyfx-jarify +29 -4
- data/lib/jrubyfx/core_ext/border_pane.rb +2 -0
- data/lib/jrubyfx/core_ext/column_constraints.rb +2 -0
- data/lib/jrubyfx/core_ext/drag_event.rb +32 -0
- data/lib/jrubyfx/core_ext/drag_event.rb~ +32 -0
- data/lib/jrubyfx/core_ext/duration.rb +2 -0
- data/lib/jrubyfx/core_ext/effects.rb +2 -0
- data/lib/jrubyfx/core_ext/file_chooser.rb +3 -0
- data/lib/jrubyfx/core_ext/image_view.rb +24 -0
- data/lib/jrubyfx/core_ext/image_view.rb~ +24 -0
- data/lib/jrubyfx/core_ext/media_player.rb +2 -0
- data/lib/jrubyfx/core_ext/menu.rb +25 -0
- data/lib/jrubyfx/core_ext/menu.rb~ +26 -0
- data/lib/jrubyfx/core_ext/menu_bar.rb +25 -0
- data/lib/jrubyfx/core_ext/menu_bar.rb~ +24 -0
- data/lib/jrubyfx/core_ext/menu_item.rb +22 -0
- data/lib/jrubyfx/core_ext/node.rb +2 -0
- data/lib/jrubyfx/core_ext/pagination.rb +4 -2
- data/lib/jrubyfx/core_ext/path.rb +2 -0
- data/lib/jrubyfx/core_ext/progress_indicator.rb +3 -0
- data/lib/jrubyfx/core_ext/region.rb +3 -0
- data/lib/jrubyfx/core_ext/rotate.rb +2 -0
- data/lib/jrubyfx/core_ext/shape.rb +2 -0
- data/lib/jrubyfx/core_ext/stop.rb +2 -0
- data/lib/jrubyfx/core_ext/timeline.rb +13 -0
- data/lib/jrubyfx/core_ext/transition.rb +1 -0
- data/lib/jrubyfx/core_ext/tree_item.rb +25 -0
- data/lib/jrubyfx/core_ext/tree_item.rb~ +25 -0
- data/lib/jrubyfx/core_ext/tree_view.rb +40 -0
- data/lib/jrubyfx/core_ext/tree_view.rb~ +33 -0
- data/lib/jrubyfx/dsl.rb +46 -7
- data/lib/jrubyfx/fxml_controller.rb +85 -30
- data/lib/jrubyfx/jfx_imports.rb +25 -23
- data/lib/jrubyfx/utils/__ignore_java_stupid_rdoc.rb +6 -0
- data/lib/jrubyfx/utils/common_converters.rb +50 -2
- data/lib/jrubyfx/version.rb +1 -1
- data/lib/jrubyfx_tasks.rb +54 -10
- metadata +18 -5
@@ -14,6 +14,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
See the License for the specific language governing permissions and
|
15
15
|
limitations under the License.
|
16
16
|
=end
|
17
|
+
require 'jrubyfx/dsl'
|
18
|
+
|
17
19
|
# JRubyFX DSL extensions for JavaFX Paths
|
18
20
|
class Java::javafx::scene::shape::Path
|
19
21
|
java_import Java::javafx.scene.shape.PathElement
|
@@ -14,6 +14,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
See the License for the specific language governing permissions and
|
15
15
|
limitations under the License.
|
16
16
|
=end
|
17
|
+
require 'jrubyfx/dsl'
|
18
|
+
|
17
19
|
# JRubyFX DSL extensions for JavaFX Progress *
|
18
20
|
class Java::javafx::scene::control::ProgressIndicator
|
19
21
|
extend JRubyFX::Utils::CommonConverters
|
@@ -25,6 +27,7 @@ class Java::javafx::scene::control::ProgressIndicator
|
|
25
27
|
converter_for :new, [], [progress_conv]
|
26
28
|
|
27
29
|
end
|
30
|
+
|
28
31
|
# JRubyFX DSL extensions for JavaFX Progress *
|
29
32
|
class Java::javafx::scene::control::ProgressBar
|
30
33
|
extend JRubyFX::Utils::CommonConverters
|
@@ -14,6 +14,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
See the License for the specific language governing permissions and
|
15
15
|
limitations under the License.
|
16
16
|
=end
|
17
|
+
require 'jrubyfx/dsl'
|
18
|
+
|
17
19
|
# JRubyFX DSL extensions for JavaFX color stops
|
18
20
|
class Java::javafx::scene::layout::Region
|
19
21
|
extend JRubyFX::Utils::CommonConverters
|
@@ -36,4 +38,5 @@ class Java::javafx::scene::layout::Region
|
|
36
38
|
converter_for :max_width, [use_sizes]
|
37
39
|
converter_for :max_height, [use_sizes]
|
38
40
|
|
41
|
+
converter_for :padding, [:insets]
|
39
42
|
end
|
@@ -14,6 +14,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
See the License for the specific language governing permissions and
|
15
15
|
limitations under the License.
|
16
16
|
=end
|
17
|
+
require 'jrubyfx/dsl'
|
18
|
+
|
17
19
|
# JRubyFX DSL extensions for JavaFX color stops
|
18
20
|
class Java::javafx::scene::transform::Rotate
|
19
21
|
extend JRubyFX::Utils::CommonConverters
|
@@ -14,6 +14,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
See the License for the specific language governing permissions and
|
15
15
|
limitations under the License.
|
16
16
|
=end
|
17
|
+
require 'jrubyfx/dsl'
|
18
|
+
|
17
19
|
# JRubyFX DSL extensions for JavaFX Shapes
|
18
20
|
class Java::javafx::scene::shape::Shape
|
19
21
|
extend JRubyFX::Utils::CommonConverters
|
@@ -14,6 +14,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
See the License for the specific language governing permissions and
|
15
15
|
limitations under the License.
|
16
16
|
=end
|
17
|
+
require 'jrubyfx/dsl'
|
18
|
+
|
17
19
|
# JRubyFX DSL extensions for JavaFX color stops
|
18
20
|
class Java::javafx::scene::paint::Stop
|
19
21
|
extend JRubyFX::Utils::CommonConverters
|
@@ -14,6 +14,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
See the License for the specific language governing permissions and
|
15
15
|
limitations under the License.
|
16
16
|
=end
|
17
|
+
require 'jrubyfx/dsl'
|
18
|
+
|
17
19
|
# JRubyFX DSL extensions for JavaFX animation Timelines
|
18
20
|
class Java::javafx::animation::Timeline
|
19
21
|
java_import Java::javafx.animation.KeyFrame
|
@@ -24,6 +26,17 @@ class Java::javafx::animation::Timeline
|
|
24
26
|
include_add :key_frames
|
25
27
|
include_method_missing KeyFrame
|
26
28
|
|
29
|
+
# call-seq:
|
30
|
+
# animate myProperty, from_duration => to_duration, start_value => next_value
|
31
|
+
# animate myProperty, from_duration => [with_duration, ..., to_duration], start_value => [next_value, ...]
|
32
|
+
#
|
33
|
+
# Animates a given JavaFX property over the given duration, using the given values
|
34
|
+
# as keyFrames
|
35
|
+
#
|
36
|
+
# === Examples
|
37
|
+
# animate translateXProperty, 0.sec => [100.ms, 1.sec], 0 => [500, 200]
|
38
|
+
# animate translateYProperty, 0.sec => 1.sec, 0 => 200
|
39
|
+
#
|
27
40
|
def animate(prop, args)
|
28
41
|
time = []
|
29
42
|
values = []
|
@@ -15,6 +15,7 @@ See the License for the specific language governing permissions and
|
|
15
15
|
limitations under the License.
|
16
16
|
=end
|
17
17
|
|
18
|
+
#:nodoc:
|
18
19
|
{:Rotate => :angle, :Scale => [:x, :y, :z], :Translate => [:x, :y, :z],
|
19
20
|
:Fade => :value, :Fill => :value, :Stroke => :value}.each do |clas, anim_props|
|
20
21
|
JavaUtilities.get_proxy_class("javafx.animation.#{clas}Transition").class_eval do
|
@@ -0,0 +1,25 @@
|
|
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 Tree items
|
20
|
+
class Java::javafx::scene::control::TreeItem
|
21
|
+
include JRubyFX::DSL
|
22
|
+
|
23
|
+
include_add
|
24
|
+
include_method_missing TreeItem
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
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::TreeItem
|
21
|
+
include JRubyFX::DSL
|
22
|
+
extend JRubyFX::Utils::CommonConverters
|
23
|
+
|
24
|
+
include_add
|
25
|
+
end
|
@@ -0,0 +1,40 @@
|
|
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 Tree views
|
20
|
+
class Java::javafx::scene::control::TreeView
|
21
|
+
include JRubyFX::DSL
|
22
|
+
|
23
|
+
##
|
24
|
+
# get_tree_item interferes with idiomatic construction of a root
|
25
|
+
# tree_item. We override and users should use get_tree_item(i)
|
26
|
+
# if they want the original method.
|
27
|
+
def tree_item(*args, &block)
|
28
|
+
method_missing(:tree_item, *args, &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Add any child tree items as the root node. Note, that there
|
33
|
+
# is only one root and successive tree_items in a tree_view will
|
34
|
+
# keep replacing the root.
|
35
|
+
def method_missing(name, *args, &block)
|
36
|
+
super.tap do |obj|
|
37
|
+
set_root(obj) if obj.kind_of? TreeItem
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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
|
data/lib/jrubyfx/dsl.rb
CHANGED
@@ -27,10 +27,41 @@ module JRubyFX
|
|
27
27
|
module ClassUtils
|
28
28
|
include JRubyFX::FXImports
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
##
|
31
|
+
# Register your own type for use in the DSL.
|
32
|
+
#
|
33
|
+
# class MyFooWidget < Region
|
34
|
+
# #...
|
35
|
+
# end
|
36
|
+
# #...
|
37
|
+
# register_type(MyFooWidget)
|
38
|
+
# register_type(MyFooWidget, "aliased_name")
|
39
|
+
#
|
40
|
+
# Note, this also makes it possible to override existing definitions
|
41
|
+
# of built-in components.
|
42
|
+
#
|
43
|
+
def register_type(type, name=nil)
|
44
|
+
name = type.name.snake_case unless name
|
32
45
|
JRubyFX::DSL::NAME_TO_CLASSES[name.to_s] = type
|
33
46
|
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# Define a dual-mode method which acts as both a getter and
|
50
|
+
# setter depending on whether it has been supplied an argument
|
51
|
+
# or not.
|
52
|
+
#
|
53
|
+
def getter_setter(name)
|
54
|
+
self.class_eval do
|
55
|
+
# FIXME: Is arity of splat the best way to do this?
|
56
|
+
define_method(name) do |*r|
|
57
|
+
if r.length > 0
|
58
|
+
set_effect *r
|
59
|
+
else
|
60
|
+
get_effect
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
34
65
|
|
35
66
|
# Lots of DSL extensions use these methods, so define them here so multiple classes can use them
|
36
67
|
|
@@ -75,7 +106,7 @@ module JRubyFX
|
|
75
106
|
define_method :method_missing do |name, *args, &block|
|
76
107
|
# we must manually call super otherwise it will call super(type)
|
77
108
|
super(name, *args, &block).tap do |obj|
|
78
|
-
add(obj) if obj.kind_of?
|
109
|
+
add(obj) if obj.kind_of?(type) && !name.to_s.end_with?('!')
|
79
110
|
end
|
80
111
|
end
|
81
112
|
end
|
@@ -129,8 +160,16 @@ module JRubyFX
|
|
129
160
|
# you can say
|
130
161
|
# java_class(hash) { ... }
|
131
162
|
#
|
163
|
+
# Another major portion of the DSL is the ability to implicitly add new
|
164
|
+
# created components to their parent on construction. There are a few
|
165
|
+
# places where this is undesirable. In order to prevent implicit
|
166
|
+
# construction you can add a '!' on the end:
|
167
|
+
# circle!(30)
|
168
|
+
# This will construct a Circle but it will not add it into its parent
|
169
|
+
# container. This is useful for specifying clipping regions in particular.
|
170
|
+
#
|
132
171
|
def method_missing(name, *args, &block)
|
133
|
-
clazz = NAME_TO_CLASSES[name.to_s]
|
172
|
+
clazz = NAME_TO_CLASSES[name.to_s.gsub(/!$/, '')]
|
134
173
|
super unless clazz
|
135
174
|
|
136
175
|
build(clazz, *args, &block)
|
@@ -206,9 +245,9 @@ module JRubyFX
|
|
206
245
|
# This loads the entire DSL. Call this immediately after requiring
|
207
246
|
# this file, but not inside this file, or it requires itself twice.
|
208
247
|
def self.load_dsl
|
209
|
-
rt = "#{File.dirname(__FILE__)}/core_ext
|
210
|
-
Dir.
|
211
|
-
|
248
|
+
rt = "#{File.dirname(__FILE__)}/core_ext"
|
249
|
+
Dir.glob("#{rt}/*.rb") do |file|
|
250
|
+
require file
|
212
251
|
end
|
213
252
|
|
214
253
|
JRubyFX::DSL.load_enum_converter()
|
@@ -23,16 +23,16 @@ class JRubyFX::Controller
|
|
23
23
|
include JRubyFX::DSL
|
24
24
|
java_import 'java.net.URL'
|
25
25
|
java_import 'javafx.fxml.FXMLLoader'
|
26
|
-
|
26
|
+
|
27
27
|
# Controllers usually need access to the stage.
|
28
28
|
attr_accessor :stage
|
29
|
-
|
29
|
+
|
30
30
|
##
|
31
31
|
# call-seq:
|
32
32
|
# fx_handler(callback) { |event_info| block } => Method
|
33
33
|
# fx_handler(callback, EventType) { |event_info| block } => Method
|
34
34
|
# fx_type_handler(callback) { |event_info| block } => Method
|
35
|
-
#
|
35
|
+
#
|
36
36
|
# Registers a function of name `name` for a FXML defined event with the body in the block
|
37
37
|
# Note: there are overrides for most of the default types, so you should never
|
38
38
|
# need to manually specify the `type` argument unless you have custom events.
|
@@ -51,32 +51,32 @@ class JRubyFX::Controller
|
|
51
51
|
# * fx_window_handler is for WindowEvent
|
52
52
|
# * fx_action_handler is for ActionEvent
|
53
53
|
# * fx_generic_handler is for Event
|
54
|
-
#
|
54
|
+
#
|
55
55
|
# === Examples
|
56
56
|
# fx_handler :click do
|
57
57
|
# puts "button clicked"
|
58
58
|
# end
|
59
|
-
#
|
59
|
+
#
|
60
60
|
# fx_mouse_handler :moved do |event|
|
61
61
|
# puts "Mouse Moved"
|
62
62
|
# p event
|
63
63
|
# end
|
64
|
-
#
|
64
|
+
#
|
65
65
|
# fx_key_handler :keypress do
|
66
66
|
# puts "Key Pressed"
|
67
67
|
# end
|
68
|
-
#
|
68
|
+
#
|
69
69
|
# === Equivalent Java
|
70
70
|
# @FXML
|
71
71
|
# private void click(ActionEvent event) {
|
72
72
|
# System.out.println("button clicked");
|
73
73
|
# }
|
74
|
-
#
|
74
|
+
#
|
75
75
|
# @FXML
|
76
76
|
# private void moved(MouseEvent event) {
|
77
77
|
# System.out.println("Mouse Moved");
|
78
78
|
# }
|
79
|
-
#
|
79
|
+
#
|
80
80
|
# @FXML
|
81
81
|
# private void keypress(KeyEvent event) {
|
82
82
|
# System.out.println("Key Pressed");
|
@@ -92,7 +92,7 @@ class JRubyFX::Controller
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
# Get the singleton class, and add special overloads as fx_EVENT_handler
|
97
97
|
# This funky syntax allows us to define methods on self (like define_method("self.method"),
|
98
98
|
# except that does not work)
|
@@ -119,44 +119,97 @@ class JRubyFX::Controller
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
122
|
-
|
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
|
+
|
123
176
|
# FXML linked variable names by subclass
|
124
177
|
@@fxml_linked_args = {}
|
125
|
-
|
178
|
+
|
126
179
|
##
|
127
180
|
# call-seq:
|
128
181
|
# fx_id :name, ...
|
129
|
-
#
|
182
|
+
#
|
130
183
|
# Register one or more variable names to bind to a fx:id in the FXML file.
|
131
184
|
# === Example
|
132
185
|
# fx_id :myVar
|
133
|
-
#
|
186
|
+
#
|
134
187
|
# === Equivalent Java
|
135
188
|
# @FXML
|
136
189
|
# private ClassName myVar;
|
137
|
-
#
|
190
|
+
#
|
138
191
|
def self.fx_id(*name)
|
139
192
|
# we must distinguish between subclasses, hence self.
|
140
193
|
(@@fxml_linked_args[self] ||= []).concat(name)
|
141
194
|
end
|
142
|
-
|
195
|
+
|
143
196
|
##
|
144
197
|
# call-seq:
|
145
198
|
# fx_id_optional :name, ...
|
146
|
-
#
|
199
|
+
#
|
147
200
|
# Register one or more variable name to bind to a fx:id in the FXML file if it exists.
|
148
201
|
# If the name cannot be found, don't complain.
|
149
202
|
# === Example
|
150
203
|
# fx_id_optional :myVar
|
151
|
-
#
|
204
|
+
#
|
152
205
|
# === Equivalent Java
|
153
206
|
# @FXML
|
154
207
|
# private ClassName myVar;
|
155
|
-
#
|
208
|
+
#
|
156
209
|
def self.fx_id_optional(*names)
|
157
210
|
fx_id *names.map {|i| {i => :quiet} }
|
158
211
|
end
|
159
|
-
|
212
|
+
|
160
213
|
##
|
161
214
|
# Set scene object (setter), and update fxml-injected values. If you are manually
|
162
215
|
# loading FXML, you MUST call this to link `fx_id` specified names.
|
@@ -177,20 +230,20 @@ class JRubyFX::Controller
|
|
177
230
|
instance_variable_set("@#{name}".to_sym, val)
|
178
231
|
end
|
179
232
|
end
|
180
|
-
|
233
|
+
|
181
234
|
##
|
182
235
|
# Return the scene object (getter)
|
183
236
|
def scene()
|
184
237
|
@scene
|
185
238
|
end
|
186
|
-
|
239
|
+
|
187
240
|
##
|
188
241
|
# Magic self-java-ifying new call. (Creates a Java instance)
|
189
242
|
def self.new_java(*args)
|
190
243
|
self.become_java!
|
191
244
|
self.new(*args)
|
192
245
|
end
|
193
|
-
|
246
|
+
|
194
247
|
##
|
195
248
|
# Load given fxml file onto the given stage. `settings` is an optional hash of:
|
196
249
|
# * :initialize => [array of arguments to pass to the initialize function]
|
@@ -204,7 +257,7 @@ class JRubyFX::Controller
|
|
204
257
|
# === Examples
|
205
258
|
#
|
206
259
|
# controller = MyFXController.load_fxml("Demo.fxml", stage)
|
207
|
-
#
|
260
|
+
#
|
208
261
|
# === Equivalent Java
|
209
262
|
# Parent root = FXMLLoader.load(getClass().getResource("Demo.fxml"));
|
210
263
|
# Scene scene = new Scene(root);
|
@@ -213,7 +266,7 @@ class JRubyFX::Controller
|
|
213
266
|
#
|
214
267
|
def self.load_fxml(filename, stage, settings={})
|
215
268
|
# Create our class as a java class with any arguments it wants
|
216
|
-
ctrl = self.new_java *
|
269
|
+
ctrl = self.new_java *settings[:initialize_ruby].to_a
|
217
270
|
# save the stage so we can reference it if needed later
|
218
271
|
ctrl.stage = stage
|
219
272
|
# load the FXML file
|
@@ -226,25 +279,27 @@ class JRubyFX::Controller
|
|
226
279
|
else
|
227
280
|
Scene.new(parent, settings[:width] || -1, settings[:height] || -1, settings[:depth_buffer] || settings[:depthBuffer] || false)
|
228
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)
|
229
284
|
# return the controller. If they want the new scene, they can call the scene() method on it
|
230
285
|
return ctrl
|
231
286
|
end
|
232
|
-
|
287
|
+
|
233
288
|
##
|
234
289
|
# call-seq:
|
235
290
|
# load_fxml_resource(filename) => Parent
|
236
291
|
# load_fxml_resource(filename, controller_instance) => Parent
|
237
292
|
# load_fxml_resource(filename, controller_instance, relative_to) => Parent
|
238
|
-
#
|
293
|
+
#
|
239
294
|
# Load a FXML file given a filename and a controller and return the root element
|
240
295
|
# relative_to can be a file that this should be relative to, or an index
|
241
|
-
# of the caller number. If you are calling this from a function, pass 0
|
296
|
+
# of the caller number. If you are calling this from a function, pass 0
|
242
297
|
# as you are the immediate caller of this function.
|
243
298
|
# === Examples
|
244
299
|
# root = JRubyFX::Controller.load_fxml_resource("Demo.fxml")
|
245
|
-
#
|
300
|
+
#
|
246
301
|
# root = JRubyFX::Controller.load_fxml_resource("Demo.fxml", my_controller)
|
247
|
-
#
|
302
|
+
#
|
248
303
|
# === Equivalent Java
|
249
304
|
# Parent root = FXMLLoader.load(getClass().getResource("Demo.fxml"));
|
250
305
|
#
|