├── .gitignore ├── LICENSE ├── README.md ├── RELEASENOTES-ADAPTER.md ├── pom.xml ├── release ├── PubSubExample.html ├── SimpleDockingExample.html ├── SimpleOpenFinApp.html ├── app.asar ├── busdemo.html ├── channel.bat ├── embed.bat ├── fxdemo.bat ├── junit.bat ├── launchExternal.html ├── layout.html ├── layoutclient1.json ├── layoutclient2.json ├── lib │ ├── TableLayout-20050920.jar │ ├── hamcrest-core-1.3.jar │ ├── hamcrest-library-1.1.jar │ ├── jetty-client-9.4.18.v20190429.jar │ ├── jetty-http-9.4.18.v20190429.jar │ ├── jetty-io-9.4.18.v20190429.jar │ ├── jetty-util-9.4.18.v20190429.jar │ ├── jetty-xml-9.4.18.v20190429.jar │ ├── jna-4.5.1.jar │ ├── jna-platform-4.5.1.jar │ ├── json-20160810.jar │ ├── junit-4.11.jar │ ├── log4j-1.2.17.jar │ ├── mockito-core-1.9.5.jar │ ├── objenesis-1.0.jar │ ├── openfin-desktop-java-adapter-9.2.0.jar │ ├── openfin-desktop-java-example-9.0.1.jar │ ├── openfin-desktop-java-example-9.2.1-tests.jar │ ├── openfin-desktop-java-example-9.2.2.jar │ ├── slf4j-api-1.7.21.jar │ ├── slf4j-jdk14-1.6.1.jar │ ├── slf4j-log4j12-1.7.18.jar │ ├── websocket-api-9.4.18.v20190429.jar │ ├── websocket-client-9.4.18.v20190429.jar │ └── websocket-common-9.4.18.v20190429.jar ├── log4j.xml ├── logging.properties ├── manifest.bat ├── notification.bat ├── preload.js ├── profile.bat ├── publisher.bat ├── run.bat ├── run.sh ├── stockflux.json ├── subscriber.bat ├── testWindowPosition.bat └── watchlist.json ├── src ├── main │ ├── java │ │ └── com │ │ │ └── openfin │ │ │ └── desktop │ │ │ └── demo │ │ │ ├── AppCreateDialog.java │ │ │ ├── ChannelExample.java │ │ │ ├── DemoUtils.java │ │ │ ├── FxDemo.java │ │ │ ├── FxLayoutFrame.java │ │ │ ├── JNLPExample.java │ │ │ ├── LaunchManifestDemo.java │ │ │ ├── LauncherBusDemo.java │ │ │ ├── LayoutFrame.java │ │ │ ├── LayoutServiceDemo.java │ │ │ ├── LoadAppsDialog.java │ │ │ ├── MemoryProfile.java │ │ │ ├── NoGui.java │ │ │ ├── NotificationServiceDemo.java │ │ │ ├── OpenFinDesktopDemo.java │ │ │ ├── PubSubTest.java │ │ │ ├── Signer.java │ │ │ └── WindowEmbedDemo.java │ └── resources │ │ └── META-INF │ │ └── MANIFEST.MF └── test │ └── java │ └── com │ └── openfin │ └── desktop │ ├── AllTests.java │ ├── ApplicationTest.java │ ├── ChannelTest.java │ ├── DesktopConnectionTest.java │ ├── InterApplicationBusTest.java │ ├── InteropTest.java │ ├── NotificationTest.java │ ├── OpenFinRuntimeTest.java │ ├── RuntimeConfigTest.java │ ├── SnapshotTest.java │ ├── SystemTest.java │ ├── TestExample.java │ ├── TestUtils.java │ ├── WindowPositionTest.java │ └── WindowTest.java └── webstart ├── JNLPExample.jnlp ├── OpenFinSigner.csr ├── jna-4.1.0.jar ├── jna-platform-4.1.0.jar ├── json-20140107.jar ├── openfin-desktop-java-adapter-4.40.2.8.jar ├── openfin-desktop-java-adapter-5.44.2.0.jar ├── openfin-desktop-java-example-3.0.1.5.jar └── openfin-desktop-java-example-5.44.2.0.jar /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.war 8 | *.ear 9 | 10 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 11 | hs_err_pid* 12 | 13 | # IDEA 14 | *.iml 15 | .idea/** 16 | target/** 17 | /target/ 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 OpenFin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java Adapter Example 2 | 3 | ## Overview 4 | The following repo contains examples for OpenFin's Java adapter. 5 | 6 | ## Guidelines 7 | Run the example of connecting to OpenFin and creating applications 8 | 9 | 1. Clone this repository 10 | 11 | 2. Go to release directory and start run.bat 12 | 13 | 3. Once the java app starts, click on Start button, which should start OpenFin Runtime. The java app will wait and try to connect to OpenFin Runtime. 14 | 15 | 4. Once OpenFin Runtime is started and Java app connects successfully, "Create Application" button is enabled. You can click on the button to bring up a dialog for entering configuration of any HTML5 app. By default, the dialog is pre-populated with configuration for Hello OpenFin demo app. 16 | 17 | 5. You can use buttons in Window Control section to move and re-size HTML5 window of Hello OpenFin app. 18 | 19 | 6. Click "Create Application" button, which should start a dialog with all the fields pre-populated for our Hello OpenFin demo HTML5 application. Just click on "Create" button. 20 | 21 | 7. After Hello OpenFin starts, you can use the buttons under Window Control of Java app to control Hello OpenFin window. 22 | 23 | ## Source Code Review 24 | 25 | 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: 26 | 27 | 1. Create connection object: 28 | 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. 33 | 34 | 2. Launch and connect to stable version of OpenFin runtime: 35 | 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 | ``` 42 | listener is an instance of DesktopStateListener which provides callback on status of connections to runtime. 43 | 44 | 3. Create new application when clicking on Create App: 45 | 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 | ``` 58 | options is an instance of ApplicationOptions, which is populated from App Create dialog. AckListener interface provides callback for the operation. 59 | 60 | Once the application is created successfully, you can take actions on its window: 61 | 62 | 4. Change opacity: 63 | 64 | ```java 65 | WindowOptions options = new WindowOptions(); 66 | options.setOpacity(newOpacityValue); 67 | application.getWindow().updateOptions(options, null); 68 | ``` 69 | 70 | 5. Change Window size 71 | 72 | ```java 73 | application.getWindow().resizeBy(10, 10, "top-left"); 74 | ``` 75 | 76 | 6. Publishes messages to a topic with InterApplicationBus 77 | 78 | ```java 79 | org.json.JSONObject message = createSomeJsonMessage(); 80 | desktopConnection.getInterApplicationBus().publish("someTopic", message); 81 | ``` 82 | 83 | 7. Subscribes to a topic with InterApplicationBus 84 | 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 | ``` 92 | 93 | ## Run the example of embedding HTML5 application into a Java Swing window 94 | 95 | 1. Clone this repository 96 | 97 | 2. Go to release directory and start embed.bat ( the default embedded url is https://openfin.co. Pass the url you wish to load if you want something different e.g. embed.bat https://www.mydomain.com ) 98 | 99 | 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 (or your custom url if you specified one) 100 | 101 | 4. Click "Shutdown OpenFin" button to close HTML5 application and the Java Swing window 102 | 103 | If there is a problem rendering the url please check your windows display settings to see ensure scaling is set to 100%. 104 | 105 | ## Source Code Review for embedded OpenFin application 106 | 107 | Source code for the example is located in /src/main/java/com/openfin/desktop/demo/WindowEmbedDemo.java 108 | 109 | 1. create a canvas and place it where the HTML5 application should be embedded. 110 | 111 | ```java 112 | embedCanvas = new java.awt.Canvas(); 113 | panel.add(embedCanvas, BorderLayout.CENTER); 114 | ``` 115 | 116 | 2. listen to the canvas resize event, and resize embedded HTML5 application accordingly. 117 | 118 | ```java 119 | embedCanvas.addComponentListener(new ComponentAdapter() { 120 | @Override 121 | public void componentResized(ComponentEvent event) { 122 | super.componentResized(event); 123 | Dimension newSize = event.getComponent().getSize(); 124 | try { 125 | if (startupHtml5app != null) { 126 | startupHtml5app.getWindow().embedComponentSizeChange((int)newSize.getWidth(), (int)newSize.getHeight()); 127 | } 128 | } catch (Exception e) { 129 | e.printStackTrace(); 130 | } 131 | } 132 | }); 133 | ``` 134 | 135 | 3. launch and connect to OpenFin runtime 136 | 137 | ```java 138 | this.desktopConnection = new DesktopConnection(appUuid); 139 | DesktopStateListener listener = new DesktopStateListener() {...}; 140 | RuntimeConfiguration configuration = new RuntimeConfiguration(); 141 | configuration.setRuntimeVersion(desktopVersion); 142 | desktopConnection.connect(configuration, listener, 60); 143 | ``` 144 | 145 | 4. create HTML5 application 146 | 147 | ```java 148 | ApplicationOptions options = new ApplicationOptions(startupUuid, startupUuid, openfin_app_url); 149 | WindowOptions mainWindowOptions = new WindowOptions(); 150 | options.setMainWindowOptions(mainWindowOptions); 151 | DemoUtils.runApplication(options, this.desktopConnection, new AckListener() {...}); 152 | ``` 153 | 154 | 5. embed HTML5 application into the canvas 155 | 156 | ```java 157 | startupHtml5app = Application.wrap(this.startupUuid, this.desktopConnection); 158 | Window html5Wnd = startupHtml5app.getWindow(); 159 | long parentHWndId = Native.getComponentID(this.embedCanvas); 160 | html5Wnd.embedInto(parentHWndId, this.embedCanvas.getWidth(), this.embedCanvas.getHeight(), new AckListener() {...}); 161 | ``` 162 | 163 | ## More Info 164 | More information and API documentation can be found at https://openfin.co/java-api/ 165 | 166 | ## Disclaimers 167 | * This is a starter example and intended to demonstrate to app providers a sample of how to approach an implementation. There are potentially other ways to approach it and alternatives could be considered. 168 | * Its possible that the repo is not actively maintained. 169 | 170 | ## License 171 | MIT 172 | 173 | The code in this repository is covered by the included license. 174 | 175 | However, if you run this code, it may call on the OpenFin RVM or OpenFin Runtime, which are covered by OpenFin’s Developer, Community, and Enterprise licenses. You can learn more about OpenFin licensing at the links listed below or just email us at support@openfin.co with questions. 176 | 177 | https://openfin.co/developer-agreement/
178 | https://openfin.co/licensing/ 179 | 180 | ## Support 181 | Please enter an issue in the repo for any questions or problems. 182 |
Alternatively, please contact us at support@openfin.co 183 | -------------------------------------------------------------------------------- /RELEASENOTES-ADAPTER.md: -------------------------------------------------------------------------------- 1 | # Version 7.2.1 2 | ## New Features 3 | * Add support for FDC3 service 4 | 5 | # Version 7.1.3 6 | ## New Features 7 | * Add support for the new notification service 8 | * DesktopStateListener.onError is called for exceptions from websocket 9 | 10 | # Version 7.1.2 11 | ## Bug Fixes 12 | 13 | * Fixed an issue with dependencies 14 | 15 | # Version 7.1.1 16 | 17 | ## New Features 18 | * Added Channel API 19 | * Launch pre-installed RVM directly to improve performance 20 | * Better naming of local app manifest file 21 | * Requires JDK1.8+ 22 | 23 | ## Bug Fixes 24 | 25 | * Fixed an issue with synchronization in InterApplicationBus.send 26 | 27 | # Version 7.0.2 28 | 29 | ## Bug Fixes 30 | * Fixed an issue with setting timeout if RuntimeConfiguration.setRuntimePort is called. 31 | 32 | # Version 7.0.1 33 | 34 | ## New Features 35 | * Improved thread safety with concurrent collection classes. 36 | * Added error message to DesktopStateListener.onClose (breaking change) 37 | * Added OpenFinRuntime.getRuntimeInfo 38 | * Added OpenFinRuntime.getRvmInfo 39 | * Improved thread safety with concurrent collection classes. 40 | 41 | ## Bug Fixes 42 | * Fixed an issue with passing arguments in System.launchExternalProcess 43 | 44 | # Version 6.0.2.1 45 | 46 | ## New Features 47 | * Added Application.registerUser. 48 | * Upgrade JNA library to 4.5.1. 49 | 50 | # Version 6.0.1.3 51 | 52 | ## New Features 53 | * Port discovery support on Mac and Linux with openfin-cli. 54 | * Add support for legacy connecting to Runtime by hard-coded port number 55 | 56 | # Version 6.0.1.2 57 | 58 | ## Bug Fixes 59 | * Fixed an issue with deprecated DesktopConnect.connect method. 60 | * Fixed an issue with sending connection info to Runtime. 61 | 62 | # Version 6.0.1.1 63 | ## New Features 64 | * Requires JDK1.7+ 65 | * Add browser-style navigation to Window class 66 | * Add support for fallbackVersion of Runtime 67 | * Add support for non-persistent connections to Runtime 68 | * Improve support for app assets 69 | 70 | ## Bug Fixes 71 | * Fixed an issue with loop of re-connecting to Runtime 72 | * Fixed an issue with Window.close defaulting 'force' to true 73 | 74 | # Version 6.0.1.0 75 | ## New Features 76 | 77 | * Support for launching Runtime from a remote manifest. 78 | * Added Window.executeJavaScript 79 | * Added Window.showDeveloperTools 80 | * Added Window.navigate 81 | * Added Application.wrapWindow 82 | * Added OpenFinRuntime.getHostSpecs 83 | * Support for port discovery of Runtime process at different integrity levels 84 | 85 | ## Bug Fixes 86 | 87 | * Use ProcessBuilder to launch OpenFin to solve an issue with security on Citrix server. 88 | * Added proper clean-up for ExternalWindowObserver 89 | * Fixed an issue with retrying connection to Runtime 90 | 91 | # Version 6.0.0.2 92 | ## New Features 93 | * added ApplicationOptions.put method. 94 | 95 | ## Bug Fixes 96 | * Fixed an issue with websocket timeout 97 | 98 | # Version 6.0.0.1 99 | 100 | ## New Features 101 | * Requires Version 6.0+ version of OpenFin Runtime. 102 | * Improved support for window embedding 103 | * Replaced WebSocket library with org.eclipse.jetty.websocket 104 | 105 | # Version 5.44.5.3 106 | * Fixed an issue with connection timeout at 5 seconds 107 | 108 | # Version 5.44.5.2 109 | ## New Features 110 | * Add support for fallbackVersion of Runtime 111 | 112 | # Version 5.44.5.1 113 | ## New Features 114 | * Branch from Version 6.0.1.1 to support Java 1.6 115 | 116 | # Version 5.44.3.6 117 | 118 | * Fixed an issue with loop of re-connecting to Runtime 119 | 120 | # Version 5.44.3.5 121 | 122 | * Fixed an issue with Window.close defaulting 'force' to true 123 | 124 | # Version 5.44.3.4 125 | 126 | * Fixed an issue with retrying connection to Runtime 127 | 128 | # Version 5.44.3.3 129 | 130 | ## New Features 131 | * Support for port discovery of Runtime process at different integrity levels 132 | 133 | # Version 5.44.3.2 134 | 135 | ## New Features 136 | 137 | * Users ProcessBuilder to launch OpenFinLauncher. 138 | 139 | # Version 5.44.3.1 140 | 141 | ## New Features 142 | 143 | * Added RuntimeConfiguration class to improve configurability of Runtime from Java programs. 144 | * Added DesktopConnection.connect(RuntimeConfiguration) 145 | * Added DesktopStateListener.onClose to notify connection to Runtime is closed. 146 | * Added Application.getGroups 147 | 148 | ## Bug Fixes 149 | * Fixed API doc for WindowOptions.setTaskbarIcon 150 | * Updated OpenFinInstaller.exe to handle client certificate 151 | * Fixed an issue with duplicate UUIDs for DesktopConnection in version 5.44.11.10 of Runtime 152 | 153 | # Version 5.44.2.5 154 | 155 | ## New Features 156 | * Support for port discovery of Runtime process at different integrity levels 157 | 158 | # Version 5.44.2.4 159 | ## New Features 160 | * Added setRdmUrl and setRuntimeAssetesUrl in DesktopConnect 161 | * Use proper names for threads created by DesktopConnection during launching Runtime 162 | 163 | # Version 5.44.2.3 164 | ## New Features 165 | * Cross-app docking: Windows from different HTML5 applications now can join the same group and dock to each other. Runtime 5.44.11.10 is required. 166 | * DesktopConnection catches exceptions from onSuccess and onError in AckListener 167 | 168 | ## Bug Fixes 169 | * Application.close(AckListener) is deprecated 170 | * fixed an issue in getGroup 171 | 172 | # Version 5.44.2.2 173 | ## New Features 174 | * Implemented timeout logout logic for DesktopConnection.connectToVersion 175 | * Added support for app-connected event for Window class 176 | * Added Application.createChildWindow method 177 | * Replaced java logging with slf4j. 178 | 179 | ## Bug Fixes 180 | * Fixed an issue with reconnect with port discovery. 181 | * Fixed an issue with Window.addEventListener 182 | 183 | # Version 5.44.2.1 184 | ## New Features 185 | * InterApplicationBus.send/publish accepts AckListener callback. 186 | * Added support for security realm in DesktopConnection 187 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | co.openfin 8 | openfin-desktop-java-example 9 | 9.0.1 10 | jar 11 | 12 | openfin-desktop-java-example 13 | Examples of OpenFin Java API 14 | http://www.openfin.co 15 | 16 | 17 | support@openfin.co 18 | 1.8 19 | 1.8 20 | true 21 | 22 | 23 | 24 | 25 | The MIT License (MIT) 26 | http://www.opensource.org/licenses/mit-license.php 27 | repo 28 | 29 | 30 | 31 | 32 | 33 | support@openfin.co 34 | OpenFin 35 | https://openfin.co 36 | openfin 37 | 38 | 39 | 40 | 41 | scm:hg:https://github.com/openfin/java-example.git 42 | scm:hg:https://github.com/openfin/java-example.git 43 | https://github.com/openfin/java-example.git 44 | 45 | 46 | 47 | 48 | oss-sonatype 49 | oss-sonatype 50 | https://oss.sonatype.org/content/repositories/snapshots/ 51 | 52 | true 53 | 54 | 55 | 56 | 57 | 58 | 59 | co.openfin 60 | openfin-desktop-java-adapter 61 | 9.2.0 62 | 63 | 64 | tablelayout 65 | TableLayout 66 | 20050920 67 | 68 | 69 | junit 70 | junit 71 | 4.11 72 | 73 | 74 | org.hamcrest 75 | hamcrest-core 76 | 1.3 77 | 78 | 79 | org.hamcrest 80 | hamcrest-library 81 | 1.1 82 | 83 | 84 | org.mockito 85 | mockito-core 86 | 1.9.5 87 | 88 | 89 | org.slf4j 90 | slf4j-api 91 | 1.7.21 92 | 93 | 94 | org.slf4j 95 | slf4j-jdk14 96 | 1.6.1 97 | 98 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | org.apache.maven.plugins 119 | maven-assembly-plugin 120 | 121 | 122 | ${basedir}/target/classes/META-INF/MANIFEST.MF 123 | 124 | 125 | 126 | 127 | org.apache.maven.plugins 128 | maven-jar-plugin 129 | 2.5 130 | 131 | 132 | ${basedir}/target/classes/META-INF/MANIFEST.MF 133 | 134 | true 135 | com.openfin.desktop.demo.OpenFinDesktopDemo 136 | 137 | 138 | 139 | 140 | 141 | 142 | test-jar 143 | 144 | 145 | 146 | 147 | 148 | 149 | org.apache.maven.plugins 150 | maven-dependency-plugin 151 | 152 | 153 | copy 154 | install 155 | 156 | copy-dependencies 157 | 158 | 159 | 160 | ${project.build.directory}/ 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | org.apache.maven.plugins 171 | maven-surefire-plugin 172 | 2.19.1 173 | 174 | ${skipTests} 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | src/main/resources 183 | true 184 | 185 | 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /release/PubSubExample.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Example for Pub/Sub with OpenFin API 5 | 28 | 29 | 30 |
Example OpenFin app to test publish and susbcribe API calls
31 |
32 | 33 | 34 | -------------------------------------------------------------------------------- /release/SimpleDockingExample.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Simple OpenFin app 5 | 43 | 44 | 45 |
Simple OpenFin app
46 |
47 | 48 | 49 | -------------------------------------------------------------------------------- /release/SimpleOpenFinApp.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Simple OpenFin app 5 | 13 | 14 | 15 |
Simple OpenFin app
16 |
17 | 18 | -------------------------------------------------------------------------------- /release/app.asar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/app.asar -------------------------------------------------------------------------------- /release/busdemo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Inter Application Bus demo 4 | 5 | 6 | 44 | 45 | 46 | 49 | 50 |

Demo for Inter Application Bus

51 |
52 |
53 |
54 | 55 |
56 |
57 | 58 |
59 | 60 | 61 | -------------------------------------------------------------------------------- /release/channel.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | REM This program is an example of channel API. It can be run as channel provider or client 3 | REM Channel name: ChannelExample 4 | REM usage: channel.bat [ provider | client ] 5 | set mode=%1 6 | IF "%~1" == "" set mode=provider 7 | echo Channel type set to: %mode% 8 | java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-9.0.1-SNAPSHOT.jar;lib/openfin-desktop-java-example-9.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.demo.version=stable com.openfin.desktop.demo.ChannelExample %mode% 9 | 10 | -------------------------------------------------------------------------------- /release/embed.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | set url=%1 3 | IF "%~1" == "" set url=https://openfin.co 4 | echo Embedded url set to: %url% 5 | java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/log4j-1.2.17.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-9.0.1-SNAPSHOT.jar;lib/openfin-desktop-java-example-9.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.demo.embed.URL=%URL% -Dcom.openfin.demo.version=stable com.openfin.desktop.demo.WindowEmbedDemo 6 | -------------------------------------------------------------------------------- /release/fxdemo.bat: -------------------------------------------------------------------------------- 1 | java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/log4j-1.2.17.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-8.0.8.jar;lib/openfin-desktop-java-example-7.1.1-tests.jar;lib/openfin-desktop-java-example-7.1.1.jar;lib/openfin-snap-dock-1.0.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.demo.embed.URL=https://openfin.co com.openfin.desktop.demo.FxDemo 2 | -------------------------------------------------------------------------------- /release/junit.bat: -------------------------------------------------------------------------------- 1 | REM usage: junit.bat runtime_version 2 | REM version defaults to stable 3 | if "%1" == "" ( 4 | set RuntimeVersion="stable" 5 | ) else ( 6 | set RuntimeVersion="%1" 7 | ) 8 | 9 | java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/log4j-1.2.17.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-9.2.0.jar;lib/openfin-desktop-java-example-9.2.1-tests.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.test.runtime.version=%RuntimeVersion% org.junit.runner.JUnitCore com.openfin.desktop.AllTests 10 | -------------------------------------------------------------------------------- /release/launchExternal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | LaunchExternalProcess example 4 | 5 | 30 | 31 | 32 | 35 | 36 |

LaunchExternalProcess example

37 |
38 |
39 |
40 | Full Path 41 | 42 |
43 | 44 | 45 | -------------------------------------------------------------------------------- /release/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Openfin Layouts Example 4 | 5 | 6 | 23 | 24 | 25 | 26 |

Openfin Layouts Library is included via script tag in this window. Accessible with global var OpenfinLayouts

27 |
28 | 29 |
30 | -------------------------------------------------------------------------------- /release/layoutclient1.json: -------------------------------------------------------------------------------- 1 | { 2 | "startup_app": { 3 | "name": "Layout Client1", 4 | "uuid": "Layout Client1", 5 | "defaultTop": 100, 6 | "defaultLeft": 100, 7 | "defaultWidth": 420, 8 | "defaultHeight": 420, 9 | "url": "http://localhost:8888/busdemo.html", 10 | "resizable": true, 11 | "autoShow": true, 12 | "saveWindowState": false, 13 | "contextMenu": true 14 | }, 15 | "services": [{ 16 | "manifestUrl": "https://cdn.openfin.co/services/openfin/layouts/1.0.0/app.json", 17 | "name": "layouts", 18 | "config": { 19 | "features": { 20 | "tab": true, 21 | "dock": true 22 | } 23 | } 24 | }], 25 | "runtime": { 26 | "arguments": "--v=1 --security-realm=java-test --enable-mesh ", 27 | "version": "9.61.38.40" 28 | } 29 | } -------------------------------------------------------------------------------- /release/layoutclient2.json: -------------------------------------------------------------------------------- 1 | { 2 | "startup_app": { 3 | "name": "Layout Client2", 4 | "uuid": "Layout Client2", 5 | "defaultTop": 600, 6 | "defaultLeft": 100, 7 | "defaultWidth": 420, 8 | "defaultHeight": 420, 9 | "url": "http://localhost:8888/busdemo.html", 10 | "resizable": true, 11 | "autoShow": true, 12 | "saveWindowState": false, 13 | "contextMenu": true 14 | }, 15 | "services": [{ 16 | "manifestUrl": "https://cdn.openfin.co/services/openfin/layouts/1.0.0/app.json", 17 | "name": "layouts", 18 | "config": { 19 | "features": { 20 | "tab": true, 21 | "dock": true 22 | } 23 | } 24 | }], 25 | "runtime": { 26 | "arguments": "--v=1 --security-realm=java-test --enable-mesh ", 27 | "version": "9.61.38.40" 28 | } 29 | } -------------------------------------------------------------------------------- /release/lib/TableLayout-20050920.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/TableLayout-20050920.jar -------------------------------------------------------------------------------- /release/lib/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /release/lib/hamcrest-library-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/hamcrest-library-1.1.jar -------------------------------------------------------------------------------- /release/lib/jetty-client-9.4.18.v20190429.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/jetty-client-9.4.18.v20190429.jar -------------------------------------------------------------------------------- /release/lib/jetty-http-9.4.18.v20190429.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/jetty-http-9.4.18.v20190429.jar -------------------------------------------------------------------------------- /release/lib/jetty-io-9.4.18.v20190429.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/jetty-io-9.4.18.v20190429.jar -------------------------------------------------------------------------------- /release/lib/jetty-util-9.4.18.v20190429.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/jetty-util-9.4.18.v20190429.jar -------------------------------------------------------------------------------- /release/lib/jetty-xml-9.4.18.v20190429.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/jetty-xml-9.4.18.v20190429.jar -------------------------------------------------------------------------------- /release/lib/jna-4.5.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/jna-4.5.1.jar -------------------------------------------------------------------------------- /release/lib/jna-platform-4.5.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/jna-platform-4.5.1.jar -------------------------------------------------------------------------------- /release/lib/json-20160810.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/json-20160810.jar -------------------------------------------------------------------------------- /release/lib/junit-4.11.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/junit-4.11.jar -------------------------------------------------------------------------------- /release/lib/log4j-1.2.17.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/log4j-1.2.17.jar -------------------------------------------------------------------------------- /release/lib/mockito-core-1.9.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/mockito-core-1.9.5.jar -------------------------------------------------------------------------------- /release/lib/objenesis-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/objenesis-1.0.jar -------------------------------------------------------------------------------- /release/lib/openfin-desktop-java-adapter-9.2.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/openfin-desktop-java-adapter-9.2.0.jar -------------------------------------------------------------------------------- /release/lib/openfin-desktop-java-example-9.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/openfin-desktop-java-example-9.0.1.jar -------------------------------------------------------------------------------- /release/lib/openfin-desktop-java-example-9.2.1-tests.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/openfin-desktop-java-example-9.2.1-tests.jar -------------------------------------------------------------------------------- /release/lib/openfin-desktop-java-example-9.2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/openfin-desktop-java-example-9.2.2.jar -------------------------------------------------------------------------------- /release/lib/slf4j-api-1.7.21.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/slf4j-api-1.7.21.jar -------------------------------------------------------------------------------- /release/lib/slf4j-jdk14-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/slf4j-jdk14-1.6.1.jar -------------------------------------------------------------------------------- /release/lib/slf4j-log4j12-1.7.18.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/slf4j-log4j12-1.7.18.jar -------------------------------------------------------------------------------- /release/lib/websocket-api-9.4.18.v20190429.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/websocket-api-9.4.18.v20190429.jar -------------------------------------------------------------------------------- /release/lib/websocket-client-9.4.18.v20190429.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/websocket-client-9.4.18.v20190429.jar -------------------------------------------------------------------------------- /release/lib/websocket-common-9.4.18.v20190429.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/release/lib/websocket-common-9.4.18.v20190429.jar -------------------------------------------------------------------------------- /release/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /release/logging.properties: -------------------------------------------------------------------------------- 1 | # Properties file which configures the operation of the JDK 2 | # logging facility. 3 | 4 | # The system will look for this config file, first using 5 | # a System property specified at startup: 6 | # 7 | # >java -Djava.util.logging.config.file=myLoggingConfigFilePath 8 | 9 | #handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler 10 | handlers=java.util.logging.ConsoleHandler 11 | 12 | # Default global logging level. 13 | # Loggers and Handlers may override this level 14 | .level=INFO 15 | 16 | # Limit the message that are printed on the console to INFO and above. 17 | java.util.logging.ConsoleHandler.level = FINE 18 | java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter 19 | 20 | # Log level for all OpenFin classes 21 | com.openfin.level=FINE 22 | 23 | # Log level for all WebSocket classes 24 | org.eclipse.jetty.level=INFO 25 | -------------------------------------------------------------------------------- /release/manifest.bat: -------------------------------------------------------------------------------- 1 | java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/log4j-1.2.17.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-8.0.8.jar;lib/openfin-desktop-java-example-7.1.1-tests.jar;lib/openfin-desktop-java-example-7.1.1.jar;lib/openfin-snap-dock-1.0.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties com.openfin.desktop.demo.LaunchManifestDemo 2 | -------------------------------------------------------------------------------- /release/notification.bat: -------------------------------------------------------------------------------- 1 | java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-8.0.11-SNAPSHOT.jar;lib/openfin-desktop-java-example-7.1.1-tests.jar;lib/openfin-desktop-java-example-7.1.1.jar;lib/openfin-snap-dock-1.0.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.temp=%LocalAppData%\OpenFin\temp -Dcom.openfin.demo.version=stable com.openfin.desktop.demo.NotificationServiceDemo 2 | 3 | -------------------------------------------------------------------------------- /release/preload.js: -------------------------------------------------------------------------------- 1 | var _preload = 12345 -------------------------------------------------------------------------------- /release/profile.bat: -------------------------------------------------------------------------------- 1 | java -Xmx100m -Xms100m -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-9.2.3-SNAPSHOT.jar;lib/openfin-desktop-java-example-9.0.1-tests.jar;lib/openfin-desktop-java-example-9.2.2.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.temp=%LocalAppData%\OpenFin\temp -Dcom.openfin.demo.version=stable -Dcom.openfin.demo.licenseKey=123456 com.openfin.desktop.demo.MemoryProfile 2 | 3 | -------------------------------------------------------------------------------- /release/publisher.bat: -------------------------------------------------------------------------------- 1 | java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-8.0.8.jar;lib/openfin-desktop-java-example-7.1.1-tests.jar;lib/openfin-desktop-java-example-7.1.1.jar;lib/openfin-snap-dock-1.0.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.demo.runtime.version=canary -Dcom.openfin.demo.publish.frequency=2000 -Dcom.openfin.demo.publish.size=2048 com.openfin.desktop.demo.PubSubTest publisher 2 | -------------------------------------------------------------------------------- /release/run.bat: -------------------------------------------------------------------------------- 1 | java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-9.0.1-SNAPSHOT.jar;lib/openfin-desktop-java-example-9.0.1-tests.jar;lib/openfin-desktop-java-example-9.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.temp=%LocalAppData%\OpenFin\temp -Dcom.openfin.demo.version=stable -Dcom.openfin.demo.licenseKey=123456 com.openfin.desktop.demo.OpenFinDesktopDemo 2 | 3 | -------------------------------------------------------------------------------- /release/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Example shell script to launch Runtime on Mac & Linux 3 | # Since RVM is not available, this script uses openfin-cli to launch Runtime 4 | # After installing openfin-cli, the following script needs to be created as start.sh in openfin-cli root directory 5 | 6 | #cd "$(dirname ${BASH_SOURCE[0]})" 7 | 8 | #if [[ $1 == file:///* ]] ; 9 | #then 10 | # configFile=`echo $1 | cut -c8-` 11 | #else 12 | # configFile=$1 13 | #fi 14 | #node cli.js -l -c $configFile 15 | 16 | java -cp openfin-desktop-java-example-7.1.1.jar;openfin-desktop-java-adapter-7.1.2.jar:TableLayout-20050920.jar:jna-4.2.2.jar:jna-platform-4.2.2.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.installer.location=/path-to-openfin-cli/start.sh -Dcom.openfin.demo.version=8.56.27.22 com.openfin.desktop.demo.OpenFinDesktopDemo 17 | 18 | -------------------------------------------------------------------------------- /release/stockflux.json: -------------------------------------------------------------------------------- 1 | { 2 | "startup_app": { 3 | "name": "StockFlux", 4 | "uuid": "StockFlux", 5 | "maxWidth": 0, 6 | "maxHeight": 0, 7 | "defaultWidth": 0, 8 | "defaultHeight": 0, 9 | "frame": false, 10 | "showTaskbarIcon": false, 11 | "url": "http://scottlogic.github.io/StockFlux/master/parent.html", 12 | "autoShow": false, 13 | "applicationIcon": "http://scottlogic.github.io/StockFlux/master/favicon.ico" 14 | }, 15 | "services": [{ 16 | "manifestUrl": "https://cdn.openfin.co/services/openfin/layouts/1.0.0/app.json", 17 | "name": "layouts", 18 | "config": { 19 | "features": { 20 | "tab": false, 21 | "dock": true 22 | } 23 | } 24 | }], 25 | "runtime": { 26 | "arguments": "--enable-aggressive-domstorage-flushing", 27 | "version": "9.61.38.40" 28 | }, 29 | "splashScreenImage": "http://scottlogic.github.io/StockFlux/master/splashscreen.png" 30 | } -------------------------------------------------------------------------------- /release/subscriber.bat: -------------------------------------------------------------------------------- 1 | java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-8.0.8.jar;lib/openfin-desktop-java-example-7.1.1-tests.jar;lib/openfin-desktop-java-example-7.1.1.jar;lib/openfin-snap-dock-1.0.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.demo.runtime.version=canary com.openfin.desktop.demo.PubSubTest subscriber 2 | -------------------------------------------------------------------------------- /release/testWindowPosition.bat: -------------------------------------------------------------------------------- 1 | java -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/log4j-1.2.17.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-8.0.8.jar;lib/openfin-desktop-java-example-7.1.1-tests.jar;lib/openfin-desktop-java-example-7.1.1.jar;lib/openfin-snap-dock-1.0.0.1.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties org.junit.runner.JUnitCore com.openfin.desktop.WindowPositionTest 2 | -------------------------------------------------------------------------------- /release/watchlist.json: -------------------------------------------------------------------------------- 1 | { 2 | "devtools_port": 9090, 3 | "startup_app": { 4 | "name": "GiantMachinesWatchlist", 5 | "url": "http://watchlist.giantmachines.com", 6 | "uuid": "GiantMachinesWatchlist", 7 | "applicationIcon": "http://watchlist.giantmachines.com/watchlist-icon.png", 8 | "autoShow": true, 9 | "frame": false, 10 | "defaultHeight": 600, 11 | "defaultWidth": 450, 12 | "defaultTop": 50, 13 | "defaultLeft": 50, 14 | "resizable": false, 15 | "maximizable": false 16 | }, 17 | "runtime": { 18 | "arguments": "--v=1", 19 | "version": "9.61.38.40", 20 | "forceLatest": true 21 | }, 22 | "services": [{ 23 | "manifestUrl": "https://cdn.openfin.co/services/openfin/layouts/1.0.0/app.json", 24 | "name": "layouts", 25 | "config": { 26 | "features": { 27 | "tab": false, 28 | "dock": true 29 | } 30 | } 31 | }], 32 | "splashScreenImage": "http://watchlist.giantmachines.com/watchlist-splash.png" 33 | } -------------------------------------------------------------------------------- /src/main/java/com/openfin/desktop/demo/AppCreateDialog.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop.demo; 2 | 3 | import com.openfin.desktop.ApplicationOptions; 4 | import com.openfin.desktop.WindowOptions; 5 | import info.clearthought.layout.TableLayout; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | import java.awt.event.ActionEvent; 10 | import java.awt.event.ActionListener; 11 | import java.util.UUID; 12 | 13 | /** 14 | * Created by richard on 2/28/15. 15 | */ 16 | public class AppCreateDialog extends JDialog { 17 | protected JTextField uuidText, nameText, urlText, applicationIconText, 18 | defaultLeftText, defaultTopText, defaultWidthText, defaultHeightText; 19 | 20 | protected JLabel uuidLabel, nameLabel, urlLabel, applicationIconLabel, 21 | defaultLeftLabel, defaultTopLabel, defaultWidthLabel, defaultHeightLabel; 22 | 23 | protected JCheckBox resizeCheck, frameCheck, showTaskbarIconCheck, autoShowCheck; 24 | 25 | protected JButton createButton; 26 | protected boolean createClicked = false; 27 | 28 | public AppCreateDialog() { 29 | super(); 30 | setTitle("Create Application"); 31 | setModal(true); 32 | setLayout(new BorderLayout()); 33 | 34 | this.add(layoutDescriptionPanel(), BorderLayout.CENTER); 35 | this.add(layoutActionButtonPanel(), BorderLayout.SOUTH); 36 | 37 | setSize(500, 600); 38 | } 39 | 40 | private JPanel layoutDescriptionPanel() { 41 | 42 | uuidLabel = new JLabel("UUID: "); 43 | uuidLabel.setHorizontalAlignment(SwingConstants.RIGHT); 44 | uuidText = new JTextField("Hello OpenFin"); 45 | uuidText.setColumns(50); 46 | 47 | nameLabel = new JLabel("Name: "); 48 | nameLabel.setHorizontalAlignment(SwingConstants.RIGHT); 49 | nameText = new JTextField("Hello OpenFin"); 50 | nameText.setColumns(50); 51 | 52 | urlLabel = new JLabel("URL: "); 53 | urlLabel.setHorizontalAlignment(SwingConstants.RIGHT); 54 | urlText = new JTextField("http://demoappdirectory.openf.in/desktop/config/apps/OpenFin/HelloOpenFin/index.html"); 55 | urlText.setColumns(50); 56 | 57 | applicationIconLabel = new JLabel("Icon URL:" ); 58 | applicationIconLabel.setHorizontalAlignment(SwingConstants.RIGHT); 59 | applicationIconText = new JTextField("http://demoappdirectory.openf.in/desktop/config/apps/OpenFin/HelloOpenFin/img/openfin.ico"); 60 | applicationIconText.setColumns(50); 61 | 62 | defaultLeftLabel = new JLabel("Left: "); 63 | defaultLeftLabel.setHorizontalAlignment(SwingConstants.RIGHT); 64 | defaultLeftText = new JTextField("10"); 65 | defaultLeftText.setColumns(4); 66 | 67 | defaultTopLabel = new JLabel("Top: "); 68 | defaultTopLabel.setHorizontalAlignment(SwingConstants.RIGHT); 69 | defaultTopText = new JTextField("50"); 70 | defaultTopText.setColumns(4); 71 | 72 | defaultWidthLabel = new JLabel("Width: "); 73 | defaultWidthLabel.setHorizontalAlignment(SwingConstants.RIGHT); 74 | defaultWidthText = new JTextField("395"); 75 | defaultWidthText.setColumns(4); 76 | 77 | defaultHeightLabel = new JLabel("Height: "); 78 | defaultHeightLabel.setHorizontalAlignment(SwingConstants.RIGHT); 79 | defaultHeightText = new JTextField("525"); 80 | defaultHeightText.setColumns(4); 81 | 82 | resizeCheck = new JCheckBox("resize", false); 83 | frameCheck = new JCheckBox("frame", false); 84 | showTaskbarIconCheck = new JCheckBox("showTaskbarIcon", true); 85 | autoShowCheck = new JCheckBox("autoShow", true); 86 | 87 | JPanel fieldPanel = new JPanel(); 88 | 89 | fieldPanel.setLayout(new javax.swing.BoxLayout(fieldPanel, javax.swing.BoxLayout.Y_AXIS)); 90 | 91 | double size[][] = 92 | {{0.25, 0.75}, 93 | {30,30,30,30,30,30,30,30,30,30,30,30}}; 94 | 95 | TableLayout twoColLayout = new TableLayout(size); 96 | JPanel twoColPanel = new JPanel(twoColLayout); 97 | 98 | twoColPanel.add(uuidLabel, "0, 0"); 99 | twoColPanel.add(uuidText, "1, 0"); 100 | twoColPanel.add(nameLabel , "0, 1"); 101 | twoColPanel.add(nameText , "1, 1"); 102 | twoColPanel.add(urlLabel , "0, 2"); 103 | twoColPanel.add(urlText , "1, 2"); 104 | 105 | twoColPanel.add(applicationIconLabel , "0, 3"); 106 | twoColPanel.add(applicationIconText , "1, 3"); 107 | twoColPanel.add(defaultLeftLabel , "0, 4"); 108 | twoColPanel.add(defaultLeftText , "1, 4"); 109 | twoColPanel.add(defaultTopLabel , "0, 5"); 110 | twoColPanel.add(defaultTopText , "1, 5"); 111 | twoColPanel.add(defaultWidthLabel , "0, 6"); 112 | twoColPanel.add(defaultWidthText , "1, 6"); 113 | twoColPanel.add(defaultHeightLabel , "0, 7"); 114 | twoColPanel.add(defaultHeightText , "1, 7"); 115 | 116 | fieldPanel.add(twoColPanel); 117 | fieldPanel.add(resizeCheck); 118 | fieldPanel.add(frameCheck); 119 | fieldPanel.add(showTaskbarIconCheck); 120 | fieldPanel.add(autoShowCheck); 121 | return fieldPanel; 122 | } 123 | 124 | public ApplicationOptions getApplicatonOptions() { 125 | ApplicationOptions options = null; 126 | if (createClicked) { 127 | options = getApplicationOptionsFromUI(); 128 | } 129 | return options; 130 | } 131 | 132 | public ApplicationOptions getApplicationOptionsFromUI() { 133 | String uuid = uuidText.getText(); 134 | String name = nameText.getText(); 135 | String url = urlText.getText(); 136 | String applicationIcon = applicationIconText.getText(); 137 | int defaultLeft = Integer.parseInt(defaultLeftText.getText()); 138 | int defaultTop = Integer.parseInt(defaultTopText.getText()); 139 | int defaultWidth = Integer.parseInt(defaultWidthText.getText()); 140 | int defaultHeight = Integer.parseInt(defaultHeightText.getText()); 141 | boolean resize = resizeCheck.isSelected(); 142 | boolean frame = frameCheck.isSelected(); 143 | boolean showTaskbarIcon = showTaskbarIconCheck.isSelected(); 144 | boolean autoShow = autoShowCheck.isSelected(); 145 | 146 | ApplicationOptions options = new ApplicationOptions(name, uuid, url); 147 | options.setApplicationIcon(applicationIcon); 148 | 149 | WindowOptions mainWindowOptions = new WindowOptions(); 150 | 151 | mainWindowOptions.setAutoShow(autoShow); 152 | mainWindowOptions.setDefaultHeight(defaultHeight); 153 | mainWindowOptions.setDefaultLeft(defaultLeft); 154 | mainWindowOptions.setDefaultTop(defaultTop); 155 | mainWindowOptions.setDefaultWidth(defaultWidth); 156 | mainWindowOptions.setResizable(resize); 157 | mainWindowOptions.setFrame(frame); 158 | mainWindowOptions.setShowTaskbarIcon(showTaskbarIcon); 159 | 160 | options.setMainWindowOptions(mainWindowOptions); 161 | return options; 162 | } 163 | 164 | public void show(Component parent) { 165 | this.createClicked = false; 166 | uuidText.setText("OpenFinDesktopDemo"); 167 | this.setLocationRelativeTo(parent); 168 | setVisible(true); 169 | } 170 | 171 | private JPanel layoutActionButtonPanel() { 172 | JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); 173 | 174 | createButton = new JButton("Create"); 175 | createButton.addActionListener(new ActionListener() { 176 | @Override 177 | public void actionPerformed(ActionEvent actionEvent) { 178 | createClicked = true; 179 | AppCreateDialog.this.setVisible(false); 180 | } 181 | }); 182 | buttonPanel.add(createButton); 183 | 184 | return buttonPanel; 185 | } 186 | 187 | } 188 | -------------------------------------------------------------------------------- /src/main/java/com/openfin/desktop/demo/ChannelExample.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop.demo; 2 | 3 | import java.util.concurrent.CountDownLatch; 4 | import java.util.concurrent.atomic.AtomicInteger; 5 | 6 | import com.openfin.desktop.channel.*; 7 | import org.json.JSONObject; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.openfin.desktop.Ack; 12 | import com.openfin.desktop.AckListener; 13 | import com.openfin.desktop.AsyncCallback; 14 | import com.openfin.desktop.DesktopConnection; 15 | import com.openfin.desktop.DesktopException; 16 | import com.openfin.desktop.DesktopStateListener; 17 | import com.openfin.desktop.RuntimeConfiguration; 18 | 19 | public class ChannelExample implements DesktopStateListener { 20 | 21 | private static Logger logger = LoggerFactory.getLogger(ChannelExample.class.getName()); 22 | private static CountDownLatch latch = new CountDownLatch(1); 23 | private static String CHANNEL_NAME="ChannelExample"; 24 | 25 | private DesktopConnection desktopConnection; 26 | 27 | private static String channelType; // client or provider, if not set, both 28 | 29 | public ChannelExample() { 30 | try { 31 | StringBuilder sb = new StringBuilder("ChannelExample"); 32 | if (channelType != null) { 33 | sb.append(channelType); 34 | } 35 | desktopConnection = new DesktopConnection(sb.toString()); 36 | String desktopVersion = java.lang.System.getProperty("com.openfin.demo.runtime.version", "stable"); 37 | RuntimeConfiguration configuration = new RuntimeConfiguration(); 38 | configuration.setRuntimeVersion(desktopVersion); 39 | desktopConnection.connect(configuration, this, 60); 40 | } 41 | catch (Exception ex) { 42 | logger.error("Error launching Runtime", ex); 43 | } 44 | } 45 | 46 | /** 47 | * Create a provider that supports "getValue", "increment" and "incrementBy n" actions 48 | */ 49 | public void createChannelProvider() { 50 | 51 | // Create the channel provider. 52 | desktopConnection.getChannel(CHANNEL_NAME).createAsync().thenAccept(provider -> { 53 | provider.addProviderListener(new ChannelProviderListener() { 54 | 55 | // Create the onChannelConnect event handler. 56 | @Override 57 | public void onClientConnect(ChannelClientConnectEvent connectionEvent) throws Exception { 58 | 59 | // Add a line to the log file to identify the UUID of the caller. 60 | logger.info(String.format("provider receives client connect event from %s ", connectionEvent.getUuid())); 61 | 62 | // Extract the JSON payload. 63 | JSONObject payload = (JSONObject) connectionEvent.getPayload(); 64 | 65 | // If the "name" element of the payload says the client is invalid, reject the request. 66 | if (payload != null) { 67 | String name = payload.optString("name"); 68 | if ("Invalid Client".equals(name)) { 69 | throw new Exception("request rejected"); 70 | } 71 | } 72 | } 73 | 74 | // Create the onChannelDisconnect event handler. 75 | @Override 76 | public void onClientDisconnect(ChannelClientConnectEvent connectionEvent) { 77 | 78 | // Add a line to the log file identifying the UUID of the caller. 79 | logger.info(String.format("provider receives channel disconnect event from %s ", connectionEvent.getUuid())); 80 | } 81 | }); 82 | 83 | // The provider was created. Now to register the actions. 84 | // ------------------------------------------------------ 85 | 86 | // This variable is used as the "value" element for the getValue, increment, and incrementBy actions. 87 | AtomicInteger localInteger = new AtomicInteger(0); 88 | 89 | // Register the "getValue" action. 90 | // This action will return the value of the localInteger variable. 91 | provider.register("getValue", new ChannelAction() { 92 | 93 | // This is the logic for the "getValue" action. 94 | @Override 95 | public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { 96 | 97 | // Write a string to the logfile that shows the requested action and payload. 98 | logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString())); 99 | 100 | // Create a JSON object to return to the channel client. 101 | JSONObject obj = new JSONObject(); 102 | 103 | // Set the "value" JSON element to the value of the localInteger variable. 104 | obj.put("value", localInteger.get()); 105 | 106 | // Return the JSON object to the channel client. 107 | return obj; 108 | } 109 | }); 110 | 111 | // Register the "increment" action. 112 | // This action will increment the value of the localInteger variable by one. 113 | provider.register("increment", new ChannelAction() { 114 | 115 | // This is the logic for the "increment" action. 116 | @Override 117 | public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { 118 | 119 | // Write a string to the logfile that identifies the action and payload. 120 | logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString())); 121 | 122 | // Create a JSON object to return to the channel client. 123 | JSONObject obj = new JSONObject(); 124 | 125 | // Increment localInteger and set the "value" JSON element to the new value of localInteger. 126 | obj.put("value", localInteger.incrementAndGet()); 127 | provider.publish("event", obj, null); 128 | 129 | // Return the JSON object to the channel client. 130 | return obj; 131 | } 132 | }); 133 | 134 | // Register the "incrementBy" action. 135 | // This action will increment the value of the localInteger variable by a specified amount. 136 | provider.register("incrementBy", new ChannelAction() { 137 | 138 | // This is the logic for the "incrementBy" action. 139 | @Override 140 | public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { 141 | 142 | // Write a string to the logfile that identifies the action and payload. 143 | logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString())); 144 | 145 | // Extract the increment amount (delta) from the payload JSON object. 146 | int delta = ((JSONObject)payload).getInt("delta"); 147 | 148 | // Create a new JSON object to return to the channel client. 149 | JSONObject obj = new JSONObject(); 150 | 151 | // Increase localInteger by the delta amount and set the "value" JSON element to the new value of localInteger. 152 | obj.put("value", localInteger.addAndGet(delta)); 153 | 154 | // Return the new JSON object to the channel client. 155 | return obj; 156 | } 157 | }); 158 | }); 159 | } 160 | 161 | /** 162 | * Create a channel client that invokes "getValue", "increment" and "incrementBy n" actions 163 | */ 164 | public void createChannelClient() { 165 | JSONObject payload = new JSONObject(); 166 | payload.put("name", "java example"); 167 | desktopConnection.getChannel(CHANNEL_NAME).connectAsync(false, payload).thenAccept(client -> { 168 | client.addChannelListener(new ChannelListener() { 169 | @Override 170 | public void onChannelConnect(ConnectionEvent connectionEvent) { 171 | } 172 | @Override 173 | public void onChannelDisconnect(ConnectionEvent connectionEvent) { 174 | logger.info("channel disconnected {}", connectionEvent.getChannelId()); 175 | } 176 | }); 177 | client.register("event", new ChannelAction() { 178 | @Override 179 | public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { 180 | logger.info("channel event {}", action); 181 | return null; 182 | } 183 | }); 184 | 185 | client.dispatch("getValue", null, new AckListener() { 186 | @Override 187 | public void onSuccess(Ack ack) { 188 | logger.info("current value={}", ack.getJsonObject().getJSONObject("data").getJSONObject("result").getInt("value")); 189 | 190 | //got current value, do increment 191 | client.dispatch("increment", null, new AckListener() { 192 | @Override 193 | public void onSuccess(Ack ack) { 194 | logger.info("after invoking increment, value={}", ack.getJsonObject().getJSONObject("data").getJSONObject("result").getInt("value")); 195 | 196 | //let's do increatmentBy 10 197 | JSONObject payload = new JSONObject(); 198 | payload.put("delta", 10); 199 | client.dispatch("incrementBy", payload, new AckListener() { 200 | @Override 201 | public void onSuccess(Ack ack) { 202 | logger.info("after invoking incrementBy, value={}", ack.getJsonObject().getJSONObject("data").getJSONObject("result").getInt("value")); 203 | 204 | try { 205 | desktopConnection.disconnect(); 206 | } catch (DesktopException e) { 207 | e.printStackTrace(); 208 | } 209 | } 210 | 211 | @Override 212 | public void onError(Ack ack) { 213 | } 214 | }); 215 | } 216 | 217 | @Override 218 | public void onError(Ack ack) { 219 | } 220 | }); 221 | } 222 | 223 | @Override 224 | public void onError(Ack ack) { 225 | } 226 | }); 227 | }); 228 | } 229 | 230 | @Override 231 | public void onReady() { 232 | if ("provider".equals(channelType) || channelType == null) { 233 | createChannelProvider(); 234 | } 235 | if ("client".equals(channelType) || channelType == null) { 236 | createChannelClient(); 237 | } 238 | } 239 | 240 | @Override 241 | public void onClose(String error) { 242 | logger.info("onClose, value={}", error); 243 | latch.countDown(); 244 | } 245 | 246 | @Override 247 | public void onError(String reason) { 248 | logger.info("onError, value={}", reason); 249 | } 250 | 251 | @Override 252 | public void onMessage(String message) { 253 | 254 | } 255 | 256 | @Override 257 | public void onOutgoingMessage(String message) { 258 | 259 | } 260 | 261 | public static void main(String[] args) { 262 | if (args.length > 0) { 263 | channelType = args[0]; 264 | } 265 | try { 266 | new ChannelExample(); 267 | latch.await(); 268 | } 269 | catch (InterruptedException e) { 270 | // TODO Auto-generated catch block 271 | e.printStackTrace(); 272 | } 273 | 274 | java.lang.System.exit(0); 275 | } 276 | } 277 | -------------------------------------------------------------------------------- /src/main/java/com/openfin/desktop/demo/DemoUtils.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop.demo; 2 | 3 | import com.openfin.desktop.*; 4 | import org.json.JSONObject; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.util.Objects; 9 | import java.util.concurrent.CountDownLatch; 10 | import java.util.concurrent.ExecutionException; 11 | import java.util.concurrent.TimeUnit; 12 | import java.util.concurrent.atomic.AtomicReference; 13 | 14 | /** 15 | * Created by wche on 2/12/16. 16 | */ 17 | public class DemoUtils { 18 | private static Logger logger = LoggerFactory.getLogger(DemoUtils.class.getName()); 19 | 20 | public static void addEventListener(Application application, String evenType, EventListener eventListener, AckListener ackListener) throws Exception { 21 | logger.debug("addEventListener " + evenType); 22 | application.addEventListener(evenType, eventListener, new AckListener() { 23 | @Override 24 | public void onSuccess(Ack ack) { 25 | logger.debug("addEventListener ack " + ack.isSuccessful()); 26 | ackSuccess(ackListener, application); 27 | } 28 | @Override 29 | public void onError(Ack ack) { 30 | logger.error(String.format("Error adding event listener %s %s", evenType, ack.getReason())); 31 | ackError(ackListener, ack.getReason()); 32 | } 33 | }); 34 | } 35 | 36 | public static void runApplication(ApplicationOptions options, DesktopConnection desktopConnection, AckListener ackListener) throws Exception { 37 | AtomicReference appRef = new AtomicReference<>(); 38 | Application application = createApplication(options, desktopConnection, new AckListener() { 39 | @Override 40 | public void onSuccess(Ack ack) { 41 | try { 42 | runApplication(appRef.get(), true, ackListener); 43 | } catch (Exception e) { 44 | logger.error("Error running application", e); 45 | ackError(ackListener, e.getMessage()); 46 | } 47 | } 48 | @Override 49 | public void onError(Ack ack) { 50 | logger.error(String.format("onError %s", ack.getReason())); 51 | ackError(ackListener, ack.getReason()); 52 | } 53 | }); 54 | appRef.set(application); 55 | } 56 | 57 | public static void runApplication(Application application, boolean checkAppConnected, AckListener ackListener) throws Exception { 58 | EventListener listener = new EventListener() { 59 | @Override 60 | public void eventReceived(ActionEvent actionEvent) { 61 | if (actionEvent.getType().equals("started")) { 62 | if (!checkAppConnected) { 63 | ackSuccess(ackListener, application); 64 | } 65 | } 66 | else if (actionEvent.getType().equals("app-connected")) { 67 | if (checkAppConnected) { 68 | ackSuccess(ackListener, application); 69 | } 70 | } 71 | } 72 | }; 73 | 74 | AckListener eventAddAck = new AckListener() { 75 | @Override 76 | public void onSuccess(Ack ack) { 77 | application.run(new AckListener() { 78 | @Override 79 | public void onSuccess(Ack ack) { 80 | logger.debug(String.format("Successful run %s", application.getOptions().getUUID())); 81 | } 82 | @Override 83 | public void onError(Ack ack) { 84 | ackError(ackListener, ack.getReason()); 85 | logger.error("Error running application", ack.getReason()); 86 | } 87 | }); 88 | } 89 | @Override 90 | public void onError(Ack ack) { 91 | logger.error(String.format("Error adding event listener %s", ack.getReason())); 92 | } 93 | }; 94 | if (checkAppConnected) { 95 | addEventListener(application.getWindow(), "app-connected", listener, eventAddAck); 96 | } else { 97 | addEventListener(application, "started", listener, eventAddAck); 98 | } 99 | 100 | } 101 | 102 | public static Application createApplication(ApplicationOptions options, DesktopConnection desktopConnection, AckListener ackListener) throws Exception { 103 | Application application = new Application(options, desktopConnection, new AckListener() { 104 | @Override 105 | public void onSuccess(Ack ack) { 106 | ackSuccess(ackListener, options); 107 | } 108 | 109 | @Override 110 | public void onError(Ack ack) { 111 | logger.error("Error creating application", ack.getReason()); 112 | ackError(ackListener, ack.getReason()); 113 | } 114 | }); 115 | return application; 116 | } 117 | 118 | public static void addEventListener(Window window, String evenType, EventListener eventListener, AckListener ackListener) throws Exception { 119 | logger.debug("addEventListener " + evenType); 120 | window.addEventListener(evenType, eventListener, new AckListener() { 121 | @Override 122 | public void onSuccess(Ack ack) { 123 | logger.debug("addEventListener ack " + ack.isSuccessful()); 124 | ackSuccess(ackListener, window); 125 | } 126 | @Override 127 | public void onError(Ack ack) { 128 | logger.error(String.format("Error adding event listener %s %s", evenType, ack.getReason())); 129 | ackError(ackListener, ack.getReason()); 130 | } 131 | }); 132 | } 133 | 134 | public static void ackSuccess(AckListener ackListener, Object source) { 135 | if (ackListener != null) { 136 | ackListener.onSuccess(new Ack(new JSONObject(), source)); 137 | } 138 | } 139 | 140 | public static void ackError(AckListener ackListener, String reason) { 141 | if (ackListener != null) { 142 | JSONObject obj = new JSONObject(); 143 | obj.put("reason", reason); 144 | ackListener.onError(new Ack(obj, ackListener)); 145 | } 146 | } 147 | 148 | } 149 | -------------------------------------------------------------------------------- /src/main/java/com/openfin/desktop/demo/FxDemo.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop.demo; 2 | 3 | import com.openfin.desktop.*; 4 | import com.openfin.desktop.Window; 5 | import com.sun.javafx.tk.TKStage; 6 | import com.sun.jna.Pointer; 7 | import com.sun.jna.platform.win32.User32; 8 | import com.sun.jna.platform.win32.WinDef; 9 | 10 | import javafx.application.Application; 11 | import javafx.application.Platform; 12 | import javafx.collections.ObservableList; 13 | import javafx.event.ActionEvent; 14 | import javafx.event.EventHandler; 15 | import javafx.scene.Group; 16 | import javafx.scene.Scene; 17 | import javafx.scene.control.Button; 18 | import javafx.scene.layout.AnchorPane; 19 | import javafx.scene.layout.StackPane; 20 | import javafx.stage.Stage; 21 | import org.slf4j.Logger; 22 | import org.slf4j.LoggerFactory; 23 | 24 | import java.lang.reflect.Method; 25 | 26 | /** 27 | * Java example to embed HTML5 window in JavaFX window 28 | * 29 | * Created by wche on 3/13/15. 30 | * 31 | */ 32 | 33 | public class FxDemo extends Application implements DesktopStateListener { 34 | private final static Logger logger = LoggerFactory.getLogger(FxDemo.class.getName()); 35 | private final static String WINDOW_TITLE = "FX Demo"; 36 | 37 | private DesktopConnection desktopConnection; 38 | private Button btnStart, btnStop; 39 | private StackPane embedPane; 40 | 41 | protected String openfin_app_url = "https://cdn.openfin.co/examples/junit/SimpleDockingExample.html"; // source is in release/SimpleDockingExample.html 42 | protected String startupUuid = "OpenFinHelloWorld"; 43 | private long stageHWndId; 44 | private com.openfin.desktop.Application startupHtml5app; 45 | 46 | @Override 47 | public void start(Stage stage) { 48 | btnStart = new Button(); 49 | btnStart.setText("Launch OpenFin"); 50 | btnStart.setLayoutX(10); 51 | btnStart.setLayoutY(10); 52 | btnStart.setOnAction(new EventHandler() { 53 | @Override 54 | public void handle(ActionEvent event) { 55 | launchOpenFin(); 56 | } 57 | }); 58 | btnStop = new Button(); 59 | btnStop.setText("Shut down OpenFin"); 60 | btnStop.setLayoutX(200); 61 | btnStop.setLayoutY(10); 62 | btnStop.setDisable(true); 63 | btnStop.setOnAction(new EventHandler() { 64 | @Override 65 | public void handle(ActionEvent event) { 66 | shutDown(); 67 | } 68 | }); 69 | 70 | AnchorPane anchorPane = new AnchorPane(); 71 | anchorPane.getChildren().add(btnStart); 72 | anchorPane.getChildren().add(btnStop); 73 | 74 | //Creating a Group object 75 | Group root = new Group(); 76 | 77 | //Retrieving the observable list object 78 | ObservableList list = root.getChildren(); 79 | 80 | 81 | embedPane = new StackPane(); 82 | embedPane.setLayoutX(10); 83 | embedPane.setLayoutY(50); 84 | AnchorPane.setTopAnchor(embedPane, 50.0); 85 | AnchorPane.setBottomAnchor(embedPane, 0.0); 86 | AnchorPane.setLeftAnchor(embedPane, 0.0); 87 | AnchorPane.setRightAnchor(embedPane, 0.0); 88 | anchorPane.getChildren().add(embedPane); 89 | embedPane.widthProperty().addListener(observable -> { 90 | onEmbedComponentSizeChange(); 91 | }); 92 | embedPane.heightProperty().addListener(observable -> { 93 | onEmbedComponentSizeChange(); 94 | }); 95 | 96 | //Creating a scene object 97 | Scene scene = new Scene(anchorPane, 800, 800); 98 | 99 | //Setting title to the Stage 100 | stage.setTitle(WINDOW_TITLE); 101 | 102 | //Adding scene to the stage 103 | stage.setScene(scene); 104 | 105 | //Displaying the contents of the stage 106 | stage.show(); 107 | 108 | this.stageHWndId = getWindowHandle(stage); 109 | } 110 | 111 | private void launchOpenFin() { 112 | RuntimeConfiguration cfg = new RuntimeConfiguration(); 113 | cfg.setRuntimeVersion("stable"); 114 | cfg.setAdditionalRuntimeArguments(" --v=1 "); 115 | try { 116 | desktopConnection = new DesktopConnection("JavaFxDemo"); 117 | desktopConnection.connect(cfg, this, 60); 118 | } catch (Exception e) { 119 | e.printStackTrace(); 120 | } 121 | } 122 | 123 | private void launchHtmlApp() { 124 | // launch 5 instances of same example app 125 | int width = 500, height=500; 126 | try { 127 | String url = java.lang.System.getProperty("com.openfin.demo.embed.URL"); 128 | if (url != null) { 129 | openfin_app_url = url; 130 | } 131 | ApplicationOptions options = new ApplicationOptions(startupUuid, startupUuid, openfin_app_url); 132 | options.setApplicationIcon("http://openfin.github.io/snap-and-dock/openfin.ico"); 133 | WindowOptions mainWindowOptions = new WindowOptions(); 134 | mainWindowOptions.setAutoShow(false); 135 | mainWindowOptions.setDefaultHeight(height); 136 | mainWindowOptions.setDefaultLeft(10); 137 | mainWindowOptions.setDefaultTop(50); 138 | mainWindowOptions.setDefaultWidth(width); 139 | mainWindowOptions.setShowTaskbarIcon(true); 140 | mainWindowOptions.setSaveWindowState(false); // set to false so all windows start at same initial positions for each run 141 | mainWindowOptions.setFrame(false); 142 | mainWindowOptions.setContextMenu(true); 143 | mainWindowOptions.setResizeRegionSize(0); 144 | options.setMainWindowOptions(mainWindowOptions); 145 | DemoUtils.runApplication(options, this.desktopConnection, new AckListener() { 146 | @Override 147 | public void onSuccess(Ack ack) { 148 | com.openfin.desktop.Application app = (com.openfin.desktop.Application) ack.getSource(); 149 | try { 150 | Thread.sleep(1000); 151 | embedStartupApp(); 152 | } catch (Exception ex) { 153 | ex.printStackTrace(); 154 | } 155 | } 156 | @Override 157 | public void onError(Ack ack) { 158 | logger.error(String.format("Error launching %s %s", options.getUUID(), ack.getReason())); 159 | } 160 | }); 161 | } catch (Exception e) { 162 | logger.error("Error launching app", e); 163 | } 164 | } 165 | 166 | private void embedStartupApp() { 167 | try { 168 | if (startupHtml5app == null) { 169 | startupHtml5app = com.openfin.desktop.Application.wrap(this.startupUuid, this.desktopConnection); 170 | } 171 | 172 | Window html5Wnd = startupHtml5app.getWindow(); 173 | html5Wnd.embedInto(stageHWndId, (int)this.embedPane.getLayoutX(), (int)this.embedPane.getLayoutY(), 174 | (int)this.embedPane.getWidth(), (int)this.embedPane.getHeight(), new AckListener() { 175 | @Override 176 | public void onSuccess(Ack ack) { 177 | if (ack.isSuccessful()) { 178 | } else { 179 | logger.error("embedding failed: " + ack.getJsonObject().toString()); 180 | } 181 | } 182 | @Override 183 | public void onError(Ack ack) { 184 | } 185 | }); 186 | } catch (Exception e) { 187 | e.printStackTrace(); 188 | } 189 | } 190 | 191 | private void onEmbedComponentSizeChange() { 192 | logger.info(String.format("%f %f ", this.embedPane.getLayoutX(), this.embedPane.getLayoutY())); 193 | if (startupHtml5app != null) { 194 | startupHtml5app.getWindow().embedComponentSizeChange((int)this.embedPane.getLayoutX(), (int)this.embedPane.getLayoutY(), 195 | (int)this.embedPane.getWidth(), (int)this.embedPane.getHeight()); 196 | } 197 | } 198 | 199 | private void shutDown() { 200 | try { 201 | this.desktopConnection.exit(); 202 | Platform.exit(); 203 | } catch (Exception e) { 204 | e.printStackTrace(); 205 | } 206 | } 207 | 208 | private long getWindowHandle(Stage stage) { 209 | long handle = -1; 210 | try { 211 | WinDef.HWND hWnd = User32.INSTANCE.FindWindow(null, WINDOW_TITLE); 212 | handle = Pointer.nativeValue(hWnd.getPointer()); 213 | } catch (Throwable e) { 214 | logger.error("Error getting Window Pointer", e); 215 | } 216 | logger.info(String.format("Stage hwnd %d", handle)); 217 | return handle; 218 | } 219 | 220 | @Override 221 | public void onReady() { 222 | logger.info("Connected to OpenFin Runtime"); 223 | btnStart.setDisable(true); 224 | btnStop.setDisable(false); 225 | launchHtmlApp(); 226 | } 227 | 228 | @Override 229 | public void onClose(String error) { 230 | logger.info("Disconnected from OpenFin Runtime"); 231 | btnStart.setDisable(false); 232 | btnStop.setDisable(true); 233 | } 234 | 235 | @Override 236 | public void onError(String s) { 237 | } 238 | 239 | @Override 240 | public void onMessage(String s) { 241 | } 242 | 243 | @Override 244 | public void onOutgoingMessage(String s) { 245 | } 246 | 247 | public static void main(String args[]) { 248 | launch(args); 249 | } 250 | 251 | } -------------------------------------------------------------------------------- /src/main/java/com/openfin/desktop/demo/FxLayoutFrame.java: -------------------------------------------------------------------------------- 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 static String LayoutServiceChannelName = "of-layouts-service-v1"; 20 | private ExternalWindowObserver externalWindowObserver; 21 | private String windowName; 22 | private Stage stage; 23 | private static JFXPanel jFXPanel; 24 | 25 | public FxLayoutFrame(DesktopConnection desktopConnection, String appUuid, String windowName) { 26 | System.out.println(windowName + " being created "); 27 | this.windowName = windowName; 28 | if (jFXPanel == null) { 29 | jFXPanel = new JFXPanel(); 30 | javafx.application.Platform.setImplicitExit(false); 31 | } 32 | javafx.application.Platform.runLater(new Runnable() { 33 | @Override 34 | public void run() { 35 | Button btnUndock = new Button("undock"); 36 | btnUndock.setDisable(true); 37 | 38 | StackPane secondaryLayout = new StackPane(); 39 | secondaryLayout.getChildren().add(btnUndock); 40 | 41 | Scene secondScene = new Scene(secondaryLayout, 640, 480); 42 | 43 | FxLayoutFrame.this.stage = new Stage(); 44 | FxLayoutFrame.this.stage.setTitle(windowName); 45 | FxLayoutFrame.this.stage.setScene(secondScene); 46 | 47 | // Set position of second window, related to primary window. 48 | FxLayoutFrame.this.stage.setX(640); 49 | FxLayoutFrame.this.stage.setY(480); 50 | FxLayoutFrame.this.stage.show(); 51 | 52 | // FxLayoutFrame.this.stage.setOnCloseRequest(event -> FxLayoutFrame.this.cleanup()); 53 | 54 | try { 55 | FxLayoutFrame.this.externalWindowObserver = 56 | new ExternalWindowObserver(desktopConnection.getPort(), appUuid, windowName, FxLayoutFrame.this.stage, 57 | new AckListener() { 58 | @Override 59 | public void onSuccess(Ack ack) { 60 | ExternalWindowObserver observer = (ExternalWindowObserver) ack.getSource(); 61 | observer.getDesktopConnection().getChannel(LayoutServiceChannelName).connect( 62 | new AsyncCallback() { 63 | @Override 64 | public void onSuccess(ChannelClient client) { 65 | btnUndock.setOnAction(new EventHandler() { 66 | @Override 67 | public void handle(javafx.event.ActionEvent e) { 68 | JSONObject payload = new JSONObject(); 69 | payload.put("uuid", appUuid); 70 | payload.put("name", windowName); 71 | client.dispatch("UNDOCK-WINDOW", payload, null); 72 | } 73 | }); 74 | } 75 | }); 76 | } 77 | 78 | @Override 79 | public void onError(Ack ack) { 80 | } 81 | }); 82 | 83 | Window w = Window.wrap(appUuid, windowName, desktopConnection); 84 | w.addEventListener("group-changed", new EventListener() { 85 | @Override 86 | public void eventReceived(com.openfin.desktop.ActionEvent actionEvent) { 87 | JSONObject eventObj = actionEvent.getEventObject(); 88 | w.getGroup(new AsyncCallback>() { 89 | @Override 90 | public void onSuccess(java.util.List result) { 91 | if (result.size() > 0) { 92 | btnUndock.setDisable(false); 93 | } else { 94 | btnUndock.setDisable(true); 95 | } 96 | } 97 | }, null); 98 | } 99 | }, null); 100 | 101 | try { 102 | FxLayoutFrame.this.externalWindowObserver.start(); 103 | } catch (Exception e) { 104 | e.printStackTrace(); 105 | } 106 | 107 | } catch (DesktopException e) { 108 | e.printStackTrace(); 109 | } 110 | } 111 | }); 112 | } 113 | 114 | public String getWindowName() { 115 | return windowName; 116 | } 117 | 118 | public Stage getStage() { 119 | return stage; 120 | } 121 | 122 | public void cleanup() { 123 | try { 124 | System.out.println(windowName + " cleaning up "); 125 | if (this.externalWindowObserver != null) { 126 | this.externalWindowObserver.dispose(); 127 | } 128 | } 129 | catch (Exception e) { 130 | e.printStackTrace(); 131 | } 132 | this.externalWindowObserver = null; 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/com/openfin/desktop/demo/JNLPExample.java: -------------------------------------------------------------------------------- 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 | 33 | @Override 34 | public void onClose(String error) { 35 | java.lang.System.out.println("Connection closed"); 36 | } 37 | 38 | @Override 39 | public void onError(String reason) { 40 | java.lang.System.out.println("Connection failed: " + reason); 41 | } 42 | 43 | @Override 44 | public void onMessage(String message) { 45 | } 46 | 47 | @Override 48 | public void onOutgoingMessage(String message) { 49 | } 50 | }; 51 | 52 | 53 | public JNLPExample() throws DesktopException { 54 | super("Jave Web Start Example on OpenFin"); 55 | this.setSize(350, 200); 56 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 57 | this.setLayout(null); 58 | 59 | startButton.setSize(200, 30); 60 | startButton.setLocation(80, 50); 61 | this.getContentPane().add(startButton); 62 | 63 | startButton.addActionListener(new ActionListener() { 64 | public void actionPerformed(ActionEvent e) { 65 | try { 66 | RuntimeConfiguration cfg = new RuntimeConfiguration(); 67 | cfg.setRuntimeVersion("stable"); 68 | desktopConnection.connect(cfg, listener, 30); 69 | } catch (Exception ex) { 70 | ex.printStackTrace(); 71 | } 72 | } 73 | }); 74 | 75 | 76 | this.desktopConnection = new DesktopConnection("WebStartExample"); 77 | } 78 | 79 | private void launchHTML5App() { 80 | 81 | ApplicationOptions applicationOptions = new ApplicationOptions("Hello OpenFin", "Hello OpenFin", 82 | "http://demoappdirectory.openf.in/desktop/config/apps/OpenFin/HelloOpenFin/index.html"); 83 | WindowOptions windowOptions = new WindowOptions(); 84 | windowOptions.setAutoShow(true); 85 | windowOptions.setFrame(false); 86 | windowOptions.setResizable(false); 87 | windowOptions.setDefaultHeight(525); 88 | windowOptions.setDefaultWidth(395); 89 | windowOptions.setDefaultTop(50); 90 | windowOptions.setDefaultLeft(10); 91 | applicationOptions.setMainWindowOptions(windowOptions); 92 | Application app = new Application(applicationOptions, desktopConnection, new AckListener() { 93 | @Override 94 | public void onSuccess(Ack ack) { 95 | if (ack.isSuccessful()) { 96 | Application application = (Application) ack.getSource(); 97 | try { 98 | application.run(); 99 | } catch (Exception e) { 100 | e.printStackTrace(); 101 | } 102 | } 103 | } 104 | @Override 105 | public void onError(Ack ack) { 106 | 107 | } 108 | }); 109 | } 110 | 111 | public static void main(String[] args) throws DesktopException { 112 | JNLPExample exp = new JNLPExample(); 113 | exp.setVisible(true); 114 | } 115 | 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/com/openfin/desktop/demo/LaunchManifestDemo.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop.demo; 2 | 3 | import com.openfin.desktop.*; 4 | import com.openfin.desktop.channel.ChannelAction; 5 | import com.openfin.desktop.channel.ChannelClient; 6 | import com.openfin.desktop.win32.ExternalWindowObserver; 7 | import javafx.application.Application; 8 | import javafx.collections.ObservableList; 9 | import javafx.event.ActionEvent; 10 | import javafx.event.EventHandler; 11 | import javafx.scene.Group; 12 | import javafx.scene.Scene; 13 | import javafx.scene.control.Button; 14 | import javafx.scene.layout.AnchorPane; 15 | import javafx.stage.Stage; 16 | import org.json.JSONArray; 17 | import org.json.JSONObject; 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | import java.lang.System; 22 | 23 | public class LaunchManifestDemo extends Application implements DesktopStateListener { 24 | 25 | private final static Logger logger = LoggerFactory.getLogger(LaunchManifestDemo.class.getName()); 26 | private final static String WINDOW_TITLE = "Launch Manifest Demo"; 27 | 28 | private static String LayoutServiceChannelName = "of-layouts-service-v1"; 29 | private static String appUuid = "LaunchManifestDemo"; // App UUID for startup app in manifest 30 | private final static String javaConnectUuid = "LaunchManifestDemo-Java"; // connection UUID for Java app 31 | private DesktopConnection desktopConnection; 32 | private ChannelClient channelClient; // for communicating with layout service 33 | private Button btnGiantMachine, btnScottLogic; 34 | private Button btnUndock; 35 | private Stage stage; 36 | 37 | private ExternalWindowObserver externalWindowObserver; // required for Layout service 38 | 39 | @Override 40 | public void start(Stage stage) { 41 | btnGiantMachine = new Button(); 42 | btnGiantMachine.setText("Launch Watchlist by Giant Machines"); 43 | btnGiantMachine.setLayoutX(10); 44 | btnGiantMachine.setLayoutY(10); 45 | btnGiantMachine.setOnAction(new EventHandler() { 46 | @Override 47 | public void handle(ActionEvent event) { 48 | launchGiantMachine(); 49 | } 50 | }); 51 | btnGiantMachine.setDisable(true); 52 | 53 | btnScottLogic = new Button(); 54 | btnScottLogic.setText("Launch StockFlux by Scott Logic"); 55 | btnScottLogic.setLayoutX(10); 56 | btnScottLogic.setLayoutY(50); 57 | btnScottLogic.setOnAction(new EventHandler() { 58 | @Override 59 | public void handle(ActionEvent event) { 60 | launchScottLogic(); 61 | } 62 | }); 63 | btnScottLogic.setDisable(true); 64 | 65 | btnUndock = new Button(); 66 | btnUndock.setText("Undock"); 67 | btnUndock.setLayoutX(10); 68 | btnUndock.setLayoutY(90); 69 | btnUndock.setDisable(true); 70 | 71 | AnchorPane anchorPane = new AnchorPane(); 72 | anchorPane.getChildren().add(btnGiantMachine); 73 | anchorPane.getChildren().add(btnScottLogic); 74 | anchorPane.getChildren().add(btnUndock); 75 | 76 | //Creating a Group object 77 | Group root = new Group(); 78 | 79 | //Retrieving the observable list object 80 | ObservableList list = root.getChildren(); 81 | 82 | //Creating a scene object 83 | Scene scene = new Scene(anchorPane, 800, 800); 84 | 85 | //Setting title to the Stage 86 | stage.setTitle(WINDOW_TITLE); 87 | 88 | //Adding scene to the stage 89 | stage.setScene(scene); 90 | 91 | //Displaying the contents of the stage 92 | stage.show(); 93 | 94 | this.stage = stage; 95 | launchOpenFin(); 96 | } 97 | 98 | private void launchOpenFin() { 99 | RuntimeConfiguration config = new RuntimeConfiguration(); 100 | config.setRuntimeVersion("stable"); 101 | // config.setRuntimeVersion("9.61.38.40"); 102 | config.setAdditionalRuntimeArguments("--v=1 --remote-debugging-port=9090 "); 103 | JSONArray serviceConfig = new JSONArray(); 104 | // add Layout service to app manifest 105 | JSONObject layout = new JSONObject(); 106 | layout.put("name", "layouts"); 107 | JSONObject scfg = new JSONObject(); 108 | JSONObject sfeatures = new JSONObject(); 109 | sfeatures.put("dock", true); 110 | sfeatures.put("tab", false); 111 | scfg.put("features", sfeatures); 112 | layout.put("config", scfg); 113 | layout.put("manifestUrl", "https://cdn.openfin.co/services/openfin/layouts/1.0.0/app.json"); 114 | serviceConfig.put(0, layout); 115 | config.addConfigurationItem("services", serviceConfig); 116 | 117 | JSONObject startupApp = new JSONObject(); 118 | startupApp.put("uuid", appUuid); 119 | startupApp.put("name", appUuid); 120 | startupApp.put("url", "about:blank"); 121 | startupApp.put("autoShow", false); 122 | config.setStartupApp(startupApp); 123 | 124 | try { 125 | this.desktopConnection = new DesktopConnection(javaConnectUuid); 126 | this.desktopConnection.connect(config, this, 60); 127 | } catch (Exception ex){ 128 | ex.printStackTrace(); 129 | } 130 | } 131 | 132 | private void launchGiantMachine() { 133 | launchAppFromManifest("http://localhost:8000/watchlist.json"); 134 | } 135 | 136 | private void launchScottLogic() { 137 | launchAppFromManifest("http://localhost:8000/stockflux.json"); 138 | } 139 | 140 | private void launchAppFromManifest(String manifest) { 141 | try { 142 | com.openfin.desktop.Application.createFromManifest(manifest, 143 | new AsyncCallback() { 144 | @Override 145 | public void onSuccess(com.openfin.desktop.Application app) { 146 | try { 147 | app.run(); 148 | } catch (Exception ex) { 149 | ex.printStackTrace(); 150 | } 151 | } 152 | }, new AckListener() { 153 | @Override 154 | public void onSuccess(Ack ack) { 155 | } 156 | 157 | @Override 158 | public void onError(Ack ack) { 159 | logger.info("error creating app: {}", ack.getReason()); 160 | } 161 | }, desktopConnection); 162 | } catch (Exception ex) { 163 | ex.printStackTrace(); 164 | } 165 | } 166 | 167 | private void createExternalWindowObserver() { 168 | if (this.externalWindowObserver != null) { 169 | // only needs to happen once 170 | return; 171 | } 172 | String windowName = appUuid + "-Java-Window"; 173 | try { 174 | this.externalWindowObserver = new ExternalWindowObserver(desktopConnection.getPort(), appUuid, windowName, this.stage, 175 | new AckListener() { 176 | @Override 177 | public void onSuccess(Ack ack) { 178 | ExternalWindowObserver observer = (ExternalWindowObserver) ack.getSource(); 179 | observer.getDesktopConnection().getChannel(LayoutServiceChannelName).connect( 180 | new AsyncCallback() { 181 | @Override 182 | public void onSuccess(ChannelClient client) { 183 | LaunchManifestDemo.this.channelClient = client; 184 | 185 | client.register("event", new ChannelAction() { 186 | @Override 187 | public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { 188 | System.out.printf("channel event " + action); 189 | return null; 190 | } 191 | }); 192 | } 193 | }); 194 | } 195 | 196 | @Override 197 | public void onError(Ack ack) { 198 | System.out.println(windowName + ": unable to register external window, " + ack.getReason()); 199 | } 200 | }); 201 | } catch (Exception ex) { 202 | ex.printStackTrace(); 203 | } 204 | 205 | // when this Java window is docked or undocked by layout service, "group-changed" is fired. 206 | // calling getGroup to determine if btnUndock should enabled. 207 | Window w = Window.wrap(appUuid, windowName, desktopConnection); 208 | w.addEventListener("group-changed", new EventListener() { 209 | @Override 210 | public void eventReceived(com.openfin.desktop.ActionEvent actionEvent) { 211 | w.getGroup(new AsyncCallback>() { 212 | @Override 213 | public void onSuccess(java.util.List result) { 214 | if (result.size() > 0) { 215 | btnUndock.setDisable(false); 216 | } else { 217 | btnUndock.setDisable(true); 218 | } 219 | } 220 | }, null); 221 | } 222 | }, null); 223 | 224 | try { 225 | this.externalWindowObserver.start(); 226 | } catch (Exception e) { 227 | e.printStackTrace(); 228 | } 229 | } 230 | 231 | @Override 232 | public void onReady() { 233 | btnGiantMachine.setDisable(false); 234 | btnScottLogic.setDisable(false); 235 | this.createExternalWindowObserver(); 236 | } 237 | 238 | @Override 239 | public void onClose(String error) { 240 | 241 | } 242 | 243 | @Override 244 | public void onError(String reason) { 245 | 246 | } 247 | 248 | @Override 249 | public void onMessage(String message) { 250 | 251 | } 252 | 253 | @Override 254 | public void onOutgoingMessage(String message) { 255 | 256 | } 257 | 258 | public static void main(String args[]) { 259 | launch(args); 260 | } 261 | 262 | 263 | 264 | } 265 | -------------------------------------------------------------------------------- /src/main/java/com/openfin/desktop/demo/LayoutFrame.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop.demo; 2 | 3 | /** 4 | * Example of Java window that can be managed by OpenFin layout service for snap&dock 5 | */ 6 | 7 | import com.openfin.desktop.*; 8 | import com.openfin.desktop.Window; 9 | import com.openfin.desktop.channel.ChannelAction; 10 | import com.openfin.desktop.channel.ChannelClient; 11 | import com.openfin.desktop.win32.ExternalWindowObserver; 12 | import com.sun.jna.Native; 13 | import com.sun.jna.platform.win32.WinDef; 14 | import org.json.JSONArray; 15 | import org.json.JSONObject; 16 | 17 | import javax.swing.*; 18 | import java.awt.*; 19 | import java.awt.event.ActionEvent; 20 | import java.awt.event.ActionListener; 21 | import java.awt.event.MouseAdapter; 22 | import java.awt.event.MouseEvent; 23 | import java.awt.event.WindowAdapter; 24 | import java.awt.event.WindowEvent; 25 | import java.lang.System; 26 | 27 | public class LayoutFrame extends JFrame { 28 | private static String LayoutServiceChannelName = "of-layouts-service-v1"; 29 | private ExternalWindowObserver externalWindowObserver; 30 | private JLabel labelName; 31 | private JButton btnUndock; 32 | private String windowName; 33 | private ChannelClient channelClient; 34 | private String appUuid; 35 | private boolean frameless; 36 | 37 | public LayoutFrame(DesktopConnection desktopConnection, String appUuid, String windowName) throws DesktopException { 38 | this(desktopConnection, appUuid, windowName, false); 39 | } 40 | 41 | public LayoutFrame(DesktopConnection desktopConnection, String appUuid, String windowName, boolean frameless) throws DesktopException { 42 | super(); 43 | this.setTitle(windowName); 44 | System.out.println(windowName + " being created "); 45 | this.appUuid = appUuid; 46 | this.windowName = windowName; 47 | this.frameless = frameless; 48 | this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 49 | this.setPreferredSize(new Dimension(640, 480)); 50 | JPanel pnl = new JPanel(); 51 | pnl.setLayout(new BoxLayout(pnl, BoxLayout.Y_AXIS)); 52 | this.labelName = new JLabel(windowName); 53 | pnl.add(labelName); 54 | this.btnUndock = new JButton("undock"); 55 | this.btnUndock.setEnabled(false); 56 | pnl.add(btnUndock); 57 | this.getContentPane().add(pnl); 58 | 59 | if (frameless) { 60 | this.setUndecorated(true); 61 | JPanel titleBar = new JPanel(new BorderLayout()); 62 | titleBar.setBackground(Color.DARK_GRAY); 63 | MouseAdapter myListener = new MouseAdapter() { 64 | int pressedAtX, pressedAtY; 65 | @Override 66 | public void mousePressed(MouseEvent e) { 67 | pressedAtX = e.getX(); 68 | pressedAtY = e.getY(); 69 | System.out.println("mouse pressed at x=" + pressedAtX + ", y=" + pressedAtY); 70 | LayoutFrame.this.externalWindowObserver.enterSizeMove(); 71 | } 72 | @Override 73 | public void mouseDragged(MouseEvent e) { 74 | int distanceX = e.getX() - pressedAtX; 75 | int distanceY = e.getY() - pressedAtY; 76 | System.out.println("dragged x=" + distanceX + ", y=" + distanceY); 77 | Point frameLocation = LayoutFrame.this.getLocation(); 78 | Dimension dimension = LayoutFrame.this.getSize(); 79 | WindowBounds bounds = new WindowBounds(frameLocation.x + distanceX, frameLocation.y + distanceY, 80 | dimension.width, dimension.height); 81 | Point point = new Point(e.getX(), e.getY()); 82 | if (!LayoutFrame.this.externalWindowObserver.onMoving(bounds, point)) { 83 | LayoutFrame.this.setLocation(frameLocation.x + distanceX, frameLocation.y + distanceY); 84 | } 85 | } 86 | @Override 87 | public void mouseReleased(MouseEvent e) { 88 | LayoutFrame.this.externalWindowObserver.exitSizeMove(); 89 | } 90 | }; 91 | titleBar.addMouseListener(myListener); 92 | titleBar.addMouseMotionListener(myListener); 93 | 94 | JButton btnClose = new JButton("X"); 95 | btnClose.addActionListener(new ActionListener() { 96 | 97 | @Override 98 | public void actionPerformed(ActionEvent e) { 99 | LayoutFrame.this.dispose(); 100 | }}); 101 | titleBar.add(btnClose, BorderLayout.EAST); 102 | 103 | this.getContentPane().add(titleBar, BorderLayout.NORTH); 104 | 105 | } 106 | 107 | this.pack(); 108 | this.setLocationRelativeTo(null); 109 | this.setVisible(true); 110 | 111 | this.externalWindowObserver = new ExternalWindowObserver(desktopConnection.getPort(), appUuid, windowName, this, 112 | new AckListener() { 113 | @Override 114 | public void onSuccess(Ack ack) { 115 | ExternalWindowObserver observer = (ExternalWindowObserver) ack.getSource(); 116 | observer.getDesktopConnection().getChannel(LayoutServiceChannelName).connect( 117 | new AsyncCallback() { 118 | @Override 119 | public void onSuccess(ChannelClient client) { 120 | LayoutFrame.this.channelClient = client; 121 | btnUndock.addActionListener(new ActionListener() { 122 | @Override 123 | public void actionPerformed(ActionEvent e) { 124 | JSONObject payload = new JSONObject(); 125 | payload.put("uuid", appUuid); 126 | payload.put("name", windowName); 127 | client.dispatch("UNDOCK-WINDOW", payload, null); 128 | } 129 | }); 130 | 131 | client.register("event", new ChannelAction() { 132 | @Override 133 | public JSONObject invoke(String action, Object payload, JSONObject senderIdentity) { 134 | System.out.printf("channel event " + action); 135 | return null; 136 | } 137 | }); 138 | } 139 | }); 140 | } 141 | 142 | @Override 143 | public void onError(Ack ack) { 144 | System.out.println(windowName + ": unable to register external window, " + ack.getReason()); 145 | } 146 | }); 147 | // this.externalWindowObserver.setUserGesture(!this.frameless); 148 | try { 149 | // if (this.frameless) { 150 | // WindowOptions options = new WindowOptions(); 151 | // options.setFrame(false); 152 | // this.externalWindowObserver.setWindowOptions(options); 153 | // } 154 | this.externalWindowObserver.start(); 155 | } catch (Exception e) { 156 | e.printStackTrace(); 157 | } 158 | 159 | Window w = Window.wrap(appUuid, windowName, desktopConnection); 160 | w.addEventListener("group-changed", new EventListener() { 161 | @Override 162 | public void eventReceived(com.openfin.desktop.ActionEvent actionEvent) { 163 | JSONObject eventObj = actionEvent.getEventObject(); 164 | w.getGroup(new AsyncCallback>() { 165 | @Override 166 | public void onSuccess(java.util.List result) { 167 | if (result.size() > 0) { 168 | checkTabbing(); 169 | } else { 170 | LayoutFrame.this.btnUndock.setEnabled(false); 171 | setHasFrame(LayoutFrame.this, true); 172 | } 173 | } 174 | }, null); 175 | } 176 | }, null); 177 | 178 | this.addWindowListener(new WindowAdapter() { 179 | public void windowClosing(WindowEvent e) { 180 | super.windowClosing(e); 181 | try { 182 | LayoutFrame.this.cleanup(); 183 | LayoutFrame.this.dispose(); 184 | } 185 | catch (Exception e1) { 186 | e1.printStackTrace(); 187 | } 188 | } 189 | 190 | public void windowClosed(WindowEvent e) { 191 | super.windowClosed(e); 192 | System.out.println(windowName + " closed "); 193 | } 194 | }); 195 | } 196 | 197 | private void checkTabbing() { 198 | JSONObject payload = new JSONObject(); 199 | payload.put("uuid", appUuid); 200 | payload.put("name", windowName); 201 | channelClient.dispatch("GETTABS", payload, new AckListener() { 202 | @Override 203 | public void onSuccess(Ack ack) { 204 | System.out.printf("channel GETTABS "); 205 | JSONObject data = (JSONObject) ack.getData(); 206 | Object result = data.get("result"); 207 | if (result != null && result instanceof JSONArray) { 208 | JSONArray tabs = (JSONArray) result; 209 | boolean enabled = !(tabs != null && tabs.length() > 0); 210 | LayoutFrame.this.btnUndock.setEnabled(enabled); 211 | setHasFrame(LayoutFrame.this, false); 212 | } else { 213 | LayoutFrame.this.btnUndock.setEnabled(true); 214 | setHasFrame(LayoutFrame.this, true); 215 | } 216 | } 217 | 218 | @Override 219 | public void onError(Ack ack) { 220 | System.out.printf("channel GETTABS error " + ack.getReason()); 221 | } 222 | }); 223 | } 224 | 225 | private void setHasFrame(JFrame frame, boolean hasFrame) { 226 | if (!this.frameless) { 227 | SwingUtilities.invokeLater(new Runnable() { 228 | @Override 229 | public void run() { 230 | System.out.println(windowName + " hasFrame=" + hasFrame); 231 | WinDef.HWND hWnd = new WinDef.HWND(); 232 | hWnd.setPointer(Native.getComponentPointer(frame)); 233 | LayoutFrame.this.externalWindowObserver.setHasFrame(hWnd, hasFrame); 234 | frame.setResizable(hasFrame); 235 | frame.invalidate(); 236 | frame.validate(); 237 | frame.repaint(); 238 | SwingUtilities.updateComponentTreeUI(frame); 239 | } 240 | }); 241 | } 242 | } 243 | 244 | public String getWindowName() { 245 | return windowName; 246 | } 247 | 248 | public void cleanup() { 249 | try { 250 | System.out.println(windowName + " cleaning up "); 251 | this.externalWindowObserver.dispose(); 252 | } 253 | catch (Exception e) { 254 | e.printStackTrace(); 255 | } 256 | } 257 | 258 | 259 | public static void main(String[] args) { 260 | final JFrame frame = new JFrame(); 261 | frame.setPreferredSize(new Dimension(640, 480)); 262 | JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER)); 263 | 264 | frame.setUndecorated(true); 265 | JPanel titleBar = new JPanel(new BorderLayout()); 266 | titleBar.setBackground(Color.DARK_GRAY); 267 | MouseAdapter myListener = new MouseAdapter() { 268 | int pressedAtX, pressedAtY; 269 | @Override 270 | public void mousePressed(MouseEvent e) { 271 | pressedAtX = e.getX(); 272 | pressedAtY = e.getY(); 273 | System.out.println("mouse pressed at x=" + pressedAtX + ", y=" + pressedAtY); 274 | } 275 | @Override 276 | public void mouseDragged(MouseEvent e) { 277 | int distanceX = e.getX() - pressedAtX; 278 | int distanceY = e.getY() - pressedAtY; 279 | System.out.println("dragged x=" + distanceX + ", y=" + distanceY); 280 | Point frameLocation = frame.getLocation(); 281 | frame.setLocation(frameLocation.x + distanceX, frameLocation.y + distanceY); 282 | } 283 | @Override 284 | public void mouseReleased(MouseEvent e) { 285 | pressedAtX = e.getX(); 286 | pressedAtY = e.getY(); 287 | System.out.println("mouse released at x=" + pressedAtX + ", y=" + pressedAtY); 288 | } 289 | }; 290 | titleBar.addMouseListener(myListener); 291 | titleBar.addMouseMotionListener(myListener); 292 | 293 | JButton btnClose = new JButton("X"); 294 | btnClose.addActionListener(new ActionListener() { 295 | @Override 296 | public void actionPerformed(ActionEvent e) { 297 | frame.dispose(); 298 | }}); 299 | titleBar.add(btnClose, BorderLayout.EAST); 300 | frame.getContentPane().add(titleBar, BorderLayout.NORTH); 301 | frame.pack(); 302 | frame.setLocationRelativeTo(null); 303 | frame.setVisible(true); 304 | } 305 | 306 | } 307 | -------------------------------------------------------------------------------- /src/main/java/com/openfin/desktop/demo/LayoutServiceDemo.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop.demo; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Dimension; 5 | import java.awt.FlowLayout; 6 | import java.awt.event.ActionEvent; 7 | import java.awt.event.ActionListener; 8 | import java.awt.event.WindowAdapter; 9 | import java.awt.event.WindowEvent; 10 | import java.io.IOException; 11 | import java.lang.System; 12 | import java.util.*; 13 | import java.util.concurrent.CountDownLatch; 14 | 15 | import javax.swing.BorderFactory; 16 | import javax.swing.JButton; 17 | import javax.swing.JFrame; 18 | import javax.swing.JLabel; 19 | import javax.swing.JPanel; 20 | import javax.swing.SwingUtilities; 21 | 22 | import com.openfin.desktop.*; 23 | import org.json.JSONArray; 24 | import org.json.JSONObject; 25 | 26 | public class LayoutServiceDemo implements DesktopStateListener { 27 | 28 | private final static String appUuid = "layoutServiceDemo-" + UUID.randomUUID(); 29 | private final static String javaConnectUuid = "layoutServiceDemoJava-" + UUID.randomUUID(); 30 | 31 | private DesktopConnection desktopConnection; 32 | private CountDownLatch latch = new CountDownLatch(1); 33 | private JFrame mainWindow; 34 | private JButton btnCreateOpenfinWindow; 35 | private JButton btnCreateJavaWindow; 36 | private Application application; 37 | 38 | private JSONArray serviceConfig = new JSONArray(); 39 | private Map childFrames = new HashMap(); 40 | private Map childFxFrames = new HashMap(); 41 | private WindowAdapter childFrameCleanListener; 42 | private JButton btnCreateFramelessJavaWindow; 43 | private JButton btnCreateJavaFxWindow; 44 | 45 | LayoutServiceDemo() { 46 | try { 47 | this.createMainWindow(); 48 | this.launchOpenfin(); 49 | 50 | this.childFrameCleanListener = new WindowAdapter() { 51 | @Override 52 | public void windowClosed(WindowEvent e) { 53 | super.windowClosed(e); 54 | LayoutFrame frame = (LayoutFrame) e.getWindow(); 55 | childFrames.remove(frame.getWindowName()); 56 | } 57 | }; 58 | } 59 | catch (Exception e) { 60 | e.printStackTrace(); 61 | } 62 | } 63 | 64 | void createMainWindow() { 65 | this.mainWindow = new JFrame("Layout Service Demo"); 66 | this.mainWindow.setResizable(false); 67 | this.mainWindow.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 68 | this.mainWindow.addWindowListener(new WindowAdapter() { 69 | @Override 70 | public void windowClosing(WindowEvent we) { 71 | try { 72 | childFrames.values().forEach(frame -> { 73 | frame.cleanup(); 74 | }); 75 | childFxFrames.values().forEach(frame -> { 76 | frame.cleanup(); 77 | }); 78 | application.close(); 79 | Thread.sleep(1000); 80 | OpenFinRuntime runtime = new OpenFinRuntime(desktopConnection); 81 | runtime.exit(); 82 | Thread.sleep(1000); 83 | java.lang.System.exit(0); 84 | } 85 | catch (Exception de) { 86 | de.printStackTrace(); 87 | } 88 | } 89 | }); 90 | 91 | this.btnCreateOpenfinWindow = new JButton("Create Openfin Window"); 92 | this.btnCreateOpenfinWindow.addActionListener(new ActionListener() { 93 | @Override 94 | public void actionPerformed(ActionEvent e) { 95 | createOpenfinWindow(); 96 | } 97 | }); 98 | this.btnCreateJavaWindow = new JButton("Create Java Window"); 99 | this.btnCreateJavaWindow.addActionListener(new ActionListener() { 100 | @Override 101 | public void actionPerformed(ActionEvent e) { 102 | try { 103 | createJavaWindow(); 104 | } 105 | catch (DesktopException e1) { 106 | e1.printStackTrace(); 107 | } 108 | } 109 | }); 110 | this.btnCreateFramelessJavaWindow = new JButton("Create Frameless Java Window"); 111 | this.btnCreateFramelessJavaWindow.addActionListener(new ActionListener() { 112 | @Override 113 | public void actionPerformed(ActionEvent e) { 114 | try { 115 | createFramelessJavaWindow(); 116 | } 117 | catch (DesktopException e1) { 118 | e1.printStackTrace(); 119 | } 120 | } 121 | }); 122 | this.btnCreateJavaFxWindow = new JButton("Create JavaFX Window"); 123 | this.btnCreateJavaFxWindow.addActionListener(new ActionListener() { 124 | @Override 125 | public void actionPerformed(ActionEvent e) { 126 | createJavaFxWindow(); 127 | } 128 | }); 129 | 130 | this.btnCreateOpenfinWindow.setEnabled(false); 131 | this.btnCreateJavaWindow.setEnabled(false); 132 | this.btnCreateFramelessJavaWindow.setEnabled(false); 133 | this.btnCreateJavaFxWindow.setEnabled(false); 134 | JPanel contentPnl = new JPanel(new BorderLayout(10, 10)); 135 | contentPnl.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); 136 | JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER)); 137 | pnl.add(btnCreateOpenfinWindow); 138 | pnl.add(btnCreateJavaWindow); 139 | if (System.getProperty("com.openfin.demo.layout.frameless") != null) { 140 | // This example is experimental and not available yet 141 | pnl.add(btnCreateFramelessJavaWindow); 142 | } 143 | pnl.add(btnCreateJavaFxWindow); 144 | 145 | contentPnl.add(new JLabel("Undock Openfin windows with global hotkey (CTRL+SHIFT+U or CMD+SHIFT+U)"), 146 | BorderLayout.NORTH); 147 | contentPnl.add(pnl, BorderLayout.CENTER); 148 | 149 | this.mainWindow.getContentPane().add(contentPnl); 150 | 151 | this.mainWindow.pack(); 152 | this.mainWindow.setLocationRelativeTo(null); 153 | this.mainWindow.setVisible(true); 154 | } 155 | 156 | void launchOpenfin() throws DesktopException, DesktopIOException, IOException, InterruptedException { 157 | RuntimeConfiguration config = new RuntimeConfiguration(); 158 | String rvm = System.getProperty("com.openfin.demo.layout.rvm"); 159 | if (rvm != null) { 160 | config.setLaunchRVMPath(rvm); 161 | } 162 | config.setRuntimeVersion("alpha"); 163 | config.setAdditionalRuntimeArguments("--v=1 "); 164 | serviceConfig = new JSONArray(); 165 | JSONObject layout = new JSONObject(); 166 | layout.put("name", "layouts"); 167 | // layout.put("manifestUrl", "http://localhost:8081/app3.json"); 168 | JSONObject scfg = new JSONObject(); 169 | JSONObject sfeatures = new JSONObject(); 170 | sfeatures.put("dock", true); 171 | sfeatures.put("tab", true); 172 | scfg.put("features", sfeatures); 173 | layout.put("config", scfg); 174 | serviceConfig.put(0, layout); 175 | config.addConfigurationItem("services", serviceConfig); 176 | 177 | JSONObject startupApp = new JSONObject(); 178 | startupApp.put("uuid", appUuid); 179 | startupApp.put("name", appUuid); 180 | startupApp.put("url", "about:blank"); 181 | startupApp.put("autoShow", false); 182 | config.setStartupApp(startupApp); 183 | 184 | this.desktopConnection = new DesktopConnection(javaConnectUuid); 185 | this.desktopConnection.connect(config, this, 60); 186 | latch.await(); 187 | } 188 | 189 | void createApplication(String name, String uuid, String url, AckListener listener) { 190 | ApplicationOptions appOpt = new ApplicationOptions(name, uuid, url); 191 | WindowOptions mainWindowOptions = new WindowOptions(); 192 | mainWindowOptions.setAutoShow(false); 193 | appOpt.setMainWindowOptions(mainWindowOptions); 194 | appOpt.put("services", serviceConfig); 195 | 196 | this.application = new Application(appOpt, this.desktopConnection, new AckListener() { 197 | @Override 198 | public void onSuccess(Ack ack) { 199 | application.run(listener); 200 | SwingUtilities.invokeLater(new Runnable() { 201 | 202 | @Override 203 | public void run() { 204 | btnCreateOpenfinWindow.setEnabled(true); 205 | btnCreateJavaWindow.setEnabled(true); 206 | btnCreateFramelessJavaWindow.setEnabled(true); 207 | btnCreateJavaFxWindow.setEnabled(true); 208 | } 209 | }); 210 | } 211 | 212 | @Override 213 | public void onError(Ack ack) { 214 | } 215 | }); 216 | } 217 | 218 | void createJavaWindow() throws DesktopException { 219 | String windowName = "Java-" + UUID.randomUUID().toString(); 220 | LayoutFrame frame = new LayoutFrame(this.desktopConnection, appUuid, windowName); 221 | this.childFrames.put(windowName, frame); 222 | frame.addWindowListener(this.childFrameCleanListener); 223 | } 224 | 225 | void createFramelessJavaWindow() throws DesktopException { 226 | String windowName = "Java-" + UUID.randomUUID().toString(); 227 | LayoutFrame frame = new LayoutFrame(this.desktopConnection, appUuid, windowName, true); 228 | this.childFrames.put(windowName, frame); 229 | frame.addWindowListener(this.childFrameCleanListener); 230 | } 231 | 232 | void createJavaFxWindow() { 233 | String windowName = "JavaFX-" + UUID.randomUUID().toString(); 234 | FxLayoutFrame frame = new FxLayoutFrame(this.desktopConnection, appUuid, windowName); 235 | this.childFxFrames.put(windowName, frame); 236 | } 237 | 238 | void createOpenfinWindow() { 239 | try { 240 | WindowOptions winOpts = new WindowOptions(); 241 | winOpts.setAutoShow(true); 242 | winOpts.setDefaultHeight(480); 243 | winOpts.setDefaultWidth(640); 244 | winOpts.setResizable(true); 245 | winOpts.setFrame(true); 246 | winOpts.setName(UUID.randomUUID().toString()); 247 | String url = java.lang.System.getProperty("com.openfin.demo.layout.url"); 248 | winOpts.setUrl(url == null ? "https://openfin.co" : url); 249 | application.createChildWindow(winOpts, new AckListener() { 250 | @Override 251 | public void onSuccess(Ack ack) { 252 | } 253 | 254 | @Override 255 | public void onError(Ack ack) { 256 | System.out.println("unable to create openfin window: " + ack.getReason()); 257 | } 258 | }); 259 | } 260 | catch (DesktopException e) { 261 | e.printStackTrace(); 262 | } 263 | } 264 | 265 | @Override 266 | public void onReady() { 267 | this.application = Application.wrap(appUuid, this.desktopConnection); 268 | btnCreateOpenfinWindow.setEnabled(true); 269 | btnCreateJavaWindow.setEnabled(true); 270 | btnCreateFramelessJavaWindow.setEnabled(true); 271 | btnCreateJavaFxWindow.setEnabled(true); 272 | } 273 | 274 | @Override 275 | public void onClose(String error) { 276 | latch.countDown(); 277 | } 278 | 279 | @Override 280 | public void onError(String reason) { 281 | } 282 | 283 | @Override 284 | public void onMessage(String message) { 285 | } 286 | 287 | @Override 288 | public void onOutgoingMessage(String message) { 289 | } 290 | 291 | public static void main(String[] args) { 292 | new LayoutServiceDemo(); 293 | } 294 | } 295 | -------------------------------------------------------------------------------- /src/main/java/com/openfin/desktop/demo/LoadAppsDialog.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop.demo; 2 | 3 | import info.clearthought.layout.TableLayout; 4 | import org.json.JSONException; 5 | import org.json.JSONObject; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | import java.awt.event.ActionEvent; 10 | import java.awt.event.ActionListener; 11 | 12 | /** 13 | * Created by richard on 2/28/15. 14 | */ 15 | public class LoadAppsDialog extends JDialog { 16 | protected JTextField username; 17 | protected JPasswordField password; 18 | 19 | protected JLabel usernameLabel, passwordLabel; 20 | 21 | protected JButton retrieveApps; 22 | protected boolean retrieveClicked = false; 23 | 24 | public LoadAppsDialog() { 25 | super(); 26 | setTitle("Load Apps"); 27 | setModal(true); 28 | setLayout(new BorderLayout()); 29 | 30 | this.add(layoutDescriptionPanel(), BorderLayout.CENTER); 31 | this.add(layoutActionButtonPanel(), BorderLayout.SOUTH); 32 | 33 | setSize(300, 140); 34 | } 35 | 36 | private JPanel layoutDescriptionPanel() { 37 | 38 | usernameLabel = new JLabel("Username: "); 39 | usernameLabel.setHorizontalAlignment(SwingConstants.RIGHT); 40 | username = new JTextField(); 41 | username.setColumns(50); 42 | 43 | passwordLabel = new JLabel("password: "); 44 | passwordLabel.setHorizontalAlignment(SwingConstants.RIGHT); 45 | password = new JPasswordField(); 46 | password.setColumns(50); 47 | 48 | double size[][] = 49 | {{0.25, 0.75}, 50 | {30,30}}; 51 | 52 | TableLayout twoColLayout = new TableLayout(size); 53 | JPanel twoColPanel = new JPanel(twoColLayout); 54 | 55 | twoColPanel.add(usernameLabel, "0, 0"); 56 | twoColPanel.add(username, "1, 0"); 57 | twoColPanel.add(passwordLabel , "0, 1"); 58 | twoColPanel.add(password , "1, 1"); 59 | 60 | return twoColPanel; 61 | } 62 | 63 | public JSONObject getCredentials() { 64 | JSONObject credentials = new JSONObject(); 65 | if (retrieveClicked) { 66 | String email = username.getText(); 67 | char[] pwd = password.getPassword(); 68 | 69 | try { 70 | credentials.put("email", email); 71 | credentials.put("password", new String(pwd)); 72 | } catch (JSONException e) { 73 | } 74 | } 75 | return credentials; 76 | } 77 | 78 | public void show(Component parent) { 79 | this.retrieveClicked = false; 80 | this.setLocationRelativeTo(parent); 81 | setVisible(true); 82 | } 83 | 84 | private JPanel layoutActionButtonPanel() { 85 | JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); 86 | 87 | retrieveApps = new JButton("Load Apps"); 88 | retrieveApps.addActionListener(new ActionListener() { 89 | @Override 90 | public void actionPerformed(ActionEvent actionEvent) { 91 | retrieveClicked = true; 92 | LoadAppsDialog.this.setVisible(false); 93 | } 94 | }); 95 | buttonPanel.add(retrieveApps); 96 | 97 | return buttonPanel; 98 | } 99 | 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/com/openfin/desktop/demo/MemoryProfile.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop.demo; 2 | 3 | import com.openfin.desktop.*; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | import java.util.concurrent.CountDownLatch; 8 | import java.util.concurrent.TimeUnit; 9 | import java.util.concurrent.atomic.AtomicBoolean; 10 | import java.util.concurrent.atomic.AtomicInteger; 11 | 12 | 13 | /** 14 | * This class can be used to profile memory usage of Java Adapter for communicating with Runtime. The initial version 15 | * just keeps calling getMachineId API. It can easily extended to test other APIs. 16 | * 17 | * VisualVM, available from https://visualvm.github.io/, can be used to monitor memory usgage while this code is running 18 | */ 19 | 20 | public class MemoryProfile { 21 | private final static Logger logger = LoggerFactory.getLogger(MemoryProfile.class.getName()); 22 | 23 | public static void main(String[] args) { 24 | RuntimeConfiguration runtimeConfiguration = new RuntimeConfiguration(); 25 | String connectionUuid = MemoryProfile.class.getName(); 26 | String desktopVersion = java.lang.System.getProperty("com.openfin.demo.version"); 27 | if (desktopVersion == null) { 28 | desktopVersion = "stable"; 29 | } 30 | runtimeConfiguration.setRuntimeVersion(desktopVersion); 31 | try { 32 | final DesktopConnection desktopConnection = new DesktopConnection(connectionUuid); 33 | DesktopStateListener listener = new DesktopStateListener() { 34 | @Override 35 | public void onReady() { 36 | launchThread(desktopConnection); 37 | } 38 | @Override 39 | public void onClose(String error) { 40 | 41 | } 42 | @Override 43 | public void onError(String reason) { 44 | logger.error(String.format("onError %s", reason)); 45 | } 46 | 47 | @Override 48 | public void onMessage(String message) { 49 | } 50 | @Override 51 | public void onOutgoingMessage(String message) { 52 | } 53 | }; 54 | desktopConnection.connect(runtimeConfiguration, listener, 50); 55 | } catch (Exception e) { 56 | logger.error("", e); 57 | } 58 | } 59 | 60 | private static void launchThread(DesktopConnection desktopConnection) { 61 | Thread t = new Thread() { 62 | @Override 63 | public void run() { 64 | OpenFinRuntime openfinSystem = new OpenFinRuntime(desktopConnection); 65 | AtomicInteger callCount = new AtomicInteger(); 66 | AtomicBoolean shouldRun = new AtomicBoolean(true); 67 | while (shouldRun.get()) { 68 | try { 69 | CountDownLatch latch = new CountDownLatch(1); 70 | openfinSystem.getMachineId(new AckListener() { 71 | @Override 72 | public void onSuccess(Ack ack) { 73 | if (ack.isSuccessful()) { 74 | logger.info(String.format("API call count %d", callCount.incrementAndGet())); 75 | latch.countDown(); 76 | } else { 77 | logger.error(String.format("API failed %s", ack.getReason())); 78 | shouldRun.set(false); 79 | } 80 | } 81 | @Override 82 | public void onError(Ack ack) { 83 | logger.error(String.format("API failed %s", ack.getReason())); 84 | shouldRun.set(false); 85 | } 86 | }); 87 | latch.await(1, TimeUnit.SECONDS); 88 | } catch (Exception ex) { 89 | ex.printStackTrace(); 90 | } 91 | } 92 | } 93 | }; 94 | t.start(); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/openfin/desktop/demo/NoGui.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop.demo; 2 | 3 | import com.openfin.desktop.*; 4 | 5 | import java.io.IOException; 6 | import java.lang.System; 7 | import java.util.UUID; 8 | 9 | /** 10 | * Example for launching OpenFin Runtime without Swing 11 | * 12 | * Created by wche on 9/4/2016. 13 | */ 14 | public class NoGui { 15 | private static boolean connected = false; 16 | 17 | public static void main(String[] args) { 18 | 19 | try { 20 | final DesktopConnection desktopConnection = new DesktopConnection(UUID.randomUUID().toString()); 21 | DesktopStateListener listener = new DesktopStateListener() { 22 | @Override 23 | public void onReady() { 24 | try { 25 | connected = true; 26 | ApplicationOptions applicationOptions = new ApplicationOptions("HelloOpenFin", UUID.randomUUID().toString(), "http://demoappdirectory.openf.in/desktop/config/apps/OpenFin/HelloOpenFin/index.html"); 27 | WindowOptions windowOptions = new WindowOptions(); 28 | windowOptions.setAutoShow(true); 29 | applicationOptions.setMainWindowOptions(windowOptions); 30 | Application application = new Application(applicationOptions, desktopConnection, new AckListener() { 31 | @Override 32 | public void onSuccess(Ack ack) { 33 | System.out.println("Main.onSuccess"); 34 | } 35 | 36 | @Override 37 | public void onError(Ack ack) { 38 | System.out.println("Main.onError"); 39 | } 40 | }); 41 | 42 | // application.run(new AckListener() { 43 | // @Override 44 | // public void onSuccess(Ack ack) { 45 | // System.out.println("Main.onSuccess"); 46 | // } 47 | // 48 | // @Override 49 | // public void onError(Ack ack) { 50 | // System.out.println("Main.onError"); 51 | // } 52 | // }); 53 | 54 | } catch (Exception e) { 55 | e.printStackTrace(); 56 | } 57 | } 58 | 59 | @Override 60 | public void onClose(String error) { 61 | System.out.println("Main.onClose"); 62 | } 63 | 64 | @Override 65 | public void onError(String reason) { 66 | System.out.println("Main.onError"); 67 | } 68 | 69 | @Override 70 | public void onMessage(String message) { 71 | System.out.println("Main.onMessage"); 72 | } 73 | 74 | @Override 75 | public void onOutgoingMessage(String message) { 76 | System.out.println("Main.onOutgoingMessage"); 77 | } 78 | }; 79 | RuntimeConfiguration cfg = new RuntimeConfiguration(); 80 | cfg.setRuntimeVersion("stable"); 81 | desktopConnection.connect(cfg, listener, 50); 82 | 83 | try { 84 | // keep Runtime running for 10 seconds 85 | Thread.sleep(20000); 86 | desktopConnection.exit(); 87 | // Give Runtime some time to exit 88 | Thread.sleep(3000); 89 | } catch (Exception e) { 90 | e.printStackTrace(); 91 | } 92 | System.out.println("Before exit"); 93 | 94 | } catch (DesktopException e) { 95 | e.printStackTrace(); 96 | } catch (DesktopIOException e) { 97 | e.printStackTrace(); 98 | } catch (IOException e) { 99 | e.printStackTrace(); 100 | } 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/com/openfin/desktop/demo/NotificationServiceDemo.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop.demo; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Color; 5 | import java.awt.Dimension; 6 | import java.awt.FlowLayout; 7 | import java.awt.GridBagConstraints; 8 | import java.awt.GridBagLayout; 9 | import java.awt.Insets; 10 | import java.awt.event.WindowAdapter; 11 | import java.awt.event.WindowEvent; 12 | import java.io.IOException; 13 | import java.util.Date; 14 | import java.util.UUID; 15 | 16 | import javax.swing.BorderFactory; 17 | import javax.swing.JButton; 18 | import javax.swing.JComboBox; 19 | import javax.swing.JFrame; 20 | import javax.swing.JLabel; 21 | import javax.swing.JPanel; 22 | import javax.swing.JTextField; 23 | import javax.swing.SwingUtilities; 24 | 25 | import org.json.JSONObject; 26 | 27 | import com.openfin.desktop.DesktopConnection; 28 | import com.openfin.desktop.DesktopException; 29 | import com.openfin.desktop.DesktopIOException; 30 | import com.openfin.desktop.DesktopStateListener; 31 | import com.openfin.desktop.RuntimeConfiguration; 32 | import com.openfin.desktop.notifications.ButtonOptions; 33 | import com.openfin.desktop.notifications.NotificationActionResult; 34 | import com.openfin.desktop.notifications.NotificationIndicator; 35 | import com.openfin.desktop.notifications.NotificationOptions; 36 | import com.openfin.desktop.notifications.Notifications; 37 | import com.openfin.desktop.notifications.events.NotificationActionEvent; 38 | 39 | public class NotificationServiceDemo { 40 | 41 | private JFrame demoWindow; 42 | private DesktopConnection desktopConnection; 43 | private JPanel glassPane; 44 | private Notifications notifications; 45 | 46 | public NotificationServiceDemo() { 47 | this.demoWindow = new JFrame("OpenFin Notification Service Demo"); 48 | this.demoWindow.setContentPane(this.createContentPanel()); 49 | this.demoWindow.setGlassPane(this.createGlassPane()); 50 | this.demoWindow.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 51 | this.demoWindow.addWindowListener(new WindowAdapter() { 52 | @Override 53 | public void windowClosing(WindowEvent e) { 54 | if (desktopConnection != null) { 55 | try { 56 | desktopConnection.disconnect(); 57 | } 58 | catch (DesktopException e1) { 59 | e1.printStackTrace(); 60 | } 61 | } 62 | } 63 | }); 64 | 65 | this.demoWindow.pack(); 66 | this.demoWindow.setLocationRelativeTo(null); 67 | this.demoWindow.setVisible(true); 68 | this.glassPane.setVisible(true); 69 | this.initOpenFin(); 70 | } 71 | 72 | private void initOpenFin() { 73 | try { 74 | this.desktopConnection = new DesktopConnection("OpenFin Notification Service Demo"); 75 | RuntimeConfiguration config = new RuntimeConfiguration(); 76 | config.setRuntimeVersion("stable"); 77 | this.desktopConnection.connect(config, new DesktopStateListener() { 78 | 79 | @Override 80 | public void onReady() { 81 | notifications = new Notifications(desktopConnection); 82 | 83 | 84 | notifications.addEventListener(Notifications.EVENT_TYPE_ACTION, ne ->{ 85 | NotificationActionEvent actionEvent = (NotificationActionEvent) ne; 86 | NotificationActionResult actionResult = actionEvent.getResult(); 87 | System.out.println("actionResult: notificationId: " + actionEvent.getNotificationOptions().getId() + ", user clicked on btn: " + actionResult.getString("btn")); 88 | }); 89 | 90 | SwingUtilities.invokeLater(()->{ 91 | glassPane.setVisible(false); 92 | }); 93 | } 94 | 95 | @Override 96 | public void onClose(String error) { 97 | System.exit(0); 98 | } 99 | 100 | @Override 101 | public void onError(String reason) { 102 | 103 | } 104 | 105 | @Override 106 | public void onMessage(String message) { 107 | 108 | } 109 | 110 | @Override 111 | public void onOutgoingMessage(String message) { 112 | 113 | } 114 | 115 | }, 60); 116 | 117 | } 118 | catch (DesktopException | DesktopIOException | IOException e) { 119 | e.printStackTrace(); 120 | } 121 | finally { 122 | 123 | } 124 | } 125 | 126 | private JPanel createGlassPane() { 127 | this.glassPane = new JPanel(new BorderLayout()); 128 | JLabel l = new JLabel("Loading, please wait......"); 129 | l.setHorizontalAlignment(JLabel.CENTER); 130 | this.glassPane.add(l, BorderLayout.CENTER); 131 | this.glassPane.setBackground(Color.LIGHT_GRAY); 132 | return this.glassPane; 133 | } 134 | 135 | 136 | private JPanel createToggleNotificationCenterPanel() { 137 | JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER)); 138 | pnl.setBorder(BorderFactory.createTitledBorder("Notification Center")); 139 | JButton btnToggleNotificationCenter = new JButton("Toggle Notification Center"); 140 | btnToggleNotificationCenter.addActionListener(e->{ 141 | this.notifications.toggleNotificationCenter(); 142 | }); 143 | JButton btnClearAll = new JButton("Clear All"); 144 | btnClearAll.addActionListener(e->{ 145 | this.notifications.clearAll(); 146 | }); 147 | pnl.add(btnToggleNotificationCenter); 148 | pnl.add(btnClearAll); 149 | return pnl; 150 | } 151 | 152 | private JPanel createCreateNotificationPanel() { 153 | JPanel pnl = new JPanel(new BorderLayout()); 154 | pnl.setBorder(BorderFactory.createTitledBorder("Notification")); 155 | 156 | JTextField tfTitle = new JTextField("Title"); 157 | JTextField tfBody = new JTextField("Body"); 158 | JTextField tfCategory = new JTextField("Category"); 159 | JTextField tfIcon = new JTextField("https://openfin.co/favicon-32x32.png"); 160 | JTextField tfIndicatorText = new JTextField("Hello From Java"); 161 | JTextField tfExpiresInSecs = new JTextField("60"); 162 | 163 | JComboBox cbSticky = new JComboBox<>(); 164 | cbSticky.addItem(NotificationOptions.STICKY_STICKY); 165 | cbSticky.addItem(NotificationOptions.STICKY_TRANSIENT); 166 | 167 | JComboBox cbIndicator = new JComboBox<>(); 168 | cbIndicator.addItem(NotificationIndicator.TYPE_FAILURE); 169 | cbIndicator.addItem(NotificationIndicator.TYPE_WARNING); 170 | cbIndicator.addItem(NotificationIndicator.TYPE_SUCCESS); 171 | cbIndicator.setSelectedIndex(2); 172 | 173 | JPanel pnlCenter = new JPanel(new GridBagLayout()); 174 | GridBagConstraints gbConst = new GridBagConstraints(); 175 | gbConst.gridx = 0; 176 | gbConst.gridy = 0; 177 | gbConst.weightx = 0; 178 | gbConst.insets = new Insets(5, 5, 5, 5); 179 | gbConst.anchor = GridBagConstraints.EAST; 180 | pnlCenter.add(new JLabel("Title"), gbConst); 181 | gbConst.gridy++; 182 | pnlCenter.add(new JLabel("Body"), gbConst); 183 | gbConst.gridy++; 184 | pnlCenter.add(new JLabel("Category"), gbConst); 185 | gbConst.gridy++; 186 | pnlCenter.add(new JLabel("Icon"), gbConst); 187 | gbConst.gridy++; 188 | pnlCenter.add(new JLabel("Sticky"), gbConst); 189 | gbConst.gridy++; 190 | pnlCenter.add(new JLabel("Indicator"), gbConst); 191 | gbConst.gridy++; 192 | pnlCenter.add(new JLabel("Indicator Text"), gbConst); 193 | gbConst.gridy++; 194 | pnlCenter.add(new JLabel("Expires (in seconds)"), gbConst); 195 | gbConst.gridx = 1; 196 | gbConst.gridy = 0; 197 | gbConst.weightx = 0.5; 198 | gbConst.insets = new Insets(5, 0, 5, 5); 199 | gbConst.fill = GridBagConstraints.BOTH; 200 | pnlCenter.add(tfTitle, gbConst); 201 | gbConst.gridy++; 202 | pnlCenter.add(tfBody, gbConst); 203 | gbConst.gridy++; 204 | pnlCenter.add(tfCategory, gbConst); 205 | gbConst.gridy++; 206 | pnlCenter.add(tfIcon, gbConst); 207 | gbConst.gridy++; 208 | pnlCenter.add(cbSticky, gbConst); 209 | gbConst.gridy++; 210 | pnlCenter.add(cbIndicator, gbConst); 211 | gbConst.gridy++; 212 | pnlCenter.add(tfIndicatorText, gbConst); 213 | gbConst.gridy++; 214 | pnlCenter.add(tfExpiresInSecs, gbConst); 215 | gbConst.weighty = 0.5; 216 | gbConst.gridy++; 217 | pnlCenter.add(new JLabel(), gbConst); 218 | 219 | 220 | JButton btnCreate = new JButton("Create Notification"); 221 | btnCreate.addActionListener(e->{ 222 | NotificationOptions opt = new NotificationOptions(tfTitle.getText(), tfBody.getText(), tfCategory.getText()); 223 | String icon = tfIcon.getText().trim(); 224 | if (!icon.isEmpty()) { 225 | opt.setIcon(icon); 226 | } 227 | opt.setSticky((String) cbSticky.getSelectedItem()); 228 | NotificationIndicator indicatorOpts = new NotificationIndicator((String) cbIndicator.getSelectedItem()); 229 | String indicatorText = tfIndicatorText.getText().trim(); 230 | if (!indicatorText.isEmpty()) { 231 | indicatorOpts.setText(indicatorText); 232 | } 233 | opt.setIndicator(indicatorOpts); 234 | 235 | String expires = tfExpiresInSecs.getText().trim(); 236 | if (!expires.isEmpty()) { 237 | opt.setExpires(new Date(System.currentTimeMillis() + (1000 * (Integer.parseInt(expires))))); 238 | } 239 | 240 | ButtonOptions bo1 = new ButtonOptions("Button 1"); 241 | bo1.setOnClick(new NotificationActionResult(new JSONObject().put("btn", "btn1"))); 242 | ButtonOptions bo2 = new ButtonOptions("Button 2"); 243 | bo2.setOnClick(new NotificationActionResult(new JSONObject().put("btn", "btn2"))); 244 | bo2.setCta(true); 245 | opt.setButtons(bo1, bo2); 246 | 247 | this.notifications.create(opt); 248 | }); 249 | JPanel pnlBottom = new JPanel(new FlowLayout(FlowLayout.RIGHT)); 250 | pnlBottom.add(btnCreate); 251 | pnl.add(pnlCenter, BorderLayout.CENTER); 252 | pnl.add(pnlBottom, BorderLayout.SOUTH); 253 | return pnl; 254 | } 255 | 256 | private JPanel createContentPanel() { 257 | JPanel p = new JPanel(new BorderLayout()); 258 | p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); 259 | p.setPreferredSize(new Dimension(550, 400)); 260 | p.add(this.createToggleNotificationCenterPanel(), BorderLayout.NORTH); 261 | p.add(this.createCreateNotificationPanel(), BorderLayout.CENTER); 262 | return p; 263 | } 264 | 265 | public static void main(String[] args) { 266 | new NotificationServiceDemo(); 267 | } 268 | 269 | } -------------------------------------------------------------------------------- /src/main/java/com/openfin/desktop/demo/Signer.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop.demo; 2 | 3 | import java.io.InputStream; 4 | import java.security.CodeSigner; 5 | import java.security.cert.Certificate; 6 | import java.security.cert.X509Certificate; 7 | import java.util.Enumeration; 8 | import java.util.HashSet; 9 | import java.util.Map; 10 | import java.util.Set; 11 | import java.util.jar.Attributes; 12 | import java.util.jar.JarEntry; 13 | import java.util.jar.JarFile; 14 | import java.util.jar.Manifest; 15 | 16 | public class Signer { 17 | private final String filename; 18 | 19 | public Signer(String filename) { 20 | this.filename = filename; 21 | } 22 | 23 | public void verify() throws Exception { 24 | JarFile jar = new JarFile(this.filename, true); 25 | 26 | Enumeration entries = jar.entries(); 27 | while (entries.hasMoreElements()) { 28 | JarEntry entry = entries.nextElement(); 29 | byte[] buffer = new byte[8192]; 30 | InputStream is = jar.getInputStream(entry); 31 | while ((is.read(buffer, 0, buffer.length)) != -1) { 32 | // We just read. This will throw a SecurityException 33 | // if a signature/digest check fails. 34 | } 35 | is.close(); 36 | } 37 | 38 | if (!checkSign(jar)) { 39 | throw new SecurityException("not signed"); 40 | } 41 | 42 | } 43 | 44 | private boolean checkSign(JarFile jar) throws Exception { 45 | InputStream jis = jar.getInputStream(jar.getEntry("META-INF/MANIFEST.MF")); 46 | Manifest man = new Manifest(jis); 47 | jis.close(); 48 | 49 | HashSet signed = new HashSet<>(); 50 | for(Map.Entry entry: man.getEntries().entrySet()) { 51 | for(Object attrkey: entry.getValue().keySet()) { 52 | if (attrkey instanceof Attributes.Name && attrkey.toString().contains("-Digest")) { 53 | signed.add(entry.getKey()); 54 | } 55 | } 56 | } 57 | System.out.printf("Number of Digest from manifest %d \n", signed.size()); 58 | 59 | Set entries = new HashSet<>(); 60 | for(Enumeration entry = jar.entries(); entry.hasMoreElements(); ) { 61 | JarEntry je = entry.nextElement(); 62 | String fileName = je.getName().toUpperCase(); 63 | if (!je.isDirectory() 64 | && !fileName.endsWith(".MF") 65 | && !fileName.endsWith(".SF") 66 | && !fileName.endsWith(".DSA") 67 | && !fileName.endsWith(".EC") 68 | && !fileName.endsWith(".RSA") 69 | ) { 70 | CodeSigner[] signers = je.getCodeSigners(); 71 | if (signers != null && signers.length == 1) { 72 | CodeSigner signer = signers[0]; 73 | if (signer.getSignerCertPath().getCertificates().size() != 4) { 74 | throw new SecurityException(String.format("invalid cert chain %s", je.getName())); 75 | } 76 | X509Certificate cert = (X509Certificate) signer.getSignerCertPath().getCertificates().get(0); 77 | if (!cert.getSubjectDN().toString().contains("OpenFin Inc.")) { 78 | throw new SecurityException(String.format("invalid signed %s", je.getName())); 79 | } 80 | entries.add(je.getName()); 81 | } else { 82 | throw new SecurityException(String.format("missing cert %s", je.getName())); 83 | } 84 | } 85 | } 86 | System.out.printf("Number of signed entries %d \n", entries.size()); 87 | 88 | Set unsigned = new HashSet<>(entries); 89 | unsigned.removeAll(signed); 90 | return unsigned.size() == 0; 91 | } 92 | 93 | public static void main(String[] args) throws Exception { 94 | Signer signer = new Signer(args[0]); 95 | signer.verify(); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/openfin/desktop/demo/WindowEmbedDemo.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop.demo; 2 | 3 | import com.openfin.desktop.*; 4 | import com.openfin.desktop.ActionEvent; 5 | import com.openfin.desktop.Window; 6 | import com.sun.jna.Native; 7 | import info.clearthought.layout.TableLayout; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import javax.swing.*; 12 | import java.awt.*; 13 | import java.awt.event.*; 14 | import java.lang.System; 15 | 16 | /** 17 | * Java example to embed HTML5 window in Swing window 18 | * 19 | * Created by wche on 3/13/15. 20 | * 21 | */ 22 | public class WindowEmbedDemo extends JPanel implements ActionListener, WindowListener { 23 | private final static Logger logger = LoggerFactory.getLogger(WindowEmbedDemo.class.getName()); 24 | 25 | private static JFrame jFrame; 26 | protected String appUuid = "JavaEmbedding"; 27 | protected String startupUuid = "OpenFinHelloWorld"; 28 | protected DesktopConnection desktopConnection; 29 | 30 | protected String openfin_app_url = "https://cdn.openfin.co/examples/junit/SimpleDockingExample.html"; // source is in release/SimpleDockingExample.html 31 | 32 | protected JButton launch, close; 33 | protected java.awt.Canvas embedCanvas; 34 | protected Long previousPrarentHwndId; 35 | 36 | public WindowEmbedDemo(final String startupUuid) { 37 | this.startupUuid = startupUuid; 38 | try { 39 | this.desktopConnection = new DesktopConnection(appUuid); 40 | } catch (DesktopException desktopError) { 41 | desktopError.printStackTrace(); 42 | } 43 | setLayout(new BorderLayout()); 44 | add(layoutCenterPanel(), BorderLayout.CENTER); 45 | setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); 46 | setMainButtonsEnabled(false); 47 | } 48 | 49 | private JPanel layoutCenterPanel() { 50 | JPanel panel = new JPanel(); 51 | double size[][] = {{TableLayout.FILL}, {120, TableLayout.FILL}}; 52 | panel.setLayout(new TableLayout(size)); 53 | panel.add(layoutActionButtonPanel(), "0,0,0,0"); 54 | panel.add(layoutEmbedPanel(), "0, 1, 0, 1"); 55 | return panel; 56 | } 57 | 58 | private JPanel layoutActionButtonPanel() { 59 | JPanel buttonPanel = new JPanel(); 60 | 61 | JPanel topPanel = new JPanel(); 62 | double size[][] = {{10, 190, 20, 190, 10}, {25, 10, 25, 10}}; 63 | topPanel.setLayout(new TableLayout(size)); 64 | topPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(2), "Desktop")); 65 | 66 | launch = new JButton("Launch OpenFin"); 67 | launch.setActionCommand("start"); 68 | close = new JButton("Shutdown OpenFin"); 69 | close.setActionCommand("close"); 70 | topPanel.add(launch, "1,0,1,0"); 71 | topPanel.add(close, "3,0,3,0"); 72 | 73 | 74 | close.addActionListener(this); 75 | launch.addActionListener(this); 76 | 77 | buttonPanel.add(topPanel, "0,0"); 78 | return buttonPanel; 79 | } 80 | 81 | protected JPanel layoutEmbedPanel() { 82 | JPanel panel = new JPanel(); 83 | panel.setLayout(new BorderLayout()); 84 | panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createBevelBorder(2), "HTML5 app")); 85 | 86 | embedCanvas = new java.awt.Canvas(); 87 | panel.add(embedCanvas, BorderLayout.CENTER); 88 | 89 | embedCanvas.addComponentListener(new ComponentAdapter() { 90 | @Override 91 | public void componentResized(ComponentEvent event) { 92 | super.componentResized(event); 93 | Dimension newSize = event.getComponent().getSize(); 94 | try { 95 | if (startupHtml5app != null) { 96 | startupHtml5app.getWindow().embedComponentSizeChange((int)newSize.getWidth(), (int)newSize.getHeight()); 97 | } 98 | } catch (Exception e) { 99 | e.printStackTrace(); 100 | } 101 | } 102 | }); 103 | 104 | 105 | return panel; 106 | } 107 | 108 | private void setMainButtonsEnabled(boolean enabled) { 109 | launch.setEnabled(!enabled); 110 | close.setEnabled(enabled); 111 | 112 | if (enabled) { 113 | this.desktopConnection.getInterApplicationBus().addSubscribeListener(new SubscriptionListener() { 114 | public void subscribed(String uuid, String topic) { 115 | System.out.println("subscribed " + uuid + " on topic " + topic); 116 | } 117 | 118 | public void unsubscribed(String uuid, String topic) { 119 | System.out.println("unsubscribed " + uuid + " on topic " + topic); 120 | 121 | } 122 | }); 123 | } 124 | } 125 | 126 | private static void createAndShowGUI(final String startupUuid) { 127 | //Create and set up the window. 128 | jFrame = new JFrame("Java Embedding Demo"); 129 | // jFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); 130 | //Create and set up the content pane. 131 | WindowEmbedDemo newContentPane = new WindowEmbedDemo(startupUuid); 132 | newContentPane.setOpaque(true); //content panes must be opaque 133 | jFrame.setContentPane(newContentPane); 134 | jFrame.addWindowListener(newContentPane); 135 | //Display the window. 136 | jFrame.pack(); 137 | jFrame.setSize(800, 800); 138 | jFrame.setLocationRelativeTo(null); 139 | jFrame.setResizable(true); 140 | jFrame.setVisible(true); 141 | } 142 | 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 | 154 | private void closeDesktop() { 155 | this.closeEmbeddedApp(); 156 | 157 | if (desktopConnection != null && desktopConnection.isConnected()) { 158 | try { 159 | // new com.openfin.desktop.System(desktopConnection).exit(); 160 | System.out.println("disconnecting "); 161 | desktopConnection.disconnect(); 162 | } catch (Exception e) { 163 | e.printStackTrace(); 164 | } 165 | } 166 | 167 | //closeWebSocket(); 168 | SwingUtilities.invokeLater(new Runnable() { 169 | @Override 170 | public void run() { 171 | jFrame.dispose(); 172 | } 173 | }); 174 | try { 175 | Thread.sleep(1000); 176 | java.lang.System.exit(0); 177 | } catch (InterruptedException e) { 178 | e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 179 | } 180 | } 181 | 182 | @Override 183 | public void windowOpened(WindowEvent e) { 184 | } 185 | 186 | @Override 187 | public void windowClosing(WindowEvent e) { 188 | closeDesktop(); 189 | } 190 | 191 | @Override 192 | public void windowClosed(WindowEvent e) { 193 | } 194 | 195 | @Override 196 | public void windowIconified(WindowEvent e) { 197 | } 198 | 199 | @Override 200 | public void windowDeiconified(WindowEvent e) { 201 | } 202 | 203 | @Override 204 | public void windowActivated(WindowEvent e) { 205 | } 206 | 207 | @Override 208 | public void windowDeactivated(WindowEvent e) { 209 | } 210 | 211 | public void actionPerformed(java.awt.event.ActionEvent e) { 212 | if ("start".equals(e.getActionCommand())) { 213 | runStartAction(); 214 | } else if ("close".equals(e.getActionCommand())) { 215 | closeDesktop(); 216 | } else if ("embed-window".equals(e.getActionCommand())) { 217 | embedStartupApp(); 218 | } 219 | } 220 | 221 | private void runStartAction() { 222 | try { 223 | DesktopStateListener listener = new DesktopStateListener() { 224 | @Override 225 | public void onReady() { 226 | setMainButtonsEnabled(true); 227 | launchHtmlApp(); 228 | } 229 | 230 | @Override 231 | public void onClose(String error) { 232 | } 233 | 234 | @Override 235 | public void onError(String reason) { 236 | 237 | } 238 | @Override 239 | public void onMessage(String message) { 240 | } 241 | @Override 242 | public void onOutgoingMessage(String message) { 243 | } 244 | }; 245 | RuntimeConfiguration configuration = new RuntimeConfiguration(); 246 | configuration.setAdditionalRuntimeArguments(" --v=1 "); // enable additional logging from Runtime 247 | String desktopVersion = java.lang.System.getProperty("com.openfin.demo.version"); 248 | if (desktopVersion == null) { 249 | desktopVersion = "stable"; 250 | } 251 | configuration.setRuntimeVersion(desktopVersion); 252 | desktopConnection.connect(configuration, listener, 60); 253 | 254 | } catch (Exception e) { 255 | e.printStackTrace(); 256 | } 257 | } 258 | 259 | private void launchHtmlApp() { 260 | // launch 5 instances of same example app 261 | int width = 500, height=500; 262 | try { 263 | String url = java.lang.System.getProperty("com.openfin.demo.embed.URL"); 264 | if (url != null) { 265 | openfin_app_url = url; 266 | } 267 | ApplicationOptions options = new ApplicationOptions(startupUuid, startupUuid, openfin_app_url); 268 | options.setApplicationIcon("http://openfin.github.io/snap-and-dock/openfin.ico"); 269 | WindowOptions mainWindowOptions = new WindowOptions(); 270 | mainWindowOptions.setAutoShow(false); 271 | mainWindowOptions.setDefaultHeight(height); 272 | mainWindowOptions.setDefaultLeft(10); 273 | mainWindowOptions.setDefaultTop(50); 274 | mainWindowOptions.setDefaultWidth(width); 275 | mainWindowOptions.setShowTaskbarIcon(true); 276 | mainWindowOptions.setSaveWindowState(false); // set to false so all windows start at same initial positions for each run 277 | mainWindowOptions.setFrame(false); 278 | mainWindowOptions.setContextMenu(true); 279 | mainWindowOptions.setResizeRegionSize(0); // need this to turn off resize region for embedded (child) window 280 | options.setMainWindowOptions(mainWindowOptions); 281 | DemoUtils.runApplication(options, this.desktopConnection, new AckListener() { 282 | @Override 283 | public void onSuccess(Ack ack) { 284 | Application app = (Application) ack.getSource(); 285 | try { 286 | Thread.sleep(1000); 287 | embedStartupApp(); 288 | } catch (Exception ex) { 289 | ex.printStackTrace(); 290 | } 291 | } 292 | @Override 293 | public void onError(Ack ack) { 294 | logger.error(String.format("Error launching %s %s", options.getUUID(), ack.getReason())); 295 | } 296 | }); 297 | } catch (Exception e) { 298 | logger.error("Error launching app", e); 299 | } 300 | } 301 | 302 | private boolean trayIconAdded = false; 303 | private Application startupHtml5app; 304 | 305 | private void embedStartupApp() { 306 | try { 307 | if (startupHtml5app == null) { 308 | startupHtml5app = Application.wrap(this.startupUuid, this.desktopConnection); 309 | } 310 | if (!trayIconAdded) { 311 | startupHtml5app.setTrayIcon("http://icons.iconarchive.com/icons/marcus-roberto/google-play/512/Google-Search-icon.png", new EventListener() { 312 | public void eventReceived(ActionEvent actionEvent) { 313 | java.lang.System.out.println("Tray icon clicked"); 314 | } 315 | }, null); 316 | trayIconAdded = true; 317 | } else { 318 | startupHtml5app.removeTrayIcon(null); 319 | trayIconAdded = false; 320 | } 321 | 322 | Window html5Wnd = startupHtml5app.getWindow(); 323 | long parentHWndId = Native.getComponentID(this.embedCanvas); 324 | System.out.println("Canvas HWND " + Long.toHexString(parentHWndId)); 325 | html5Wnd.embedInto(parentHWndId, this.embedCanvas.getWidth(), this.embedCanvas.getHeight(), new AckListener() { 326 | @Override 327 | public void onSuccess(Ack ack) { 328 | if (ack.isSuccessful()) { 329 | previousPrarentHwndId = ack.getJsonObject().getLong("hWndPreviousParent"); 330 | } else { 331 | java.lang.System.out.println("embedding failed: " + ack.getJsonObject().toString()); 332 | } 333 | } 334 | @Override 335 | public void onError(Ack ack) { 336 | } 337 | }); 338 | } catch (Exception e) { 339 | e.printStackTrace(); 340 | } 341 | } 342 | 343 | /** 344 | * 345 | * @param args 346 | */ 347 | public static void main(String[] args) { 348 | java.lang.System.out.println("starting: "); 349 | javax.swing.SwingUtilities.invokeLater(new Runnable() { 350 | public void run() { 351 | createAndShowGUI("OpenFin Embed Example"); 352 | } 353 | }); 354 | } 355 | } 356 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 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 9 | Permissions: all-permissions 10 | -------------------------------------------------------------------------------- /src/test/java/com/openfin/desktop/AllTests.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.junit.runners.Suite; 5 | 6 | /** 7 | * Run all tests 8 | * 9 | * Created by wche on 1/25/16. 10 | */ 11 | 12 | @RunWith(Suite.class) 13 | @Suite.SuiteClasses({ ApplicationTest.class, OpenFinRuntimeTest.class, WindowTest.class, SystemTest.class, InterApplicationBusTest.class, ChannelTest.class, RuntimeConfigTest.class, InteropTest.class, SnapshotTest.class}) 14 | public class AllTests { 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/openfin/desktop/DesktopConnectionTest.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.util.concurrent.BrokenBarrierException; 6 | import java.util.concurrent.CountDownLatch; 7 | import java.util.concurrent.CyclicBarrier; 8 | import java.util.concurrent.TimeUnit; 9 | import java.util.concurrent.atomic.AtomicInteger; 10 | 11 | import org.junit.AfterClass; 12 | import org.junit.BeforeClass; 13 | import org.junit.Test; 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | 17 | public class DesktopConnectionTest { 18 | private static Logger logger = LoggerFactory.getLogger(DesktopConnectionTest.class.getName()); 19 | 20 | private static final String DESKTOP_UUID = DesktopConnectionTest.class.getName(); 21 | 22 | @BeforeClass 23 | public static void setup() throws Exception { 24 | } 25 | 26 | @AfterClass 27 | public static void teardown() throws Exception { 28 | } 29 | 30 | @Test 31 | public void reconnect() throws Exception { 32 | // IAB subscription shouldn't survive reconnection 33 | 34 | final AtomicInteger invokeCnt = new AtomicInteger(0); 35 | String topic1 = "myTopic1"; 36 | String topic2 = "myTopic2"; 37 | String message1 = "myMessage1"; 38 | String message2 = "myMessage2"; 39 | final CyclicBarrier connectLatch = new CyclicBarrier(2); 40 | final CountDownLatch disconnectLatch = new CountDownLatch(1); 41 | DesktopConnection conn = new DesktopConnection(DESKTOP_UUID); 42 | RuntimeConfiguration conf = new RuntimeConfiguration(); 43 | conf.setRuntimeVersion(TestUtils.getRuntimeVersion()); 44 | 45 | DesktopStateListener listener = new DesktopStateListener() { 46 | 47 | @Override 48 | public void onReady() { 49 | try { 50 | connectLatch.await(); 51 | logger.debug("onReady"); 52 | } 53 | catch (InterruptedException e) { 54 | e.printStackTrace(); 55 | } 56 | catch (BrokenBarrierException e) { 57 | e.printStackTrace(); 58 | } 59 | } 60 | 61 | @Override 62 | public void onClose(String error) { 63 | disconnectLatch.countDown(); 64 | logger.debug("onClose: " + error); 65 | } 66 | 67 | @Override 68 | public void onError(String reason) { 69 | } 70 | 71 | @Override 72 | public void onMessage(String message) { 73 | } 74 | 75 | @Override 76 | public void onOutgoingMessage(String message) { 77 | } 78 | 79 | }; 80 | 81 | conn.connect(conf, listener, 10); 82 | connectLatch.await(10, TimeUnit.SECONDS); 83 | 84 | assertEquals(0, connectLatch.getNumberWaiting()); 85 | 86 | // create an app and let it sit through the reconnection. 87 | ApplicationOptions options = TestUtils.getAppOptions(null); 88 | Application application = TestUtils.runApplication(options, conn); 89 | 90 | CountDownLatch listener1Latch = new CountDownLatch(1); 91 | // subscribe to a topic 92 | conn.getInterApplicationBus().subscribe("*", topic1, new BusListener() { 93 | 94 | @Override 95 | public void onMessageReceived(String sourceUuid, String topic, Object payload) { 96 | logger.info("listener1 received: " + payload.toString()); 97 | invokeCnt.incrementAndGet(); 98 | if (message1.equals(payload.toString())) { 99 | listener1Latch.countDown(); 100 | } 101 | } 102 | }, new AckListener() { 103 | @Override 104 | public void onSuccess(Ack ack) { 105 | if (ack.isSuccessful()) { 106 | try { 107 | conn.getInterApplicationBus().publish(topic1, message1); 108 | } 109 | catch (DesktopException e) { 110 | e.printStackTrace(); 111 | } 112 | } 113 | } 114 | 115 | @Override 116 | public void onError(Ack ack) { 117 | logger.error(ack.getReason()); 118 | } 119 | }); 120 | 121 | listener1Latch.await(5, TimeUnit.SECONDS); 122 | assertEquals(0, listener1Latch.getCount()); 123 | 124 | try { 125 | conn.disconnect("junit test"); 126 | } 127 | catch (DesktopException e) { 128 | e.printStackTrace(); 129 | } 130 | 131 | disconnectLatch.await(5, TimeUnit.SECONDS); 132 | 133 | assertEquals(0, disconnectLatch.getCount()); 134 | 135 | // connect it again. 136 | connectLatch.reset(); 137 | conn.connect(conf, listener, 10); 138 | connectLatch.await(10, TimeUnit.SECONDS); 139 | assertEquals(0, connectLatch.getNumberWaiting()); 140 | 141 | CountDownLatch listener2Latch = new CountDownLatch(1); 142 | 143 | conn.getInterApplicationBus().subscribe("*", topic2, new BusListener() { 144 | 145 | @Override 146 | public void onMessageReceived(String sourceUuid, String topic, Object payload) { 147 | listener2Latch.countDown(); 148 | logger.info("listener2 received: " + payload.toString()); 149 | } 150 | }, new AckListener() { 151 | @Override 152 | public void onSuccess(Ack ack) { 153 | if (ack.isSuccessful()) { 154 | try { 155 | conn.getInterApplicationBus().publish(topic1, message2); 156 | conn.getInterApplicationBus().publish(topic2, message2); 157 | } 158 | catch (DesktopException e) { 159 | e.printStackTrace(); 160 | } 161 | catch (Exception e) { 162 | e.printStackTrace(); 163 | } 164 | } 165 | } 166 | 167 | @Override 168 | public void onError(Ack ack) { 169 | logger.error(ack.getReason()); 170 | } 171 | }); 172 | 173 | //can kill the app now. 174 | Application app = Application.wrap(application.uuid, conn); 175 | app.close(); 176 | 177 | listener2Latch.await(5, TimeUnit.SECONDS); 178 | 179 | assertEquals(0, listener2Latch.getCount()); 180 | assertEquals(1, invokeCnt.get()); 181 | } 182 | 183 | } 184 | -------------------------------------------------------------------------------- /src/test/java/com/openfin/desktop/InteropTest.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | import static org.junit.Assert.assertTrue; 6 | 7 | import java.util.concurrent.CompletableFuture; 8 | import java.util.concurrent.CompletionStage; 9 | import java.util.concurrent.TimeUnit; 10 | import java.util.concurrent.atomic.AtomicInteger; 11 | 12 | import com.openfin.desktop.interop.Intent; 13 | import com.openfin.desktop.interop.InteropClient; 14 | import org.json.JSONObject; 15 | import org.junit.AfterClass; 16 | import org.junit.BeforeClass; 17 | import org.junit.Test; 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | import com.openfin.desktop.interop.Context; 22 | import com.openfin.desktop.interop.ContextGroupInfo; 23 | 24 | public class InteropTest { 25 | private static Logger logger = LoggerFactory.getLogger(InteropTest.class.getName()); 26 | 27 | private static final String DESKTOP_UUID = InteropTest.class.getName(); 28 | private static final String BROKER_NANE = "AdapterInteropTest"; // created by javascript side 29 | private static DesktopConnection desktopConnection; 30 | 31 | @BeforeClass 32 | public static void setup() throws Exception { 33 | logger.debug("starting"); 34 | RuntimeConfiguration cfg = new RuntimeConfiguration(); 35 | cfg.setManifestLocation("https://testing-assets.openfin.co/adapters/interop/app.json"); 36 | // cfg.setManifestLocation("http://localhost:5555/app.json"); 37 | desktopConnection = TestUtils.setupConnection(DESKTOP_UUID, cfg); 38 | Thread.sleep(3000); // give time for the js app to start up and configure everything properly 39 | } 40 | 41 | @AfterClass 42 | public static void teardown() throws Exception { 43 | TestUtils.teardownDesktopConnection(desktopConnection); 44 | } 45 | 46 | @Test 47 | public void clientGetContextGroupInfo() throws Exception { 48 | CompletionStage getContextFuture = desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{ 49 | return client.getContextGroups(); 50 | }); 51 | 52 | ContextGroupInfo[] contextGroupInfo = getContextFuture.toCompletableFuture().get(10, TimeUnit.SECONDS); 53 | assertNotNull(contextGroupInfo); 54 | assertTrue(contextGroupInfo.length > 0); 55 | assertNotNull(contextGroupInfo[0].getDisplayMetadata().getColor()); 56 | } 57 | 58 | @Test 59 | public void clientGetInfoForContextGroup() throws Exception { 60 | CompletionStage getContextFuture = desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{ 61 | return client.getInfoForContextGroup("red"); 62 | }); 63 | 64 | ContextGroupInfo contextGroupInfo = getContextFuture.toCompletableFuture().get(10, TimeUnit.SECONDS); 65 | assertNotNull(contextGroupInfo); 66 | assertNotNull(contextGroupInfo.getDisplayMetadata().getColor()); 67 | } 68 | 69 | @Test 70 | public void clientGetAllClientsInContextGroup() throws Exception { 71 | CompletionStage getContextFuture = desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{ 72 | return client.joinContextGroup("red").thenCompose(v->{ 73 | return client.getAllClientsInContextGroup("red"); 74 | }); 75 | }); 76 | 77 | ClientIdentity[] clientIdentity = getContextFuture.toCompletableFuture().get(10, TimeUnit.SECONDS); 78 | assertNotNull(clientIdentity); 79 | assertTrue(clientIdentity.length > 0); 80 | assertNotNull(clientIdentity[0].getEndpointId()); 81 | } 82 | 83 | @Test 84 | public void clientJoinThenRemoveFromContextGroup() throws Exception { 85 | AtomicInteger clientCntAfterJoin = new AtomicInteger(0); 86 | AtomicInteger clientCntAfterRemove = new AtomicInteger(0); 87 | CompletionStage testFuture = desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{ 88 | return client.joinContextGroup("green").thenCompose(v->{ 89 | return client.getAllClientsInContextGroup("green"); 90 | }).thenAccept(clients->{ 91 | logger.info(String.format("clientJoinThenRemoveFromContextGroup after join %d", clients.length)); 92 | clientCntAfterJoin.set(clients.length); 93 | }).thenCompose(v->{ 94 | return client.removeFromContextGroup(); 95 | }).thenCompose(v->{ 96 | return client.getAllClientsInContextGroup("green"); 97 | }).thenAccept(clients->{ 98 | logger.info(String.format("clientJoinThenRemoveFromContextGroup after remove %d", clients.length)); 99 | clientCntAfterRemove.set(clients.length); 100 | }); 101 | }); 102 | 103 | testFuture.toCompletableFuture().get(10, TimeUnit.SECONDS); 104 | assertEquals(clientCntAfterJoin.get(), clientCntAfterRemove.incrementAndGet()); 105 | } 106 | 107 | @Test 108 | public void clientSetContext() throws Exception { 109 | final Context context = getRandomContext(); 110 | CompletionStage setContextFuture = desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{ 111 | return client.getContextGroups().thenCompose(groups->{ 112 | return client.joinContextGroup("red").thenCompose(v->{ 113 | return client.setContext(context); 114 | }); 115 | }); 116 | }); 117 | 118 | setContextFuture.toCompletableFuture().get(10, TimeUnit.SECONDS); 119 | } 120 | 121 | @Test 122 | public void clientAddContextListener() throws Exception { 123 | final Context context = getRandomContext(); 124 | 125 | CompletableFuture listenerInvokedFuture = new CompletableFuture<>(); 126 | 127 | desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{ 128 | return client.addContextListener(ctx->{ 129 | String ticker = ctx.getId().optString("ticker", ""); 130 | StringBuilder sb = new StringBuilder(context.getId().getString("ticker")); 131 | if (ticker.equals(sb.append("1").toString())) { 132 | listenerInvokedFuture.complete(ctx); 133 | } 134 | }).thenApply(v->{ 135 | return client; 136 | }); 137 | }).thenCompose(client->{ 138 | return client.joinContextGroup("red").thenCompose(v->{ 139 | return client.setContext(context); 140 | }); 141 | }); 142 | 143 | Context ctx = listenerInvokedFuture.toCompletableFuture().get(10, TimeUnit.SECONDS); 144 | assertNotNull(ctx); 145 | } 146 | 147 | @Test 148 | public void clientFireIntent() throws Exception { 149 | final Context context = getRandomContext(); 150 | Intent intent = new Intent(); 151 | intent.setName("JavaIntent"); 152 | intent.setContext(context); 153 | CompletionStage fireIntentFuture = desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{ 154 | return client.fireIntent(intent); 155 | }); 156 | desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{ 157 | return client.registerIntentListener("JavaIntent", intentReceived->{ 158 | String ticker = intentReceived.getContext().getId().optString("ticker", ""); 159 | StringBuilder sb = new StringBuilder(context.getId().getString("ticker")); 160 | }).thenCompose(v -> { 161 | return client.fireIntent(intent); 162 | }); 163 | }); 164 | 165 | 166 | fireIntentFuture.toCompletableFuture().get(10, TimeUnit.SECONDS); 167 | } 168 | 169 | @Test 170 | public void clientFireAndRegisterIntentListener() throws Exception { 171 | final Context context = getRandomContext(); 172 | 173 | CompletableFuture listenerInvokedFuture = new CompletableFuture<>(); 174 | desktopConnection.getInterop().connect(BROKER_NANE).thenCompose(client->{ 175 | return client.registerIntentListener("JavaIntent", intentReceived->{ 176 | String ticker = intentReceived.getContext().getId().optString("ticker", ""); 177 | StringBuilder sb = new StringBuilder(context.getId().getString("ticker")); 178 | if (ticker.equals(sb.append("1").toString())) { 179 | listenerInvokedFuture.complete(intentReceived); 180 | } 181 | }).thenCompose(v -> { 182 | Intent intent = new Intent(); 183 | intent.setName("JsTestIntent"); 184 | intent.setContext(context); 185 | return client.fireIntent(intent); 186 | }); 187 | }); 188 | 189 | Intent intent = listenerInvokedFuture.toCompletableFuture().get(60, TimeUnit.SECONDS); 190 | assertNotNull(intent); 191 | } 192 | 193 | private Context getRandomContext() { 194 | Long randomTicker = Math.round(Math.random() * 100); 195 | final Context context = new Context(); 196 | JSONObject id = new JSONObject(); 197 | id.put("ticker", String.format("%d", randomTicker)); 198 | context.setId(id); 199 | context.setType("java"); 200 | context.setName("java"); 201 | return context; 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /src/test/java/com/openfin/desktop/NotificationTest.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.fail; 5 | 6 | import java.util.concurrent.CountDownLatch; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | import org.json.JSONObject; 10 | import org.junit.AfterClass; 11 | import org.junit.BeforeClass; 12 | import org.junit.Test; 13 | import org.slf4j.Logger; 14 | import org.slf4j.LoggerFactory; 15 | 16 | /** 17 | * Tests for com.openfin.desktop.Notification class 18 | * 19 | * Created by wche on 1/26/16. 20 | */ 21 | 22 | public class NotificationTest { 23 | private static Logger logger = LoggerFactory.getLogger(NotificationTest.class.getName()); 24 | 25 | private static final String DESKTOP_UUID = NotificationTest.class.getName(); 26 | private static DesktopConnection desktopConnection; 27 | // notification used by Hello OpenFin demo app. 28 | private static final String notification_url = "http://demoappdirectory.openf.in/desktop/config/apps/OpenFin/HelloOpenFin/views/notification.html"; 29 | 30 | @BeforeClass 31 | public static void setup() throws Exception { 32 | logger.debug("starting"); 33 | desktopConnection = TestUtils.setupConnection(DESKTOP_UUID); 34 | 35 | // for Runtime 6.0+, needs to start at least one app for notifications to work 36 | ApplicationOptions options = TestUtils.getAppOptions(null); 37 | Application application = TestUtils.runApplication(options, desktopConnection); 38 | 39 | logger.info("Waiting for notification center to be ready"); 40 | // @TODO currently there is no way to know Notification center is ready, so we just sleep here 41 | // @TODO we will fix notification center to generate an event when it finishes initialization and is ready to process requests 42 | Thread.sleep(8000); 43 | } 44 | 45 | @AfterClass 46 | public static void teardown() throws Exception { 47 | TestUtils.teardownDesktopConnection(desktopConnection); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/openfin/desktop/RuntimeConfigTest.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import java.net.Socket; 7 | import java.util.UUID; 8 | import java.util.concurrent.CountDownLatch; 9 | import java.util.concurrent.TimeUnit; 10 | import java.util.concurrent.atomic.AtomicReference; 11 | 12 | import org.json.JSONArray; 13 | import org.json.JSONObject; 14 | import org.junit.AfterClass; 15 | import org.junit.BeforeClass; 16 | import org.junit.Test; 17 | import org.slf4j.Logger; 18 | import org.slf4j.LoggerFactory; 19 | 20 | /** 21 | * Created by richard on 4/1/2016. 22 | */ 23 | public class RuntimeConfigTest { 24 | private static Logger logger = LoggerFactory.getLogger(RuntimeConfigTest.class.getName()); 25 | 26 | private static final String DESKTOP_UUID = RuntimeConfigTest.class.getName(); 27 | private static RuntimeConfiguration configuration; 28 | private static String appUUID = UUID.randomUUID().toString(); 29 | 30 | public static void setup() throws Exception { 31 | logger.debug("starting"); 32 | } 33 | 34 | private static RuntimeConfiguration getDefaultRuntimeConfiguration() { 35 | RuntimeConfiguration configuration = new RuntimeConfiguration(); 36 | configuration.setRuntimeVersion(TestUtils.getRuntimeVersion()); 37 | configuration.setDevToolsPort(9090); 38 | configuration.setAdditionalRuntimeArguments("--v=1"); 39 | 40 | JSONObject startupApp = new JSONObject(); 41 | startupApp.put("name", "TVBWebTest"); 42 | startupApp.put("uuid", appUUID); 43 | startupApp.put("url", TestUtils.openfin_app_url); 44 | startupApp.put("applicationIcon", TestUtils.icon_url); 45 | startupApp.put("autoShow", true); 46 | startupApp.put("defaultTop", 100); 47 | startupApp.put("defaultLeft", 100); 48 | startupApp.put("defaultWidth", 200); 49 | startupApp.put("defaultHeight", 200); 50 | startupApp.put("delay_connection", true); 51 | startupApp.put("frame", true); 52 | startupApp.put("saveWindowState", false); 53 | configuration.setStartupApp(startupApp); 54 | 55 | return configuration; 56 | } 57 | 58 | @Test 59 | public void launchFromConfig() throws Exception { 60 | RuntimeConfiguration configuration = getDefaultRuntimeConfiguration(); 61 | DesktopConnection conn = TestUtils.setupConnection(DESKTOP_UUID, configuration); 62 | assertTrue(isWindowCreated(appUUID, conn)); 63 | TestUtils.teardownDesktopConnection(conn); 64 | } 65 | 66 | @Test 67 | public void launchFromRemoteConfig() throws Exception { 68 | RuntimeConfiguration configuration = new RuntimeConfiguration(); 69 | configuration.setManifestLocation(TestUtils.hello_app_manifest_url); 70 | DesktopConnection conn = TestUtils.setupConnection(DESKTOP_UUID, configuration); 71 | assertTrue(isWindowCreated("OpenFinHelloWorld", conn)); 72 | TestUtils.teardownDesktopConnection(conn); 73 | } 74 | 75 | private boolean isWindowCreated(String uuid, DesktopConnection conn) throws Exception { 76 | CountDownLatch latch = new CountDownLatch(1); 77 | AtomicReference atomicReference = new AtomicReference<>(); 78 | atomicReference.set(false); 79 | OpenFinRuntime runtime = new OpenFinRuntime(conn); 80 | runtime.getAllWindows(new AckListener() { 81 | @Override 82 | public void onSuccess(Ack ack) { 83 | if (ack.isSuccessful()) { 84 | JSONArray data = (JSONArray) ack.getData(); 85 | logger.debug(String.format("All windows info %s", data.toString())); 86 | for (int i = 0; i < data.length(); i++) { 87 | JSONObject window = data.getJSONObject(i); 88 | if (window.has("uuid") && window.has("mainWindow") && window.getString("uuid").equals(uuid)) { 89 | atomicReference.set(true); 90 | } 91 | } 92 | latch.countDown(); 93 | } 94 | } 95 | @Override 96 | public void onError(Ack ack) { 97 | logger.error("Connection failed: %s", ack.getReason()); 98 | } 99 | }); 100 | latch.await(5, TimeUnit.SECONDS); 101 | return atomicReference.get(); 102 | } 103 | 104 | private static boolean serverListening(int port) 105 | { 106 | Socket s = null; 107 | try 108 | { 109 | s = new Socket("localhost", port); 110 | return true; 111 | } 112 | catch (Exception e) 113 | { 114 | return false; 115 | } 116 | finally 117 | { 118 | if(s != null) 119 | try {s.close();} 120 | catch(Exception e){} 121 | } 122 | } 123 | 124 | 125 | @Test 126 | public void setDevToolsPort() throws Exception { 127 | int devPort = 7777; 128 | 129 | RuntimeConfiguration configuration = getDefaultRuntimeConfiguration(); 130 | configuration.setDevToolsPort(devPort); 131 | DesktopConnection conn = TestUtils.setupConnection(DESKTOP_UUID, configuration); 132 | assertTrue(serverListening(devPort)); 133 | TestUtils.teardownDesktopConnection(conn); 134 | } 135 | } 136 | 137 | -------------------------------------------------------------------------------- /src/test/java/com/openfin/desktop/SnapshotTest.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop; 2 | 3 | import com.openfin.desktop.snapshot.SnapshotSourceProvider; 4 | import org.json.JSONObject; 5 | import org.junit.AfterClass; 6 | import org.junit.BeforeClass; 7 | import org.junit.Ignore; 8 | import org.junit.Test; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import java.util.concurrent.CountDownLatch; 13 | import java.util.concurrent.TimeUnit; 14 | 15 | import static org.junit.Assert.assertEquals; 16 | 17 | public class SnapshotTest implements SnapshotSourceProvider { 18 | 19 | private static Logger logger = LoggerFactory.getLogger(SnapshotTest.class.getName()); 20 | 21 | private static final String DESKTOP_UUID = SnapshotTest.class.getName(); 22 | private static DesktopConnection desktopConnection; 23 | private static OpenFinRuntime runtime; 24 | private static final JSONObject SNAPSHOT_CONTENT = new JSONObject("{width: 123}"); 25 | 26 | private JSONObject randomSnapshot; 27 | 28 | @BeforeClass 29 | public static void setup() throws Exception { 30 | logger.debug("starting"); 31 | desktopConnection = TestUtils.setupConnection(DESKTOP_UUID); 32 | if (desktopConnection != null) { 33 | runtime = new OpenFinRuntime(desktopConnection); 34 | } 35 | } 36 | 37 | @AfterClass 38 | public static void teardown() throws Exception { 39 | TestUtils.teardownDesktopConnection(desktopConnection); 40 | } 41 | 42 | @Test 43 | public void initProviderThenCreateClient() throws Exception { 44 | CountDownLatch latch = new CountDownLatch(2); 45 | final String appUuid = "initProviderThenCreateClient"; 46 | desktopConnection.getSnapshotSource().initSnapshotSourceProviderAsync(appUuid, this).thenAccept(provider -> { 47 | logger.debug("Snapshot provider created"); 48 | latch.countDown(); 49 | }); 50 | desktopConnection.getSnapshotSource().createSnapshotSourceClientAsync(appUuid).thenAccept(client -> { 51 | logger.debug("Snapshot client created"); 52 | latch.countDown(); 53 | }); 54 | 55 | latch.await(5, TimeUnit.SECONDS); 56 | 57 | assertEquals("initProviderThenCreateClient timeout", latch.getCount(), 0); 58 | } 59 | 60 | @Test 61 | public void initProviderThenCreateClientThenGetSnapshot() throws Exception { 62 | CountDownLatch latch = new CountDownLatch(2); 63 | final String appUuid = "initProviderThenCreateClientThenGetSnapshot"; 64 | desktopConnection.getSnapshotSource().initSnapshotSourceProviderAsync(appUuid, this).thenAccept(provider -> { 65 | logger.debug("Snapshot provider created"); 66 | latch.countDown(); 67 | }); 68 | 69 | desktopConnection.getSnapshotSource().createSnapshotSourceClientAsync(appUuid).thenAccept(client -> { 70 | client.getSnapshotAsync().thenAccept(snapshot -> { 71 | if (SNAPSHOT_CONTENT.toString().equals(snapshot.toString())) { 72 | latch.countDown(); 73 | } 74 | }); 75 | }); 76 | 77 | latch.await(5, TimeUnit.SECONDS); 78 | 79 | assertEquals("initProviderThenCreateClientThenGetSnapshot timeout", latch.getCount(), 0); 80 | } 81 | 82 | @Test 83 | public void initProviderThenCreateClientThenApplySnapshot() throws Exception { 84 | CountDownLatch latch = new CountDownLatch(2); 85 | final JSONObject random = new JSONObject(String.format("{value: %f}", Math.random())); 86 | final String appUuid = "initProviderThenCreateClientThenApplySnapshot"; 87 | desktopConnection.getSnapshotSource().initSnapshotSourceProviderAsync(appUuid, this).thenAccept(provider -> { 88 | latch.countDown(); 89 | }); 90 | 91 | desktopConnection.getSnapshotSource().createSnapshotSourceClientAsync(appUuid).thenAccept(client -> { 92 | client.applySnapshotAsync(random).thenAccept(ack -> { 93 | client.getSnapshotAsync().thenAccept(snapshot -> { 94 | if (random.toString().equals(snapshot.toString())) { 95 | latch.countDown(); 96 | } 97 | }); 98 | 99 | }); 100 | }); 101 | 102 | latch.await(5, TimeUnit.SECONDS); 103 | 104 | assertEquals("initProviderThenCreateClientThenGetSnapshot timeout", latch.getCount(), 0); 105 | } 106 | 107 | @Override 108 | public JSONObject getSnapshot() { 109 | if (this.randomSnapshot != null) { 110 | return this.randomSnapshot; 111 | } else { 112 | return SNAPSHOT_CONTENT; 113 | } 114 | } 115 | 116 | @Override 117 | public void applySnapshot(JSONObject snapshot) { 118 | this.randomSnapshot = snapshot; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/test/java/com/openfin/desktop/TestExample.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.util.LinkedHashMap; 6 | import java.util.concurrent.CountDownLatch; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | import org.json.JSONObject; 10 | import org.junit.Test; 11 | 12 | /** 13 | * Created by wche on 9/15/2016. 14 | */ 15 | @SuppressWarnings("unchecked") 16 | public class TestExample { 17 | 18 | private final String uuidForJavaApp = "OpenFinPOCExampleJava"; 19 | private final String uuidForHtml5 = "OpenFinPOCExample"; 20 | private DesktopConnection desktopConnection; 21 | 22 | @Test 23 | public void testOpenFin() throws Exception { 24 | CountDownLatch latch = new CountDownLatch(1); 25 | 26 | desktopConnection = new DesktopConnection(this.uuidForJavaApp); 27 | final DesktopStateListener desktopStateListener = new DesktopStateListener(){ 28 | @Override 29 | public void onReady() { 30 | // Java adapter is connected to Runtime. we can create HTML5 app now 31 | java.lang.System.out.printf("onReady"); 32 | latch.countDown(); 33 | publishMessages(); 34 | } 35 | @Override 36 | public void onClose(String error) { 37 | } 38 | 39 | @Override 40 | public void onError(String reason) { 41 | java.lang.System.out.printf(reason); 42 | } 43 | @Override 44 | public void onMessage(String message) { 45 | } 46 | @Override 47 | public void onOutgoingMessage(String message) { 48 | } 49 | }; 50 | 51 | final RuntimeConfiguration runtimeConfig = new RuntimeConfiguration(); 52 | this.populateAppJsonConfigFile(runtimeConfig); 53 | desktopConnection.connect(runtimeConfig, desktopStateListener, 60); 54 | 55 | latch.await(30, TimeUnit.SECONDS); 56 | assertEquals("onReady timed out", latch.getCount(), 0); 57 | Thread.sleep(10000); // keep Runtime running for 10 seconds 58 | desktopConnection.exit(); 59 | Thread.sleep(5000); // Give Runtime few seconds to exit 60 | } 61 | 62 | private void publishMessages() { 63 | 64 | desktopConnection.isConnected(); 65 | 66 | final JSONObject jsonMessage = new JSONObject(); 67 | final String topic = "Test Topic"; 68 | jsonMessage.put(topic, "Hello World!"); 69 | 70 | try { 71 | desktopConnection.getInterApplicationBus().publish(topic, jsonMessage); 72 | } catch (DesktopException e) { 73 | e.printStackTrace(); 74 | } 75 | 76 | } 77 | 78 | private void populateAppJsonConfigFile(RuntimeConfiguration runtimeConfig) { 79 | final LinkedHashMap startupAppMap = new LinkedHashMap<>(); 80 | startupAppMap.put("name", "OpenFin-Desktop"); 81 | startupAppMap.put("description", "OpenFin POC"); 82 | startupAppMap.put("url", "https://cdn.openfin.co/examples/junit/SimpleOpenFinApp.html"); 83 | startupAppMap.put("uuid", this.uuidForHtml5); 84 | startupAppMap.put("autoShow", true); 85 | startupAppMap.put("defaultWidth", 1280); 86 | startupAppMap.put("minWidth", 1280); 87 | startupAppMap.put("defaultHeight", 920); 88 | startupAppMap.put("minHeight", 920); 89 | startupAppMap.put("resizable", false); 90 | startupAppMap.put("maximizable", true); 91 | 92 | final LinkedHashMap runtimeMap = new LinkedHashMap<>(); 93 | runtimeMap.put("arguments", ""); 94 | runtimeMap.put("forceLatest", true); 95 | 96 | /* skip creating shortcut 97 | final LinkedHashMap shortcutMap = new LinkedHashMap<>(); 98 | shortcutMap.put("company", "TPI"); 99 | shortcutMap.put("description", "OpenFin POC"); 100 | shortcutMap.put("name", "OpenFin-Desktop"); 101 | runtimeConfig.setShortCut(new JSONObject(shortcutMap)); 102 | */ 103 | 104 | runtimeConfig.setDevToolsPort(9090); 105 | runtimeConfig.setStartupApp(new JSONObject(startupAppMap)); 106 | 107 | runtimeConfig.setRuntimeVersion("stable"); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /src/test/java/com/openfin/desktop/WindowPositionTest.java: -------------------------------------------------------------------------------- 1 | package com.openfin.desktop; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.fail; 5 | 6 | import java.util.UUID; 7 | import java.util.concurrent.CountDownLatch; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | import org.junit.AfterClass; 11 | import org.junit.BeforeClass; 12 | import org.junit.Ignore; 13 | import org.junit.Test; 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | 17 | /** 18 | * 19 | * Test to verify Runtime saves Window positions between restarts. 20 | * 21 | * This test is not included in AllTests.java 22 | * 23 | * Created by wche on 2/23/16. 24 | * 25 | */ 26 | public class WindowPositionTest { 27 | private static Logger logger = LoggerFactory.getLogger(WindowPositionTest.class.getName()); 28 | 29 | private static final String DESKTOP_UUID = WindowTest.class.getName(); 30 | private static DesktopConnection desktopConnection; 31 | 32 | private static String appUuid; 33 | private static int defaultHeight, defaultWidth, defaultTop, defaultLeft; 34 | private static boolean successRun = true; 35 | 36 | @BeforeClass 37 | public static void setup() throws Exception { 38 | logger.debug("starting"); 39 | desktopConnection = TestUtils.setupConnection(DESKTOP_UUID); 40 | 41 | // assign random bounds. Runtime adjusts bounds to try to fit windows inside the monitor, so bounds need to be within boundary of the monitor 42 | appUuid = UUID.randomUUID().toString(); 43 | defaultTop = getRandomNumber(); 44 | defaultLeft = getRandomNumber(); 45 | defaultHeight = getRandomNumber() + 38; // chromium enforces 140/38 as min height/width 46 | defaultWidth = getRandomNumber() + 140; 47 | } 48 | 49 | /** 50 | * return random int between 1 and 300 51 | * @return 52 | */ 53 | private static int getRandomNumber() { 54 | return (int) Math.round(Math.random() * 300); // 300 should be small enough to fit most monitors 55 | } 56 | 57 | @AfterClass 58 | public static void teardown() throws Exception { 59 | TestUtils.teardownDesktopConnection(desktopConnection); 60 | } 61 | 62 | @Test 63 | public void saveWindowStateWithRuntimeRestart() throws Exception { 64 | int repeat = 3; 65 | String value = java.lang.System.getProperty("com.openfin.desktop.WindowPositionTest.repeat"); 66 | if (value != null) { 67 | repeat = Integer.parseInt(value); 68 | } 69 | logger.debug(String.format("Running test %d times", repeat)); 70 | for (int i = 0; i < repeat; i++) { 71 | runAndClose(); 72 | TestUtils.teardownDesktopConnection(desktopConnection); 73 | desktopConnection = TestUtils.setupConnection(DESKTOP_UUID); 74 | } 75 | } 76 | 77 | @Test 78 | public void defaultWindowPosition() throws Exception { 79 | int repeat = 100; 80 | String value = java.lang.System.getProperty("com.openfin.desktop.WindowPositionTest.repeat"); 81 | if (value != null) { 82 | repeat = Integer.parseInt(value); 83 | } 84 | logger.debug(String.format("Running test %d times", repeat)); 85 | for (int i = 0; i < repeat; i++) { 86 | appUuid = UUID.randomUUID().toString(); 87 | defaultTop = 10; //getRandomNumber(); 88 | defaultLeft = 10; //getRandomNumber(); 89 | defaultHeight = 500; //getRandomNumber() + 38; // chromium enforces 140/38 as min height/width 90 | defaultWidth = 500; //getRandomNumber() + 140; 91 | runAndClose(); 92 | } 93 | } 94 | 95 | private void runAndClose() throws Exception { 96 | ApplicationOptions options = TestUtils.getAppOptions(appUuid, null); 97 | options.getMainWindowOptions().setDefaultHeight(defaultHeight); 98 | options.getMainWindowOptions().setDefaultWidth(defaultWidth); 99 | options.getMainWindowOptions().setDefaultTop(defaultTop); 100 | options.getMainWindowOptions().setDefaultLeft(defaultLeft); 101 | 102 | Window mainWindow = Window.wrap(options.getUUID(), options.getUUID(), desktopConnection); 103 | CountDownLatch shownLatch = new CountDownLatch(1); 104 | TestUtils.addEventListener(mainWindow, "shown", actionEvent -> { 105 | if (actionEvent.getType().equals("shown")) { 106 | shownLatch.countDown(); 107 | } 108 | }); 109 | 110 | Application application = TestUtils.runApplication(options, desktopConnection); 111 | 112 | shownLatch.await(1000, TimeUnit.SECONDS); 113 | assertEquals("shown timeout " + options.getUUID(), shownLatch.getCount(), 0); 114 | 115 | WindowBounds bounds = TestUtils.getBounds(application.getWindow()); 116 | logger.debug(String.format("default bounds %s %d %d %d %d", appUuid, defaultHeight, defaultWidth, defaultTop, defaultLeft)); 117 | logger.debug(String.format("shown bounds %d %d %d %d", bounds.getHeight(), bounds.getWidth(), bounds.getTop(), bounds.getLeft())); 118 | if (bounds.getHeight() != defaultHeight || bounds.getWidth() != defaultWidth || bounds.getTop() != defaultTop || bounds.getLeft() != defaultLeft) { 119 | successRun = false; 120 | logger.info(String.format("default bounds %s %d %d %d %d", appUuid, defaultHeight, defaultWidth, defaultTop, defaultLeft)); 121 | logger.info(String.format("shown bounds %d %d %d %d", bounds.getHeight(), bounds.getWidth(), bounds.getTop(), bounds.getLeft())); 122 | fail("Window bounds do not match saved bounds"); 123 | } 124 | 125 | TestUtils.closeApplication(application); 126 | } 127 | 128 | } -------------------------------------------------------------------------------- /webstart/JNLPExample.jnlp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JNLP Example of OpenFin Runtime 5 | OpenFin 6 | 7 | JNLP Example to start OpenFin Runtime 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /webstart/OpenFinSigner.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFWjCCBEKgAwIBAgIQI2uZSMRY8LJPVhu76nUzqjANBgkqhkiG9w0BAQUFADB7MQswCQYDVQQG 3 | EwJHQjEbMBkGA1UECBMSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQHEwdTYWxmb3JkMRowGAYD 4 | VQQKExFDT01PRE8gQ0EgTGltaXRlZDEhMB8GA1UEAxMYQ09NT0RPIENvZGUgU2lnbmluZyBDQSAy 5 | MB4XDTE0MTEyNTAwMDAwMFoXDTE1MTEyNTIzNTk1OVowgawxCzAJBgNVBAYTAlVTMQ4wDAYDVQQR 6 | DAUxMDAwNDELMAkGA1UECAwCTlkxETAPBgNVBAcMCE5ldyBZb3JrMRkwFwYDVQQJDBAyNSBCcm9h 7 | ZHdheSBGTCA5MQ4wDAYDVQQSDAUxMDAwNDEVMBMGA1UECgwMT3BlbkZpbiBJbmMuMRQwEgYDVQQL 8 | DAtPcGVuRmluIEluYzEVMBMGA1UEAwwMT3BlbkZpbiBJbmMuMIIBIjANBgkqhkiG9w0BAQEFAAOC 9 | AQ8AMIIBCgKCAQEAu2MVHBf3FVlADQYe+WfOL4KPl8jt/AX1QxI7gs8NVas81o+MUbWyYapzva0v 10 | t1XJrEhaEjErNxQpDvuq6xBKQW1X19Jn7ymIWa2jdkZ3AZotUMM7TvRXQiQ7kMKiN1fSnTm3h6r1 11 | rUYMqQatOm3aOxkzyWfby18SpaaP+tbO3hn73AJOHZ/9Cs756NFuARlSXF0/E3SoX/bv+VYcCmMQ 12 | mdc9aNjH8AsYyRnmUHNaAFTRje7nFdRLPl/8ibp/fwHh6k/5Ea46u4m1gxgnGv9Ad1RYpwe3aQHO 13 | BWoKGYlDxpaWAQNwK8ZOPS53ROrxbW7jD9bwPwdimQMwG1NyNo0UFQIDAQABo4IBpjCCAaIwHwYD 14 | VR0jBBgwFoAUHsWxLH2H2gJofCW8DAeEP7bP3vEwHQYDVR0OBBYEFDRPKElGMKV/ngWzhQS+zNPx 15 | kDSWMA4GA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMBMGA1UdJQQMMAoGCCsGAQUFBwMDMBEG 16 | CWCGSAGG+EIBAQQEAwIEEDBGBgNVHSAEPzA9MDsGDCsGAQQBsjEBAgEDAjArMCkGCCsGAQUFBwIB 17 | Fh1odHRwczovL3NlY3VyZS5jb21vZG8ubmV0L0NQUzBBBgNVHR8EOjA4MDagNKAyhjBodHRwOi8v 18 | Y3JsLmNvbW9kb2NhLmNvbS9DT01PRE9Db2RlU2lnbmluZ0NBMi5jcmwwcgYIKwYBBQUHAQEEZjBk 19 | MDwGCCsGAQUFBzAChjBodHRwOi8vY3J0LmNvbW9kb2NhLmNvbS9DT01PRE9Db2RlU2lnbmluZ0NB 20 | Mi5jcnQwJAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmNvbW9kb2NhLmNvbTAbBgNVHREEFDASgRBj 21 | aHVja0BvcGVuZmluLmNvMA0GCSqGSIb3DQEBBQUAA4IBAQAg6hmKiQEMl6PFqKKyeR5nibr2qXeG 22 | KVxBhXFY5m6xp2UY9yS17emQUOXlskqJLvGs9/VR6gsKBxwfsPOGtk7TBlT3s0nMRCFM9qOUcBU0 23 | 5nBNMG2NT1yKj/hi5AIQ/jteWcJnK92AgF7nQOUt98ABFJK8LHxiALffgklKC7qUO4AmUwtiEaXj 24 | cmG1q5AU9AXJr59ndubvk7TOhkhSWqIqvSmstrl8SD4qMnNerOf728rTsXC4W0E0MtG+jHHOkjZw 25 | 9JC5gO8wq+3PrpNepVATxkIlBFH7PaYAagOCqpgM37+DQ2BxfBeIHbs30sSBtqclMfZU33lCBc50 26 | AH0dX9Am 27 | -----END CERTIFICATE----- 28 | -------------------------------------------------------------------------------- /webstart/jna-4.1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/webstart/jna-4.1.0.jar -------------------------------------------------------------------------------- /webstart/jna-platform-4.1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/webstart/jna-platform-4.1.0.jar -------------------------------------------------------------------------------- /webstart/json-20140107.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/webstart/json-20140107.jar -------------------------------------------------------------------------------- /webstart/openfin-desktop-java-adapter-4.40.2.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/webstart/openfin-desktop-java-adapter-4.40.2.8.jar -------------------------------------------------------------------------------- /webstart/openfin-desktop-java-adapter-5.44.2.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/webstart/openfin-desktop-java-adapter-5.44.2.0.jar -------------------------------------------------------------------------------- /webstart/openfin-desktop-java-example-3.0.1.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/webstart/openfin-desktop-java-example-3.0.1.5.jar -------------------------------------------------------------------------------- /webstart/openfin-desktop-java-example-5.44.2.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openfin/java-example/1c3c4b83a129d5a2d20a99ace6c76b9033e02a52/webstart/openfin-desktop-java-example-5.44.2.0.jar --------------------------------------------------------------------------------