├── .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 | [![License](//img.shields.io/badge/license-EPLv1-blue.svg?style=flat)](https://opensource.org/licenses/EPL-1.0) 2 | [![Clojars](//img.shields.io/badge/clojars-0.4.0-blue.svg?style=flat)](https://clojars.org/clojurefx/versions/0.4.0) 3 | [![Liberapay](//img.shields.io/liberapay/receives/Changaco.svg)](//liberapay.com/zilti) 4 | [![Flattr this](//api.flattr.com/button/flattr-badge-large.png)](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 |
2 | 3 | 4 | 7 | 8 | 9 | 10 | ClojureFX Manual 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |

ClojureFX Manual

55 | 56 | 57 | 58 | 59 |

Table of Contents

60 | 61 |
62 | 63 | 84 |
85 | 86 | 87 | 88 |
89 |

90 | Next: , Up: (dir)   [Contents][Index]

91 |
92 | 93 |

ClojureFX

94 | 95 |

This is the documentation to ClojureFX, version 0.5.0. 96 |

97 | 98 | 100 | 102 | 104 | 106 | 108 | 110 | 112 | 113 | 114 |
115 | 116 |
117 |

118 | Next: , Previous: , Up: Top   [Contents][Index]

119 |
120 | 121 |

1 Installation and deployment

122 | 123 |

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 |

127 |
128 | 129 |
130 |

131 | Next: , Previous: , Up: Top   [Contents][Index]

132 |
133 | 134 |

2 Getting started

135 | 136 |

(require '[clojurefx.clojurefx :as fx]) 137 |

138 |

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 defonce before 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 |

142 |

(defonce force-toolkit-init (javafx.embed.swing.JFXPanel.)) 143 |

144 |

Alternatively, and preferredly, you can use start-app: 145 |

146 |
147 |
(ns example.core
148 |   (:require [clojurefx.clojurefx :as fx])
149 |   (:gen-class))
150 | 
151 | (defn init []
152 |   nil)
153 | 
154 | (defn start [^javafx.stage.Stage stage]
155 |   (.show stage))
156 | 
157 | (defn stop []
158 |   nil)
159 | 
160 | (defn -main [& args]
161 |     (fx/start-app init start stop))
162 | 
163 | 164 | 165 | 167 | 168 | 169 |
170 | 171 |
172 |

173 | Up: Getting started   [Contents][Index]

174 |
175 | 176 |

2.1 Core API

177 | 178 |
179 |
clojurefx.clojurefx: run-now code
180 |

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-later code
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: fi interface 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: connect instance 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 |

197 | 198 |
199 |
clojurefx.clojurefx: find-child-by-class node clazz
200 |

With this function, you can find an element / elements in a scenegraph by one of its CSS classes. 201 |

202 | 203 |
204 |
clojurefx.clojurefx: find-child-by-id node id
205 |

Analogous to find-child-by-class, but to find an element by fx:id. 206 |

207 | 208 |
209 | 210 |
211 |

212 | Next: , Previous: , Up: Top   [Contents][Index]

213 |
214 | 215 |

3 Coding a scenegraph

216 | 217 |

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 |

219 |

(defonce force-toolkit-init (javafx.embed.swing.JFXPanel.)) 220 |

221 |

There are no further dependencies for this, since the calls are made using Clojure’s reflection API. Let’s look at an example: 222 |

223 |
224 |
(require '[clojurefx.clojure :refer [compile]])
225 | (compile [Scene {:root [VBox {:id "TopLevelVBox"
226 |                                         :children [Label {:text "Hi!"}
227 |                                                    Label {:text "I'm ClojureFX!"}
228 |                                                    HBox {:id "HorizontalBox"
229 |                                                          :children [Button {:text "Alright."}]}]}]}])
230 | 
231 | 232 | 233 | 235 | 236 | 237 |
238 | 239 |
240 |

241 | Up: Coding a scenegraph   [Contents][Index]

242 |
243 | 244 |

3.1 API

245 | 246 |
247 |
clojurefx.clojurefx: compile code
248 |

Turns the Hiccup-like tree into a JavaFX-Node. 249 |

250 | 251 |
252 | 253 |
254 |

255 | Next: , Previous: , Up: Top   [Contents][Index]

256 |
257 | 258 |

4 FXML and controllers

259 | 260 |

(require '[clojurefx.fxml :as fxml]) 261 |

262 |

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 |

266 | 267 | 269 | 271 | 273 | 275 | 276 | 277 |
278 | 279 |
280 |

281 | Next: , Up: FXML and controllers   [Contents][Index]

282 |
283 | 284 |

4.1 Loading FXML files

285 | 286 |

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 |

288 |
289 |
(require '[clojurefx.fxml :as fxml])
290 | (def mainwindow (fxml/load-fxml "resources/fxml/mainwindow.fxml"))
291 |      ;; => javafx.scene.Node
292 | (.setContent my-scroll-pane mainwindow)
293 | 
294 | 295 |

You’re already good to go! 296 |

297 |
298 | 299 |
300 |

301 | Next: , Previous: , Up: FXML and controllers   [Contents][Index]

302 |
303 | 304 |

4.2 Generating controller classes

305 | 306 |

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 |

317 |
318 | 319 |
320 |

321 | Next: , Previous: , Up: FXML and controllers   [Contents][Index]

322 |
323 | 324 |

4.3 FXML scripting

325 | 326 |

Unfortunately, FXML scripting is currently broken (outdated JSR-223 implementation). Stay tuned! 327 |

328 |
329 | 330 |
331 |

332 | Previous: , Up: FXML and controllers   [Contents][Index]

333 |
334 | 335 |

4.4 API

336 | 337 |
338 |
clojurefx.fxml: load-fxml filename
339 |

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 |

341 | 342 |
343 |
clojurefx.fxml: generate-controller filename init-fn
344 |

Generates a controller using the fx:id definitions in the given filename. 345 |

346 | 347 |
348 |
clojurefx.fxml: load-fxml-with-controller filename init-fn
349 |

Like load-fxml, but also generates and loads an accompanying controller class using generate-controller. 350 |

351 | 352 |
353 | 354 |
355 |

356 | Next: , Previous: , Up: Top   [Contents][Index]

357 |
358 | 359 |

5 Event handling

360 | 361 |

Coming soon. 362 |

363 |
364 | 365 |
366 |

367 | Next: , Previous: , Up: Top   [Contents][Index]

368 |
369 | 370 |

6 Roadmap

371 | 372 | 377 | 378 |
379 | 380 |
381 |

382 | Previous: , Up: Top   [Contents][Index]

383 |
384 | 385 |

Index

386 | 387 |
Jump to:   C 388 |   389 | F 390 |   391 | G 392 |   393 | L 394 |   395 | R 396 |   397 |
398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 |
Index Entry  Section

C
compile: Scenegraph API
connect: Core API

F
fi: Core API
find-child-by-class: Core API
find-child-by-id: Core API

G
generate-controller: FXML API

L
load-fxml: FXML API
load-fxml-with-controller: FXML API

R
run-later: Core API
run-now: Core API

422 |
Jump to:   C 423 |   424 | F 425 |   426 | G 427 |   428 | L 429 |   430 | R 431 |   432 |
433 | 434 |
435 | 436 | 437 | 438 | 439 | 440 |
441 | -------------------------------------------------------------------------------- /docs/datamash-texinfo.css: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | datamash.git - GNU Datamash 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 23 | 24 |
25 | summaryrefslogtreecommitdiffabout
26 | 32 | 33 | 34 |
35 |
36 |
path: root/doc/datamash-texinfo.css
blob: 2e82f6b6834f4972a9615ceab308d7efb07c328f (plain) 37 | 38 | 273 |
1
 39 | 2
 40 | 3
 41 | 4
 42 | 5
 43 | 6
 44 | 7
 45 | 8
 46 | 9
 47 | 10
 48 | 11
 49 | 12
 50 | 13
 51 | 14
 52 | 15
 53 | 16
 54 | 17
 55 | 18
 56 | 19
 57 | 20
 58 | 21
 59 | 22
 60 | 23
 61 | 24
 62 | 25
 63 | 26
 64 | 27
 65 | 28
 66 | 29
 67 | 30
 68 | 31
 69 | 32
 70 | 33
 71 | 34
 72 | 35
 73 | 36
 74 | 37
 75 | 38
 76 | 39
 77 | 40
 78 | 41
 79 | 42
 80 | 43
 81 | 44
 82 | 45
 83 | 46
 84 | 47
 85 | 48
 86 | 49
 87 | 50
 88 | 51
 89 | 52
 90 | 53
 91 | 54
 92 | 55
 93 | 56
 94 | 57
 95 | 58
 96 | 59
 97 | 60
 98 | 61
 99 | 62
100 | 63
101 | 64
102 | 65
103 | 66
104 | 67
105 | 68
106 | 69
107 | 70
108 | 71
109 | 72
110 | 73
111 | 74
112 | 75
113 | 76
114 | 77
115 | 78
116 | 79
117 | 80
118 | 81
119 | 82
120 | 83
121 | 84
122 | 85
123 | 86
124 | 87
125 | 88
126 | 89
127 | 90
128 | 91
129 | 92
130 | 93
131 | 94
132 | 95
133 | 96
134 | 97
135 | 98
136 | 99
137 | 100
138 | 101
139 | 102
140 | 103
141 | 104
142 | 105
143 | 106
144 | 107
145 | 108
146 | 109
147 | 110
148 | 111
149 | 112
150 | 113
151 | 114
152 | 115
153 | 116
154 | 117
155 | 118
156 | 119
157 | 120
158 | 121
159 | 122
160 | 123
161 | 124
162 | 125
163 | 126
164 | 127
165 | 128
166 | 129
167 | 130
168 | 131
169 | 132
170 | 133
171 | 134
172 | 135
173 | 136
174 | 137
175 | 138
176 | 139
177 | 140
178 | 141
179 | 142
180 | 143
181 | 144
182 | 145
183 | 146
184 | 147
185 | 148
186 | 149
187 | 150
188 | 151
189 | 152
190 | 153
191 | 154
192 | 155
193 | 156
194 | 157
195 | 158
196 | 159
197 | 160
198 | 161
199 | 162
200 | 163
201 | 164
202 | 165
203 | 166
204 | 167
205 | 168
206 | 169
207 | 170
208 | 171
209 | 172
210 | 173
211 | 174
212 | 175
213 | 176
214 | 177
215 | 178
216 | 179
217 | 180
218 | 181
219 | 182
220 | 183
221 | 184
222 | 185
223 | 186
224 | 187
225 | 188
226 | 189
227 | 190
228 | 191
229 | 192
230 | 193
231 | 194
232 | 195
233 | 196
234 | 197
235 | 198
236 | 199
237 | 200
238 | 201
239 | 202
240 | 203
241 | 204
242 | 205
243 | 206
244 | 207
245 | 208
246 | 209
247 | 210
248 | 211
249 | 212
250 | 213
251 | 214
252 | 215
253 | 216
254 | 217
255 | 218
256 | 219
257 | 220
258 | 221
259 | 222
260 | 223
261 | 224
262 | 225
263 | 226
264 | 227
265 | 228
266 | 229
267 | 230
268 | 231
269 | 232
270 | 233
271 | 234
272 | 
/*
274 | CSS for TexInfo/HTML files.
275 | 
276 | Copyright (C) 2015-2016 Assaf Gordon (assafgordon@gmail.com)
277 | 
278 | License:
279 |  GNU All Permissive License
280 |  http://www.gnu.org/prep/maintain/html_node/License-Notices-for-Other-Files.html
281 | 
282 |  Copying and distribution of this file, with or without modification,
283 |  are permitted in any medium without royalty provided the copyright
284 |  notice and this notice are preserved.  This file is offered as-is,
285 |  without any warranty.
286 | 
287 | 
288 | The used tags/classes were collected from a Texinfo-generated HTML using:
289 | 
290 |   cd coreutils
291 |   makeinfo --html --no-split -o coreutils.html doc/coreutils.texi
292 |   cat coreutils.html | sed 's/</\n</g' | sed 's;>.*;>;g' \
293 |          | grep '^<' | grep 'class=' | sort -u \
294 |          | perl -lane 'm/<(\w+) .*class="([-\w]+)"/ ; print $1, "\t", $2' \
295 |          | sort -u
296 | 
297 | */
298 | body {
299 |   font-family: sans-serif;
300 |   font-size: 16px;
301 |   margin: 1em;
302 | 
303 |   overflow-x: hidden; /* Coupled with the div.header trick,
304 | 			 this will extend the header lines
305 | 			 access the entire page width without causing
306 | 			 a horizontal scroll bar to appear. */
307 | }
308 | 
309 | 
310 | a {
311 |   text-decoration: none;
312 |   outline-style: none;
313 |   color: blue;
314 | }
315 | a:visited {
316 |   color: rgb(16,0,112);
317 | }
318 | a:hover {
319 |   text-decoration: underline;
320 | }
321 | 
322 | 
323 | /*****************************************************
324 |    Titles / Headers
325 | ******************************************************/
326 | 
327 | /* @settitle:
328 |    The title of the document at the top of the document/header */
329 | h1.settitle {
330 |   color: rgb(51,70,131);
331 |   text-shadow: rgb(153,153,153) 1px 1px 0px;
332 | }
333 | 
334 | /* The title at the beginning of the document, before the @menu */
335 | h1.top {
336 |   color: rgb(51,70,131);
337 |   text-shadow: rgb(153,153,153) 1px 1px 0px;
338 | }
339 | 
340 | /* @chapter */
341 | h2.chapter {
342 | }
343 | 
344 | h2.appendix { }
345 | h2.unnumbered { }
346 | 
347 | /* @section */
348 | h3.section {
349 | }
350 | /* @unnumberedsec */
351 | h3.unnumberedsec {
352 | }
353 | /* @heading (seems to be only used in fdl.texi) */
354 | h3.heading {
355 | }
356 | 
357 | /* @subsection */
358 | h4.subsection {
359 | }
360 | 
361 | 
362 | /**************************************************
363 |   Short Contents (if @shortcontents command is used)
364 | ***************************************************/
365 | h2.shortcontents-heading { }
366 | div.shortcontents { }
367 | div.shortcontents ul { }
368 | div.shortcontents ul li { }
369 | 
370 | 
371 | /**************************************************
372 |   Contents (if @contents command is used)
373 | ***************************************************/
374 | h2.contents-heading { }
375 | div.contents { }
376 | div.contents ul { }
377 | div.contents ul li { }
378 | 
379 | 
380 | /* The @menu table */
381 | table.menu { }
382 | pre.menu-comment {}
383 | 
384 | 
385 | 
386 | /************************************
387 |   @example   and   @verbatim
388 | ************************************/
389 | div.example {
390 |   margin-left: 2em;
391 |   margin-right: 2em;
392 | }
393 | div.example pre.example {
394 |   /* Round Corners */
395 |   -webkit-border-radius: 3px;
396 |   -moz-border-radius: 3px;
397 |   border-radius: 3px;
398 |   border: 1px solid #c0c0c0;
399 | 
400 |   padding: 1ex;
401 |   background-color: #f3f3f3;
402 | }
403 | 
404 | /* Note: @verbatim is also rendered inside a 'div.example' */
405 | div.example pre.verbatim {
406 |   /* Round Corners */
407 |   -webkit-border-radius: 3px;
408 |   -moz-border-radius: 3px;
409 |   border-radius: 3px;
410 |   border: 1px solid #c0c0c0;
411 | 
412 |   padding: 1ex;
413 |   background-color: #f3f3f3;
414 | }
415 | 
416 | 
417 | 
418 | /************************************
419 |   @smallexample
420 | ************************************/
421 | div.smallexample {
422 | }
423 | div.smallexample pre.smallexample {
424 | }
425 | 
426 | /***********************************
427 |   @display
428 | ***********************************/
429 | div.display {
430 | }
431 | div.display pre.display {
432 | }
433 | 
434 | 
435 | 
436 | /**************************************
437 |   @footnote
438 | **************************************/
439 | div.footnote { }
440 | h4.footnotes-heading { }
441 | 
442 | /**************************************
443 | The header at the top of each page / section
444 | (the next/previous/top/up links)
445 | **************************************/
446 | div.header {
447 |    padding-top: 0.5ex;
448 |    padding-bottom: 0.5ex;
449 |    /*background-color: #ddddff;*/
450 | 
451 |    /* This will extend the background color of the header
452 |       bar to the entire width of the page (and beyond),
453 |       requires 'overflow-x: hidden' in the 'body'. */
454 |    padding-left: 3000px;
455 |    margin-left: -3000px;
456 |    padding-right: 3000px;
457 |    margin-right: -3000px;
458 | }
459 | 
460 | /* Disable any additional margins */
461 | div.header p {
462 |     margin: 0;
463 | }
464 | div.header p a {
465 |     color: blue;
466 | }
467 | 
468 | 
469 | /**************************************
470 |    @table is rendered as <dl> (defnition list),
471 |    @item  is rendered as <dt> (definition term),
472 |    text is rendered as <dd> (definition description)
473 | **************************************/
474 | dl {
475 |    margin: 0 1em;
476 | }
477 | dl dt {
478 |    margin: 1em 0;
479 | }
480 | dl dd {
481 |    margin-left: 2em;
482 | }
483 | 
484 | /*******************************************************
485 |   Text Styles
486 | *******************************************************/
487 | 
488 | /* @var{} */
489 | var {
490 |   color: #CC0000;
491 | }
492 | 
493 | /* @samp{} */
494 | samp {
495 |   color: #6600CC;
496 | }
497 | 
498 | /* @env{} will result in <p><code>X</code></p> */
499 | p code {
500 |   color: #532c14;
501 | }
502 | 
503 | /* @option{} */
504 | span.nocodebreak {
505 |   color: #5D4C46;
506 | }
507 | 
508 |
509 |
510 | 511 | 512 | -------------------------------------------------------------------------------- /docs/makedocs-web.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cd docs 3 | makeinfo --css-ref=datamash-texinfo.css --html --no-split manual.texinfo 4 | echo '0a 5 |
6 | . 7 | $a 8 |
9 | . 10 | w' | ed clojurefx.html 11 | -------------------------------------------------------------------------------- /docs/makedocs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | makeinfo --css-ref=datamash-texinfo.css --html --no-split manual.texinfo 3 | makeinfo --no-split manual.texinfo 4 | makeinfo -o linicms-manual.docbook --no-split --docbook manual.texinfo 5 | makeinfo -o linicms-manual.pdf --pdf manual.texinfo 6 | dbtoepub linicms-manual.docbook -o linicms-manual.epub 7 | -------------------------------------------------------------------------------- /docs/manual.texinfo: -------------------------------------------------------------------------------- 1 | \input texinfo 2 | @setfilename clojurefx 3 | @settitle ClojureFX Manual 4 | 5 | @copying 6 | This manual is for ClojureFX, version 0.4.0. 7 | 8 | Copyright @copyright{} 2016-2018 Daniel Ziltener. 9 | @end copying 10 | 11 | @titlepage 12 | @title ClojureFX Manual 13 | @author Daniel Ziltener 14 | 15 | @page 16 | @vskip 0pt plus 1filll 17 | @insertcopying 18 | 19 | @end titlepage 20 | 21 | @contents 22 | 23 | @c@ifnottex 24 | @node Top 25 | @top ClojureFX 26 | 27 | This is the documentation to ClojureFX, version 0.5.0. 28 | @c@end ifnottex 29 | 30 | @menu 31 | * Installation and deployment:: adding ClojureFX and probably tools.jar to your build tool. 32 | * Getting started:: the little ceremony necessary to get a window ``up and running''. 33 | * Coding a scenegraph:: for everyone who wants to write an UI the old-school way. 34 | * FXML and controllers:: loading FXML files and generating a controller. 35 | * Event handling:: a short chapter about handling events. 36 | * Roadmap:: what's up next?. 37 | * Index::. 38 | @end menu 39 | 40 | @node Installation and deployment 41 | @chapter Installation and deployment 42 | 43 | The first, straightforward part of this is to add the dependency to your @file{project.clj} or @file{build.boot}, which consists simply of adding @code{[clojurefx "0.5.0"]}. 44 | 45 | For the users of @emph{OpenJDK} 7 and 8, @emph{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 @uref{https://wiki.openjdk.java.net/display/OpenJFX/Building+OpenJFX, ``Building OpenJFX''}. Starting with OpenJDK 9, JavaFX is available as a library. Alternatively, you can of course install the Oracle JDK manually. 46 | 47 | @node Getting started 48 | @chapter Getting started 49 | 50 | @code{(require '[clojurefx.clojurefx :as fx])} 51 | 52 | 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 @indicateurl{javafx.application.Application}. 53 | 54 | For the ``nasty hack'', you have to add a @code{defonce} @emph{before} you import JavaFX classes (so, best suited for a @file{core.clj} ns). You can then manually create a @code{Stage} and add a @code{Scene} to it. 55 | 56 | @code{(defonce force-toolkit-init (javafx.embed.swing.JFXPanel.))} 57 | 58 | Alternatively, and preferredly, you can use @code{start-app}: 59 | 60 | @lisp 61 | (ns example.core 62 | (:require [clojurefx.clojurefx :as fx]) 63 | (:gen-class)) 64 | 65 | (defn init [] 66 | nil) 67 | 68 | (defn start [^javafx.stage.Stage stage] 69 | (.show stage)) 70 | 71 | (defn stop [] 72 | nil) 73 | 74 | (defn -main [& args] 75 | (fx/start-app init start stop)) 76 | @end lisp 77 | 78 | @node Core API 79 | @section Core API 80 | 81 | @deffn clojurefx.clojurefx run-now code 82 | This macro runs the code given on the JavaFX thread and blocks the current thread until the execution has finished. 83 | @end deffn 84 | 85 | @deffn clojurefx.clojurefx run-later code 86 | 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 @code{run-now}. 87 | @end deffn 88 | 89 | @deffn clojurefx.clojurefx fi interface args & code 90 | This macro is used to use a Clojure function as a functional interface. The interface name is needed: @code{(fx/fi javafx.event.Event [event] eventhandling-code)} 91 | @end deffn 92 | 93 | @deffn clojurefx.clojurefx connect instance function args & code 94 | This macro is used to use a Clojure function as a functional interface. The function must be written in kebab case: @code{(fx/connect btn set-on-action [event] (do-something-with event))} 95 | @end deffn 96 | 97 | @deffn clojurefx.clojurefx find-child-by-class node clazz 98 | With this function, you can find an element / elements in a scenegraph by one of its CSS classes. 99 | @end deffn 100 | 101 | @deffn clojurefx.clojurefx find-child-by-id node id 102 | Analogous to find-child-by-class, but to find an element by fx:id. 103 | @end deffn 104 | 105 | @node Coding a scenegraph 106 | @chapter Coding a scenegraph 107 | 108 | You can write a scenegraph in-code using the @code{compile} function. It is straightforward, alternating between the class name and the element's properties. Make sure though to either use @code{start-app} function or first initialize the toolkit: 109 | 110 | @code{(defonce force-toolkit-init (javafx.embed.swing.JFXPanel.))} 111 | 112 | There are no further dependencies for this, since the calls are made using Clojure's reflection API. Let's look at an example: 113 | 114 | @lisp 115 | (require '[clojurefx.clojure :refer [compile]]) 116 | (compile [Scene @{:root [VBox @{:id "TopLevelVBox" 117 | :children [Label @{:text "Hi!"@} 118 | Label @{:text "I'm ClojureFX!"@} 119 | HBox @{:id "HorizontalBox" 120 | :children [Button @{:text "Alright."@}]@}]@}]@}]) 121 | @end lisp 122 | 123 | @node Scenegraph API 124 | @section API 125 | 126 | @deffn clojurefx.clojurefx compile code 127 | Turns the Hiccup-like tree into a JavaFX-Node. 128 | @end deffn 129 | 130 | @node FXML and controllers 131 | @chapter FXML and controllers 132 | 133 | @code{(require '[clojurefx.fxml :as fxml])} 134 | 135 | @acronym{FXML} is an @acronym{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 @uref{https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/doc-files/introduction_to_fxml.html, on this site}. 136 | 137 | ClojureFX provides an idiomatic interface to load FXML files, and in this new version can even generate a controller class for you at runtime. 138 | 139 | @node Loading FXML files 140 | @section Loading FXML files 141 | 142 | So you created an @acronym{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. 143 | 144 | @lisp 145 | (require '[clojurefx.fxml :as fxml]) 146 | (def mainwindow (fxml/load-fxml "resources/fxml/mainwindow.fxml")) 147 | ;; => javafx.scene.Node 148 | (.setContent my-scroll-pane mainwindow) 149 | @end lisp 150 | 151 | You're already good to go! 152 | 153 | @node Generating controller classes 154 | @section Generating controller classes 155 | 156 | When creating an @acronym{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 @acronym{FXML} file to get the most out of it. 157 | 158 | First, at your outermost element in the file, you have to tell it the class name of its @acronym{JVM} sibling it is going to call. For that, open it, and add the @option{fx:controller} attribute: @code{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. 159 | 160 | To bind any element to your new controller (in the form of a @code{Property}), you need the @option{fx:id} attribute. Let's try it with that label: @code{