Skip to content

Commit f8062ae

Browse files
committed
ADAP-139 updated embedded code and script, added description in readme
1 parent 1b0e500 commit f8062ae

File tree

8 files changed

+78
-6
lines changed

8 files changed

+78
-6
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ hs_err_pid*
1313
# IDEA
1414
*.iml
1515
.idea/**
16-
target/**
16+
target/**
17+
/target/

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,65 @@ Source code for the example is located in /src/main/java/com/openfin/desktop/dem
132132

133133
Once the demo is running, Windows snap while being draggted close to other windows. Snapped windows dock on mounse release.
134134

135+
## Run the example of embedding HTML5 application into a Java Swing window
136+
137+
1. Clone this repository
138+
139+
2. Go to release directory and start embed.bat
140+
141+
3. Once the java app starts, click on "Launch OpenFin" button, which should start OpenFin Runtime and embed the OpenFin application that points to https://openfin.co
142+
143+
4. Click "Shutdown OpenFin" button to close HTML5 application and the Java Swing window
144+
145+
## Source Code Review for embedded OpenFin application
146+
147+
Source code for the example is located in /src/main/java/com/openfin/desktop/demo/WindowEmbedDemo.java
148+
149+
1. create a canvas and place it where the HTML5 application should be embedded.
150+
151+
embedCanvas = new java.awt.Canvas();
152+
panel.add(embedCanvas, BorderLayout.CENTER);
153+
154+
2. listen to the canvas resize event, and resize embedded HTML5 application accordingly.
155+
156+
embedCanvas.addComponentListener(new ComponentAdapter() {
157+
@Override
158+
public void componentResized(ComponentEvent event) {
159+
super.componentResized(event);
160+
Dimension newSize = event.getComponent().getSize();
161+
try {
162+
if (startupHtml5app != null) {
163+
startupHtml5app.getWindow().embedComponentSizeChange((int)newSize.getWidth(), (int)newSize.getHeight());
164+
}
165+
} catch (Exception e) {
166+
e.printStackTrace();
167+
}
168+
}
169+
});
170+
171+
3. launch and connect to OpenFin runtime
172+
173+
this.desktopConnection = new DesktopConnection(appUuid);
174+
DesktopStateListener listener = new DesktopStateListener() {...};
175+
RuntimeConfiguration configuration = new RuntimeConfiguration();
176+
configuration.setRuntimeVersion(desktopVersion);
177+
desktopConnection.connect(configuration, listener, 60);
178+
179+
4. create HTML5 application
180+
181+
ApplicationOptions options = new ApplicationOptions(startupUuid, startupUuid, openfin_app_url);
182+
WindowOptions mainWindowOptions = new WindowOptions();
183+
options.setMainWindowOptions(mainWindowOptions);
184+
DemoUtils.runApplication(options, this.desktopConnection, new AckListener() {...});
185+
186+
5. embed HTML5 application into the canvas
187+
188+
startupHtml5app = Application.wrap(this.startupUuid, this.desktopConnection);
189+
Window html5Wnd = startupHtml5app.getWindow();
190+
long parentHWndId = Native.getComponentID(this.embedCanvas);
191+
html5Wnd.embedInto(parentHWndId, this.embedCanvas.getWidth(), this.embedCanvas.getHeight(), new AckListener() {...});
192+
193+
135194
## More Info
136195

137196
More information and API documentation can be found at https://openfin.co/java-api/

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>co.openfin</groupId>
88
<artifactId>openfin-desktop-java-example</artifactId>
9-
<version>6.0.1.2</version>
9+
<version>6.0.1.3-SNAPSHOT</version>
1010
<packaging>jar</packaging>
1111

1212
<name>openfin-desktop-java-example</name>

release/embed.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
java -cp openfin-desktop-java-example-6.0.1.2.jar;openfin-desktop-java-adapter-6.0.2.1-SNAPSHOT.jar;TableLayout-20050920.jar;jna-4.5.1.jar;jna-platform-4.5.1.jar;json-20140107.jar;slf4j-api-1.7.5.jar;slf4j-jdk14-1.6.1.jar;websocket-api-9.3.12.v20160915.jar;websocket-client-9.3.12.v20160915.jar;websocket-common-9.3.12.v20160915.jar;jetty-io-9.3.12.v20160915.jar;jetty-util-9.3.12.v20160915.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.demo.embed.URL=https://openfin.co -Dcom.openfin.demo.version=stable com.openfin.desktop.demo.WindowEmbedDemo
1+
java -cp openfin-desktop-java-example-6.0.1.3-SNAPSHOT.jar;openfin-desktop-java-adapter-7.0.1.jar;TableLayout-20050920.jar;jna-4.5.1.jar;jna-platform-4.5.1.jar;json-20140107.jar;slf4j-api-1.7.5.jar;slf4j-jdk14-1.6.1.jar;websocket-api-9.3.12.v20160915.jar;websocket-client-9.3.12.v20160915.jar;websocket-common-9.3.12.v20160915.jar;jetty-io-9.3.12.v20160915.jar;jetty-util-9.3.12.v20160915.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.demo.embed.URL=https://openfin.co -Dcom.openfin.demo.version=stable com.openfin.desktop.demo.WindowEmbedDemo
337 KB
Binary file not shown.
171 KB
Binary file not shown.

src/main/java/com/openfin/desktop/demo/DemoUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public static void ackError(AckListener ackListener, String reason) {
141141
if (ackListener != null) {
142142
JSONObject obj = new JSONObject();
143143
obj.put("reason", reason);
144-
ackListener.onError(new Ack(obj, null));
144+
ackListener.onError(new Ack(obj, ackListener));
145145
}
146146
}
147147

src/main/java/com/openfin/desktop/demo/WindowEmbedDemo.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ protected JPanel layoutEmbedPanel() {
8686
embedCanvas = new java.awt.Canvas();
8787
panel.add(embedCanvas, BorderLayout.CENTER);
8888

89-
panel.add(embedCanvas, BorderLayout.CENTER);
90-
panel.addComponentListener(new ComponentAdapter() {
89+
embedCanvas.addComponentListener(new ComponentAdapter() {
9190
@Override
9291
public void componentResized(ComponentEvent event) {
9392
super.componentResized(event);
@@ -141,7 +140,20 @@ private static void createAndShowGUI(final String startupUuid) {
141140
jFrame.setVisible(true);
142141
}
143142

143+
private void closeEmbeddedApp() {
144+
if (this.startupHtml5app != null) {
145+
try {
146+
this.startupHtml5app.close();
147+
this.startupHtml5app = null;
148+
} catch (DesktopException e) {
149+
e.printStackTrace();
150+
}
151+
}
152+
}
153+
144154
private void closeDesktop() {
155+
this.closeEmbeddedApp();
156+
145157
if (desktopConnection != null && desktopConnection.isConnected()) {
146158
try {
147159
// new com.openfin.desktop.System(desktopConnection).exit();

0 commit comments

Comments
 (0)