Cover
Contents at a Glance
Contents
Foreword
About the Authors
About the Technical Reviewer
Acknowledgments
Getting a Jump Start in JavaFX
JavaFX Can’t Bring Rich-Client Java Back by Itself
A Brief History of JavaFX
Going to the Source: Oracle’s JavaFX Web Site
Accessing the JavaFX SDK API
Obtaining the JavaFX SDK
Other Available Tools
Developing Your First JavaFX Program: “Hello Earthrise”
Compiling and Running from the Command-Line
Understanding the Hello Earthrise Program
Building and Running the Program with NetBeans
Developing Your Second JavaFX Program: “More Cowbell!”
Building and Running the Audio Configuration Program
The Behavior of the Audio Configuration Program
Understanding the Audio Configuration Program
Creating an Instance of the Model, and the Magic of Binding
Colors and Gradients
The Model Class for the Audio Configuration Example
Defining Change Listeners in the Model class
Surveying JavaFX Features
Summary
Resources
Creating a User Interface in JavaFX
Introduction to Node-Centric UIs
Setting the Stage
Understanding the Stage Class
Using the Stage Class: The StageCoach Example
Understanding the StageCoach Program
Obtaining Program Arguments
Setting the Style of the Stage
Controlling Whether a Stage Is Resizable
Making a Stage Full Screen
Working with the Bounds of the Stage
Drawing Rounded Rectangles
Dragging the Stage on the Desktop When a Title Bar Isn’t Available
Using UI Layout Containers
Ascertaining Whether the Stage Is in Focus
Controlling the Z-Order of the Stage
Closing the Stage and Detecting When It Is closed
Making a Scene
Using the Scene Class: The OnTheScene Example
Understanding the OnTheScene Program
Setting the Cursor for the Scene
Painting the Scene’s Background
Populating the Scene with Nodes
Finding a Scene Node by ID
Accessing the Stage from the Scene
Inserting a Node into the Scene’s Content Sequence
CSS Styling the Nodes in a Scene
Handling Input Events
Surveying Mouse and Keyboard Events and Handlers
Understanding the KeyEvent Class
Understanding the MouseEvent Class
Animating Nodes in the Scene
Using a Timeline for Animation
The Metronome1 Example
Understanding the Metronome1 program
Understanding the Timeline Class
Inserting Key Frames into the Timeline
Controlling and Monitoring the Timeline
Using the Transition Classes for Animation
The MetronomeTransition Example
The Behavior of the MetronomeTransition Program
Understanding the MetronomeTransition Program
Using the TranslateTransition Class
Controlling and Monitoring the Transition
The MetronomePathTransition Example
The Behavior of the MetronomePathTransition Program
Understanding the MetronomePathTransition Program
Using the PathTransition Class
Drawing an Ellipse
The Zen of Node Collision Detection
Understanding the ZenPong Program
Using the KeyFrame Action Event Handler
Using the Node intersects() Method to Detect Collisions
Dragging a Node
Giving Keyboard Input Focus to a Node
Using the onKeyPressed Event Handler
Summary
Resources
Properties and Bindings
Forerunners of JavaFX 2.0 Binding
A Motivating Example
Understanding Key Interfaces and Concepts
Understanding the Observable Interface
Understanding the ObservableValue Interface
Understanding the WritableValue Interface
Understanding the ReadOnlyProperty Interface
Understanding the Property Interface
Understanding the Binding Interface
Type-Specific Specializations of Key Interfaces
A Common Theme for Type-Specific Interfaces
Commonly Used Classes
Creating Bindings
Understanding the Bindings Utility Class
Understanding the Fluent Interface API
Understanding the JavaFX Beans Convention
The JavaFX Beans Specification
Understanding the Eagerly Instantiated Properties Strategy
Understanding the Lazily Instantiated Properties Strategy
Using Selection Bindings
Summary
Resources
Building Dynamic UI Layouts in JavaFX
Introducing JavaFX Reversi
Board Layout and Basic Rules
Building a JavaFX Model for Reversi
Dynamic Layout Techniques
Centering Text Using Bind
Centering Revisited Using a StackPane
Aligning to Edges Using StackPanes and TilePanes
Using FlowPane and Boxes for Directional Alignment
Composing a Layout Using BorderPane
Creating Custom Regions
Building a Custom Square Region
Building a Resizable Reversi Piece
Laying Out the Tiles Using a GridPane
Aligning and Stretching with AnchorPane
When to Use Different Layouts
A New Perspective on Reversi: The JavaFX 3D Scene Graph
Bringing Reversi to Life
Highlighting Legal Moves
Highlighting the Active Cell
Taking Turns
Additional Game Enhancements
Summary
Resources
Using the JavaFX UI Controls
Trying Out the JavaFX UI Controls
Leveraging the JavaFX UI Controls
Setting the Stage for the StarterApp Program
Creating a Menu and Defining Menu Items
Creating a Toolbar
Defining Graphical Buttons
Defining Toggle Buttons
Using Toggle Groups
Inserting a Separator into a Toolbar
Creating a TabPane and Defining Tabs
Creating a TableView
Assigning Items to a Table
Defining TableView Columns
Detecting When a Row Is Selected
Creating an Accordion and Defining a TitledPane
Creating a TreeView
Defining a TreeItem
Detecting When a TreeItem Is Selected
Creating a ListView and Assigning Items to a ListView
Creating a SplitPane
Defining a ScrollPane
Using a CheckBox
Defining a RadioButton
Creating a Hyperlink
Defining a ChoiceBox
Using a MenuButton
Creating a ContextMenu
Creating a SplitMenuButton
Defining a TextField
Using a PasswordField
Creating a TextArea
Creating a Slider
Defining a ProgressIndicator
Defining a ScrollBar
Using a ProgressBar
Creating an HTMLEditor
Creating a Popup
Using a WebView
Summary
Resources
Collections and Concurrency
Understanding Observable Collections
Understanding ObservableList
Handling Change Events in ListChangeListener
Understanding ObservableMap
Using Factory and Utility Methods from FXCollections
Using the JavaFX Concurrency Framework
Identifying the Threads in a JavaFX Application
Fixing Unresponsive UIs
Understanding the javafx.concurrent Framework
Understanding the Worker Interface
Understanding the Task Abstract Class
Understanding the Service Abstract Class
Embedding JavaFX Scenes in Swing and SWT Applications
Summary
Resources
Creating Charts in JavaFX
Structure of the JavaFX Chart API
Using the JavaFX PieChart
The Simple Example
Some Modifications
Using the XYChart
Using the ScatterChart
A Simple Implementation
Improving the Simple Implementation
Using the LineChart
Using the BarChart
Using the AreaChart
Using the BubbleChart
Summary
Resources
Using the Media Classes
The Foundation
Supported Media Formats
Working with Audio Clips
Controlling the Playback Parameters of an AudioClip
Constructing the Scene
AudioClip Wrap-Up
Working with Media
Playing Audio
Error Handling
Displaying Metadata
Loading Media
Controlling Playback
Laying Out the Player Controls
Creating Playback Controls
Seeking
Controlling Volume
Repetition
Audio Equalization
MediaPlayer Wrap-Up
Playing Video
Controlling the Size of a MediaView
MediaView and Effects
Using Markers
One Player, Multiple Views
Converting AudioPlayer into a VideoPlayer
Summary
Accessing Web Services
Front-end and Back-end Platforms
Merging JavaFX and Java Enterprise Modules in the Same Environment
Using JavaFX to Call Remote (Web) Services
SOAP
REST
Setting Up the Application
Using the Twitter API
Using External Libraries
Summary
JavaFX Languages and Markup
A Quick Comparison of Alternative Languages
Vanishing Circles in Java
Vanishing Circles in Alternative JVM Languages
Making Your JavaFX Groovy
Introduction to GroovyFX
Properties in GroovyFX
GroovyFX Binding
GroovyFX API Enhancements
Animation
Tables
Layouts
Scala and JavaFX
Getting Started with ScalaFX
ScalaFX Proxies and Implicit Conversions
JavaFX Properties in Scala
ScalaFX Bind APIs
API Enhancements
Closures
Layout Constraints
Animation
Visage, the JavaFX Language
Advantages of Using Visage
Getting Started with Visage
Constructing UIs with FXML Markup
Learning FXML by Example
Controlling FXML Applications
Summary
Resources
The Visage Language in Depth
An Overview of Visage
Variables, Values, and Their Types
Variable Names
Variable Types
Primitive Types
Boolean Type
Boolean Literals and the Default Value
Boolean Operators
The Backing Class of the Boolean Type
Integer Type
Integer Literals and the Default Value
Arithmetic Operators
The Backing Class of the Integer Type
Character Type
Sources of Character Values and the Default Value
Arithmetic Operations
The Backing Class of the Character Type
Byte, Short, and Long Types
Sources of Byte and Short Values, Long Literals, and the Default Values
Arithmetic Operations
The Backing Classes of the Byte, Short, and Long Types
Float and Number Types
Number Literals and the Default Value
Arithmetic Operations
The Backing Class of the Number Type
Double Types
Double Literals and the Default Value
The Backing Class of the Double Type
String Type
String Literals and the Default Value
String Expressions
The Backing Class of the String Type
Duration Type
Duration Literals and the Default Value
Arithmetic Operations Involving Durations
The Backing Class of the Duration Type
Length Type
Length Literals and the Default Value
Core Types of Length Literals
Length Arithmetic and Conversions
The Backing Class of the Length Type
Angle Type
Angle Literals and the Default Value
Angle Arithmetic and Conversions
The Backing Class of the Angle Type
Color Type
Color Literals and the Default Value
Color Arithmetic
The Backing Class of the Color Type
Working with Sequences
Sequence Types
Constructing Sequences Using Explicit Sequence Expressions
Constructing Numeric Sequences Using Range Expressions
Manipulating Sequences
Accessing the Size of a Sequence
Accessing an Element in a Sequence
Accessing a Slice of a Sequence
Accessing a Subset of a Sequence Through a Predicate
Reversing a Sequence
Inserting an Element into a Sequence
Inserting Another Sequence into a Sequence
Deleting Elements from a Sequence
Sequence Manipulation Example
Comprehending Sequences
Using Utility Functions in visage.util.Sequences
Visage Expressions
Expressions and Their Types
Block Expression
Precedence and Groupings
Expression Separator
Variable and Constant Declarations
Assignment Operator
Compound Assignment Operators
Relational Operators
While Expression
Revisiting the for Expression
If Expression
Object Literals
Classes and Objects
The Object Literal Expression
Initializing Instance Variables
Default Instance Variables
Declaring Constants and Variables
Overriding Instance Functions and Instance Variables
Manipulating Objects
Manipulating Object States
Invoking Instance Functions
Handling Nulls in Visage
Creating Java Objects with the new Operator
Making of a Declarative Syntax
Working with Data Bindings
Bind Expression
What Does the Data Binding Remember?
Binding to if Expressions
Binding to for Expressions
Binding to a Block
Binding to Function Invocation Expressions
Binding to Object Literal Expressions
Bidirectional Bindings and Lazy Bindings
Working with Functions
Function Definitions
Return Types
Parameters and Their Types
Function Bodies and the Return Expression
Function Body Scope
Overloaded Functions
Implicit Type Conversions
Resolving Overloaded Functions
Function Types and Anonymous Functions
More Details on Function Type Specifiers
More Details on Anonymous Function Expressions
More Details on Closures
Bound Functions
Handling Exceptions
The Call Stack
Throwing Exceptions
Handling Exceptions
Working with Classes
Class Definitions
Instance Variables
Declaring Default Instance Variables
Instance Functions
The this Expression
init Blocks
Creating Class Hierarchies
Mix-in Classes
Extending Classes
Overriding Instance Variables
Overriding Instance Functions
The super Keyword
Using Abstract and Mix-in Classes
Conflict Resolution in Mix-in Inheritance
Casting and the instanceof and as Operators
Organizing Visage Code
Scripts
Modules
A Special Provision for Classes
Packages
Import Directives
Access Modifiers
Protected Modifiers
public-init and public-read Modifiers
Triggers
Accessing the Old and New Values in Trigger Blocks
Accessing Sequence Modification Information in Trigger Blocks
Debugging with Triggers
String Formatting and Internationalization
Using String Format Specifications
Internationalizing Visage Programs
Leveraging Java from Visage
Instantiating Java Classes
Accessing Java Object Fields
Calling Java Methods
Accessing Static Fields and Methods
Quoting Visage Keywords
Accessing Nested Classes
Accessing Java Enums
Extending Java Classes and Interfaces
Dealing with Java Arrays
Iterating Through Java Collections
Visage Reflection
Mirror-Based Reflection
Entering the Reflection World
Programming Through Reflection
Getting and Setting Values of Instance and Script Variables
Invoking Instance and Script Functions
Other Reflection Capabilities
Resources
Index
A
B
C
E
F
G
H
I
J
K
L
M
O
S
T
U
V
W, X, Y, Z