jrubyfx-openjfx.patch 1.2.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.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +202 -0
  3. data/README.md +121 -0
  4. data/bin/jrubyfx-compile +32 -0
  5. data/bin/jrubyfx-generator +98 -0
  6. data/bin/jrubyfx-jarify +115 -0
  7. data/lib/jrubyfx.rb +41 -0
  8. data/lib/jrubyfx/application.rb +42 -0
  9. data/lib/jrubyfx/compiler_app.rb +51 -0
  10. data/lib/jrubyfx/controller.rb +375 -0
  11. data/lib/jrubyfx/core_ext/border_pane.rb +30 -0
  12. data/lib/jrubyfx/core_ext/column_constraints.rb +43 -0
  13. data/lib/jrubyfx/core_ext/drag_event.rb +32 -0
  14. data/lib/jrubyfx/core_ext/duration.rb +30 -0
  15. data/lib/jrubyfx/core_ext/effects.rb +32 -0
  16. data/lib/jrubyfx/core_ext/exts.yml +57 -0
  17. data/lib/jrubyfx/core_ext/file_chooser.rb +63 -0
  18. data/lib/jrubyfx/core_ext/geometry.rb +27 -0
  19. data/lib/jrubyfx/core_ext/grid_pane.rb +30 -0
  20. data/lib/jrubyfx/core_ext/image_view.rb +25 -0
  21. data/lib/jrubyfx/core_ext/media_player.rb +25 -0
  22. data/lib/jrubyfx/core_ext/observable_value.rb +158 -0
  23. data/lib/jrubyfx/core_ext/pagination.rb +28 -0
  24. data/lib/jrubyfx/core_ext/path.rb +37 -0
  25. data/lib/jrubyfx/core_ext/precompiled.rb +1883 -0
  26. data/lib/jrubyfx/core_ext/progress_indicator.rb +41 -0
  27. data/lib/jrubyfx/core_ext/radial_gradient.rb +37 -0
  28. data/lib/jrubyfx/core_ext/region.rb +42 -0
  29. data/lib/jrubyfx/core_ext/rotate.rb +39 -0
  30. data/lib/jrubyfx/core_ext/stage.rb +89 -0
  31. data/lib/jrubyfx/core_ext/table_view.rb +31 -0
  32. data/lib/jrubyfx/core_ext/timeline.rb +56 -0
  33. data/lib/jrubyfx/core_ext/transition.rb +26 -0
  34. data/lib/jrubyfx/core_ext/tree_view.rb +40 -0
  35. data/lib/jrubyfx/core_ext/xy_chart.rb +53 -0
  36. data/lib/jrubyfx/dsl.rb +330 -0
  37. data/lib/jrubyfx/dsl_control.rb +28 -0
  38. data/lib/jrubyfx/dsl_map.rb +273 -0
  39. data/lib/jrubyfx/imports.rb +324 -0
  40. data/lib/jrubyfx/java_fx_impl.rb +144 -0
  41. data/lib/jrubyfx/module.rb +178 -0
  42. data/lib/jrubyfx/part_imports.rb +141 -0
  43. data/lib/jrubyfx/utils.rb +86 -0
  44. data/lib/jrubyfx/utils/__ignore_java_stupid_rdoc.rb +30 -0
  45. data/lib/jrubyfx/utils/common_converters.rb +223 -0
  46. data/lib/jrubyfx/utils/common_utils.rb +72 -0
  47. data/lib/jrubyfx/utils/string_utils.rb +48 -0
  48. data/lib/jrubyfx/version.rb +4 -0
  49. data/lib/jrubyfx_tasks.rb +183 -0
  50. metadata +145 -0
@@ -0,0 +1,324 @@
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_relative 'utils'
19
+
20
+ # Update load path to include the JavaFX runtime and fail nicely if we can't find it
21
+ begin
22
+ if ENV['JFX_DIR']
23
+ $LOAD_PATH << ENV['JFX_DIR']
24
+ else #should we check for 1.7 vs 1.8? oh well, adding extra paths won't hurt anybody (maybe performance loading)
25
+ jfx_path = ENV_JAVA["sun.boot.library.path"]
26
+ $LOAD_PATH << if jfx_path.include? ":\\" and !jfx_path.include? "/" # can be tricked, but should work fine
27
+ #windows
28
+ jfx_path.gsub(/\\bin[\\]*$/i, "\\lib")
29
+ else
30
+ # *nix
31
+ jfx_path.gsub(/[\/\\][amdix345678_]+$/, "") # strip i386 or amd64 (including variants). TODO: ARM
32
+ end
33
+ end
34
+
35
+ # Java 8 (after ea-b75) and above has JavaFX as part of the normal distib, only require it if we are 7 or below
36
+ jre = ENV_JAVA["java.runtime.version"].match %r{^(?<version>(?<major>\d+)\.(?<minor>\d+))\.(?<patch>\d+)(_\d+)?-?(?<release>ea|u\d)?(-?b(?<build>\d+))?}
37
+ # add OpenJFX support if follow instruction from https://openjfx.io
38
+ if ENV['JFX_DIR'] or
39
+ jre[:version].to_f < 1.8 or
40
+ (jre[:version].to_f == 1.8 and jre[:release] == 'ea' and jre[:build].to_i < 75)
41
+ require 'jfxrt.jar'
42
+ elsif ENV['PATH_TO_FX'] # support the OpenJFX installation as in https://openjfx.io/openjfx-docs/#install-javafx as of 15th May 2020
43
+ Dir.glob(File.join(ENV['PATH_TO_FX'],"*.jar")).each do |jar|
44
+ require jar
45
+ end
46
+ end
47
+
48
+ # Java 8 at some point requires explicit toolkit/platform initialization
49
+ # before any controls can be loaded.
50
+ JRubyFX.load_fx
51
+
52
+ # Attempt to load a javafx class
53
+ Java.javafx.application.Application
54
+ rescue LoadError, NameError
55
+ # Advice user too about the OpenJFX support
56
+ puts "JavaFX runtime not found. Please install Java 7u6 or newer, set environment variable JFX_DIR to the folder that contains jfxrt.jar or set the environment variable PATH_TO_FX that points to the OpenJFX libraries"
57
+ puts "If you have Java 7u6 or later, this is a bug. Please report to the issue tracker on github. Include your OS version, 32/64bit, and architecture (x86, ARM, PPC, etc)"
58
+ exit -1
59
+ end
60
+
61
+ module JRubyFX
62
+ # If you need JavaFX, just include this module. Its sole purpose in life is to
63
+ # import all JavaFX stuff, plus a few useful Java classes (like Void)
64
+ module FXImports
65
+
66
+ # If something is missing, just java_import it in your code.
67
+ # And then ask us to put it in this list
68
+ #
69
+
70
+ # The below lines are generated by `rake reflect`. Do not edit.
71
+
72
+ def const_missing(c)
73
+ if LOCAL_NAME_MAP.has_key? c
74
+ java_import(LOCAL_NAME_MAP[c])[0]
75
+ else
76
+ super
77
+ end
78
+ end
79
+
80
+ LOCAL_NAME_MAP = {
81
+ :Animation => "javafx.animation.Animation",
82
+ :AnimationTimer => "javafx.animation.AnimationTimer",
83
+ :FadeTransition => "javafx.animation.FadeTransition",
84
+ :FillTransition => "javafx.animation.FillTransition",
85
+ :Interpolator => "javafx.animation.Interpolator",
86
+ :KeyFrame => "javafx.animation.KeyFrame",
87
+ :KeyValue => "javafx.animation.KeyValue",
88
+ :ParallelTransition => "javafx.animation.ParallelTransition",
89
+ :PathTransition => "javafx.animation.PathTransition",
90
+ :PauseTransition => "javafx.animation.PauseTransition",
91
+ :RotateTransition => "javafx.animation.RotateTransition",
92
+ :ScaleTransition => "javafx.animation.ScaleTransition",
93
+ :SequentialTransition => "javafx.animation.SequentialTransition",
94
+ :StrokeTransition => "javafx.animation.StrokeTransition",
95
+ :Timeline => "javafx.animation.Timeline",
96
+ :Transition => "javafx.animation.Transition",
97
+ :TranslateTransition => "javafx.animation.TranslateTransition",
98
+ :Platform => "javafx.application.Platform",
99
+ :SimpleBooleanProperty => "javafx.beans.property.SimpleBooleanProperty",
100
+ :SimpleDoubleProperty => "javafx.beans.property.SimpleDoubleProperty",
101
+ :SimpleFloatProperty => "javafx.beans.property.SimpleFloatProperty",
102
+ :SimpleIntegerProperty => "javafx.beans.property.SimpleIntegerProperty",
103
+ :SimpleListProperty => "javafx.beans.property.SimpleListProperty",
104
+ :SimpleLongProperty => "javafx.beans.property.SimpleLongProperty",
105
+ :SimpleMapProperty => "javafx.beans.property.SimpleMapProperty",
106
+ :SimpleObjectProperty => "javafx.beans.property.SimpleObjectProperty",
107
+ :SimpleSetProperty => "javafx.beans.property.SimpleSetProperty",
108
+ :SimpleStringProperty => "javafx.beans.property.SimpleStringProperty",
109
+ :ChangeListener => "javafx.beans.value.ChangeListener",
110
+ :FXCollections => "javafx.collections.FXCollections",
111
+ :Worker => "javafx.concurrent.Worker",
112
+ :Task => "javafx.concurrent.Task",
113
+ :Service => "javafx.concurrent.Service",
114
+ :Event => "javafx.event.Event",
115
+ :ActionEvent => "javafx.event.ActionEvent",
116
+ :EventHandler => "javafx.event.EventHandler",
117
+ :Initializable => "javafx.fxml.Initializable",
118
+ :LoadException => "javafx.fxml.LoadException",
119
+ :HorizontalDirection => "javafx.geometry.HorizontalDirection",
120
+ :HPos => "javafx.geometry.HPos",
121
+ :Insets => "javafx.geometry.Insets",
122
+ :Orientation => "javafx.geometry.Orientation",
123
+ :Pos => "javafx.geometry.Pos",
124
+ :Rectangle2D => "javafx.geometry.Rectangle2D",
125
+ :Side => "javafx.geometry.Side",
126
+ :VerticalDirection => "javafx.geometry.VerticalDirection",
127
+ :VPos => "javafx.geometry.VPos",
128
+ :Group => "javafx.scene.Group",
129
+ :Node => "javafx.scene.Node",
130
+ :Parent => "javafx.scene.Parent",
131
+ :Scene => "javafx.scene.Scene",
132
+ :Canvas => "javafx.scene.canvas.Canvas",
133
+ :AreaChart => "javafx.scene.chart.AreaChart",
134
+ :Axis => "javafx.scene.chart.Axis",
135
+ :BarChart => "javafx.scene.chart.BarChart",
136
+ :BubbleChart => "javafx.scene.chart.BubbleChart",
137
+ :CategoryAxis => "javafx.scene.chart.CategoryAxis",
138
+ :Chart => "javafx.scene.chart.Chart",
139
+ :LineChart => "javafx.scene.chart.LineChart",
140
+ :NumberAxis => "javafx.scene.chart.NumberAxis",
141
+ :PieChart => "javafx.scene.chart.PieChart",
142
+ :ScatterChart => "javafx.scene.chart.ScatterChart",
143
+ :StackedAreaChart => "javafx.scene.chart.StackedAreaChart",
144
+ :StackedBarChart => "javafx.scene.chart.StackedBarChart",
145
+ :ValueAxis => "javafx.scene.chart.ValueAxis",
146
+ :XYChart => "javafx.scene.chart.XYChart",
147
+ :Accordion => "javafx.scene.control.Accordion",
148
+ :Button => "javafx.scene.control.Button",
149
+ :Cell => "javafx.scene.control.Cell",
150
+ :CheckBox => "javafx.scene.control.CheckBox",
151
+ :CheckBoxTreeItem => "javafx.scene.control.CheckBoxTreeItem",
152
+ :CheckMenuItem => "javafx.scene.control.CheckMenuItem",
153
+ :ChoiceBox => "javafx.scene.control.ChoiceBox",
154
+ :ColorPicker => "javafx.scene.control.ColorPicker",
155
+ :ComboBox => "javafx.scene.control.ComboBox",
156
+ :ContextMenu => "javafx.scene.control.ContextMenu",
157
+ :Hyperlink => "javafx.scene.control.Hyperlink",
158
+ :Label => "javafx.scene.control.Label",
159
+ :ListCell => "javafx.scene.control.ListCell",
160
+ :ListView => "javafx.scene.control.ListView",
161
+ :Menu => "javafx.scene.control.Menu",
162
+ :MenuBar => "javafx.scene.control.MenuBar",
163
+ :MenuButton => "javafx.scene.control.MenuButton",
164
+ :MenuItem => "javafx.scene.control.MenuItem",
165
+ :Pagination => "javafx.scene.control.Pagination",
166
+ :PasswordField => "javafx.scene.control.PasswordField",
167
+ :PopupControl => "javafx.scene.control.PopupControl",
168
+ :ProgressBar => "javafx.scene.control.ProgressBar",
169
+ :ProgressIndicator => "javafx.scene.control.ProgressIndicator",
170
+ :RadioButton => "javafx.scene.control.RadioButton",
171
+ :RadioMenuItem => "javafx.scene.control.RadioMenuItem",
172
+ :ScrollBar => "javafx.scene.control.ScrollBar",
173
+ :ScrollPane => "javafx.scene.control.ScrollPane",
174
+ :Separator => "javafx.scene.control.Separator",
175
+ :SeparatorMenuItem => "javafx.scene.control.SeparatorMenuItem",
176
+ :Slider => "javafx.scene.control.Slider",
177
+ :SplitMenuButton => "javafx.scene.control.SplitMenuButton",
178
+ :SplitPane => "javafx.scene.control.SplitPane",
179
+ :Tab => "javafx.scene.control.Tab",
180
+ :TableView => "javafx.scene.control.TableView",
181
+ :TableCell => "javafx.scene.control.TableCell",
182
+ :TableColumn => "javafx.scene.control.TableColumn",
183
+ :TabPane => "javafx.scene.control.TabPane",
184
+ :TextArea => "javafx.scene.control.TextArea",
185
+ :TextField => "javafx.scene.control.TextField",
186
+ :TitledPane => "javafx.scene.control.TitledPane",
187
+ :ToggleButton => "javafx.scene.control.ToggleButton",
188
+ :ToggleGroup => "javafx.scene.control.ToggleGroup",
189
+ :ToolBar => "javafx.scene.control.ToolBar",
190
+ :Tooltip => "javafx.scene.control.Tooltip",
191
+ :TreeCell => "javafx.scene.control.TreeCell",
192
+ :TreeItem => "javafx.scene.control.TreeItem",
193
+ :TreeView => "javafx.scene.control.TreeView",
194
+ :ContentDisplay => "javafx.scene.control.ContentDisplay",
195
+ :OverrunStyle => "javafx.scene.control.OverrunStyle",
196
+ :SelectionMode => "javafx.scene.control.SelectionMode",
197
+ :Blend => "javafx.scene.effect.Blend",
198
+ :BlendMode => "javafx.scene.effect.BlendMode",
199
+ :Bloom => "javafx.scene.effect.Bloom",
200
+ :BlurType => "javafx.scene.effect.BlurType",
201
+ :BoxBlur => "javafx.scene.effect.BoxBlur",
202
+ :ColorAdjust => "javafx.scene.effect.ColorAdjust",
203
+ :ColorInput => "javafx.scene.effect.ColorInput",
204
+ :DisplacementMap => "javafx.scene.effect.DisplacementMap",
205
+ :DropShadow => "javafx.scene.effect.DropShadow",
206
+ :GaussianBlur => "javafx.scene.effect.GaussianBlur",
207
+ :Glow => "javafx.scene.effect.Glow",
208
+ :ImageInput => "javafx.scene.effect.ImageInput",
209
+ :InnerShadow => "javafx.scene.effect.InnerShadow",
210
+ :Lighting => "javafx.scene.effect.Lighting",
211
+ :MotionBlur => "javafx.scene.effect.MotionBlur",
212
+ :PerspectiveTransform => "javafx.scene.effect.PerspectiveTransform",
213
+ :Reflection => "javafx.scene.effect.Reflection",
214
+ :SepiaTone => "javafx.scene.effect.SepiaTone",
215
+ :Shadow => "javafx.scene.effect.Shadow",
216
+ :Image => "javafx.scene.image.Image",
217
+ :ImageView => "javafx.scene.image.ImageView",
218
+ :PixelReader => "javafx.scene.image.PixelReader",
219
+ :PixelWriter => "javafx.scene.image.PixelWriter",
220
+ :Clipboard => "javafx.scene.input.Clipboard",
221
+ :ClipboardContent => "javafx.scene.input.ClipboardContent",
222
+ :ContextMenuEvent => "javafx.scene.input.ContextMenuEvent",
223
+ :DragEvent => "javafx.scene.input.DragEvent",
224
+ :GestureEvent => "javafx.scene.input.GestureEvent",
225
+ :InputEvent => "javafx.scene.input.InputEvent",
226
+ :InputMethodEvent => "javafx.scene.input.InputMethodEvent",
227
+ :KeyCode => "javafx.scene.input.KeyCode",
228
+ :KeyEvent => "javafx.scene.input.KeyEvent",
229
+ :Mnemonic => "javafx.scene.input.Mnemonic",
230
+ :MouseButton => "javafx.scene.input.MouseButton",
231
+ :MouseDragEvent => "javafx.scene.input.MouseDragEvent",
232
+ :MouseEvent => "javafx.scene.input.MouseEvent",
233
+ :RotateEvent => "javafx.scene.input.RotateEvent",
234
+ :ScrollEvent => "javafx.scene.input.ScrollEvent",
235
+ :SwipeEvent => "javafx.scene.input.SwipeEvent",
236
+ :TouchEvent => "javafx.scene.input.TouchEvent",
237
+ :TransferMode => "javafx.scene.input.TransferMode",
238
+ :ZoomEvent => "javafx.scene.input.ZoomEvent",
239
+ :AnchorPane => "javafx.scene.layout.AnchorPane",
240
+ :BorderPane => "javafx.scene.layout.BorderPane",
241
+ :ColumnConstraints => "javafx.scene.layout.ColumnConstraints",
242
+ :FlowPane => "javafx.scene.layout.FlowPane",
243
+ :GridPane => "javafx.scene.layout.GridPane",
244
+ :HBox => "javafx.scene.layout.HBox",
245
+ :Pane => "javafx.scene.layout.Pane",
246
+ :Priority => "javafx.scene.layout.Priority",
247
+ :RowConstraints => "javafx.scene.layout.RowConstraints",
248
+ :StackPane => "javafx.scene.layout.StackPane",
249
+ :TilePane => "javafx.scene.layout.TilePane",
250
+ :VBox => "javafx.scene.layout.VBox",
251
+ :AudioClip => "javafx.scene.media.AudioClip",
252
+ :AudioEqualizer => "javafx.scene.media.AudioEqualizer",
253
+ :AudioTrack => "javafx.scene.media.AudioTrack",
254
+ :EqualizerBand => "javafx.scene.media.EqualizerBand",
255
+ :Media => "javafx.scene.media.Media",
256
+ :MediaException => "javafx.scene.media.MediaException",
257
+ :MediaErrorEvent => "javafx.scene.media.MediaErrorEvent",
258
+ :MediaMarkerEvent => "javafx.scene.media.MediaMarkerEvent",
259
+ :MediaPlayer => "javafx.scene.media.MediaPlayer",
260
+ :MediaView => "javafx.scene.media.MediaView",
261
+ :VideoTrack => "javafx.scene.media.VideoTrack",
262
+ :Color => "javafx.scene.paint.Color",
263
+ :CycleMethod => "javafx.scene.paint.CycleMethod",
264
+ :ImagePattern => "javafx.scene.paint.ImagePattern",
265
+ :LinearGradient => "javafx.scene.paint.LinearGradient",
266
+ :Paint => "javafx.scene.paint.Paint",
267
+ :RadialGradient => "javafx.scene.paint.RadialGradient",
268
+ :Stop => "javafx.scene.paint.Stop",
269
+ :Arc => "javafx.scene.shape.Arc",
270
+ :ArcTo => "javafx.scene.shape.ArcTo",
271
+ :ArcType => "javafx.scene.shape.ArcType",
272
+ :Circle => "javafx.scene.shape.Circle",
273
+ :ClosePath => "javafx.scene.shape.ClosePath",
274
+ :CubicCurve => "javafx.scene.shape.CubicCurve",
275
+ :CubicCurveTo => "javafx.scene.shape.CubicCurveTo",
276
+ :Ellipse => "javafx.scene.shape.Ellipse",
277
+ :FillRule => "javafx.scene.shape.FillRule",
278
+ :HLineTo => "javafx.scene.shape.HLineTo",
279
+ :Line => "javafx.scene.shape.Line",
280
+ :LineTo => "javafx.scene.shape.LineTo",
281
+ :MoveTo => "javafx.scene.shape.MoveTo",
282
+ :Path => "javafx.scene.shape.Path",
283
+ :PathElement => "javafx.scene.shape.PathElement",
284
+ :Polygon => "javafx.scene.shape.Polygon",
285
+ :Polyline => "javafx.scene.shape.Polyline",
286
+ :QuadCurve => "javafx.scene.shape.QuadCurve",
287
+ :QuadCurveTo => "javafx.scene.shape.QuadCurveTo",
288
+ :Rectangle => "javafx.scene.shape.Rectangle",
289
+ :Shape => "javafx.scene.shape.Shape",
290
+ :StrokeLineCap => "javafx.scene.shape.StrokeLineCap",
291
+ :StrokeLineJoin => "javafx.scene.shape.StrokeLineJoin",
292
+ :StrokeType => "javafx.scene.shape.StrokeType",
293
+ :SVGPath => "javafx.scene.shape.SVGPath",
294
+ :VLineTo => "javafx.scene.shape.VLineTo",
295
+ :Font => "javafx.scene.text.Font",
296
+ :FontPosture => "javafx.scene.text.FontPosture",
297
+ :FontSmoothingType => "javafx.scene.text.FontSmoothingType",
298
+ :FontWeight => "javafx.scene.text.FontWeight",
299
+ :Text => "javafx.scene.text.Text",
300
+ :TextAlignment => "javafx.scene.text.TextAlignment",
301
+ :TextBoundsType => "javafx.scene.text.TextBoundsType",
302
+ :Affine => "javafx.scene.transform.Affine",
303
+ :Rotate => "javafx.scene.transform.Rotate",
304
+ :Scale => "javafx.scene.transform.Scale",
305
+ :Shear => "javafx.scene.transform.Shear",
306
+ :Translate => "javafx.scene.transform.Translate",
307
+ :WebView => "javafx.scene.web.WebView",
308
+ :HTMLEditor => "javafx.scene.web.HTMLEditor",
309
+ :DirectoryChooser => "javafx.stage.DirectoryChooser",
310
+ :FileChooser => "javafx.stage.FileChooser",
311
+ :Modality => "javafx.stage.Modality",
312
+ :Popup => "javafx.stage.Popup",
313
+ :PopupWindow => "javafx.stage.PopupWindow",
314
+ :Screen => "javafx.stage.Screen",
315
+ :Stage => "javafx.stage.Stage",
316
+ :StageStyle => "javafx.stage.StageStyle",
317
+ :Window => "javafx.stage.Window",
318
+ :WindowEvent => "javafx.stage.WindowEvent",
319
+ :Duration => "javafx.util.Duration"
320
+ }
321
+ java_import 'java.lang.Void'
322
+ end
323
+ end
324
+
@@ -0,0 +1,144 @@
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
+ #:nodoc: all
18
+
19
+ # Due to certain bugs in JRuby 1.7 (namely some newInstance mapping bugs), we
20
+ # are forced to re-create the Launcher if we want a pure ruby wrapper
21
+ # I can't wait to delete this. The _ONLY_ code that should use this is
22
+ # JRubyFX::Application.launch. Do _NOT_ use this code anywhere else.
23
+ module JavaFXImpl #:nodoc: all
24
+ java_import 'com.sun.javafx.application.PlatformImpl'
25
+ java_import 'javafx.stage.Stage'
26
+
27
+ #JRuby, you make me have to create real classes!
28
+ class FinisherInterface
29
+ include PlatformImpl::FinishListener
30
+
31
+ def initialize(&block)
32
+ @exitBlock = block
33
+ end
34
+
35
+ def idle(someBoolean)
36
+ @exitBlock.call
37
+ end
38
+
39
+ def exitCalled()
40
+ @exitBlock.call
41
+ end
42
+ end
43
+
44
+ class Launcher
45
+ java_import 'java.util.concurrent.atomic.AtomicBoolean'
46
+ java_import 'java.util.concurrent.CountDownLatch'
47
+ java_import 'java.lang.IllegalStateException'
48
+ java_import 'com.sun.javafx.application.ParametersImpl'
49
+
50
+ @@launchCalled = AtomicBoolean.new(false) # Atomic boolean go boom on bikini
51
+
52
+ def self.launch_app(application_class, *args)
53
+ #prevent multiple!
54
+ if @@launchCalled.getAndSet(true)
55
+ throw IllegalStateException.new "Application launch must not be called more than once"
56
+ end
57
+
58
+ begin
59
+ #create a java thread, and run the real worker, and wait till it exits
60
+ count_down_latch = CountDownLatch.new(1)
61
+ thread = Java.java.lang.Thread.new do
62
+ begin
63
+ launch_app_from_thread(application_class, args)
64
+ rescue => ex
65
+ puts "Exception starting app:"
66
+ p ex
67
+ p ex.backtrace
68
+ end
69
+ count_down_latch.countDown #always count down
70
+ end
71
+ thread.name = "JavaFX-Launcher"
72
+ thread.start
73
+ count_down_latch.await
74
+ rescue => ex
75
+ puts "Exception launching JavaFX-Launcher thread:"
76
+ p ex
77
+ puts ex.backtrace
78
+ end
79
+ end
80
+
81
+ def self.launch_app_from_thread(application_class, args)
82
+ begin
83
+ launch_app_after_platform(application_class, args)
84
+ rescue => ex
85
+ puts "Error running Application:"
86
+ p ex
87
+ puts ex.backtrace
88
+ end
89
+
90
+ PlatformImpl.tkExit # kill the toolkit and exit
91
+ end
92
+
93
+ def self.launch_app_after_platform(application_class, args)
94
+ #listeners - for the end
95
+ finished_latch = CountDownLatch.new(1)
96
+
97
+ # register for shutdown
98
+ PlatformImpl.addListener(FinisherInterface.new {
99
+ # this is called when the stage exits
100
+ finished_latch.countDown
101
+ })
102
+
103
+ application = application_class.new
104
+
105
+ unless application.is_a? Java::javafx.application.Application
106
+ raise "Invalid type: cannot launch non-Application"
107
+ end
108
+
109
+ ParametersImpl.registerParameters(application, ParametersImpl.new(args))
110
+
111
+ application.init
112
+
113
+ error = false
114
+ #RUN! and hope it works!
115
+ PlatformImpl.runAndWait do
116
+ begin
117
+ stage = Stage.new
118
+ if stage.respond_to? :impl_setPrimary
119
+ stage.impl_setPrimary(true)
120
+ else
121
+ # java 9 is awful
122
+ sp = Stage.java_class.to_java.getDeclaredMethod("setPrimary", Java::boolean)
123
+ sp.accessible = true
124
+ sp.invoke(stage, true)
125
+ end
126
+ application.start(stage)
127
+ # no countDown here because its up top... yes I know
128
+ rescue => ex
129
+ puts "Exception running Application:"
130
+ p ex
131
+ puts ex.backtrace
132
+ error = true
133
+ finished_latch.countDown # but if we fail, we need to unlatch it
134
+ end
135
+ end
136
+
137
+ #wait for stage exit
138
+ finished_latch.await
139
+
140
+ # call stop on the interface
141
+ application.stop unless error
142
+ end
143
+ end
144
+ end