55import com .openfin .desktop .Window ;
66import com .openfin .desktop .win32 .ExternalWindowObserver ;
77import info .clearthought .layout .TableLayout ;
8- import org .json .JSONObject ;
98
109import javax .swing .*;
1110import java .awt .*;
@@ -33,17 +32,14 @@ public class OpenFinDockingDemo extends JPanel implements ActionListener, Window
3332 protected String javaWindowName = "Java Dock Window" ;
3433 protected String appUuid = "JavaDocking" ;
3534 protected String startupUuid = "OpenFinHelloWorld" ;
36- protected String desktopOption ;
3735
38- protected DesktopConnection controller ;
36+ protected DesktopConnection desktopConnection ;
3937
4038 protected JTextArea status ;
4139
42- public OpenFinDockingDemo (final String desktopOption , final String startupUuid ) {
43- this .startupUuid = startupUuid ;
44- this .desktopOption = desktopOption ;
40+ public OpenFinDockingDemo () {
4541 try {
46- this .controller = new DesktopConnection (appUuid , "localhost" , 9696 );
42+ this .desktopConnection = new DesktopConnection (appUuid );
4743 } catch (DesktopException desktopError ) {
4844 desktopError .printStackTrace ();
4945 }
@@ -181,9 +177,9 @@ public void run() {
181177
182178
183179 private void closeDesktop () {
184- if (controller != null && controller .isConnected ()) {
180+ if (desktopConnection != null && desktopConnection .isConnected ()) {
185181 try {
186- new System (controller ).exit ();
182+ new System (desktopConnection ).exit ();
187183 } catch (Exception e ) {
188184 e .printStackTrace ();
189185 }
@@ -207,14 +203,14 @@ public void run() {
207203 private void dockToStartupApp () {
208204 try {
209205 createNotification ("Docking Java and HTML5" );
210- externalWindowObserver = new ExternalWindowObserver (controller .getPort (), startupUuid , javaWindowName , jFrame ,
206+ externalWindowObserver = new ExternalWindowObserver (desktopConnection .getPort (), startupUuid , javaWindowName , jFrame ,
211207 new AckListener () {
212208 @ Override
213209 public void onSuccess (Ack ack ) {
214210 if (ack .isSuccessful ()) {
215211 try {
216- Window w = Window .wrap (startupUuid , javaWindowName , controller );
217- w .joinGroup (Window .wrap (startupUuid , startupUuid , controller ));
212+ Window w = Window .wrap (startupUuid , javaWindowName , desktopConnection );
213+ w .joinGroup (Window .wrap (startupUuid , startupUuid , desktopConnection ));
218214 dock .setEnabled (false );
219215 undock .setEnabled (true );
220216 } catch (Exception e ) {
@@ -265,13 +261,13 @@ public void onMessage(Ack ack) {
265261 public void onShow (Ack ack ) {
266262 java .lang .System .out .println ("notification onShow" );
267263 }
268- }, this .controller , null );
264+ }, this .desktopConnection , null );
269265 }
270266
271267 private void undockFromStartupApp () {
272268 try {
273269 createNotification ("Undocking Java and HTML5" );
274- Window w = Window .wrap (startupUuid , javaWindowName , controller );
270+ Window w = Window .wrap (startupUuid , javaWindowName , desktopConnection );
275271 w .leaveGroup ();
276272 externalWindowObserver .dispose ();
277273 } catch (Exception e ) {
@@ -288,6 +284,7 @@ private void runStartAction() {
288284 public void onReady () {
289285 updateMessagePanel ("Connection authorized." );
290286 setMainButtonsEnabled (true );
287+ launchHelloOpenFin ();
291288 }
292289
293290 @ Override
@@ -306,7 +303,7 @@ public void onOutgoingMessage(String message) {
306303 }
307304
308305 };
309- controller . launchAndConnect ( null , desktopOption , listener , 10000 );
306+ desktopConnection . connectToVersion ( "stable" , listener , 10000 );
310307
311308 } catch (Exception e ) {
312309 e .printStackTrace ();
@@ -335,14 +332,44 @@ private void setMainButtonsEnabled(boolean enabled) {
335332 private void setAppButtonsEnabled (boolean enabled ) {
336333 }
337334
335+ private void launchHelloOpenFin () {
336+ ApplicationOptions options = new ApplicationOptions (startupUuid , startupUuid , "http://demoappdirectory.openf.in/desktop/config/apps/OpenFin/HelloOpenFin/index.html" );
337+ options .setApplicationIcon ("http://demoappdirectory.openf.in/desktop/config/apps/OpenFin/HelloOpenFin/img/openfin.ico" );
338+
339+ WindowOptions mainWindowOptions = new WindowOptions ();
340+ mainWindowOptions .setAutoShow (false );
341+ mainWindowOptions .setDefaultHeight (525 );
342+ mainWindowOptions .setDefaultLeft (10 );
343+ mainWindowOptions .setDefaultTop (50 );
344+ mainWindowOptions .setDefaultWidth (395 );
345+ mainWindowOptions .setResizable (false );
346+ mainWindowOptions .setFrame (false );
347+ mainWindowOptions .setShowTaskbarIcon (true );
348+ options .setMainWindowOptions (mainWindowOptions );
349+
350+ Application app = new Application (options , desktopConnection , new AckListener () {
351+ @ Override
352+ public void onSuccess (Ack ack ) {
353+ Application application = (Application ) ack .getSource ();
354+ try {
355+ application .run ();
356+ } catch (Exception e ) {
357+ e .printStackTrace ();
358+ }
359+ }
360+ @ Override
361+ public void onError (Ack ack ) {
362+ }
363+ });
364+ }
338365
339- private static void createAndShowGUI (final String desktopOption , final String startupUuid ) {
366+ private static void createAndShowGUI () {
340367 //Create and set up the window.
341368 jFrame = new JFrame ("Java Docking Demo" );
342369 jFrame .setDefaultCloseOperation (JFrame .HIDE_ON_CLOSE );
343370
344371 //Create and set up the content pane.
345- OpenFinDockingDemo newContentPane = new OpenFinDockingDemo (desktopOption , startupUuid );
372+ OpenFinDockingDemo newContentPane = new OpenFinDockingDemo ();
346373 newContentPane .setOpaque (true ); //content panes must be opaque
347374 jFrame .setContentPane (newContentPane );
348375 jFrame .addWindowListener (newContentPane );
@@ -355,26 +382,15 @@ private static void createAndShowGUI(final String desktopOption, final String st
355382 jFrame .setVisible (true );
356383 }
357384
385+
358386 /**
359- * To start OpenFin Desktop and Connect, pass full path of OpenFin with*
360- * -DOpenFinOption=--config=\"RemoteConfigUrl\"
361- *
362- * Set UUID of startup HTML5 app to dock to
363- * -DStartupUUID="550e8400-e29b-41d4-a716-4466333333000"
364387 *
365388 * @param args
366389 */
367390 public static void main (String [] args ) {
368- final String desktop_option = java .lang .System .getProperty ("OpenFinOption" );
369- final String startupUUID ;
370- if (java .lang .System .getProperty ("StartupUUID" ) != null ) {
371- startupUUID = java .lang .System .getProperty ("StartupUUID" );
372- } else {
373- startupUUID = "OpenFinHelloWorld" ;
374- }
375391 javax .swing .SwingUtilities .invokeLater (new Runnable () {
376392 public void run () {
377- createAndShowGUI (desktop_option , startupUUID );
393+ createAndShowGUI ();
378394 }
379395 });
380396 }
0 commit comments