Skip to content

Commit 45cf42b

Browse files
author
Wenjun Che
committed
ADAP-37: create examples for WebStart
1 parent b02fb5a commit 45cf42b

File tree

10 files changed

+192
-2
lines changed

10 files changed

+192
-2
lines changed

pom.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,30 @@
1010
<packaging>jar</packaging>
1111

1212
<name>openfin-desktop-java-example</name>
13+
<description>Examples of OpenFin Java API</description>
1314
<url>http://www.openfin.co</url>
1415

1516
<properties>
1617
<user.name>[email protected]</user.name>
1718
</properties>
1819

20+
<licenses>
21+
<license>
22+
<name>The MIT License (MIT)</name>
23+
<url>http://www.opensource.org/licenses/mit-license.php</url>
24+
<distribution>repo</distribution>
25+
</license>
26+
</licenses>
27+
28+
<developers>
29+
<developer>
30+
<email>[email protected]</email>
31+
<name>OpenFin</name>
32+
<url>https://openfin.co</url>
33+
<id>openfin</id>
34+
</developer>
35+
</developers>
36+
1937
<dependencies>
2038
<dependency>
2139
<groupId>co.openfin</groupId>
@@ -43,9 +61,26 @@
4361
</archive>
4462
</configuration>
4563
</plugin>
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-jar-plugin</artifactId>
67+
<version>2.5</version>
68+
<configuration>
69+
<archive>
70+
<manifestFile>${basedir}/target/classes/META-INF/MANIFEST.MF</manifestFile>
71+
</archive>
72+
</configuration>
73+
</plugin>
4674

4775
</plugins>
4876

77+
<resources>
78+
<resource>
79+
<directory>src/main/resources</directory>
80+
<filtering>true</filtering>
81+
</resource>
82+
</resources>
83+
4984
</build>
5085

5186

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package com.openfin.desktop.demo;
2+
3+
import com.openfin.desktop.*;
4+
5+
import javax.swing.*;
6+
import java.awt.event.ActionEvent;
7+
import java.awt.event.ActionListener;
8+
9+
/**
10+
*
11+
* Example of running OpenFin from WebStart
12+
*
13+
*/
14+
15+
public class JNLPExample extends JFrame {
16+
17+
private JButton startButton = new JButton("Start Hello OpenFin Demo");
18+
private DesktopConnection desktopConnection;
19+
20+
final DesktopStateListener listener = new DesktopStateListener() {
21+
@Override
22+
public void onReady() {
23+
java.lang.System.out.println("Connected to OpenFin Runtime");
24+
InterApplicationBus bus = desktopConnection.getInterApplicationBus();
25+
try {
26+
launchHTML5App();
27+
} catch (Exception e) {
28+
e.printStackTrace();
29+
}
30+
31+
}
32+
@Override
33+
public void onError(String reason) {
34+
java.lang.System.out.println("Connection failed: " + reason);
35+
}
36+
37+
@Override
38+
public void onMessage(String message) {
39+
}
40+
41+
@Override
42+
public void onOutgoingMessage(String message) {
43+
}
44+
};
45+
46+
47+
public JNLPExample() throws DesktopException {
48+
super("Jave Web Start Example on OpenFin");
49+
this.setSize(350, 200);
50+
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
51+
this.setLayout(null);
52+
53+
startButton.setSize(200, 30);
54+
startButton.setLocation(80, 50);
55+
this.getContentPane().add(startButton);
56+
57+
startButton.addActionListener(new ActionListener() {
58+
public void actionPerformed(ActionEvent e) {
59+
try {
60+
desktopConnection.connectToVersion("stable", listener, 100000);
61+
} catch (Exception ex) {
62+
ex.printStackTrace();
63+
}
64+
}
65+
});
66+
67+
68+
this.desktopConnection = new DesktopConnection("WebStartExample");
69+
}
70+
71+
private void launchHTML5App() {
72+
73+
ApplicationOptions applicationOptions = new ApplicationOptions("Hello OpenFin", "Hello OpenFin",
74+
"http://demoappdirectory.openf.in/desktop/config/apps/OpenFin/HelloOpenFin/index.html");
75+
WindowOptions windowOptions = new WindowOptions();
76+
windowOptions.setAutoShow(true);
77+
windowOptions.setFrame(false);
78+
windowOptions.setResizable(false);
79+
windowOptions.setDefaultHeight(525);
80+
windowOptions.setDefaultWidth(395);
81+
windowOptions.setDefaultTop(50);
82+
windowOptions.setDefaultLeft(10);
83+
applicationOptions.setMainWindowOptions(windowOptions);
84+
Application app = new Application(applicationOptions, desktopConnection, new AckListener() {
85+
@Override
86+
public void onSuccess(Ack ack) {
87+
if (ack.isSuccessful()) {
88+
Application application = (Application) ack.getSource();
89+
try {
90+
application.run();
91+
} catch (Exception e) {
92+
e.printStackTrace();
93+
}
94+
}
95+
}
96+
@Override
97+
public void onError(Ack ack) {
98+
99+
}
100+
});
101+
}
102+
103+
public static void main(String[] args) throws DesktopException {
104+
JNLPExample exp = new JNLPExample();
105+
exp.setVisible(true);
106+
}
107+
108+
109+
}

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ private void setMainButtonsEnabled(boolean enabled) {
9898
launch.setEnabled(!enabled);
9999
embed.setEnabled(enabled);
100100
close.setEnabled(enabled);
101+
102+
if (enabled) {
103+
this.controller.getInterApplicationBus().addSubscribeListener(new SubscriptionListener() {
104+
public void subscribed(String uuid, String topic) {
105+
System.out.println("subscribed " + uuid + " on topic " + topic);
106+
}
107+
108+
public void unsubscribed(String uuid, String topic) {
109+
System.out.println("unsubscribed " + uuid + " on topic " + topic);
110+
111+
}
112+
});
113+
}
101114
}
102115

103116
private static void createAndShowGUI(final String desktopOption, final String startupUuid) {
@@ -120,7 +133,9 @@ private static void createAndShowGUI(final String desktopOption, final String st
120133
private void closeDesktop() {
121134
if (controller != null && controller.isConnected()) {
122135
try {
123-
new com.openfin.desktop.System(controller).exit();
136+
// new com.openfin.desktop.System(controller).exit();
137+
System.out.println("disconnecting ");
138+
controller.disconnect();
124139
} catch (Exception e) {
125140
e.printStackTrace();
126141
}
@@ -200,7 +215,8 @@ public void onMessage(String message) {
200215
public void onOutgoingMessage(String message) {
201216
}
202217
};
203-
controller.launchAndConnect(null, desktopOption, listener, 10000);
218+
// controller.launchAndConnect(null, desktopOption, listener, 10000);
219+
controller.connect(listener);
204220

205221
} catch (Exception e) {
206222
e.printStackTrace();
@@ -283,6 +299,7 @@ public static void main(String[] args) {
283299
} else {
284300
startupUUID = "OpenFinHelloWorld";
285301
}
302+
java.lang.System.out.println("starting: ");
286303
javax.swing.SwingUtilities.invokeLater(new Runnable() {
287304
public void run() {
288305
createAndShowGUI(desktop_option, startupUUID);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Implementation-Version: ${project.version}
2+
Implementation-Title: ${project.name}
3+
groupId: ${project.groupId}
4+
artifactId: ${project.artifactId}
5+
Build-Jdk: ${java.version}
6+
Built-By: OpenFin
7+
Created-By: OpenFin
8+
Application-Name: JNLP Example of OpenFin Runtime

webstart/JNLPExample.jnlp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<jnlp spec="1.0+" codebase="http://localhost:8080/" href="JNLPExample.jnlp">
3+
<information>
4+
<title>JNLP Example of OpenFin Runtime</title>
5+
<vendor>OpenFin</vendor>
6+
<homepage href="https://openfin.co/" />
7+
<description>JNLP Example to start OpenFin Runtime</description>
8+
</information>
9+
<security>
10+
<all-permissions/>
11+
</security>
12+
<resources>
13+
<j2se version="1.6+" />
14+
<jar href="openfin-desktop-java-example-3.0.1.5.jar" main="true"/>
15+
<jar href="openfin-desktop-java-adapter-4.40.2.8.jar"/>
16+
<jar href="json-20140107.jar"/>
17+
<jar href="jna-4.1.0.jar"/>
18+
<jar href="jna-platform-4.1.0.jar"/>
19+
</resources>
20+
<application-desc main-class="com.openfin.desktop.demo.JNLPExample" />
21+
</jnlp>

webstart/jna-4.1.0.jar

908 KB
Binary file not shown.

webstart/jna-platform-4.1.0.jar

1.45 MB
Binary file not shown.

webstart/json-20140107.jar

70.3 KB
Binary file not shown.
837 KB
Binary file not shown.
84.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)