@@ -26,59 +26,69 @@ Source code for the example is located in /src/main/java/com/openfin/desktop/dem
2626
27271 . Create connection object:
2828
29- this.desktopConnection = new DesktopConnection("OpenFinDesktopDemo");
30-
31- This code just creates an instance of DesktopConnection and it does not try to connect to runtime.
29+ ``` java
30+ this . desktopConnection = new DesktopConnection (" OpenFinDesktopDemo" );
31+ ```
32+ This code just creates an instance of DesktopConnection and it does not try to connect to runtime.
3233
33342 . Launch and connect to stable version of OpenFin runtime:
3435
35- // create an instance of RuntimeConfiguration and configure Runtime by setting properties in RuntimeConfiguration
36- this.runtimeConfiguration = new RuntimeConfiguration();
37- // launch and connect to OpenFin Runtime
38- desktopConnection.connect(this.runtimeConfiguration, listener, 10000);
39-
36+ ``` java
37+ // create an instance of RuntimeConfiguration and configure Runtime by setting properties in RuntimeConfiguration
38+ this . runtimeConfiguration = new RuntimeConfiguration ();
39+ // launch and connect to OpenFin Runtime
40+ desktopConnection. connect(this . runtimeConfiguration, listener, 10000 );
41+ ```
4042 listener is an instance of DesktopStateListener which provides callback on status of connections to runtime.
4143
42443 . Create new application when clicking on Create App:
4345
44- Application app = new Application(options, desktopConnection, new AckListener() {
45- @Override
46- public void onSuccess(Ack ack) {
47- Application application = (Application) ack.getSource();
48- application.run(); // run the app
49- }
50- @Override
51- public void onError(Ack ack) {
52- }
53- });
54-
46+ ``` java
47+ Application app = new Application (options, desktopConnection, new AckListener () {
48+ @Override
49+ public void onSuccess (Ack ack ) {
50+ Application application = (Application ) ack. getSource();
51+ application. run(); // run the app
52+ }
53+ @Override
54+ public void onError (Ack ack ) {
55+ }
56+ });
57+ ```
5558 options is an instance of ApplicationOptions, which is populated from App Create dialog. AckListener interface provides callback for the operation.
5659
5760 Once the application is created successfully, you can take actions on its window:
5861
59624 . Change opacity:
6063
61- WindowOptions options = new WindowOptions();
62- options.setOpacity(newOpacityValue);
63- application.getWindow().updateOptions(options, null);
64+ ``` java
65+ WindowOptions options = new WindowOptions ();
66+ options. setOpacity(newOpacityValue);
67+ application. getWindow(). updateOptions(options, null );
68+ ```
6469
65705 . Change Window size
6671
67- application.getWindow().resizeBy(10, 10, "top-left");
68-
72+ ``` java
73+ application. getWindow(). resizeBy(10 , 10 , " top-left" );
74+ ```
6975
70766 . Publishes messages to a topic with InterApplicationBus
7177
72- org.json.JSONObject message = createSomeJsonMessage();
73- desktopConnection.getInterApplicationBus().publish("someTopic", message);
78+ ``` java
79+ org.json. JSONObject message = createSomeJsonMessage();
80+ desktopConnection. getInterApplicationBus(). publish(" someTopic" , message);
81+ ```
7482
75837 . Subscribes to a topic with InterApplicationBus
7684
77- desktopConnection.getInterApplicationBus().subscribe("*", "someTopic", new BusListener() {
78- public void onMessageReceived(String sourceUuid, String topic, Object payload) {
79- JSONObject message = (JSONObject) payload;
80- }
81- });
85+ ``` java
86+ desktopConnection. getInterApplicationBus(). subscribe(" *" , " someTopic" , new BusListener () {
87+ public void onMessageReceived (String sourceUuid , String topic , Object payload ) {
88+ JSONObject message = (JSONObject ) payload;
89+ }
90+ });
91+ ```
8292
8393## Run the example of docking Java Swing window with HTML5 application
8494
@@ -98,43 +108,124 @@ Source code for the example is located in /src/main/java/com/openfin/desktop/dem
98108
991091 . Create connection object:
100110
101- this.desktopConnection = new DesktopConnection("OpenFinDockingDemo", "localhost", port);
111+ ``` java
112+ this . desktopConnection = new DesktopConnection (" OpenFinDockingDemo" , " localhost" , port);
113+ ```
102114
103- This code just creates an instance and it does not try to connect to runtime.
115+ This code just creates an instance and it does not try to connect to runtime.
104116
1051172 . Launch and connect to stable version of OpenFin runtime:
106118
107- desktopConnection.connectToVersion("stable", listener, 60);
119+ ``` java
120+ desktopConnection. connectToVersion(" stable" , listener, 60 );
121+ ```
108122
109123 listener is an instance of DesktopStateListener which provides callback on status of connections to runtime.
110124
1111253 . Once Runtime is running, an instance of DockingManager is create with
112126
113- this.dockingManager = new DockingManager(this.desktopConnection, javaParentAppUuid);
127+ ``` java
128+ this . dockingManager = new DockingManager (this . desktopConnection, javaParentAppUuid);
129+ ```
114130
1151314 . Any OpenFin window can be registered with DockingManager with
116132
117- dockingManager.registerWindow(openFinWindow);
133+ ``` java
134+ dockingManager. registerWindow(openFinWindow);
135+ ```
118136
1191375 . Any Java window can be registered with DockingManager with
120138
121- dockingManager.registerJavaWindow(javaWindowName, jFrame, AckListener);
122-
139+ ``` java
140+ dockingManager. registerJavaWindow(javaWindowName, jFrame, AckListener );
141+ ```
142+
1231436 . An application can receive dock and undock events from DockingManger with
124144
125- desktopConnection.getInterApplicationBus().subscribe("*", "window-docked", EventListener);
126- desktopConnection.getInterApplicationBus().subscribe("*", "window-undocked", EventListener);
145+ ``` java
146+ desktopConnection. getInterApplicationBus(). subscribe(" *" , " window-docked" , EventListener );
147+ desktopConnection. getInterApplicationBus(). subscribe(" *" , " window-undocked" , EventListener );
148+ ```
127149
1281507 . An application can request DockingManager to undock a window with:
129151
130- JSONObject msg = new JSONObject();
131- msg.put("applicationUuid", javaParentAppUuid);
132- msg.put("windowName", javaWindowName);
133- desktopConnection.getInterApplicationBus().publish("undock-window", msg);
134-
152+ ``` java
153+ JSONObject msg = new JSONObject ();
154+ msg. put(" applicationUuid" , javaParentAppUuid);
155+ msg. put(" windowName" , javaWindowName);
156+ desktopConnection. getInterApplicationBus(). publish(" undock-window" , msg);
157+ ```
135158
136159Once the demo is running, Windows snap while being draggted close to other windows. Snapped windows dock on mounse release.
137160
161+ ## Run the example of embedding HTML5 application into a Java Swing window
162+
163+ 1 . Clone this repository
164+
165+ 2 . Go to release directory and start embed.bat
166+
167+ 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
168+
169+ 4 . Click "Shutdown OpenFin" button to close HTML5 application and the Java Swing window
170+
171+ ## Source Code Review for embedded OpenFin application
172+
173+ Source code for the example is located in /src/main/java/com/openfin/desktop/demo/WindowEmbedDemo.java
174+
175+ 1 . create a canvas and place it where the HTML5 application should be embedded.
176+
177+ ``` java
178+ embedCanvas = new java.awt. Canvas ();
179+ panel. add(embedCanvas, BorderLayout . CENTER );
180+ ```
181+
182+ 2 . listen to the canvas resize event, and resize embedded HTML5 application accordingly.
183+
184+ ``` java
185+ embedCanvas. addComponentListener(new ComponentAdapter () {
186+ @Override
187+ public void componentResized (ComponentEvent event ) {
188+ super . componentResized(event);
189+ Dimension newSize = event. getComponent(). getSize();
190+ try {
191+ if (startupHtml5app != null ) {
192+ startupHtml5app. getWindow(). embedComponentSizeChange((int )newSize. getWidth(), (int )newSize. getHeight());
193+ }
194+ } catch (Exception e) {
195+ e. printStackTrace();
196+ }
197+ }
198+ });
199+ ```
200+
201+ 3 . launch and connect to OpenFin runtime
202+
203+ ``` java
204+ this . desktopConnection = new DesktopConnection (appUuid);
205+ DesktopStateListener listener = new DesktopStateListener () {... };
206+ RuntimeConfiguration configuration = new RuntimeConfiguration ();
207+ configuration. setRuntimeVersion(desktopVersion);
208+ desktopConnection. connect(configuration, listener, 60 );
209+ ```
210+
211+ 4 . create HTML5 application
212+
213+ ``` java
214+ ApplicationOptions options = new ApplicationOptions (startupUuid, startupUuid, openfin_app_url);
215+ WindowOptions mainWindowOptions = new WindowOptions ();
216+ options. setMainWindowOptions(mainWindowOptions);
217+ DemoUtils . runApplication(options, this . desktopConnection, new AckListener () {... });
218+ ```
219+
220+ 5 . embed HTML5 application into the canvas
221+
222+ ``` java
223+ startupHtml5app = Application . wrap(this . startupUuid, this . desktopConnection);
224+ Window html5Wnd = startupHtml5app. getWindow();
225+ long parentHWndId = Native . getComponentID(this . embedCanvas);
226+ html5Wnd. embedInto(parentHWndId, this . embedCanvas. getWidth(), this . embedCanvas. getHeight(), new AckListener () {... });
227+ ```
228+
138229## More Info
139230More information and API documentation can be found at https://openfin.co/java-api/
140231
0 commit comments