├── .hgignore
├── .hgtags
├── .projectile
├── LICENSE
├── Makefile
├── README.md
├── deps.edn
├── docs
├── clojurefx.html
├── datamash-texinfo.css
├── makedocs-web.sh
├── makedocs.sh
└── manual.texinfo
├── logo.svg
├── project.clj
├── src
└── clojurefx
│ ├── ApplicationInitializer.java
│ ├── clojurefx.clj
│ ├── controllergen.clj
│ └── fxml.clj
├── test-resources
└── fxml
│ ├── exampleControllerWindow.fxml
│ └── exampleWindow.fxml
├── test
└── clojurefx
│ ├── fxml_test.clj
│ └── scenegraph_test.clj
└── tests.edn
/.hgignore:
--------------------------------------------------------------------------------
1 | syntax: glob
2 | init-script/
3 | target/
4 | *.orig
5 | *.html
6 | *.dot
7 | *.iml
8 | lib/
9 | classes/
10 | checkouts/
11 | /resources/public/js/frontend.js
12 | frontend.min.js
13 | tests.js
14 | .generated/
15 | repl/
16 | out/
17 | .pom.xml
18 | .pom.xml.asc
19 | .macrolog.txt
20 | *.jar
21 | *.class
22 | .DS_Store
23 | .lein-env
24 | .lein-deps-sum
25 | .lein-failures
26 | .lein-plugins
27 | .lein-repl-history
28 | .nrepl-history
29 | .nrepl-port
30 | *~
31 | .idea/
32 |
33 | syntax: glob
34 | *.xml
35 |
--------------------------------------------------------------------------------
/.hgtags:
--------------------------------------------------------------------------------
1 | 8b75d6c935de28a1cb7f52fe3ab4c7d8faa2d3d1 0.3.0
2 |
--------------------------------------------------------------------------------
/.projectile:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zilti/clojurefx/b4b11c138ae329b26f84593d584b30733b692258/.projectile
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Eclipse Public License - v 1.0
2 |
3 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
4 |
5 | 1. DEFINITIONS
6 |
7 | "Contribution" means:
8 |
9 | a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
10 | b) in the case of each subsequent Contributor:
11 |
12 | i) changes to the Program, and
13 |
14 | ii) additions to the Program;
15 |
16 | where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
17 |
18 | "Contributor" means any person or entity that distributes the Program.
19 |
20 | "Licensed Patents " mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
21 |
22 | "Program" means the Contributions distributed in accordance with this Agreement.
23 |
24 | "Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
25 |
26 | 2. GRANT OF RIGHTS
27 |
28 | a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
29 |
30 | b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
31 |
32 | c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
33 |
34 | d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
35 |
36 | 3. REQUIREMENTS
37 |
38 | A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
39 |
40 | a) it complies with the terms and conditions of this Agreement; and
41 |
42 | b) its license agreement:
43 |
44 | i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
45 |
46 | ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
47 |
48 | iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
49 |
50 | iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
51 |
52 | When the Program is made available in source code form:
53 |
54 | a) it must be made available under this Agreement; and
55 |
56 | b) a copy of this Agreement must be included with each copy of the Program.
57 |
58 | Contributors may not remove or alter any copyright notices contained within the Program.
59 |
60 | Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
61 |
62 | 4. COMMERCIAL DISTRIBUTION
63 |
64 | Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
65 |
66 | For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
67 |
68 | 5. NO WARRANTY
69 |
70 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
71 |
72 | 6. DISCLAIMER OF LIABILITY
73 |
74 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
75 |
76 | 7. GENERAL
77 |
78 | If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
79 |
80 | If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
81 |
82 | All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
83 |
84 | Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
85 |
86 | This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
87 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | classes:
2 | mkdir classes
3 |
4 | classes/clojurefx/ApplicationInitializer.class: src/clojurefx/ApplicationInitializer.java
5 | javac -classpath $$(clojure -Spath) -d classes src/clojurefx/ApplicationInitializer.java
6 |
7 | classes/%__init.class: $(wildcard src/%.*)
8 | mkdir -p $(@D)
9 | clojure -e "(compile '`echo "$*" | sed 's/\//\./g' | sed 's/_/-/g'`)"
10 |
11 | pom.xml: deps.edn
12 | clojure -Spom
13 |
14 | .PHONY: clean
15 | clean:
16 | rm -rf classes target pom.xml *.jar
17 |
18 | .PHONY: test
19 | test: classes/clojurefx/ApplicationInitializer.class
20 | clojure -A:test
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://opensource.org/licenses/EPL-1.0)
2 | [](https://clojars.org/clojurefx/versions/0.4.0)
3 | [](//liberapay.com/zilti)
4 | [](https://flattr.com/submit/auto?user_id=zilti&url=https%3A%2F%2Fbitbucket.org%2Fzilti%2Fclojurefx)
5 |
6 | # ClojureFX
7 |
8 | Bidirectionally synced GitHub mirror for [the ClojureFX repository](https://gitea.lyrion.ch/zilti/clojurefx).
9 |
--------------------------------------------------------------------------------
/deps.edn:
--------------------------------------------------------------------------------
1 | {:deps {org.clojure/clojure {:mvn/version "1.9.0"}
2 | org.clojure/core.async {:mvn/version "0.7.559"}
3 | camel-snake-kebab {:mvn/version "0.4.1"}
4 | com.taoensso/timbre {:mvn/version "4.10.0"}
5 | org.openjfx/javafx-fxml {:mvn/version "13.0.2"}}
6 | :paths ["src" "classes"]
7 | :aliases {:outdated {:extra-deps {olical/depot {:mvn/version "1.8.4"}}
8 | :main-opts ["-m" "depot.outdated.main" "-a" "outdated"]}
9 | :test {:extra-deps {lambdaisland/kaocha {:mvn/version "0.0-581"}}
10 | :main-opts ["-m" "kaocha.runner"]
11 | :extra-paths ["test"]}}}
12 |
--------------------------------------------------------------------------------
/docs/clojurefx.html:
--------------------------------------------------------------------------------
1 |
The first, straightforward part of this is to add the dependency to your project.clj or build.boot, which consists simply of adding [clojurefx "0.5.0"].
124 |
125 |
For the users of OpenJDK 7 and 8, OpenJFX, the opensource implementation of JavaFX, is not included. Luckily, many Linux distributions ship a separate OpenJFX package by now, but for those that don’t, the OpenJDK wiki has an article “Building OpenJFX”. Starting with OpenJDK 9, JavaFX is available as a library. Alternatively, you can of course install the Oracle JDK manually.
126 |
To get the JavaFX environment up and running, you can’t just initialize some classes and fire up a window, as is the case with Swing; you first have to initialise the environment. For this, you have two choices: either use a “nasty hack” Oracle themselves show, or go down the Java road and subclass ‘javafx.application.Application’.
139 |
140 |
For the “nasty hack”, you have to add a defoncebefore you import JavaFX classes (so, best suited for a core.clj ns). You can then manually create a Stage and add a Scene to it.
141 |
This macro runs the code given on the JavaFX thread and blocks the current thread until the execution has finished.
181 |
182 |
183 |
184 |
clojurefx.clojurefx: run-latercode
185 |
This macro runs the code given on the JavaFX thread and immediately returns. Prefixing the s-exp with an @ has the same effect as using run-now.
186 |
187 |
188 |
189 |
clojurefx.clojurefx: fiinterface args & code
190 |
This macro is used to use a Clojure function as a functional interface. The interface name is needed: (fx/fi javafx.event.Event [event] eventhandling-code)
191 |
192 |
193 |
194 |
clojurefx.clojurefx: connectinstance function args & code
195 |
This macro is used to use a Clojure function as a functional interface. The function must be written in kebab case: (fx/connect btn set-on-action [event] (do-something-with event))
196 |
You can write a scenegraph in-code using the compile function. It is straightforward, alternating between the class name and the element’s properties. Make sure though to either use start-app function or first initialize the toolkit:
218 |
FXML is an XML format describing a JavaFX user interface. It also allows defining action handlers and, similar to HTML, inline scripting via script tags. You can find an introduction on this site.
263 |
264 |
ClojureFX provides an idiomatic interface to load FXML files, and in this new version can even generate a controller class for you at runtime.
265 |
So you created an FXML file, probably with the SceneBuilder, and obviously now want to use it in your application. Doing so looks tedious in the JavaFX docs, but it is actually straightforward. All you need is some place to add the loaded Node - this could be the Scene object, or simply any JavaFX Parent element. The loader function returns a pure javafx.scene.Node-based object.
287 |
When creating an FXML file, you have built-in features to bind properties and call functions in an associated controller class. Before actually writing any Clojure, let’s see how you can prepare your FXML file to get the most out of it.
307 |
308 |
First, at your outermost element in the file, you have to tell it the class name of its JVM sibling it is going to call. For that, open it, and add the fx:controller attribute: fx:controller="ch.lyrion.MyController". It is not very important how you name the class, as long as it has a package and doesn’t exist anywhere else.
309 |
310 |
To bind any element to your new controller (in the form of a Property), you need the fx:id attribute. Let’s try it with that label: <Label fx:id="MyLabel" />. That way, you’ll always have access to it as long as you have the controller instance with you. Note that the CamelCase will be automatically converted to kebab-case when using the designated accessors from ClojureFX!
311 |
312 |
Next, you can define action handlers. Note that “Special Handlers” (as defined here) are not yet fully supported; I’m working on them! You simply provide the attribute, e.g. an onAction attribute, with the method name prefixed with a pound sign; note that the method name CamelCase will be automatically converted to kebab-case. E.g. <Button onAction="#buttonClicked" /> will call (button-clicked controller-instance event) in the namespace you provided (see below).
313 |
314 |
Now, finally, it is time to weld the parts together. But wait! Your FXML file doesn’t have any companion, no controller class, let alone the ch.lyrion.MyController we told it to look for!
315 | No worries, we got you covered. load-fxml-with-controller has your and your file’s back. It doesn’t just load the FXML and returns a Node, it also parses the source and generates your file’s companion on the fly. For that, it needs a couple more infos than load-fxml though: first, of course, the file path, but also the fully qualified clojure function in String form that will be called when the class gets initialized by JavaFX. Note that all action handlers defined above also have to be in the namespace of that function.
316 |
With this command, ClojureFX loads an FXML file and returns it as a javafx.scene.Node. Note that the filename will be parsed by clojure.io/resource before loading.
340 |