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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 612242e98c185c05c764773b0a8fb956ad7a5567
4
+ data.tar.gz: c0d4f6d4070b8947835d6c76471c97fa4c07c32a
5
+ SHA512:
6
+ metadata.gz: f81a076b5b6ce292e8a0bf6d3bdaf473e2279f8ffb4f10c449dd2f42ec04896078ef2bf3c8ef80cd65ae13812ac3f9627be2d32bd2ed9719bbf371cbcf6e2c07
7
+ data.tar.gz: 54567ba7d42a0381a9fc3b552d72d503bc787e899b04e24159a1cdb095075c3f14ef91a9212ab9cc81f076ab3b2a7b4fe1c84058adad273114611108a42fdbcf
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,121 @@
1
+ JRubyFX
2
+ =======
3
+ JRubyFX is a pure ruby wrapper for JavaFX 2.2+ with FXML support
4
+
5
+ Status
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.
9
+
10
+ Install
11
+ -----
12
+ ```text
13
+ gem install jrubyfx
14
+ ```
15
+
16
+ Manual Build and Install
17
+ -----
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.
19
+
20
+ ```text
21
+ gem install jrubyfx-fxmlloader
22
+ rake install
23
+ ```
24
+ Once the gem is installed, just run a ruby file that uses it normally.
25
+
26
+ **NOTE:** If you don't have JRuby installed as the `ruby` command, use `jruby -S rake` instead of `rake`. If
27
+ you are using RVM, this does not apply to you (though make sure you `rvm use jruby`).
28
+
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
30
+
31
+ Creating a Jar
32
+ --------------
33
+ If you want to distribute your application, you can create a jar with embedded JRuby.
34
+ Place all your sources in a folder, and run (replacing paths as appropriate):
35
+
36
+ ```text
37
+ jrubyfx-jarify samples/fxml/ --main samples/fxml/Demo.rb Demo.jar
38
+ ```
39
+ This jar can then run anywhere there is a JVM with JavaFX. Note than the main file is
40
+ renamed to jar-bootstrap.rb inside the jar. If you need to detect if you are in a jar,
41
+ use the JRubyFX::Application.in_jar? method.
42
+
43
+ You can create native application packages and installers. For now, this requires that you have [JDK8 installed](http://jdk8.java.net/download.html), although this may change in the near future. Just pass the `--native` option. The packaging toolkit can only create packages for the OS it is being used on, so for Windows installers you will need to run it on a Windows machine, for OSX installers you will need to run it on a Mac, etc.
44
+
45
+ In order for the installer to be created, you will need some additional tools installed on your system. For Windows you need either Inno Setup 5 or later for an EXE or [Windows Installer XML (WiX) toolset](http://wix.sourceforge.net/) to generate an MSI. Make sure the WiX toolset's `bin` folder is on the `PATH`. No special tools are need to generate a DMG, just a recent version of OSX. For linux, the packager uses dpkg-deb to create DEB installers and rpmbuild for RPM.
46
+
47
+ If you don't want your application to be called "JarBootstrapMain", I highly suggest passing the `--name` option with an appropriate string.
48
+
49
+ To customize the package, for example to change the icons or license pass the `-v` or `--verbose` option. This will cause the JavaFX packaging tools to enter verbose mode, and provide more details about the process, including (the important part for customization) the location of a temporary folder where the config resources for the build are held and a list of the resources and the role of each. Copy the contents of this tmp folder into a folder in your project directory (the dir you run jrubyfx-jarify from) where the packaging tools will know to look for them. For example, on linux this would be `main_project_dir/package/linux`. On OSX, it is `main_project_dir/package/macosx`. So, if I wanted to use a custom icon, I'd replace the default icon with my own, ensuring it has the same name, and place it inside that linux or macosx folder. Then run the build again. You can find more information on customizing at the [official Oracle documentation](http://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm#BCGICFDB). [This blog post](http://ed4becky.net/homepage/javafx-from-the-trenches-part-1-native-packaging/4/) may also be helpful, as he goes through the process of customizing an app for both Windows and OSX.
50
+
51
+ The JavaFX tools provide far more options than are available from this tool. You can create your own rake tasks and access them directly, however. See [this article](https://github.com/jruby/jruby/wiki/Packaging-Native-Installers-with-the-JavaFX-Ant-Tasks) in the JRuby wiki.
52
+
53
+ Example: If my project directory is `Hello`, all my files are in `src`, I have a `dist` folder created for my jar file, my main file is called `HelloWorldApp.rb`, my app's name is "Hello World App", and I want the customization info, the command line would look like this:
54
+
55
+ ```
56
+ jrubyfx-jarify src --main src/HelloWorldApp.rb dist/HelloWorldApp.jar --native --name "Hello World App" -v
57
+ ```
58
+
59
+ Also note that you can do this in code, see samples/fxml/Demo.rb for the rake task usage.
60
+
61
+ Samples
62
+ -------
63
+
64
+ To run sample:
65
+
66
+ ```text
67
+ jruby samples/fxml/Demo.rb
68
+ ```
69
+
70
+ Or, if you have not installed the gem, or are testing edits to jrubyfx.rb:
71
+
72
+ ```text
73
+ rake run main_script=samples/fxml/Demo.rb
74
+ ```
75
+
76
+ To run all samples (a nice quick way to make sure you didn't break anything), run:
77
+
78
+ ```text
79
+ jruby -I lib samples/test_all_the_samples.rb
80
+ ```
81
+
82
+ Several other files that can be used as examples are in the tests/ folder
83
+
84
+ Creating Application and Controller
85
+ -----------------------------------
86
+
87
+ Require the 'jrubyfx' file/gem, and subclass JRubyFX::Application (and JRubyFX::Controller if you are using FXML).
88
+ At the bottom of the file, call _yourFXApplicationClass_.launch().
89
+ Override start(stage) in the application. See samples/fxml/Demo.rb for commented FXML example,
90
+ or the fils in samples/javafx for non-FXML (programatic JavaFX, but you should really
91
+ look into FXML, its better) or see the [Getting Started Guide](https://github.com/jruby/jrubyfx/wiki/Getting-Started) and the Syntax Notes on the [JRubyFX github wiki](https://github.com/jruby/jrubyfx/wiki/)
92
+
93
+ If you want rdoc, run `rake rdoc`. Please note that there are lots of generated methods and conventions that are not in the RDoc. Please read the Getting Started Guide or the tutorials.
94
+
95
+ Issues
96
+ ------
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
+ * Errors loading JavaFX are bugs. Please report if you encounter this issue, tell us your platform, OS, and version of JRuby
101
+ * Jarify command needs the `jar` executable in your path.
102
+ * Any other difficulties are bugs. Please report them
103
+
104
+ Contact
105
+ -------
106
+ Find us in #jruby on freenode.
107
+
108
+ License
109
+ -------
110
+ Main code is Apache 2.0. See LICENSE.
111
+ Some samples in contrib may have other licenses.
112
+
113
+ Authors
114
+ -------
115
+ - Patrick Plenefisch (byteit101)
116
+ - Thomas E Enebo (enebo)
117
+ - Hiro Asari (BanzaiMan or asarih)
118
+ - Jeremy Ebler (whitehat101)
119
+ - Hiroshi Nakamura (nahi)
120
+ - Eric West (e_dub or edubkendo)
121
+
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env jruby
2
+ =begin
3
+ JRubyFX - Write JavaFX and FXML in Ruby
4
+ Copyright (C) 2013 The JRubyFX Team
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License");
7
+ you may not use this file except in compliance with the License.
8
+ You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
17
+ =end
18
+
19
+ def usage
20
+ puts "#{$0} fxml-file [fxml-file ...] [-- require [require ...]]"
21
+ puts <<THEOPTIONS
22
+
23
+ THEOPTIONS
24
+ exit -1
25
+ end
26
+
27
+ if ARGV.length < 1
28
+ usage
29
+ end
30
+
31
+ require 'jrubyfx_tasks'
32
+ JRubyFX::Tasks.compile(ARGV)
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env jruby
2
+ =begin
3
+ JRubyFX - Write JavaFX and FXML in Ruby
4
+ Copyright (C) 2013 The JRubyFX Team
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License");
7
+ you may not use this file except in compliance with the License.
8
+ You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
17
+ =end
18
+
19
+ require 'date'
20
+ require 'jrubyfx/utils'
21
+ require 'pathname'
22
+
23
+ if ARGV.length < 1
24
+ puts "Please specify the fxml file to parse"
25
+ puts "#{$0} some.fxml [output.rb [AppName]]"
26
+ exit -1
27
+ end
28
+
29
+ fxml = ARGV[0]
30
+ rb = File.basename(fxml.gsub(/\.fxml$/i, ".rb"))
31
+ rb = ARGV[1] if ARGV.length > 1
32
+ name_guess = "My" + File.basename(fxml).gsub(/\.fxml$/i, "").gsub(/[^a-zA-Z0-9_]/i, "") # better guess would be better
33
+ name_guess = ARGV[2] if ARGV.length > 2
34
+
35
+ print "Generating JRubyFX template for #{fxml} into #{rb}... "
36
+
37
+ File.open(rb, "w") do |output|
38
+
39
+ fx_diff_root = ("/" + Pathname.new(File.dirname fxml).relative_path_from(Pathname.new(File.dirname rb)).to_s).inspect
40
+ fx_diff_root = if fx_diff_root == '"/."'
41
+ ""
42
+ else
43
+ " + #{fx_diff_root}"
44
+ end
45
+ output << <<END
46
+ # This file was auto-generated by jrubyfx-generator at #{DateTime.now.to_s}
47
+
48
+ require 'jrubyfx'
49
+ fxml_root File.dirname(__FILE__)#{fx_diff_root}
50
+
51
+ class #{name_guess}Application < JRubyFX::Application
52
+ def start(stage)
53
+ with(stage, title: "#{name_guess}") do
54
+ fxml #{name_guess}Controller
55
+ show
56
+ end
57
+ end
58
+ end
59
+
60
+ class #{name_guess}Controller
61
+ include JRubyFX::Controller
62
+ fxml "#{File.basename(fxml)}"
63
+ END
64
+
65
+ fx_ids = []
66
+ File.open(fxml, "r") do |fx|
67
+ handlers = "\n"
68
+
69
+ fx.each_line do |line|
70
+ line.scan(/fx:id="([^ "':]+)"/) do |match|
71
+ fx_ids << match[0]
72
+ end
73
+ # TODO: may not work with funky non-latin characters
74
+ # Yes, I used regex, yes its xml, yes I now have two problems.
75
+ line.scan(/on((([A-Z]*[a-z]*)*?)[A-Z]+[a-z]+)="#([^ "':]+)"/) do |match|
76
+ handlers << " def #{match[3]}(event)\n"
77
+ handlers << " # TODO: Auto-generated event handler\n"
78
+ handlers << " puts \"#{match[0]} event '#{match[3]}' called\"\n end\n\n"
79
+ end
80
+ end
81
+ output << "\n # nodes with ruby method-like fx:ids may be accessed directly"
82
+ output << "\n def initialize\n#{fx_ids.map{|x|" puts \"fx:id=\\\"#{x}\\\" was not injected: check your FXML file '#{File.basename(fxml)}'.\" unless @#{x}"}.join "\n"}\n end\n"
83
+ output << handlers
84
+ end
85
+
86
+ output << <<END
87
+ end
88
+
89
+ #{name_guess}Application.launch
90
+ END
91
+
92
+ end
93
+
94
+ puts "Done!"
95
+
96
+ puts "Launching 'jruby #{rb}' ..."
97
+
98
+ require rb
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env jruby
2
+ =begin
3
+ JRubyFX - Write JavaFX and FXML in Ruby
4
+ Copyright (C) 2013 The JRubyFX Team
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License");
7
+ you may not use this file except in compliance with the License.
8
+ You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
17
+ =end
18
+
19
+ require 'jrubyfx_tasks'
20
+
21
+ def usage
22
+ puts "#{$0} {options} project-folder [output.jar]"
23
+ puts <<THEOPTIONS
24
+ project-folder should contain rb files and supporting files
25
+
26
+ -m|--main FILE ruby script to launch when the jar is executed.
27
+ Defaults to jar-bootstrap.rb or main.rb
28
+ -j|--include-jars Include jars in the jar. (off by default to prevent including
29
+ the jar you are building)
30
+ --native Create native application packages and installers. (Requires JDK8)
31
+ -v|--verbose Turns on the native packagers verbose mode. Useful for
32
+ customizing icons, licenses, etc.
33
+ --name STRING Name for your native package.
34
+ THEOPTIONS
35
+ exit -1
36
+ end
37
+
38
+ if ARGV.length < 1
39
+ usage
40
+ end
41
+
42
+ main = ["jar-bootstrap.rb", "main.rb"]
43
+ include_jars = false
44
+ native_bundle = false
45
+ app_name = ""
46
+ verbose = false
47
+ nargs = []
48
+ default_on_next = on_next = ->(arg){true}
49
+
50
+ # split the args manually
51
+ ARGV.each do |arg|
52
+ # some args have multiple parts. this is a cheap way to do that (lambdas)
53
+ next unless on_next.call(arg)
54
+ case arg
55
+ when "-m", "--main"
56
+ on_next = ->(arg){
57
+ main = [arg]
58
+ on_next = default_on_next
59
+ false
60
+ }
61
+ next
62
+ when "-j", "--include-jars"
63
+ include_jars = true
64
+ next
65
+ when "--native"
66
+ native_bundle = true
67
+ next
68
+ when "--name"
69
+ on_next = ->(arg){
70
+ app_name = [arg]
71
+ on_next = default_on_next
72
+ false
73
+ }
74
+ next
75
+ when "-v", "--verbose"
76
+ verbose = true
77
+ when "-h", "--help"
78
+ usage
79
+ exit 0
80
+ when /^-/
81
+ puts "ERROR! Unrecognized option '#{arg}'!"
82
+ exit -2
83
+ end
84
+ # no flag? must be positional arg
85
+ nargs << arg
86
+ end
87
+ # set jar default if none passed in
88
+ if nargs.length <= 1
89
+ nargs << File.basename(nargs[0]) + ".jar"
90
+ end
91
+ # set positional args
92
+ project_folder, output_jar = nargs
93
+
94
+ # Download the current running JRuby version
95
+ JRubyFX::Tasks::download_jruby(JRUBY_VERSION)
96
+
97
+ # set the main script to the first (must be passed in), or tries to find
98
+ # a file that does exists. Silently fails if it fails.
99
+ main_script = main[0]
100
+ if main.length > 1
101
+ main.each do |scrpt|
102
+ ps = project_folder + "/" + scrpt
103
+ if File.exists? ps
104
+ main_script = ps
105
+ break
106
+ end
107
+ end
108
+ end
109
+
110
+ # Jarify!
111
+ JRubyFX::Tasks::jarify_jrubyfx(project_folder + "/*", main_script, nil, output_jar, :file_filter => ->(filename){!filename.end_with?(".jar") or include_jars})
112
+
113
+ if native_bundle
114
+ JRubyFX::Tasks::native_bundles(Dir.pwd, output_jar, verbose, app_name[0])
115
+ end
@@ -0,0 +1,42 @@
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
+ ##
19
+ # Inherit from this class for FXML Applications. You must use this class for both
20
+ # raw JavaFX and FXML as it contains the launch method.
21
+ class JRubyFX::Application < Java.javafx.application.Application
22
+ include JRubyFX
23
+ include JRubyFX::DSL
24
+
25
+ ##
26
+ # Are we packaged in a jar? This does some comparison, and may get false positives
27
+ # and, if jruby changes, false negatives. If you are using this, it might be a
28
+ # very bad idea... (though it is handy)
29
+ def self.in_jar?()
30
+ $LOAD_PATH.inject(false) { |res,i| res || i.include?(".jar!/META-INF/jruby.home/lib/ruby/")}
31
+ end
32
+
33
+ ##
34
+ # call-seq:
35
+ # launch()
36
+ #
37
+ # When called on a subclass, this is effectively our main method.
38
+ def self.launch(*args)
39
+ #call our custom launcher to avoid a java shim
40
+ JavaFXImpl::Launcher.launch_app(self, *args)
41
+ end
42
+ end
@@ -0,0 +1,51 @@
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'
18
+
19
+ # This class is used by the rake task to compile fxml files
20
+ class CompilerApp < JRubyFX::Application
21
+ def start(stage)
22
+ begin
23
+ args = parameters.raw.to_a
24
+ if args.include? "--"
25
+ ar, requires = split(args, "--")
26
+ requires.each {|x| require x}
27
+ ar
28
+ else
29
+ args
30
+ end.each do |arg|
31
+ loader = FxmlLoader.new
32
+ loader.location = URL.new "file:#{arg}"
33
+ loader.controller = Object.new
34
+ puts "Compiling #{arg}..."
35
+ loader.load(jruby_ext: {jit: 0, dont_load: true, jit_opts: {force: true}})
36
+ end
37
+ puts "done"
38
+ rescue java.lang.Throwable, Exception => e
39
+ $JRUBYFX_AOT_ERROR = e
40
+ ensure
41
+ Platform.exit
42
+ end
43
+ end
44
+
45
+ def split(arr, delim)
46
+ index = arr.index(delim)
47
+ first = arr[0...index]
48
+ second = arr[(index+1)..-1]
49
+ return first, second
50
+ end
51
+ end