Skip to content

Commit beb24d0

Browse files
authored
Merge All changes for Layout service (openfin#26)
* ADAP-142 remove jframe frame when it's tabbed. * ADAP-142 remove thick frame when tabbed. * test code when java window is frameless.... * ADAP-142: more updates for docking * ADAP-142: fixes for docking frameless windows * ADAP-150: Example for layout service' * ADAP-150: Add FX example for docking by layout service * ADAP-150: Add FX example for docking by layout service * ADAP-148: add S&D example for FX windows
1 parent 62a10de commit beb24d0

6 files changed

Lines changed: 401 additions & 141 deletions

File tree

release/app.asar

4.47 KB
Binary file not shown.
2.44 KB
Binary file not shown.
13 KB
Binary file not shown.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package com.openfin.desktop.demo;
2+
3+
import com.openfin.desktop.*;
4+
import com.openfin.desktop.channel.ChannelClient;
5+
import com.openfin.desktop.win32.ExternalWindowObserver;
6+
import javafx.embed.swing.JFXPanel;
7+
import javafx.event.EventHandler;
8+
import javafx.scene.Scene;
9+
import javafx.scene.control.Button;
10+
import javafx.scene.layout.StackPane;
11+
import javafx.stage.Stage;
12+
import javafx.stage.WindowEvent;
13+
import org.json.JSONObject;
14+
15+
import java.lang.System;
16+
import java.util.List;
17+
18+
public class FxLayoutFrame {
19+
private ExternalWindowObserver externalWindowObserver;
20+
private String windowName;
21+
private Stage stage;
22+
private static JFXPanel jFXPanel;
23+
24+
public FxLayoutFrame(DesktopConnection desktopConnection, String appUuid, String windowName) {
25+
System.out.println(windowName + " being created ");
26+
this.windowName = windowName;
27+
if (jFXPanel == null) {
28+
jFXPanel = new JFXPanel();
29+
javafx.application.Platform.setImplicitExit(false);
30+
}
31+
javafx.application.Platform.runLater(new Runnable() {
32+
@Override
33+
public void run() {
34+
Button btnUndock = new Button("undock");
35+
btnUndock.setDisable(true);
36+
37+
StackPane secondaryLayout = new StackPane();
38+
secondaryLayout.getChildren().add(btnUndock);
39+
40+
Scene secondScene = new Scene(secondaryLayout, 640, 480);
41+
42+
FxLayoutFrame.this.stage = new Stage();
43+
FxLayoutFrame.this.stage.setTitle(windowName);
44+
FxLayoutFrame.this.stage.setScene(secondScene);
45+
46+
// Set position of second window, related to primary window.
47+
FxLayoutFrame.this.stage.setX(640);
48+
FxLayoutFrame.this.stage.setY(480);
49+
FxLayoutFrame.this.stage.show();
50+
51+
// FxLayoutFrame.this.stage.setOnCloseRequest(event -> FxLayoutFrame.this.cleanup());
52+
53+
try {
54+
FxLayoutFrame.this.externalWindowObserver =
55+
new ExternalWindowObserver(desktopConnection.getPort(), appUuid, windowName, FxLayoutFrame.this.stage,
56+
new AckListener() {
57+
@Override
58+
public void onSuccess(Ack ack) {
59+
ExternalWindowObserver observer = (ExternalWindowObserver) ack.getSource();
60+
observer.getDesktopConnection().getChannel().connect("of-layouts-service-v1",
61+
new AsyncCallback<ChannelClient>() {
62+
@Override
63+
public void onSuccess(ChannelClient client) {
64+
btnUndock.setOnAction(new EventHandler<javafx.event.ActionEvent>() {
65+
@Override
66+
public void handle(javafx.event.ActionEvent e) {
67+
JSONObject payload = new JSONObject();
68+
payload.put("uuid", appUuid);
69+
payload.put("name", windowName);
70+
client.dispatch("UNDOCK-WINDOW", payload, null);
71+
}
72+
});
73+
}
74+
});
75+
}
76+
77+
@Override
78+
public void onError(Ack ack) {
79+
}
80+
});
81+
82+
Window w = Window.wrap(appUuid, windowName, desktopConnection);
83+
w.addEventListener("group-changed", new EventListener() {
84+
@Override
85+
public void eventReceived(com.openfin.desktop.ActionEvent actionEvent) {
86+
JSONObject eventObj = actionEvent.getEventObject();
87+
w.getGroup(new AsyncCallback<List<Window>>() {
88+
@Override
89+
public void onSuccess(java.util.List<Window> result) {
90+
if (result.size() > 0) {
91+
btnUndock.setDisable(false);
92+
} else {
93+
btnUndock.setDisable(true);
94+
}
95+
}
96+
}, null);
97+
}
98+
}, null);
99+
100+
try {
101+
FxLayoutFrame.this.externalWindowObserver.start();
102+
} catch (Exception e) {
103+
e.printStackTrace();
104+
}
105+
106+
} catch (DesktopException e) {
107+
e.printStackTrace();
108+
}
109+
}
110+
});
111+
}
112+
113+
public String getWindowName() {
114+
return windowName;
115+
}
116+
117+
public Stage getStage() {
118+
return stage;
119+
}
120+
121+
public void cleanup() {
122+
try {
123+
System.out.println(windowName + " cleaning up ");
124+
if (this.externalWindowObserver != null) {
125+
this.externalWindowObserver.dispose();
126+
}
127+
}
128+
catch (Exception e) {
129+
e.printStackTrace();
130+
}
131+
this.externalWindowObserver = null;
132+
}
133+
134+
}

0 commit comments

Comments
 (0)