Exadel JavaFX Studio Guide

Version: 1.1.1


1. Introduction
2. Key Features of Exadel JavaFX Studio
3. Requirements
4. Installation
+5. Creating JavaFX Project
5.1. Creating Simple JavaFX Project
5.2. JavaFX Examples
5.3. Using a JavaFX class
+6. Launching JavaFX Project
6.1. Launching JavaFX Project: Desktop
+7. Editor Features
7.1. Code Assist
7.2. Code Highlighting
7.3. OpenOn
7.4. Line Numbering
7.5. Compiler Error Highlighting
8. Snippets
9. Help and Other Resources

Chapter 1. Introduction

JavaFX is a new platform for creating and deploying rich Internet applications inside a lightweight Java virtual machine. JavaFX Studio works as an Eclipse plugin for developing and deploying JavaFX applications. JavaFX Studio comes with numerous features and wizards to make JavaFX application development better.

Chapter 2. Key Features of Exadel JavaFX Studio

Table 2.1. Key Features of Exadel JavaFX Studio

FeatureDescription
Multi project supportIf a project depends on some other project the plug-in can resolve the dependencies during compiling, launching and code-assist.
Code AssistCompletes your code statements faster and with more accuracy
JavaFX ExamplesExadel JavaFX Studio enables you to open a example project (standard Sun JavaFX examples) and run it from the studio

Chapter 3. Requirements

  • Eclipse 3.5

  • Operating System (Window, Linux)

  • Java SDK

  • JavaFX SDK

Chapter 4. Installation

  • Install JavaFX SDK

    Download JavaFX SDK for Windows or Linux. Follow the installation instructions.

  • Install Eclipse

    The Plugin requires Eclipse 3.5. We recommend downloading "Eclipse IDE for Java EE Developers" for Windows or Linux. Then follow the installation instructions.

  • Install Plugin

    • Download the plugin(plugin download page), unzip the downloaded file

    • Start Eclipse IDE

    • On the Help menu select Software Updates

    • In the Software Updates and Add-ons dialog click on the Available Sofware tab

    • Click on the Add Site button, choose Local

    Installing the plugin

    Figure 4.1. Installing the plugin


    • Navigate to the folder with unzipped plugin, open it, select the "eclipse" directory and press Ok

    Installing the plugin

    Figure 4.2. Installing the plugin


    • You will see the "Exadel JavaFX 1.1.1 Update Site" option in the list. Check the option and press Install.

    Installing the plugin

    Figure 4.3. Installing the plugin


    Follow the steps in the installation wizard.

    • Check the JavaFX IDE option and press Next

    Installing the plugin

    Figure 4.4. Installing the plugin


    • Confirm that you accept the terms of the license agreement and hit Finish to complete the installation process

    SInstalling the plugin

    Figure 4.5. SInstalling the plugin


    When the wizard finishes, you will be prompted to restart Eclipse.

Chapter 5. Creating JavaFX Project

In this chapter you will learn how to create projects with Exadel JavaFX Studio IDE. The fist project is quite elementary, you will create a JavaFX script file, set up the configuration and run the script. Though the second project described in the chapter is more complex, it shows how to use both scripts and classes in your application.

5.1. Creating Simple JavaFX Project

This section will tell how to create a simple JavaFX with JavaFX plugin. Following the steps of this section you will be able to create a JavaFX application that runs as a standalone application and prints "Hello World!"

Once the plug-in is installed, you can create a JavaFX project.

  • Select File > New > Other...> JavaFX > JavaFX Project and click Next

New JavaFX Project

Figure 5.1. New JavaFX Project


Alternatively, if you have the JavaFX perspective activated, you can just click File > New and select JavaFX Project.

New Project with JavaFX Perspective Activated

Figure 5.2. New Project with JavaFX Perspective Activated


The New JavaFX project wizard will guide you through the step required to create a new project.

  • Type in the project name in the Project name field first. By default the project will be added to your current workspace.

New JavaFX project

Figure 5.3. New JavaFX project


Then you need to configure your JavaFX Runtime Configuration.

  • Click the Configure button, then press Add to navigate to the folder where the JavaFX SDK is installed

New JavaFX project: adding JavaFX SDK

Figure 5.4. New JavaFX project: adding JavaFX SDK


If JavaFX SDK is already configured you will see that the Use default JavaFX runtime (currently ' current SDK version ' ) option is selected. If you wish to use other SDK version you can point to it by selecting Alternative and clicking the Configure button.

You also need to specify the type of application you are about to create in the Profile section.

  • Select Desktop

The Working sets option group lets you show only resources, children of resources, and parents of resources contained in the working set. The problems view, tasks view and bookmarks view can all be filtered based on a working set. When using the search facility, you can also use working sets to restrict the set of elements that are searched.

New JavaFX project

Figure 5.5. New JavaFX project


When you are done with this dialog proceed to the next one by clicking the Next button.

New JavaFX project

Figure 5.6. New JavaFX project


The Project layout option group enables you to configure where your source and class file are to be located. By default they are located in the src and bin folder respectively. You can alter the layout configuration by clicking on Configure default.. .

  • Click Next to set up the Java build settings. Leave everything here with default values.

New JavaFX project: Java settings

Figure 5.7. New JavaFX project: Java settings


  • Press Finish to complete the wizard's job

Now you see in your Project Explorer the project you've just created.

Demo project in the Project Explorer

Figure 5.8. Demo project in the Project Explorer


Now you need to add a JavaFX script to your project.

  • Create a new package in the src folder

  • Right-click on the newly created package, select New > Other...> JavaFX > JavaFX Script and click Next

  • Type in the file name for the script and specify the folder where it will be placed.

Notice, that you don't need to add the "fx" extension, as it's added automatically.

New JavaFX project: adding a script

Figure 5.9. New JavaFX project: adding a script


  • Click Next to open the next dialog of the wizard

The dialog gives you an option to generate a simple JavaFX Stage, you can specify the title, width and height variables of the Stage with the corresponding fields.

New JavaFX project: generating a script

Figure 5.10. New JavaFX project: generating a script


When the Finish button is pressed you will see the script file in the Package Explorer and the script itself in the editor.

New JavaFX project

Figure 5.11. New JavaFX project


You can now run the "Hello World" JavaFX application. What you need to do now is to configure your Run Configuration

  • On the Run menu click Run Configurations

  • In the Run Configurations dialog double-click on the JavaFX application option to create a new configuration

    In this dialog you need to define the project for which you are creating the configuration, point to the .fx you've just created, make sure the JavaFX runtime is enable for the configuration. Leave the Profile and Run as fields with default values: "desktop" and "Applicaton" respectively.

  • Hit Run to launch the project

New JavaFX project: launching the project

Figure 5.12. New JavaFX project: launching the project


You will see the "Hello World!" message on your screen.

First JavaFX Appication

Figure 5.13. First JavaFX Appication


5.2. JavaFX Examples

In the previous section of the guide you have learned how to create a simple JavaFX project following wizard's steps. If you are familiar with JavaFX technology it will be sufficient to start developing your application. However, if you are new to JavaFX you can take a look at JavaFX example projects.

To explore a JavaFX example you should do the following:

  • Navigate to File > New > Other...> Examples > JavaFX Examples (for faster navigation you can type in "JavaFX Examples" in the input field), select JavaFX Example and press Next

    JavaFX Example

    Figure 5.14. JavaFX Example


  • Configure the project

    • Give a meaningful name to the project

    • Specify the JavaFX runtime environment or use the default on if it was configured previously

    • Define the application type in the Profile group

    • Choose an example project in the Available Example list box

    • You can optionally add the project to a working set

    JavaFX Example Settings

    Figure 5.15. JavaFX Example Settings


  • Press Next to set up JRE and project layout parameters if you need to, otherwise you can hit Finish to complete the wizard

You can now have a look a the source code of the example application and run it. For more details on running a JavaFX application from Exadel JavaFX Studio please read the Launching JavaFX Project chapter of the guide.

5.3. Using a JavaFX class

Now we will make something more complex - a puzzle game.

  • Create a new project and make a package in the src folder.

  • Generate an empty script file, call it Game.fx (File > New > Other...> JavaFX > JavaFX Script). Configure it as it's shown in the previous Creating Simple JavaFX Project, except for the last step: do not generate any content for the script.

  • When you see the newly-created file in the Package Explorer double-click on the file and add the following code:


...
package com.exadel;
import javafx.ext.swing.SwingButton;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.stage.Stage;
def cellSize:Number = 40;
def puz = PuzzleGrid { boxDim:3 }; 
def gridFont = Font 
{ name: "Arial Bold" 
size: 20 
}; 
Stage
{ title: "Game"
visible: true
scene: Scene
{ content: for(idx in [0..<puz.gridSize])
{ var x:Integer = (idx mod puz.gridDim); 
var y:Integer = (idx / puz.gridDim);
SwingButton 
{ translateX: x * cellSize; 
translateY: y * cellSize; 
width: cellSize; 
height: cellSize; 

text: bind if(puz.grid[idx]>=1) 
"{puz.grid[idx]}" else " " 
font: gridFont 
action: function():Void 
{ var v = puz.grid[idx]; 
= (v+1) mod (puz.gridDim+1); 
puz.grid[idx] = v; 
} 
} 
}
width: puz.gridDim * cellSize
height: puz.gridDim * cellSize
}
}
...
  • Create a class file. File > New > Other...> JavaFX > JavaFX Class

JavaFX project: adding a class

Figure 5.16. JavaFX project: adding a class


Call the file PuzzleGrid

  • Hit Finish

You see now the PuzzleGrid.fx file in the Package Explorer.

  • Double-click on the file to open it in the editor

  • Add the this code to the PuzzleGrid.fx file


...
package com.exadel;

public class PuzzleGrid {
public-init var boxDim:Integer = 3;
public-read def gridDim:Integer = bind boxDim*boxDim;
public-read def gridSize:Integer = bind gridDim*gridDim;
package var grid:Integer[] =
for(a in [0..<gridSize]) { 0 }
};

...

If you run the first project on the chapter you need to reconfigure your Run Configuration to set up everything for this new project, if not you need to do that from the scratch.

  • On the Run menu click Run Configurations , then select your current configuration or make a new one.

  • Select "Puzzle" project and choose the Game.fx file in the Stage field

  • Click the Run button to launch the project.

You should see a standalone Java application launch.

JavaFX project: Puzzle application

Figure 5.17. JavaFX project: Puzzle application


Chapter 6. Launching JavaFX Project

When creating a new JavaFX project the Run Configuration is set up automatically for your project, so that you don't need to configure it manually. It makes launching the project a very easy operation: you should click on the project to select it and press the Run button ( ) on the ToolBar.

In order to configure the default launching parameters of your application you need to click Run Configurations on the Run menu, select JavaFX Application, select your application configuration.

Run Configuration

Figure 6.1. Run Configuration


Another way of launching your JavaFX application with the plugin is to just select the project, right-click on it (or on script file within the project) and select Run As > Type of Application.

Launching a project

Figure 6.2. Launching a project


Moreover, having a script opened in the editor you can just call a context menu by right-clicking in the editing field and Run As > Type of Application .

Launching a project

Figure 6.3. Launching a project


6.1. Launching JavaFX Project: Desktop

If you select the Desktop profile your application can be run as:

  • Application

    Your application is run in a separate window as a standalone application.

Standalone Application

Figure 6.4. Standalone Application


  • Applet

    In case this option is selected your default browser will be pointed to an HTML file with your application as an embedded applet.

Applet

Figure 6.5. Applet


  • Java Web Start

    The application will start using Java Web Start Technology that provides an possibility for a standalone Java software applications to be deployed with a single click over the network. Java Web Start ensures the most current version of the application will be deployed, as well as the correct version of the Java.

Chapter 7. Editor Features

Exadel JavaFX Studio provides out-of-the-box an editor that can assist you in working with JavaFX projects.

7.1. Code Assist

Exadel JavaFX Studio provides a context dependent code assist/completion.

This feature is available for both script

Code Assist for Script

Figure 7.1. Code Assist for Script


and class files.

Code Assist/Completion for Class

Figure 7.2. Code Assist/Completion for Class


Code assist is available for these elements:

  • Syntax keywords

  • System classes

  • Attributes of system classes

  • User classes

  • Attributes of user classes

Alongside with code assist Exadel JavaFX Studio displays JavaFX help comments for or classes, method and attributes. The comments are shown next to the code assist box and in a box with yellow background.

JavaFX Help Comments

Figure 7.3. JavaFX Help Comments


7.2. Code Highlighting

JavaFX editor supports syntax highlighting that improves the readability of your code.

Syntax Highlighting

Figure 7.4. Syntax Highlighting


In order to identify where the block of code embraced with parentheses or curly braces starts or ends you need to place the cursor on the brace/parenthesis and you will see where the starting/ending brace/parenthesis is.

Highlighting code blocks

Figure 7.5. Highlighting code blocks


7.3. OpenOn

The editor also supports OpenOn feature that help you navigate you throughout the project: this feature turns the objects into hyper-links when you hold CTRL and hover a object. Your mouse pointer will become a hand ( ), then you can click the link to open the file where the object is stored.

JavaFX editor: OpenOn feature

Figure 7.6. JavaFX editor: OpenOn feature


7.4. Line Numbering

In order to have line numbers displayed on the left side of the JavaFX editor you need to right-click on left-hand border of the editor and check the Show Line Numbers option.

Line Numbering in Editor

Figure 7.7. Line Numbering in Editor


7.5. Compiler Error Highlighting

The Editor prevents you from making compiler error by highlighting them. The Editor verifies that you have equal number of opening and closing braces, that you typed correctly the name of the variable you had declared previously, missing semicolons and unresolved identifiers etc.

Compiler Error Highlighting

Figure 7.8. Compiler Error Highlighting


Chapter 8. Snippets

Exadel JavaFX Studio provides a rich set of code snippets that you can easily use developing your application. The palette with snippets is activated once you open a JavaFX file for editing the source code and the JavaFX perspective is also enabled. Or you can activate the Snippets view by going to Window > Show View > Other ... > General > Snippets.

Adding a JavaFX element to the Editor is simple, you just need to pick the element on the palette and drag and drop it to the editor. When you release the left mouse button to drop the element a dialog box where you can set the element's parameters will appear.

For example, we can add a blue circle to the kick start application we created in the Creating Simple JavaFX Project section of the guide.

Adding Circle Element

Figure 8.1. Adding Circle Element


Now in the Insert Template: Circle dialog you can set the parameters of the circle.

Some title

Figure 8.2. Some title


The generated code is inserted into your JavaFX file when you press the Insert button.

Circle JavaFX Code

Figure 8.3. Circle JavaFX Code


Chapter 9. Help and Other Resources

You can get help from other plunin users on the "Exadel JavaFX Studio -- Plug-In for Eclipse" forum.

Using JavaFX and Seam/Spring with Flamingo: Exadel Flamingo project page