1 | package org.expeditee.items.widgets;
|
---|
2 |
|
---|
3 | import org.expeditee.core.Image;
|
---|
4 | import org.expeditee.core.bounds.AxisAlignedBoxBounds;
|
---|
5 | import org.expeditee.gio.EcosystemManager;
|
---|
6 | import org.expeditee.gio.EcosystemManager.Ecosystem;
|
---|
7 | import org.expeditee.gio.javafx.JavaFXMiscManager;
|
---|
8 | import org.expeditee.items.ItemParentStateChangedEvent;
|
---|
9 | import org.expeditee.items.Text;
|
---|
10 | import org.expeditee.items.UserAppliedPermission;
|
---|
11 |
|
---|
12 | import javafx.scene.Group;
|
---|
13 | import javafx.scene.Node;
|
---|
14 | import javafx.scene.Scene;
|
---|
15 | import javafx.scene.SnapshotParameters;
|
---|
16 | import javafx.scene.image.WritableImage;
|
---|
17 |
|
---|
18 | public abstract class JavaFXWidget extends Widget {
|
---|
19 |
|
---|
20 | protected Scene _dummyScene;
|
---|
21 | protected Node _node;
|
---|
22 |
|
---|
23 | protected JavaFXWidget(Text source, Node jfxNode, int minWidth, int maxWidth, int minHeight, int maxHeight) {
|
---|
24 | super(source, minWidth, maxWidth, minHeight, maxHeight);
|
---|
25 | _node = jfxNode;
|
---|
26 | _dummyScene = new Scene(new Group(_node));
|
---|
27 | onSizeChanged();
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Override
|
---|
31 | protected void addWidgetContent(final ItemParentStateChangedEvent e) {
|
---|
32 | if ((e.getEventType() == ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY || e
|
---|
33 | .getEventType() == ItemParentStateChangedEvent.EVENT_TYPE_SHOWN_VIA_OVERLAY)
|
---|
34 | && e.getOverlayLevel().equals(UserAppliedPermission.none)) {
|
---|
35 | return; // item belongs to a non-active overlay
|
---|
36 | }
|
---|
37 |
|
---|
38 | //TODO: Add code here that attaches JavaFX content to the widget. This was added by Bryce
|
---|
39 | //as it was necessary for Swing widgets functionality.
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | protected void addKeyListenerToWidget() {
|
---|
44 | // TODO: Add code here that attaches JavaFX key listeners
|
---|
45 |
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | protected void addThisAsContainerListenerToContent() {
|
---|
50 | // TODO: Add code here that attaches the equiv of swings Content Listener
|
---|
51 |
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | public AxisAlignedBoxBounds getContentBounds() {
|
---|
56 | // TODO: Return the bounds of the content that is being drawn. Potentially different from the bounds of the widget.
|
---|
57 | return null;
|
---|
58 | }
|
---|
59 |
|
---|
60 | @Override
|
---|
61 | protected void layout() {
|
---|
62 | // TODO: Respond to layout
|
---|
63 | }
|
---|
64 |
|
---|
65 | @Override
|
---|
66 | protected void onBoundsChanged() {
|
---|
67 | // TODO: Respond to widget bounds changing.
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Override
|
---|
71 | public boolean isSupportedOnEcosystem(Ecosystem type) {
|
---|
72 | return type == Ecosystem.JavaFX;
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Override
|
---|
76 | public void paintWidget() {
|
---|
77 | SnapshotParameters params = new SnapshotParameters();
|
---|
78 | WritableImage snapshot = _node.snapshot(params, null);
|
---|
79 | Image image = JavaFXMiscManager.getIfUsingJavaFXImageManager().createImage(snapshot);
|
---|
80 | EcosystemManager.getGraphicsManager().drawImage(image, getPosition());
|
---|
81 | }
|
---|
82 |
|
---|
83 | @Override
|
---|
84 | protected void onMoved() {
|
---|
85 | // Do nothing
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Override
|
---|
89 | protected void onSizeChanged() {
|
---|
90 | _dummyScene.getRoot().resize(getWidth(), getHeight());
|
---|
91 | _node.resize(getWidth(), getHeight());
|
---|
92 | }
|
---|
93 | }
|
---|