enterprising javafx

47
Enterprising JavaFX Richard & Jasper (and Tor!) Sun Microsystems

Upload: richard-bair

Post on 11-Apr-2017

127 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Enterprising JavaFX

Enterprising JavaFXRichard & Jasper (and Tor!)

Sun Microsystems

Page 2: Enterprising JavaFX

ww

w.d

evox

x.co

m

Overall presentation goal

Show that JavaFX can rock in the enterprise!

Page 3: Enterprising JavaFX

ww

w.d

evox

x.co

m

Speaker’s qualifications

Core Engineers on JavaFX at Sun Microsystems

Jasper is the design wizard for FX and author of the Charts API

Richard is API design lead for FX, UI Controls lead, and key scenegraph developer

Both write lots of cool stuff

Page 4: Enterprising JavaFX

ww

w.d

evox

x.co

m

Agenda

Web Services

Controls

Styling

Tooling

Page 5: Enterprising JavaFX

ww

w.d

evox

x.co

m

Web Services

Page 6: Enterprising JavaFX

ww

w.d

evox

x.co

m

Many Choices

HTTP JSON

XML

JDBC

JAX-*SOAP

REST

XML-RPC

Page 7: Enterprising JavaFX

ww

w.d

evox

x.co

m

Threading

All data access should occur on background thread

JavaFX Script is currently single threadedNever create JavaFX objects on a background thread!

Use the Task APISubclass from JavaTaskBase

Page 8: Enterprising JavaFX

ww

w.d

evox

x.co

m

Task

Create the task

Initialize callbacks

Bind to state you want to observe

Start it

Page 9: Enterprising JavaFX

ww

w.d

evox

x.co

m

Read-only Variables

started

stopped

failed

succeeded

done

percentDone

Page 10: Enterprising JavaFX

ww

w.d

evox

x.co

m

Events

onStart

onDone

Page 11: Enterprising JavaFX

ww

w.d

evox

x.co

m

Functions

start

stop

Page 12: Enterprising JavaFX

ww

w.d

evox

x.co

m

JavaTaskBase

Used for all custom Tasks

create():RunnableFuture*

Page 13: Enterprising JavaFX

ww

w.d

evox

x.co

m

Writing a Custom Task

Step 1: Subclass from JavaTaskBase

Step 2: Create a Java implementation peer

Step 3: Callback from the peer to the task on completion

Step 4: Create FX objects, do FX work on the FX thread

Page 14: Enterprising JavaFX

Step 1: Subclass

public class LoginTask extends JavaTaskBase { public-init var username:String; public-init var password:String;

public-read var token:String; }

Page 15: Enterprising JavaFX

Step 2: Create Peer

public class LoginTaskImpl implements RunnableFuture { private JiraSoapService jira; private String username; private String password; String token;

public LoginTaskImpl(JiraSoapService jira, String username, String password) { this.jira = jira; this.username = username; this.password = password; }

public void run() throws Exception { token = jira.login(username, password); } }

Page 16: Enterprising JavaFX

Step 3: Callback

public class LoginTask extends JavaTaskBase, FinishedHandler { ... var impl:LoginTaskImpl;

override protected function create():RunnableFuture { impl = new LoginTaskImpl(jira, this, username, password) } }

Page 17: Enterprising JavaFX

Step 3: Callbackpublic class LoginTaskImpl implements RunnableFuture { ... private FinishedHandler handler;

public LoginTaskImpl(JiraSoapService jira, FinishedHandler handler, String username, String password) { ... this.handler = handler; }

public void run() throws Exception { token = jira.login(username, password); handler.backgroundWorkFinished(); } }

Page 18: Enterprising JavaFX

Step 4: FX

public class LoginTask extends JavaTaskBase, FinishedHandler { ... override public function backgroundWorkFinished():Void { FX.deferAction(function():Void { token = impl.token; }); } }

Page 19: Enterprising JavaFX

www.devoxx.com

DEMO

Page 20: Enterprising JavaFX

ww

w.d

evox

x.co

m

Controls

Page 21: Enterprising JavaFX

ww

w.d

evox

x.co

m

Our Goals

Simple

Useful

Rich

Page 22: Enterprising JavaFX

Control

Behavior

Skin

The Design

Page 23: Enterprising JavaFX

ww

w.d

evox

x.co

m

Controls :: The FamilyButton

ToggleButton

RadioButton

CheckBox

Slider

Label

Hyperlink

ProgressIndicator

ProgressBar

TextBox

ListView

TreeView*

PasswordBox*

ChoiceButton*

MenuButton*

SplitMenuButton*

Menus*

ToolBar*

ScrollBar*

ScrollView*

Multiline TextBox*

Horizontal ListView*

Popup*

Tooltip*

Page 24: Enterprising JavaFX

ww

w.d

evox

x.co

m

Controls :: The FamilyButton

ToggleButton

RadioButton

CheckBox

Slider

Label

Hyperlink

ProgressIndicator

ProgressBar

TextBox

ListView

TreeView*

PasswordBox*

ChoiceButton*

MenuButton*

SplitMenuButton*

Menus*

ToolBar*

ScrollBar*

ScrollView*

Multiline TextBox*

Horizontal ListView*

Popup*

Tooltip*

Page 25: Enterprising JavaFX

ww

w.d

evox

x.co

m

Progress Indicator

Small circular progress indicator

Bind directly to task.percentDone

Example:

var task = CustomTask { ... } ProgressIndicator { progress: bind task.percentDone }

Page 26: Enterprising JavaFX

ww

w.d

evox

x.co

m

TextBox

Single or Multiline (single style) text input

Useful for building other controlslike a search box

Example: var t:TextBox = TextBox { promptText: “Search” action: function() { startSearch(t.text); t.text = “”; } }

Page 27: Enterprising JavaFX

ww

w.d

evox

x.co

m

ListView

Horizontal or Vertical

Massively Scalable

Custom CellsDynamically variable row heights

Animated cells

Page 28: Enterprising JavaFX

Standard ListView

var list = ListView { items: [“Apples”, “Oranges”, “Pears”] }

Page 29: Enterprising JavaFX

Custom Cell

var list = ListView { items: [“Apples”, “Oranges”, “Pears”] cellFactory: function() { ListCell { node: ... } } }

Page 30: Enterprising JavaFX

ww

w.d

evox

x.co

m

Cell

Cell has 3 layersBackground

Node

Foreground

Specialize any of these 3 layers

ListCell, TreeCell, TableCell

Page 31: Enterprising JavaFX

www.devoxx.com

DEMO

Page 32: Enterprising JavaFX

ww

w.d

evox

x.co

m

Styling

Page 33: Enterprising JavaFX

ww

w.d

evox

x.co

m

Styling

Easy and Powerful (CSS)

Highly Customized (fxz)

Complete Control (code)

Page 34: Enterprising JavaFX

ww

w.d

evox

x.co

m

Styling

Easy and Powerful (CSS)

Highly Customized (fxz)

Complete Control (code)

Page 35: Enterprising JavaFX

CSS

Page 36: Enterprising JavaFX

ww

w.d

evox

x.co

m

CSS

CSS is our strategy for styling. If you use our UI Controls, you use CSS.

Caspian is our default CSS stylesheet

CSS is fast, and works on mobile, desktop, and tv

Stick to the spirit of HTML CSS, but do not be bound by it

Page 37: Enterprising JavaFX

ww

w.d

evox

x.co

m

Regions

Break control skins in stylable parts

In some ways similar to HTML CSS’s Box but not that same

Can be Rectangle with independently rounded corners or any arbitrary path

Can have multiple background fills, background images, border strokes and border images

Page 38: Enterprising JavaFX

Regions: Background Fills

Page 39: Enterprising JavaFX

Regions: Stroke Borders

Page 40: Enterprising JavaFX
Page 41: Enterprising JavaFX

Regions: ScrollBar

ScrollBar RegionThumb RegionTrack RegionLeft Button Region Right Button Region

Left Arrow Region Right Arrow Region

Page 42: Enterprising JavaFX

www.devoxx.com

DEMO

Page 43: Enterprising JavaFX

ww

w.d

evox

x.co

m

Tooling

Page 44: Enterprising JavaFX

ww

w.d

evox

x.co

m

JavaFX Authoring Tool

Lead Engineer: Tor Norbye

Tool for creating JavaFX Content

Built completely on top of JavaFX and Controls

Page 45: Enterprising JavaFX

www.devoxx.com

DEMO

Page 46: Enterprising JavaFX

ww

w.d

evox

x.co

m

Summary

JavaFX is serious about the enterpriseit is what we do

Many additional controls coming in next release

Extensive support for styling controls

Page 47: Enterprising JavaFX

ww

w.d

evox

x.co

m

Thanks for your attention!

http://fxexperience.com

http://javafx.com