52
Scratching the Surface with JavaFX Jim Weaver Java Technology Ambassador Oracle Corporation @JavaFXpert [email protected]

Scratching the Surface with JavaFX

Embed Size (px)

DESCRIPTION

One of the very interesting and useful platforms for JavaFX is touch enabled devices such as Windows 8 tablets. This session will demonstrate a variety of JavaFX applications running on a Surface Windows 8 Pro, pointing out capabilities in JavaFX designed to leverage touch capabilities.

Citation preview

Page 1: Scratching the Surface with JavaFX

Scratching the Surface with JavaFX

Jim Weaver

Java Technology Ambassador

Oracle Corporation

@JavaFXpert

[email protected]

Page 2: Scratching the Surface with JavaFX

Multi-touch considerations for JavaFX

Touch Gestures

– Swipe, Scroll, Rotate, Zoom

Touch Event and Touch Points

The Pagination Control

Accommodating Fingers

Introduction to JavaFX 3D

Example app: ZenGuitar3D

Page 3: Scratching the Surface with JavaFX

3

Please note

The following is intended to outline our general product

direction. It is intended for information purposes only, and

may not be incorporated into any contract. It is not a

commitment to deliver any material, code, or functionality,

and should not be relied upon in making purchasing

decisions. The development, release, and timing of any

features or functionality described for Oracle’s products

remains at the sole discretion of Oracle.

Page 4: Scratching the Surface with JavaFX

Touch Gestures

Page 5: Scratching the Surface with JavaFX

The Swipe Gesture

Commonly a finger drag in one direction

A single event is produced for the gesture

May be left, right, up, or down

Page 6: Scratching the Surface with JavaFX

Handling the Swipe Gesture (SwipeEvent)

Note: Lambda expressions from JDK 8 are used here to simplify event handling

Page 7: Scratching the Surface with JavaFX

Handling the Swipe Gesture (SwipeEvent)

Page 8: Scratching the Surface with JavaFX

The Scroll Gesture

User turns mouse wheel, drags finger on

touch screen, etc.

Scroll events are continuously generated,

containing x/y position-related info

Events are pixel-based or character/line-

based

If inertia is supported, scroll events may

be generated after user quits scrolling

Page 9: Scratching the Surface with JavaFX

Handling the Scroll Gesture (ScrollEvent)

Page 10: Scratching the Surface with JavaFX

The Rotate Gesture

User typically drags two fingers around

each other

Rotate events are continuously generated,

containing angle-related info

Page 11: Scratching the Surface with JavaFX

Handling the Rotate Gesture (RotateEvent)

Page 12: Scratching the Surface with JavaFX

The Zoom Gesture

User typically drags two fingers apart or

closer together

Zoom events are continuously generated,

containing zoom factor-related info

Page 13: Scratching the Surface with JavaFX

Handling the Zoom Gesture (ZoomEvent)

Page 14: Scratching the Surface with JavaFX

Touch Event and Touch Points

Thomas Laenner - http://thomas.laenner.dk/

Page 15: Scratching the Surface with JavaFX

Handling Touch (TouchEvent/TouchPoint)

A TouchEvent contains information about

a touch, including:

– Event type: Pressed, released, moved, or

stationary

– Touch points: The TouchPoint instances

that represent each of the points that were

touched

Each TouchEvent has a unique ID to identify the

events and touch points in a multi-touch action

Page 16: Scratching the Surface with JavaFX

Responding to Touch Events

Page 17: Scratching the Surface with JavaFX

A Touch Demo from the JavaFX Community

Touchyfxy app by Danno Ferrin http://speling.shemnon.com/

Touchfxy is an open source JavaFX

application developed by Danno Ferrin to

demonstrate gestures and touch events

To obtain Touchfxy, see Danno’s blog at

http://speling.shenmon.com

Page 18: Scratching the Surface with JavaFX

The Pagination Control

Page 19: Scratching the Surface with JavaFX

Using the Pagination Control

The Pagination control is used for

navigation between pages

Each page is a Node subclass

Numeric page indicators, or bullet-style

indicators, may be set with the style class STYLE_CLASS_BULLET

Page 20: Scratching the Surface with JavaFX

Using the Pagination Control

Page 21: Scratching the Surface with JavaFX

Accommodating Fingers

Page 22: Scratching the Surface with JavaFX

Making UI Controls Larger for Touching

The default sizes for

JavaFX UI controls are

conducive to using a

mouse as a pointing device

An easy way to modify the

default sizes is to use CSS

Page 23: Scratching the Surface with JavaFX

Making UI Controls Larger for Touching

Specify an -fx-font-size

property in the #root selector

Page 24: Scratching the Surface with JavaFX

Introduction to JavaFX 3D

Page 25: Scratching the Surface with JavaFX

“JavaFX 3D gives you the ability to use 3D geometry, cameras, and lights in JavaFX.”

Page 26: Scratching the Surface with JavaFX

Mesh Geometry (3D Shapes)

■ Predefined shapes

■ Box

■ Cylinder

■ Sphere

■ User-defined shapes

■ Using TriangleMesh / MeshView

26

Page 27: Scratching the Surface with JavaFX

27

Creating Primitive Shapes and Materials

Page 28: Scratching the Surface with JavaFX

3D Materials and Textures

■ PhongMaterial has these properties

■ Ambient color

■ Diffuse color, diffuse map

■ Specular color, specular map

■ Specular power

■ Bump map

■ Self-illumination map

28

https://wikis.oracle.com/display/OpenJDK/3D+Features

Page 29: Scratching the Surface with JavaFX

Duke’s nose has a Diffuse Map texture

29

Page 30: Scratching the Surface with JavaFX

This planet has a Bump Map texture

30

Page 31: Scratching the Surface with JavaFX

UV Mapping Textures to Shapes

31

Tip: A texture is a 2D image to be mapped on a 3D surface

Source: http://en.wikipedia.org/wiki/File:UVMapping.png

Page 32: Scratching the Surface with JavaFX

Placing a Texture on a Sphere

32

Page 33: Scratching the Surface with JavaFX

Placing a Texture on a Sphere

33

Page 34: Scratching the Surface with JavaFX

3D Lights

■ Lights are nodes in the scene graph

■ PointLight

■ AmbientLight

■ Default light provided if no active lights

34

Page 35: Scratching the Surface with JavaFX

35

Lights, Camera, Action!

Page 36: Scratching the Surface with JavaFX

Example multi-touch app: ZenGuitar3D

Page 37: Scratching the Surface with JavaFX

37

Showing the Picker (TouchEvent)

Page 38: Scratching the Surface with JavaFX

38

Rotating Instrument Picker with Scroll Gesture

Page 39: Scratching the Surface with JavaFX

39

Playing Strings (TouchEvent / TouchPoint)

Page 40: Scratching the Surface with JavaFX

40

Switching Modes (TouchPoint#belongsTo)

Page 41: Scratching the Surface with JavaFX

41

Setting up to Rotate on Three Axes

Page 42: Scratching the Surface with JavaFX

42

Using Scroll Gesture for X/Y Rotate

Page 43: Scratching the Surface with JavaFX

43

Using Rotate Gesture for Z Rotate

Page 44: Scratching the Surface with JavaFX

44

Using Zoom Gesture for Scaling

Page 45: Scratching the Surface with JavaFX

45

Using Timeline to Transform to Home Position

Page 46: Scratching the Surface with JavaFX

46

ZenGuitar3D Uses the JFugue5 Library

■ An open-source Java API for

programming music without the

complexities of MIDI

■ Developed by David Koelle

■ Available at http://JFugue.org

Page 47: Scratching the Surface with JavaFX

47

Start Here: http://javafxcommunity.com

Page 48: Scratching the Surface with JavaFX

48

Download JDK 8 Early Access Release

Page 49: Scratching the Surface with JavaFX

49

Visit Here: http://fxexperience.com

Tip: This site is authored by Oracle JavaFXEngineers

Page 50: Scratching the Surface with JavaFX

Questions?

Page 51: Scratching the Surface with JavaFX

Scratching the Surface with JavaFX

Jim Weaver

Java Technology Ambassador

Oracle Corporation

@JavaFXpert

[email protected]

Page 52: Scratching the Surface with JavaFX