Examples for OpenFin Java adapter
-
Clone this repository
-
Go to release directory and start run.bat
-
Once the java app starts, click on Start button, which should start OpenFin Runtime and "Hello OpenFin" HTML5 demo app. The java app will wait and try to connect to OpenFin Runtime.
-
You can use buttons in Window Control section to move and re-size HTML5 window of Hello OpenFin app.
-
Click "Create Application" button, which should start a dialog with all the fields pre-populated for our FXLive demo HTML5 application. Just click on "Create" button.
-
After FXLive starts, you can use the buttons under Window Control of Java app to control FXLive window.
Source code for the example is located in /src/main/java/com/openfin/desktop/demo/OpenFinDesktopDemo.java. The followings overview of how it communicates with OpenFin Runtime with API calls supported by the Java adapter:
-
Create connection object:
this.desktopConnection = new DesktopConnection("OpenFinDesktopDemo", "localhost", port);This code just creates an instance and it does not try to connect to runtime.
-
Launch and connect to stable version of OpenFin runtime:
desktopConnection.connectToVersion("stable", listener, 10000);listener is an instance of DesktopStateListener which provides callback on status of connections to runtime. desktopCommandLine is a string of arguments passed to OpenFinRVM. This example by default passes remote config file for Hello OpenFin app, which will be started as the first app in OpenFin Runtime.
-
Create new application when clicking on Create App:
Application app = new Application(options, controller, new AckListener() { @Override public void onSuccess(Ack ack) { Application application = (Application) ack.getSource(); application.run(); // run the app addApplication(options); } @Override public void onError(Ack ack) { } });options is an instance of ApplicationOptions, which is populated from App Create dialog. AckListener interface provides callback for the operation.
Once the application is created successfully, you can take actions on its window:
-
Change opacity:
WindowOptions options = new WindowOptions(); options.setOpacity(newOpacityValue); application.getWindow().updateOptions(options, null); -
Change Window size
application.getWindow().resizeBy(10, 10, "top-left"); -
Publishes messages to a topic with InterApplicationBus
org.json.JSONObject message = createSomeJsonMessage(); desktopConnection.getInterApplicationBus().publish("someTopic", message); -
Subscribes to a topic with InterApplicationBus
desktopConnection.getInterApplicationBus().subscribe("*", "someTopic", new BusListener() { public void onMessageReceived(String sourceUuid, String topic, Object payload) { JSONObject message = (JSONObject) payload; } });
-
Clone this repository
-
Go to release directory and start docking.bat
-
Once the java app starts, click on "Launch OpenFin" button, which should start OpenFin Runtime and "Hello OpenFin" HTML5 demo app. The java app will wait and try to connect to OpenFin Runtime.
-
After clicking "Dock to HTML5 app" button, you can move either window to see docking effect.
-
Click "Undock from HTML5 app" to undock 2 windows
Source code for the example is located in /src/main/java/com/openfin/desktop/demo/OpenFinDockingDemo.java. The followings overview of how it communicates with OpenFin Runtime with API calls supported by the Java adapter:
-
Create connection object:
this.desktopConnection = new DesktopConnection("OpenFinDockingDemo", "localhost", port);This code just creates an instance and it does not try to connect to runtime.
-
Launch and connect to stable version of OpenFin runtime:
desktopConnection.connectToVersion("stable", listener, 10000);listener is an instance of DesktopStateListener which provides callback on status of connections to runtime. desktopCommandLine is a string of arguments passed to OpenFinRVM. This example by default passes remote config file for Hello OpenFin app, which will be started as the first app in OpenFin Runtime.
-
dockToStartupApp and undockFromStartupApp show to dock and undock 2 windows.
Source code for the example is located in /src/main/java/com/openfin/desktop/demo/JNLPExample.java. The followings overview of how it communicates with OpenFin Runtime with API calls supported by the Java adapter:
-
Create connection object:
this.desktopConnection = new DesktopConnection("WebStartExample");This code just creates an instance and it does not try to connect to runtime.
-
Launch and connect to OpenFin runtime:
desktopConnection.connectToVersion("stable", listener, 100000);listener is an instance of DesktopStateListener which provides callback on status of connections to runtime. connectToVersion connects to "stable" version of Runtime. If "stable" version is not running, this method will try to start it.
-
Once the Runtime is running, launchHTML5App method is called to start Hello OpenFin demo app.
-
To run the demo, please import webstart/OpenFinSigner.csr into Java Webstart as Signer CA first, and then load Demo JNLP to start the demo.
More information and API documentation can be found at https://www.openfin.co/developers.html?url=developers/api/java/overview.html
Please contact support@openfin.co