JavaFX 1.0 FXD/FXZ API | Overview | Java FX
See also: JavaFX 1.0 F API | JavaFX Reference | javafx.com | |
javafx.fxd |
Provides functionality to load JavaFX content files (FXD and FXZ format) generated by JavaFX Production Suite. Provides functionality to load JavaFX content files (FXD and FXZ format) generated by JavaFX Production Suite. JavaFX content format contains text descriptions of the graphical content of the JavaFX application. Descriptions are loaded by this package into the application during runtime. JavaFX content format exists in two forms, FXD and FXZ. FXD is a textual format using the same object literal syntax as JavaFX Script, so it is possible to copy and paste the descriptions from the FXD file directly to the JavaFX Script code (with some exceptions noted at the end of this document). Here is an example of a simple FXD file: Group { id: "face" content: [ Circle { id:"background" centerX:40 centerY:40 radius:39 fill:Color.YELLOW stroke:Color.BLACK strokeWidth:3.0}, Circle { centerX:25 centerY:30 radius:5 fill: Color.BLACK}, Circle { centerX:55 centerY:30 radius:5 fill: Color.BLACK}, Line{ startX:32 startY:23 endX:16 endY:15 stroke:Color.BLACK strokeWidth:4.0}, Line{ startX:45 startY:23 endX:61 endY:15 stroke:Color.BLACK strokeWidth:4.0}, QuadCurve { id: "mouth" stroke:Color.BLACK strokeWidth:3.0 fill: Color.TRANSPARENT startX:20 startY:60 endX:60 endY:60 controlX:40 controlY:80 } ] }The content is loaded using the javafx.fxd.FXDLoader class. It can be inserted into the scene graph using this snipped of code: var group:Group .... // a graphics group defined elsewhere var smileyNode = FXDLoader.load("smiley.fxd"}; // loads the content insert smileyNode into group.content; // inserts the smiley into the groupThe FXD format currently supports all classes from the graphical Javafx packages. Details are provided at the end of this document. Here are the properties of FXD format, in contrast to JavaFX Script code:
{__DIR__} magic variable.
The following example demonstrates referencing embedded font and image files in the FXD description. All of the files are stored in an FXZ file called mygfx.fxz :
Group { content: [ ImageView { x: 10 y: 10 image: Image{ url: "{__DIR__}myimage.png"} }, Text { fill: Color.WHITE x: 20 y: 20 textOrigin: TextOrigin.TOP font: Font.fontFromURL(25.00, "{__DIR__}myfont.ttf") content: "Welcome !!!" }, ] }In the above example, the group contains two nodes - ImageView with
Image , which
loads its content from the myimage.png file. The other node is a Text
node and it uses a custom font with size 25. The font is loaded from the myfont.ttf
file. Both, the image and the font files are located in the same
directory as the mygfx.fxd file itself.
FXZ is simply a compressed version of the FXD content using zip compression
and file format. The FXZ file can also contain embedded assets, such as images or fonts. The structure of the FXZ file from the example above is as follows:
>
mygfx.fxz +- content.fxd +- myimage.png +- myfont.ttf +- ...The content.fxd file is the main content of the FXZ archive, containing the description of the graphic objects. The other
files, myimage.png and myfont.ttf are the embedded image and font assets.
FXZ files can be loaded in exactly the same way as FXD files, using
the javafx.fxd.FXDLoader class.
FXD Format Syntax Details
FXD format follows the same object literals syntax as JavaFX Script.
Besides object literals, constructor functions (such as Font.font) are supported. This
makes FXD format highly compatible with JavaFX Script, and it
is possible to copy the FXD content directly to the JavaFX script code (with the exception
of the Font.fontFromURL construct, which does not have a JavaFX Script equivalent).
The differences between FXD format and JavaFX Script code are the following:
//@version tag at the beginning of the FXD
file. For example:
//@version 1.0 |