jrubyfx-master 1.1.1.brakemanpro1-java

Sign up to get free protection for your applications and to get access to all the features.
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/application.rb +42 -0
  8. data/lib/jrubyfx/compiler_app.rb +51 -0
  9. data/lib/jrubyfx/controller.rb +375 -0
  10. data/lib/jrubyfx/core_ext/border_pane.rb +30 -0
  11. data/lib/jrubyfx/core_ext/column_constraints.rb +43 -0
  12. data/lib/jrubyfx/core_ext/drag_event.rb +32 -0
  13. data/lib/jrubyfx/core_ext/duration.rb +30 -0
  14. data/lib/jrubyfx/core_ext/effects.rb +32 -0
  15. data/lib/jrubyfx/core_ext/exts.yml +57 -0
  16. data/lib/jrubyfx/core_ext/file_chooser.rb +63 -0
  17. data/lib/jrubyfx/core_ext/geometry.rb +27 -0
  18. data/lib/jrubyfx/core_ext/grid_pane.rb +30 -0
  19. data/lib/jrubyfx/core_ext/image_view.rb +25 -0
  20. data/lib/jrubyfx/core_ext/media_player.rb +25 -0
  21. data/lib/jrubyfx/core_ext/observable_value.rb +158 -0
  22. data/lib/jrubyfx/core_ext/pagination.rb +28 -0
  23. data/lib/jrubyfx/core_ext/path.rb +37 -0
  24. data/lib/jrubyfx/core_ext/precompiled.rb +1883 -0
  25. data/lib/jrubyfx/core_ext/progress_indicator.rb +41 -0
  26. data/lib/jrubyfx/core_ext/radial_gradient.rb +37 -0
  27. data/lib/jrubyfx/core_ext/region.rb +42 -0
  28. data/lib/jrubyfx/core_ext/rotate.rb +39 -0
  29. data/lib/jrubyfx/core_ext/stage.rb +89 -0
  30. data/lib/jrubyfx/core_ext/table_view.rb +31 -0
  31. data/lib/jrubyfx/core_ext/timeline.rb +56 -0
  32. data/lib/jrubyfx/core_ext/transition.rb +26 -0
  33. data/lib/jrubyfx/core_ext/tree_view.rb +40 -0
  34. data/lib/jrubyfx/core_ext/xy_chart.rb +53 -0
  35. data/lib/jrubyfx/dsl.rb +330 -0
  36. data/lib/jrubyfx/dsl_control.rb +28 -0
  37. data/lib/jrubyfx/dsl_map.rb +273 -0
  38. data/lib/jrubyfx/imports.rb +310 -0
  39. data/lib/jrubyfx/java_fx_impl.rb +137 -0
  40. data/lib/jrubyfx/module.rb +178 -0
  41. data/lib/jrubyfx/part_imports.rb +127 -0
  42. data/lib/jrubyfx/utils/__ignore_java_stupid_rdoc.rb +30 -0
  43. data/lib/jrubyfx/utils/common_converters.rb +223 -0
  44. data/lib/jrubyfx/utils/common_utils.rb +72 -0
  45. data/lib/jrubyfx/utils/string_utils.rb +48 -0
  46. data/lib/jrubyfx/utils.rb +76 -0
  47. data/lib/jrubyfx/version.rb +4 -0
  48. data/lib/jrubyfx.rb +41 -0
  49. data/lib/jrubyfx_tasks.rb +183 -0
  50. metadata +145 -0
@@ -0,0 +1,310 @@
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 at some point requires explicit toolkit/platform initialization
36
+ # before any controls can be loaded.
37
+ JRubyFX.load_fx
38
+
39
+ # Attempt to load a javafx class
40
+ Java.javafx.application.Application
41
+ rescue LoadError, NameError
42
+ puts "JavaFX runtime not found. Please install Java 7u6 or newer or set environment variable JFX_DIR to the folder that contains jfxrt.jar "
43
+ 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)"
44
+ exit -1
45
+ end
46
+
47
+ module JRubyFX
48
+ # If you need JavaFX, just include this module. Its sole purpose in life is to
49
+ # import all JavaFX stuff, plus a few useful Java classes (like Void)
50
+ module FXImports
51
+
52
+ # If something is missing, just java_import it in your code.
53
+ # And then ask us to put it in this list
54
+ #
55
+
56
+ # The below lines are generated by `rake reflect`. Do not edit.
57
+
58
+ def const_missing(c)
59
+ if LOCAL_NAME_MAP.has_key? c
60
+ java_import(LOCAL_NAME_MAP[c])[0]
61
+ else
62
+ super
63
+ end
64
+ end
65
+
66
+ LOCAL_NAME_MAP = {
67
+ :Animation => "javafx.animation.Animation",
68
+ :AnimationTimer => "javafx.animation.AnimationTimer",
69
+ :FadeTransition => "javafx.animation.FadeTransition",
70
+ :FillTransition => "javafx.animation.FillTransition",
71
+ :Interpolator => "javafx.animation.Interpolator",
72
+ :KeyFrame => "javafx.animation.KeyFrame",
73
+ :KeyValue => "javafx.animation.KeyValue",
74
+ :ParallelTransition => "javafx.animation.ParallelTransition",
75
+ :PathTransition => "javafx.animation.PathTransition",
76
+ :PauseTransition => "javafx.animation.PauseTransition",
77
+ :RotateTransition => "javafx.animation.RotateTransition",
78
+ :ScaleTransition => "javafx.animation.ScaleTransition",
79
+ :SequentialTransition => "javafx.animation.SequentialTransition",
80
+ :StrokeTransition => "javafx.animation.StrokeTransition",
81
+ :Timeline => "javafx.animation.Timeline",
82
+ :Transition => "javafx.animation.Transition",
83
+ :TranslateTransition => "javafx.animation.TranslateTransition",
84
+ :Platform => "javafx.application.Platform",
85
+ :SimpleBooleanProperty => "javafx.beans.property.SimpleBooleanProperty",
86
+ :SimpleDoubleProperty => "javafx.beans.property.SimpleDoubleProperty",
87
+ :SimpleFloatProperty => "javafx.beans.property.SimpleFloatProperty",
88
+ :SimpleIntegerProperty => "javafx.beans.property.SimpleIntegerProperty",
89
+ :SimpleListProperty => "javafx.beans.property.SimpleListProperty",
90
+ :SimpleLongProperty => "javafx.beans.property.SimpleLongProperty",
91
+ :SimpleMapProperty => "javafx.beans.property.SimpleMapProperty",
92
+ :SimpleObjectProperty => "javafx.beans.property.SimpleObjectProperty",
93
+ :SimpleSetProperty => "javafx.beans.property.SimpleSetProperty",
94
+ :SimpleStringProperty => "javafx.beans.property.SimpleStringProperty",
95
+ :ChangeListener => "javafx.beans.value.ChangeListener",
96
+ :FXCollections => "javafx.collections.FXCollections",
97
+ :Worker => "javafx.concurrent.Worker",
98
+ :Task => "javafx.concurrent.Task",
99
+ :Service => "javafx.concurrent.Service",
100
+ :Event => "javafx.event.Event",
101
+ :ActionEvent => "javafx.event.ActionEvent",
102
+ :EventHandler => "javafx.event.EventHandler",
103
+ :Initializable => "javafx.fxml.Initializable",
104
+ :LoadException => "javafx.fxml.LoadException",
105
+ :HorizontalDirection => "javafx.geometry.HorizontalDirection",
106
+ :HPos => "javafx.geometry.HPos",
107
+ :Insets => "javafx.geometry.Insets",
108
+ :Orientation => "javafx.geometry.Orientation",
109
+ :Pos => "javafx.geometry.Pos",
110
+ :Rectangle2D => "javafx.geometry.Rectangle2D",
111
+ :Side => "javafx.geometry.Side",
112
+ :VerticalDirection => "javafx.geometry.VerticalDirection",
113
+ :VPos => "javafx.geometry.VPos",
114
+ :Group => "javafx.scene.Group",
115
+ :Node => "javafx.scene.Node",
116
+ :Parent => "javafx.scene.Parent",
117
+ :Scene => "javafx.scene.Scene",
118
+ :Canvas => "javafx.scene.canvas.Canvas",
119
+ :AreaChart => "javafx.scene.chart.AreaChart",
120
+ :Axis => "javafx.scene.chart.Axis",
121
+ :BarChart => "javafx.scene.chart.BarChart",
122
+ :BubbleChart => "javafx.scene.chart.BubbleChart",
123
+ :CategoryAxis => "javafx.scene.chart.CategoryAxis",
124
+ :Chart => "javafx.scene.chart.Chart",
125
+ :LineChart => "javafx.scene.chart.LineChart",
126
+ :NumberAxis => "javafx.scene.chart.NumberAxis",
127
+ :PieChart => "javafx.scene.chart.PieChart",
128
+ :ScatterChart => "javafx.scene.chart.ScatterChart",
129
+ :StackedAreaChart => "javafx.scene.chart.StackedAreaChart",
130
+ :StackedBarChart => "javafx.scene.chart.StackedBarChart",
131
+ :ValueAxis => "javafx.scene.chart.ValueAxis",
132
+ :XYChart => "javafx.scene.chart.XYChart",
133
+ :Accordion => "javafx.scene.control.Accordion",
134
+ :Button => "javafx.scene.control.Button",
135
+ :Cell => "javafx.scene.control.Cell",
136
+ :CheckBox => "javafx.scene.control.CheckBox",
137
+ :CheckBoxTreeItem => "javafx.scene.control.CheckBoxTreeItem",
138
+ :CheckMenuItem => "javafx.scene.control.CheckMenuItem",
139
+ :ChoiceBox => "javafx.scene.control.ChoiceBox",
140
+ :ColorPicker => "javafx.scene.control.ColorPicker",
141
+ :ComboBox => "javafx.scene.control.ComboBox",
142
+ :ContextMenu => "javafx.scene.control.ContextMenu",
143
+ :Hyperlink => "javafx.scene.control.Hyperlink",
144
+ :Label => "javafx.scene.control.Label",
145
+ :ListCell => "javafx.scene.control.ListCell",
146
+ :ListView => "javafx.scene.control.ListView",
147
+ :Menu => "javafx.scene.control.Menu",
148
+ :MenuBar => "javafx.scene.control.MenuBar",
149
+ :MenuButton => "javafx.scene.control.MenuButton",
150
+ :MenuItem => "javafx.scene.control.MenuItem",
151
+ :Pagination => "javafx.scene.control.Pagination",
152
+ :PasswordField => "javafx.scene.control.PasswordField",
153
+ :PopupControl => "javafx.scene.control.PopupControl",
154
+ :ProgressBar => "javafx.scene.control.ProgressBar",
155
+ :ProgressIndicator => "javafx.scene.control.ProgressIndicator",
156
+ :RadioButton => "javafx.scene.control.RadioButton",
157
+ :RadioMenuItem => "javafx.scene.control.RadioMenuItem",
158
+ :ScrollBar => "javafx.scene.control.ScrollBar",
159
+ :ScrollPane => "javafx.scene.control.ScrollPane",
160
+ :Separator => "javafx.scene.control.Separator",
161
+ :SeparatorMenuItem => "javafx.scene.control.SeparatorMenuItem",
162
+ :Slider => "javafx.scene.control.Slider",
163
+ :SplitMenuButton => "javafx.scene.control.SplitMenuButton",
164
+ :SplitPane => "javafx.scene.control.SplitPane",
165
+ :Tab => "javafx.scene.control.Tab",
166
+ :TableView => "javafx.scene.control.TableView",
167
+ :TableCell => "javafx.scene.control.TableCell",
168
+ :TableColumn => "javafx.scene.control.TableColumn",
169
+ :TabPane => "javafx.scene.control.TabPane",
170
+ :TextArea => "javafx.scene.control.TextArea",
171
+ :TextField => "javafx.scene.control.TextField",
172
+ :TitledPane => "javafx.scene.control.TitledPane",
173
+ :ToggleButton => "javafx.scene.control.ToggleButton",
174
+ :ToggleGroup => "javafx.scene.control.ToggleGroup",
175
+ :ToolBar => "javafx.scene.control.ToolBar",
176
+ :Tooltip => "javafx.scene.control.Tooltip",
177
+ :TreeCell => "javafx.scene.control.TreeCell",
178
+ :TreeItem => "javafx.scene.control.TreeItem",
179
+ :TreeView => "javafx.scene.control.TreeView",
180
+ :ContentDisplay => "javafx.scene.control.ContentDisplay",
181
+ :OverrunStyle => "javafx.scene.control.OverrunStyle",
182
+ :SelectionMode => "javafx.scene.control.SelectionMode",
183
+ :Blend => "javafx.scene.effect.Blend",
184
+ :BlendMode => "javafx.scene.effect.BlendMode",
185
+ :Bloom => "javafx.scene.effect.Bloom",
186
+ :BlurType => "javafx.scene.effect.BlurType",
187
+ :BoxBlur => "javafx.scene.effect.BoxBlur",
188
+ :ColorAdjust => "javafx.scene.effect.ColorAdjust",
189
+ :ColorInput => "javafx.scene.effect.ColorInput",
190
+ :DisplacementMap => "javafx.scene.effect.DisplacementMap",
191
+ :DropShadow => "javafx.scene.effect.DropShadow",
192
+ :GaussianBlur => "javafx.scene.effect.GaussianBlur",
193
+ :Glow => "javafx.scene.effect.Glow",
194
+ :ImageInput => "javafx.scene.effect.ImageInput",
195
+ :InnerShadow => "javafx.scene.effect.InnerShadow",
196
+ :Lighting => "javafx.scene.effect.Lighting",
197
+ :MotionBlur => "javafx.scene.effect.MotionBlur",
198
+ :PerspectiveTransform => "javafx.scene.effect.PerspectiveTransform",
199
+ :Reflection => "javafx.scene.effect.Reflection",
200
+ :SepiaTone => "javafx.scene.effect.SepiaTone",
201
+ :Shadow => "javafx.scene.effect.Shadow",
202
+ :Image => "javafx.scene.image.Image",
203
+ :ImageView => "javafx.scene.image.ImageView",
204
+ :PixelReader => "javafx.scene.image.PixelReader",
205
+ :PixelWriter => "javafx.scene.image.PixelWriter",
206
+ :Clipboard => "javafx.scene.input.Clipboard",
207
+ :ClipboardContent => "javafx.scene.input.ClipboardContent",
208
+ :ContextMenuEvent => "javafx.scene.input.ContextMenuEvent",
209
+ :DragEvent => "javafx.scene.input.DragEvent",
210
+ :GestureEvent => "javafx.scene.input.GestureEvent",
211
+ :InputEvent => "javafx.scene.input.InputEvent",
212
+ :InputMethodEvent => "javafx.scene.input.InputMethodEvent",
213
+ :KeyCode => "javafx.scene.input.KeyCode",
214
+ :KeyEvent => "javafx.scene.input.KeyEvent",
215
+ :Mnemonic => "javafx.scene.input.Mnemonic",
216
+ :MouseButton => "javafx.scene.input.MouseButton",
217
+ :MouseDragEvent => "javafx.scene.input.MouseDragEvent",
218
+ :MouseEvent => "javafx.scene.input.MouseEvent",
219
+ :RotateEvent => "javafx.scene.input.RotateEvent",
220
+ :ScrollEvent => "javafx.scene.input.ScrollEvent",
221
+ :SwipeEvent => "javafx.scene.input.SwipeEvent",
222
+ :TouchEvent => "javafx.scene.input.TouchEvent",
223
+ :TransferMode => "javafx.scene.input.TransferMode",
224
+ :ZoomEvent => "javafx.scene.input.ZoomEvent",
225
+ :AnchorPane => "javafx.scene.layout.AnchorPane",
226
+ :BorderPane => "javafx.scene.layout.BorderPane",
227
+ :ColumnConstraints => "javafx.scene.layout.ColumnConstraints",
228
+ :FlowPane => "javafx.scene.layout.FlowPane",
229
+ :GridPane => "javafx.scene.layout.GridPane",
230
+ :HBox => "javafx.scene.layout.HBox",
231
+ :Pane => "javafx.scene.layout.Pane",
232
+ :Priority => "javafx.scene.layout.Priority",
233
+ :RowConstraints => "javafx.scene.layout.RowConstraints",
234
+ :StackPane => "javafx.scene.layout.StackPane",
235
+ :TilePane => "javafx.scene.layout.TilePane",
236
+ :VBox => "javafx.scene.layout.VBox",
237
+ :AudioClip => "javafx.scene.media.AudioClip",
238
+ :AudioEqualizer => "javafx.scene.media.AudioEqualizer",
239
+ :AudioTrack => "javafx.scene.media.AudioTrack",
240
+ :EqualizerBand => "javafx.scene.media.EqualizerBand",
241
+ :Media => "javafx.scene.media.Media",
242
+ :MediaException => "javafx.scene.media.MediaException",
243
+ :MediaErrorEvent => "javafx.scene.media.MediaErrorEvent",
244
+ :MediaMarkerEvent => "javafx.scene.media.MediaMarkerEvent",
245
+ :MediaPlayer => "javafx.scene.media.MediaPlayer",
246
+ :MediaView => "javafx.scene.media.MediaView",
247
+ :VideoTrack => "javafx.scene.media.VideoTrack",
248
+ :Color => "javafx.scene.paint.Color",
249
+ :CycleMethod => "javafx.scene.paint.CycleMethod",
250
+ :ImagePattern => "javafx.scene.paint.ImagePattern",
251
+ :LinearGradient => "javafx.scene.paint.LinearGradient",
252
+ :Paint => "javafx.scene.paint.Paint",
253
+ :RadialGradient => "javafx.scene.paint.RadialGradient",
254
+ :Stop => "javafx.scene.paint.Stop",
255
+ :Arc => "javafx.scene.shape.Arc",
256
+ :ArcTo => "javafx.scene.shape.ArcTo",
257
+ :ArcType => "javafx.scene.shape.ArcType",
258
+ :Circle => "javafx.scene.shape.Circle",
259
+ :ClosePath => "javafx.scene.shape.ClosePath",
260
+ :CubicCurve => "javafx.scene.shape.CubicCurve",
261
+ :CubicCurveTo => "javafx.scene.shape.CubicCurveTo",
262
+ :Ellipse => "javafx.scene.shape.Ellipse",
263
+ :FillRule => "javafx.scene.shape.FillRule",
264
+ :HLineTo => "javafx.scene.shape.HLineTo",
265
+ :Line => "javafx.scene.shape.Line",
266
+ :LineTo => "javafx.scene.shape.LineTo",
267
+ :MoveTo => "javafx.scene.shape.MoveTo",
268
+ :Path => "javafx.scene.shape.Path",
269
+ :PathElement => "javafx.scene.shape.PathElement",
270
+ :Polygon => "javafx.scene.shape.Polygon",
271
+ :Polyline => "javafx.scene.shape.Polyline",
272
+ :QuadCurve => "javafx.scene.shape.QuadCurve",
273
+ :QuadCurveTo => "javafx.scene.shape.QuadCurveTo",
274
+ :Rectangle => "javafx.scene.shape.Rectangle",
275
+ :Shape => "javafx.scene.shape.Shape",
276
+ :StrokeLineCap => "javafx.scene.shape.StrokeLineCap",
277
+ :StrokeLineJoin => "javafx.scene.shape.StrokeLineJoin",
278
+ :StrokeType => "javafx.scene.shape.StrokeType",
279
+ :SVGPath => "javafx.scene.shape.SVGPath",
280
+ :VLineTo => "javafx.scene.shape.VLineTo",
281
+ :Font => "javafx.scene.text.Font",
282
+ :FontPosture => "javafx.scene.text.FontPosture",
283
+ :FontSmoothingType => "javafx.scene.text.FontSmoothingType",
284
+ :FontWeight => "javafx.scene.text.FontWeight",
285
+ :Text => "javafx.scene.text.Text",
286
+ :TextAlignment => "javafx.scene.text.TextAlignment",
287
+ :TextBoundsType => "javafx.scene.text.TextBoundsType",
288
+ :Affine => "javafx.scene.transform.Affine",
289
+ :Rotate => "javafx.scene.transform.Rotate",
290
+ :Scale => "javafx.scene.transform.Scale",
291
+ :Shear => "javafx.scene.transform.Shear",
292
+ :Translate => "javafx.scene.transform.Translate",
293
+ :WebView => "javafx.scene.web.WebView",
294
+ :HTMLEditor => "javafx.scene.web.HTMLEditor",
295
+ :DirectoryChooser => "javafx.stage.DirectoryChooser",
296
+ :FileChooser => "javafx.stage.FileChooser",
297
+ :Modality => "javafx.stage.Modality",
298
+ :Popup => "javafx.stage.Popup",
299
+ :PopupWindow => "javafx.stage.PopupWindow",
300
+ :Screen => "javafx.stage.Screen",
301
+ :Stage => "javafx.stage.Stage",
302
+ :StageStyle => "javafx.stage.StageStyle",
303
+ :Window => "javafx.stage.Window",
304
+ :WindowEvent => "javafx.stage.WindowEvent",
305
+ :Duration => "javafx.util.Duration"
306
+ }
307
+ java_import 'java.lang.Void'
308
+ end
309
+ end
310
+
@@ -0,0 +1,137 @@
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
+ stage.impl_setPrimary(true)
119
+ application.start(stage)
120
+ # no countDown here because its up top... yes I know
121
+ rescue => ex
122
+ puts "Exception running Application:"
123
+ p ex
124
+ puts ex.backtrace
125
+ error = true
126
+ finished_latch.countDown # but if we fail, we need to unlatch it
127
+ end
128
+ end
129
+
130
+ #wait for stage exit
131
+ finished_latch.await
132
+
133
+ # call stop on the interface
134
+ application.stop unless error
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,178 @@
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/common_utils'
19
+
20
+ # This module contains useful methods for defining JavaFX code. Include it in your
21
+ # class to use it, and the JRubyFX::FXImports. JRubyFX::Application and JRubyFX::Controller already include it.
22
+ module JRubyFX
23
+ include JRubyFX::FXImports
24
+ include JRubyFX::Utils::CommonUtils
25
+
26
+ ##
27
+ # call-seq:
28
+ # with(obj, hash) => obj
29
+ # with(obj) { block } => obj
30
+ # with(obj, hash) { block }=> obj
31
+ #
32
+ # Set properties (e.g. setters) on the passed in object plus also invoke
33
+ # any block passed against this object.
34
+ # === Examples
35
+ #
36
+ # with(grid, vgap: 2, hgap: 2) do
37
+ # set_pref_size(500, 400)
38
+ # children << location << go << view
39
+ # end
40
+ #
41
+ def with(obj, properties = {}, &block)
42
+ puts "Warning: calling 'with' on a nil object from #{caller[0]}" if obj.nil?
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
+ Java::javafx.application.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
+
98
+ def self.included(mod)
99
+ mod.extend(JRubyFX::FXMLClassUtils)
100
+ mod.extend(JRubyFX::FXImports)
101
+ end
102
+
103
+ module FXMLClassUtils
104
+ def fxml_raw_accessor(symbol_name, type=java::lang::String)
105
+ # TODO: RDoc
106
+ # TODO: somebody clean this up
107
+ # TODO: _reader and _writer
108
+ send(:define_method, symbol_name.id2name.snake_case + "=") do |val|
109
+ instance_variable_set("@#{symbol_name}", val)
110
+ end
111
+ send(:define_method, symbol_name.id2name.snake_case) do
112
+ instance_variable_get("@#{symbol_name}")
113
+ end
114
+ send(:define_method, symbol_name.id2name.snake_case + "GetType") do
115
+ return type.java_class
116
+ end
117
+ camel = symbol_name.id2name
118
+ camel = camel[0].upcase + camel[1..-1]
119
+ send(:define_method, "set" + camel) do |val|
120
+ instance_variable_set("@#{symbol_name}", val)
121
+ end
122
+ send(:define_method, "get" + camel) do
123
+ instance_variable_get("@#{symbol_name}")
124
+ end
125
+ send(:define_method, symbol_name.id2name + "GetType") do
126
+ return type.java_class
127
+ end
128
+ end
129
+ def fxml_accessor(symbol_name,ptype=Java::javafx.beans.property.SimpleStringProperty, type=nil)
130
+ # TODO: RDoc
131
+ # TODO: somebody clean this up
132
+ # TODO: _reader and _writer ? maybe? not?
133
+ pname = symbol_name.id2name + "Property"
134
+ raise "#{ptype} does not inherit from Property." unless ptype.ancestors.include? Java::javafx.beans.property.Property
135
+ unless type
136
+ type = ptype.java_class.java_instance_methods.find_all{|x|x.name == "getValue"}.map{|x|x.return_type}.find_all{|x|x != java.lang.Object.java_class}
137
+ if type.length != 1
138
+ raise "Unknown property type. Please manually supply a type or report this as a bug"
139
+ end
140
+ type = type[0]
141
+ else
142
+ type = type.java_class
143
+ end
144
+ send(:define_method, symbol_name.id2name.snake_case + "=") do |val|
145
+ send(pname).setValue val
146
+ end
147
+ send(:define_method, symbol_name.id2name.snake_case) do
148
+ send(pname).getValue
149
+ end
150
+ send(:define_method, symbol_name.id2name.snake_case + "GetType") do
151
+ return type
152
+ end
153
+ camel = symbol_name.id2name
154
+ camel = camel[0].upcase + camel[1..-1]
155
+ send(:define_method, "set" + camel) do |val|
156
+ send(pname).setValue val
157
+ end
158
+ send(:define_method, "get" + camel) do
159
+ send(pname).getValue
160
+ end
161
+ send(:define_method, symbol_name.id2name + "GetType") do
162
+ return type
163
+ end
164
+ send(:define_method, pname) do
165
+ unless instance_variable_get("@#{symbol_name}")
166
+ instance_variable_set("@#{symbol_name}", ptype.new(self, symbol_name.to_s))
167
+ end
168
+ return instance_variable_get("@#{symbol_name}")
169
+ end
170
+ send(:define_method, pname.snake_case) do
171
+ send(pname)
172
+ end
173
+ add_method_signature pname, [ptype]
174
+ add_method_signature "set" + camel, [java.lang.Void, type]
175
+ add_method_signature "get" + camel, [type]
176
+ end
177
+ end
178
+ end