1.1 --- a/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXBrwsr.java Fri Oct 02 08:57:14 2015 +0200
1.2 +++ b/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXBrwsr.java Sun Oct 11 07:24:32 2015 +0200
1.3 @@ -92,11 +92,22 @@
1.4 Executors.newFixedThreadPool(1).submit(new Runnable() {
1.5 @Override
1.6 public void run() {
1.7 - try {
1.8 - FXBrwsr.launch(FXBrwsr.class, callee);
1.9 - } catch (Throwable ex) {
1.10 - ex.printStackTrace();
1.11 - } finally {
1.12 + if (!Platform.isFxApplicationThread()) {
1.13 + try {
1.14 + Platform.runLater(this);
1.15 + } catch (IllegalStateException ex) {
1.16 + try {
1.17 + FXBrwsr.launch(FXBrwsr.class, callee);
1.18 + } catch (Throwable t) {
1.19 + t.printStackTrace();
1.20 + } finally {
1.21 + FINISHED.countDown();
1.22 + }
1.23 + }
1.24 + } else {
1.25 + FXBrwsr brwsr = new FXBrwsr();
1.26 + brwsr.start(new Stage(), callee);
1.27 + INSTANCE = brwsr;
1.28 FINISHED.countDown();
1.29 }
1.30 }
1.31 @@ -144,8 +155,12 @@
1.32
1.33 @Override
1.34 public void start(Stage primaryStage) throws Exception {
1.35 + start(primaryStage, this.getParameters().getRaw().get(0));
1.36 + }
1.37 +
1.38 + final void start(Stage primaryStage, String callee) {
1.39 BorderPane r = new BorderPane();
1.40 - Object[] arr = findInitialSize(this.getParameters().getRaw().get(0));
1.41 + Object[] arr = findInitialSize(callee);
1.42 Scene scene = new Scene(r, (Double)arr[2], (Double)arr[3]);
1.43 primaryStage.setScene(scene);
1.44 this.root = r;
1.45 @@ -220,99 +235,22 @@
1.46 private WebView newView(final URL url, final FXPresenter onLoad) {
1.47 final WebView view = new WebView();
1.48 view.setContextMenuEnabled(false);
1.49 - view.getEngine().setOnAlert(new EventHandler<WebEvent<String>>() {
1.50 - @Override
1.51 - public void handle(WebEvent<String> t) {
1.52 - final Stage dialogStage = new Stage();
1.53 - dialogStage.initModality(Modality.WINDOW_MODAL);
1.54 - dialogStage.initOwner(stage);
1.55 - ResourceBundle r = ResourceBundle.getBundle("org/netbeans/html/boot/fx/Bundle"); // NOI18N
1.56 - dialogStage.setTitle(r.getString("AlertTitle")); // NOI18N
1.57 - final Button button = new Button(r.getString("AlertCloseButton")); // NOI18N
1.58 - final Text text = new Text(t.getData());
1.59 - VBox box = new VBox();
1.60 - box.setAlignment(Pos.CENTER);
1.61 - box.setSpacing(10);
1.62 - box.setPadding(new Insets(10));
1.63 - box.getChildren().addAll(text, button);
1.64 - dialogStage.setScene(new Scene(box));
1.65 - button.setCancelButton(true);
1.66 - button.setOnAction(new CloseDialogHandler(dialogStage, null));
1.67 - dialogStage.centerOnScreen();
1.68 - dialogStage.showAndWait();
1.69 - }
1.70 - });
1.71 - view.getEngine().setConfirmHandler(new Callback<String, Boolean>() {
1.72 - @Override
1.73 - public Boolean call(String question) {
1.74 - final Stage dialogStage = new Stage();
1.75 - dialogStage.initModality(Modality.WINDOW_MODAL);
1.76 - dialogStage.initOwner(stage);
1.77 - ResourceBundle r = ResourceBundle.getBundle("org/netbeans/html/boot/fx/Bundle"); // NOI18N
1.78 - dialogStage.setTitle(r.getString("ConfirmTitle")); // NOI18N
1.79 - final Button ok = new Button(r.getString("ConfirmOKButton")); // NOI18N
1.80 - final Button cancel = new Button(r.getString("ConfirmCancelButton")); // NOI18N
1.81 - final Text text = new Text(question);
1.82 - final Insets ins = new Insets(10);
1.83 - final VBox box = new VBox();
1.84 - box.setAlignment(Pos.CENTER);
1.85 - box.setSpacing(10);
1.86 - box.setPadding(ins);
1.87 - final HBox buttons = new HBox(10);
1.88 - buttons.getChildren().addAll(ok, cancel);
1.89 - buttons.setAlignment(Pos.CENTER);
1.90 - buttons.setPadding(ins);
1.91 - box.getChildren().addAll(text, buttons);
1.92 - dialogStage.setScene(new Scene(box));
1.93 - ok.setCancelButton(false);
1.94 + Stage newStage;
1.95 + BorderPane bp;
1.96 + if (root == null) {
1.97 + newStage = new Stage();
1.98 + newStage.initOwner(stage);
1.99 + bp = new BorderPane();
1.100 + newStage.setScene(new Scene(bp));
1.101 + newStage.show();
1.102 + } else {
1.103 + bp = root;
1.104 + newStage = stage;
1.105 + root = null;
1.106 + }
1.107
1.108 - final boolean[] res = new boolean[1];
1.109 - ok.setOnAction(new CloseDialogHandler(dialogStage, res));
1.110 - cancel.setCancelButton(true);
1.111 - cancel.setOnAction(new CloseDialogHandler(dialogStage, null));
1.112 - dialogStage.centerOnScreen();
1.113 - dialogStage.showAndWait();
1.114 - return res[0];
1.115 - }
1.116 - });
1.117 - view.getEngine().setPromptHandler(new Callback<PromptData, String>() {
1.118 - @Override
1.119 - public String call(PromptData prompt) {
1.120 - final Stage dialogStage = new Stage();
1.121 - dialogStage.initModality(Modality.WINDOW_MODAL);
1.122 - dialogStage.initOwner(stage);
1.123 - ResourceBundle r = ResourceBundle.getBundle("org/netbeans/html/boot/fx/Bundle"); // NOI18N
1.124 - dialogStage.setTitle(r.getString("PromptTitle")); // NOI18N
1.125 - final Button ok = new Button(r.getString("PromptOKButton")); // NOI18N
1.126 - final Button cancel = new Button(r.getString("PromptCancelButton")); // NOI18N
1.127 - final Text text = new Text(prompt.getMessage());
1.128 - final TextField line = new TextField();
1.129 - if (prompt.getDefaultValue() != null) {
1.130 - line.setText(prompt.getDefaultValue());
1.131 - }
1.132 - final Insets ins = new Insets(10);
1.133 - final VBox box = new VBox();
1.134 - box.setAlignment(Pos.CENTER);
1.135 - box.setSpacing(10);
1.136 - box.setPadding(ins);
1.137 - final HBox buttons = new HBox(10);
1.138 - buttons.getChildren().addAll(ok, cancel);
1.139 - buttons.setAlignment(Pos.CENTER);
1.140 - buttons.setPadding(ins);
1.141 - box.getChildren().addAll(text, line, buttons);
1.142 - dialogStage.setScene(new Scene(box));
1.143 - ok.setCancelButton(false);
1.144 -
1.145 - final boolean[] res = new boolean[1];
1.146 - ok.setOnAction(new CloseDialogHandler(dialogStage, res));
1.147 - cancel.setCancelButton(true);
1.148 - cancel.setOnAction(new CloseDialogHandler(dialogStage, null));
1.149 - dialogStage.centerOnScreen();
1.150 - dialogStage.showAndWait();
1.151 - return res[0] ? line.getText() : null;
1.152 - }
1.153 - });
1.154 - root.setCenter(view);
1.155 + attachHandlers(view, newStage);
1.156 + bp.setCenter(view);
1.157 final Worker<Void> w = view.getEngine().getLoadWorker();
1.158 w.stateProperty().addListener(new ChangeListener<Worker.State>() {
1.159 private String previous;
1.160 @@ -362,6 +300,101 @@
1.161 return view;
1.162 }
1.163
1.164 + private static void attachHandlers(final WebView view, final Stage owner) {
1.165 + view.getEngine().setOnAlert(new EventHandler<WebEvent<String>>() {
1.166 + @Override
1.167 + public void handle(WebEvent<String> t) {
1.168 + final Stage dialogStage = new Stage();
1.169 + dialogStage.initModality(Modality.WINDOW_MODAL);
1.170 + dialogStage.initOwner(owner);
1.171 + ResourceBundle r = ResourceBundle.getBundle("org/netbeans/html/boot/fx/Bundle"); // NOI18N
1.172 + dialogStage.setTitle(r.getString("AlertTitle")); // NOI18N
1.173 + final Button button = new Button(r.getString("AlertCloseButton")); // NOI18N
1.174 + final Text text = new Text(t.getData());
1.175 + VBox box = new VBox();
1.176 + box.setAlignment(Pos.CENTER);
1.177 + box.setSpacing(10);
1.178 + box.setPadding(new Insets(10));
1.179 + box.getChildren().addAll(text, button);
1.180 + dialogStage.setScene(new Scene(box));
1.181 + button.setCancelButton(true);
1.182 + button.setOnAction(new CloseDialogHandler(dialogStage, null));
1.183 + dialogStage.centerOnScreen();
1.184 + dialogStage.showAndWait();
1.185 + }
1.186 + });
1.187 + view.getEngine().setConfirmHandler(new Callback<String, Boolean>() {
1.188 + @Override
1.189 + public Boolean call(String question) {
1.190 + final Stage dialogStage = new Stage();
1.191 + dialogStage.initModality(Modality.WINDOW_MODAL);
1.192 + dialogStage.initOwner(owner);
1.193 + ResourceBundle r = ResourceBundle.getBundle("org/netbeans/html/boot/fx/Bundle"); // NOI18N
1.194 + dialogStage.setTitle(r.getString("ConfirmTitle")); // NOI18N
1.195 + final Button ok = new Button(r.getString("ConfirmOKButton")); // NOI18N
1.196 + final Button cancel = new Button(r.getString("ConfirmCancelButton")); // NOI18N
1.197 + final Text text = new Text(question);
1.198 + final Insets ins = new Insets(10);
1.199 + final VBox box = new VBox();
1.200 + box.setAlignment(Pos.CENTER);
1.201 + box.setSpacing(10);
1.202 + box.setPadding(ins);
1.203 + final HBox buttons = new HBox(10);
1.204 + buttons.getChildren().addAll(ok, cancel);
1.205 + buttons.setAlignment(Pos.CENTER);
1.206 + buttons.setPadding(ins);
1.207 + box.getChildren().addAll(text, buttons);
1.208 + dialogStage.setScene(new Scene(box));
1.209 + ok.setCancelButton(false);
1.210 +
1.211 + final boolean[] res = new boolean[1];
1.212 + ok.setOnAction(new CloseDialogHandler(dialogStage, res));
1.213 + cancel.setCancelButton(true);
1.214 + cancel.setOnAction(new CloseDialogHandler(dialogStage, null));
1.215 + dialogStage.centerOnScreen();
1.216 + dialogStage.showAndWait();
1.217 + return res[0];
1.218 + }
1.219 + });
1.220 + view.getEngine().setPromptHandler(new Callback<PromptData, String>() {
1.221 + @Override
1.222 + public String call(PromptData prompt) {
1.223 + final Stage dialogStage = new Stage();
1.224 + dialogStage.initModality(Modality.WINDOW_MODAL);
1.225 + dialogStage.initOwner(owner);
1.226 + ResourceBundle r = ResourceBundle.getBundle("org/netbeans/html/boot/fx/Bundle"); // NOI18N
1.227 + dialogStage.setTitle(r.getString("PromptTitle")); // NOI18N
1.228 + final Button ok = new Button(r.getString("PromptOKButton")); // NOI18N
1.229 + final Button cancel = new Button(r.getString("PromptCancelButton")); // NOI18N
1.230 + final Text text = new Text(prompt.getMessage());
1.231 + final TextField line = new TextField();
1.232 + if (prompt.getDefaultValue() != null) {
1.233 + line.setText(prompt.getDefaultValue());
1.234 + }
1.235 + final Insets ins = new Insets(10);
1.236 + final VBox box = new VBox();
1.237 + box.setAlignment(Pos.CENTER);
1.238 + box.setSpacing(10);
1.239 + box.setPadding(ins);
1.240 + final HBox buttons = new HBox(10);
1.241 + buttons.getChildren().addAll(ok, cancel);
1.242 + buttons.setAlignment(Pos.CENTER);
1.243 + buttons.setPadding(ins);
1.244 + box.getChildren().addAll(text, line, buttons);
1.245 + dialogStage.setScene(new Scene(box));
1.246 + ok.setCancelButton(false);
1.247 +
1.248 + final boolean[] res = new boolean[1];
1.249 + ok.setOnAction(new CloseDialogHandler(dialogStage, res));
1.250 + cancel.setCancelButton(true);
1.251 + cancel.setOnAction(new CloseDialogHandler(dialogStage, null));
1.252 + dialogStage.centerOnScreen();
1.253 + dialogStage.showAndWait();
1.254 + return res[0] ? line.getText() : null;
1.255 + }
1.256 + });
1.257 + }
1.258 +
1.259 static void waitFinished() {
1.260 for (;;) {
1.261 try {