|
| 1 | +package com.openfin.desktop.demo; |
| 2 | + |
| 3 | +import com.openfin.desktop.*; |
| 4 | +import javafx.application.Application; |
| 5 | +import javafx.collections.ObservableList; |
| 6 | +import javafx.event.ActionEvent; |
| 7 | +import javafx.event.EventHandler; |
| 8 | +import javafx.scene.Group; |
| 9 | +import javafx.scene.Scene; |
| 10 | +import javafx.scene.control.Button; |
| 11 | +import javafx.scene.layout.AnchorPane; |
| 12 | +import javafx.stage.Stage; |
| 13 | +import org.slf4j.Logger; |
| 14 | +import org.slf4j.LoggerFactory; |
| 15 | + |
| 16 | + |
| 17 | +public class LaunchManifestDemo extends Application { |
| 18 | + |
| 19 | + private final static Logger logger = LoggerFactory.getLogger(LaunchManifestDemo.class.getName()); |
| 20 | + private final static String WINDOW_TITLE = "Launch Manifest Demo"; |
| 21 | + |
| 22 | + private DesktopConnection desktopConnectionGM; // connection to Watchlist by Giant Machines |
| 23 | + private DesktopConnection desktopConnectionSL; // connection to StockFlux by Scott Logic |
| 24 | + private Button btnGiantMachine, btnScottLogic; |
| 25 | + |
| 26 | + private String startupUuid = LaunchManifestDemo.class.getName(); |
| 27 | + private com.openfin.desktop.Application startupHtml5app; |
| 28 | + |
| 29 | + @Override |
| 30 | + public void start(Stage stage) { |
| 31 | + btnGiantMachine = new Button(); |
| 32 | + btnGiantMachine.setText("Launch Watchlist by Giant Machines"); |
| 33 | + btnGiantMachine.setLayoutX(10); |
| 34 | + btnGiantMachine.setLayoutY(10); |
| 35 | + btnGiantMachine.setOnAction(new EventHandler<ActionEvent>() { |
| 36 | + @Override |
| 37 | + public void handle(ActionEvent event) { |
| 38 | + launchGiantMachine(); |
| 39 | + } |
| 40 | + }); |
| 41 | + |
| 42 | + btnScottLogic = new Button(); |
| 43 | + btnScottLogic.setText("Launch StockFlux by Scott Logic"); |
| 44 | + btnScottLogic.setLayoutX(10); |
| 45 | + btnScottLogic.setLayoutY(50); |
| 46 | + btnScottLogic.setOnAction(new EventHandler<ActionEvent>() { |
| 47 | + @Override |
| 48 | + public void handle(ActionEvent event) { |
| 49 | + launchScottLogic(); |
| 50 | + } |
| 51 | + }); |
| 52 | + |
| 53 | + AnchorPane anchorPane = new AnchorPane(); |
| 54 | + anchorPane.getChildren().add(btnGiantMachine); |
| 55 | + anchorPane.getChildren().add(btnScottLogic); |
| 56 | + |
| 57 | + //Creating a Group object |
| 58 | + Group root = new Group(); |
| 59 | + |
| 60 | + //Retrieving the observable list object |
| 61 | + ObservableList list = root.getChildren(); |
| 62 | + |
| 63 | + //Creating a scene object |
| 64 | + Scene scene = new Scene(anchorPane, 800, 800); |
| 65 | + |
| 66 | + //Setting title to the Stage |
| 67 | + stage.setTitle(WINDOW_TITLE); |
| 68 | + |
| 69 | + //Adding scene to the stage |
| 70 | + stage.setScene(scene); |
| 71 | + |
| 72 | + //Displaying the contents of the stage |
| 73 | + stage.show(); |
| 74 | + |
| 75 | + } |
| 76 | + |
| 77 | + private void launchGiantMachine() { |
| 78 | + if (desktopConnectionGM == null) { |
| 79 | + RuntimeConfiguration cfg = new RuntimeConfiguration(); |
| 80 | + cfg.setManifestLocation("https://openfin.giantmachines.com/public/app.json"); |
| 81 | + try { |
| 82 | + desktopConnectionGM = new DesktopConnection(startupUuid); |
| 83 | + desktopConnectionGM.connect(cfg, new DesktopStateListener() { |
| 84 | + @Override |
| 85 | + public void onReady() { |
| 86 | + logger.info("Connected to OpenFin Runtime hosting Watchlist by Giant Machines"); |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + public void onClose(String error) { |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + public void onError(String reason) { |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public void onMessage(String message) { |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + public void onOutgoingMessage(String message) { |
| 103 | + } |
| 104 | + }, 60); |
| 105 | + } catch (Exception e) { |
| 106 | + e.printStackTrace(); |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + private void launchScottLogic() { |
| 112 | + if (desktopConnectionSL == null) { |
| 113 | + RuntimeConfiguration cfg = new RuntimeConfiguration(); |
| 114 | + cfg.setManifestLocation("http://scottlogic.github.io/StockFlux/master/app.json"); |
| 115 | + try { |
| 116 | + desktopConnectionSL = new DesktopConnection(startupUuid); |
| 117 | + desktopConnectionSL.connect(cfg, new DesktopStateListener() { |
| 118 | + @Override |
| 119 | + public void onReady() { |
| 120 | + logger.info("Connected to OpenFin Runtime hosting StockFlux by Scott Logic"); |
| 121 | + } |
| 122 | + |
| 123 | + @Override |
| 124 | + public void onClose(String error) { |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public void onError(String reason) { |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + public void onMessage(String message) { |
| 133 | + } |
| 134 | + |
| 135 | + @Override |
| 136 | + public void onOutgoingMessage(String message) { |
| 137 | + } |
| 138 | + }, 60); |
| 139 | + } catch (Exception e) { |
| 140 | + e.printStackTrace(); |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + public static void main(String args[]) { |
| 146 | + launch(args); |
| 147 | + } |
| 148 | + |
| 149 | + |
| 150 | + |
| 151 | +} |
0 commit comments