-
Notifications
You must be signed in to change notification settings - Fork 5
/
SwingSample.java
89 lines (78 loc) · 2.86 KB
/
SwingSample.java
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
package net.kurobako.gesturefx.sample;
import net.kurobako.gesturefx.GesturePane;
import net.kurobako.gesturefx.sample.SamplerController.Sample;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;
import javax.swing.border.EmptyBorder;
import javafx.animation.Interpolator;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
public class SwingSample implements Sample{
@Override
public Node mkRoot() {
Label description = new Label("GesturePane works in a JFXPanel too!");
description.setWrapText(true);
description.setPadding(new Insets(16));
Button button = new Button("Open Swing window");
button.setOnAction(e -> {
SwingUtilities.invokeLater(() -> {
try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException |
InstantiationException |
IllegalAccessException |
UnsupportedLookAndFeelException ignored) {
// give up, doesn't matter
}
JLabel label = new JLabel("This window is a Swing JFrame with JFXPanel embedded " +
"in a BorderLayout");
label.setBorder(new EmptyBorder(10, 10, 10, 10));
JPanel ops = new JPanel();
JButton centre = new JButton("Centre image");
JButton x2 = new JButton("Zoom x2");
ops.add(centre);
ops.add(x2);
JFXPanel fxPanel = new JFXPanel();
JFrame frame = new JFrame("GesturePane in Swing");
frame.getContentPane().add(label, BorderLayout.NORTH);
frame.getContentPane().add(fxPanel, BorderLayout.CENTER);
frame.getContentPane().add(ops, BorderLayout.SOUTH);
frame.setSize(500, 500);
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Platform.runLater(() -> {
GesturePane pane = new GesturePane(new ImageView(LenaSample.LENA));
Scene scene = new Scene(pane, frame.getWidth(), frame.getHeight());
fxPanel.setScene(scene);
centre.addActionListener(ae -> pane.animate(LenaSample.DURATION)
.interpolateWith(Interpolator.EASE_BOTH)
.centreOn(pane.viewportCentre()));
x2.addActionListener(ae -> pane.animate(LenaSample.DURATION)
.interpolateWith(Interpolator.EASE_BOTH)
.zoomBy(2, pane.targetPointAtViewportCentre()));
});
});
});
VBox.setVgrow(button, Priority.ALWAYS);
VBox box = new VBox(description, button);
box.setAlignment(Pos.CENTER);
return box;
}
}