1 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Informaion Protection Policy Classification from Slide 7
Nov 10, 2014
1 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Insert Informaion Protection Policy Classification from Slide 7
LOGO
Presenting with
JavaFX 2.1 - следующее поколение клиентской Java Александр Кузнецов
3 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Insert Informaion Protection Policy Classification from Slide 7
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.
4 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Интерфейс на Java
5 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JavaFX
6 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Демонстрация
7 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Архитектура JavaFX
Из чего состоит JavaFX?
UI Controls API
8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Архитектура JavaFX
Движок рендеринга● Высокопроизводительный● Аппаратно-ускоренный● Легковесный● Не использующий AWT или Swing
UI Controls API
9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Эффекты
10 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Эффекты
● Пример использования
node.setEffect(new BoxBlur(10, 10, 2));
11 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Трансформации
12 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Трансформации
● Пример использования
node.setRotate(node.getRotate() + 90);
13 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
3D-трансформации
14 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
3D-трансформации
Пример использования
Scene scene = new Scene(root, 500, 500, true);scene.setCamera(new PerspectiveCamera());...node.setRotationAxis(Rotate.Y_AXIS);node.setRotate(node.getRotate() + 20);
15 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Граф сцены (Scene graph)● Направленный связный ацикличный граф● Задает структуру графических компонентов:
● порядок отрисовки● порядок обработки событий● эффекты и трансформации
Parent
Sceneroot
children
сверхуснизу
16 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Анимация
Animation
Transition Timeline
FadeTransition, FillTransition, ParallelTransition, PathTransition, PauseTransition, RotateTransition,
ScaleTransition, SequentialTransition, StrokeTransition, TranslateTransition
17 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Анимация: Transitions
18 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Анимация: Transitions
● Пример использования:
RotateTransitionBuilder.create() .node(node) .byAngle(90) .build().play();
19 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Fluent API
RotateTransition rotateTransition = new RotateTransition();rotateTransition.setNode(node);rotateTransition.setByAngle(90);rotateTransition.play();
● Пример использования:
RotateTransitionBuilder.create() .node(node) .byAngle(90) .build().play();
20 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Анимация: Transitions● ParallelTransition, SequentialTransition, PauseTransition
ParallelTransitionBuilder.create() .cycleCount(Timeline.INDEFINITE) .autoReverse(true) .node(duke) .children( TranslateTransitionBuilder.create() .byY(50) .build(), FadeTransitionBuilder.create() .toValue(0) .build() ) .build().play();
21 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Анимация: Timeline
0s 1s 2s 3s 4s 5s 6s
Key valuex = 0 x = 100
Keyframes
Как значения изменяются во времени
TimelineBuilder.create() .keyFrames( new KeyFrame(Duration.seconds(0), new KeyValue(x, 0), ...), new KeyFrame(Duration.seconds(5), new KeyValue(x, 100), ...), ...).build();
22 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Анимация: Interpolators
23 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Свойства (Properties)
● Обычное свойство
private int radius = DEFAULT_RADIUS;
public int getRadius() { return radius; } public void setRadius(int radius) { this.radius = radius; }
24 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Свойства (Properties)
● JavaFX свойство:
private IntegerProperty radius = new SimpleIntegerProperty(DEFAULT_RADIUS); public int getRadius() { return radius.get(); } public void setRadius(int radius) { this.radius.set(radius); } public IntegerProperty radiusProperty() { return radius; }
25 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Простое связывание (Binding)
● В одну сторону: IntegerProperty x = new SimpleIntegerProperty(); IntegerProperty y = new SimpleIntegerProperty(); x.bind(y.add(5)); // x bind y + 5
● В обе стороны: IntegerProperty z = new SimpleIntegerProperty(); z.bindBidirectional(y); // z bind y with inverse
26 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Сложное связывание (Binding)
● Сложное связывание: Label label = new Label(); label.textProperty().bind(new ObjectBinding<String>() { { bind(x, z); } @Override protected String computeValue() { return x.get() == z.get() ? "Значения равны" : "x = " + x.get() + ", z = " + z.get(); } });
● Полный контроль над связыванием● unbind(), addListener(), removeListener(), isBound()
27 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Демонстрация
28 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Архитектура JavaFX
● Видео ● Аудио
UI Controls API
29 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Поддержка мультимедиа
● H.264 в JavaFX 2.1● кодеки VP6, MP3● полноэкранное видео● канал прозрачности● полностью интегрировано в графическую систему● мгновенное воспроизведение звуков (low latency)
30 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Демонстрация
31 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Архитектура JavaFX
● HTML 5.0● взаимодействие JavaScript и JavaFX● доступ к содержимому страницы
UI Controls API
32 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Демонстрация
33 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Архитектура JavaFX
Библиотека компонентов для построения графического пользовательского интерфейса
● написаны на JavaFX● открытый исходный код
http://openjdk.java.net/projects/openjfx/
UI Controls API
34 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
UI Controls API
● Анимированные диаграммы● Менеджеры расположения
компонентов● Стилизация при помощи CSS
35 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Демонстрация
36 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Что ещё?
● Java API● Средства разработки, отладки и тестирования● Взаимодействие с Swing и SWT● Развертывание (Deployment)● Что нового в версии JavaFX 2.1?
37 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java API
все возможности языка Java:● шаблоны● многопоточность● аннотации● доступен из любого JVM языка:
Ruby, Scala, Groovy
38 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Средства
● разработка:● любые Java IDE: NetBeans, Eclipse, IDEA
● отладка:● любые средства для языка Java
● тестирование: ● Jemmy3 http://jemmy.java.net/
39 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Scene Builder
● Подробнее в докладе Сергея Гринева
40 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
FXMLexample.fxml:...<GridPane id="gridPane1" ...> <children> <Label id="label1" text="Имя" ... /> <TextField id="textField1" ... />...
example.java:... Parent root = FXMLLoader.load( getClass().getResource("example.fxml")); stage.setScene(new Scene(root));...
41 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JavaFX в Swing и SWT приложениях
public class JFXPanel extends javax.swing.JComponent { … void setScene(Scene newScene) {...} …}public class FXCanvas extends org.eclipse.swt.widgets.Canvas { … void setScene(Scene newScene) {...} …}
42 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Развертывание
➔ JAR-файл➔ JNLP➔ Апплет
43 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Что будет в JavaFX 2.1
● поддержка Mac OS● beta-поддержка Linux● JavaScript -> Java вызовы● а также:
● улучшения в FXML, в рендеринге шрифтов, в SplitPane, в классах Task и Service, в поддержке меню приложения
● новые диаграммы, новый компонент ComboBox● поддержка форматов AAC, H.264/MPEG
44 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Возможности JavaFX
● Богатая графика и анимация● Мультимедиа● HTML 5.0● UI-элементы● FXML и CSS● Апплет/JNLP/JAR● Интеграция со Swing и SWT
45 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Демонстрация
46 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Ссылки
● JavaFX http://javafx.com● Примеры:
http://www.oracle.com/technetwork/java/javafx/samples/index.html
● JavaFX и Scala http://code.google.com/p/scalafx/● JavaFX и Groovy http://groovyfx.org/
47 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.