-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEffectsAndTransformDemo.java
More file actions
118 lines (95 loc) · 3.8 KB
/
EffectsAndTransformDemo.java
File metadata and controls
118 lines (95 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import javafx.application.*;
import javafx.scene.*;
import javafx.stage.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.event.*;
import javafx.geometry.*;
import javafx.scene.transform.*;
import javafx.scene.effect.*;
import javafx.scene.paint.*;
public class EffectsAndTransformDemo extends Application {
double angle = 0.0;
double angleTranslate = 0.0;
double scaleFactor = 0.4;
double blurVal = 1.0;
double glowFactor = 0.1;
Reflection reflection = new Reflection();
BoxBlur blur = new BoxBlur(1.0, 1.0, 1);
Rotate rotate = new Rotate();
Scale scale = new Scale(scaleFactor, scaleFactor);
Glow glow = new Glow(0.1);
Translate translate = new Translate();
Button btnRotate = new Button("Rotate");
Button btnBlur = new Button("Blur off");
Button btnScale = new Button("Scale");
Button btnGlow = new Button("Glow");
Button btnTranslate = new Button("Translate");
Label reflect = new Label("Reflection Adds Visual Sparcle");
public static void main(String args[]) {
launch(args);
}
public void start(Stage myStage) {
myStage.setTitle("Effects and Transforms Demo");
FlowPane rootNode = new FlowPane(20, 20);
rootNode.setAlignment(Pos.CENTER);
Scene myScene = new Scene(rootNode, 300, 120);
myStage.setScene(myScene);
btnRotate.getTransforms().add(rotate);
btnTranslate.getTransforms().add(translate);
btnScale.getTransforms().add(scale);
btnGlow.setEffect(glow);
reflection.setTopOpacity(0.7);
reflection.setBottomOpacity(0.3);
reflect.setEffect(reflection);
btnRotate.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent ae) {
angle += 15.0;
rotate.setAngle(angle);
rotate.setPivotX(btnRotate.getWidth()/2);
rotate.setPivotY(btnRotate.getHeight()/2);
}
});
btnTranslate.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent ae) {
angleTranslate += 15.0;
if(angleTranslate > 150) angleTranslate = 0.4;
translate.setX(angleTranslate);
translate.setY(angleTranslate);
translate.setZ(angleTranslate);
}
});
btnScale.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent ae) {
scaleFactor += 0.1;
if(scaleFactor > 2.0) scaleFactor = 0.4;
scale.setX(scaleFactor);
scale.setY(scaleFactor);
}
});
btnGlow.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent ae) {
glowFactor += 0.1;
if(glowFactor > 1.0) glowFactor = 0.1;
glow.setLevel(glowFactor);
}
});
btnBlur.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent ae) {
if(blurVal == 10.0) {
blurVal = 1.0;
btnBlur.setEffect(null);
btnBlur.setText("Blur off");
} else {
blurVal++;
btnBlur.setEffect(blur);
btnBlur.setText("Blur on");
}
blur.setWidth(blurVal);
blur.setHeight(blurVal);
}
});
rootNode.getChildren().addAll(btnRotate, btnScale, btnBlur, btnGlow, btnTranslate, reflect);
myStage.show();
}
}