1.1 --- a/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXBrwsr.java Tue Jul 15 21:16:36 2014 +0200
1.2 +++ b/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXBrwsr.java Tue Jul 15 21:32:14 2014 +0200
1.3 @@ -57,15 +57,18 @@
1.4 import javafx.event.EventHandler;
1.5 import javafx.geometry.Insets;
1.6 import javafx.geometry.Pos;
1.7 +import javafx.scene.Group;
1.8 import javafx.scene.Scene;
1.9 import javafx.scene.control.Button;
1.10 import javafx.scene.layout.BorderPane;
1.11 +import javafx.scene.layout.HBox;
1.12 import javafx.scene.layout.VBox;
1.13 import javafx.scene.text.Text;
1.14 import javafx.scene.web.WebEvent;
1.15 import javafx.scene.web.WebView;
1.16 import javafx.stage.Modality;
1.17 import javafx.stage.Stage;
1.18 +import javafx.util.Callback;
1.19
1.20 /** This is an implementation class, to implement browser builder API. Just
1.21 * include this JAR on classpath and the browser builder API will find
1.22 @@ -158,16 +161,44 @@
1.23 box.getChildren().addAll(text, button);
1.24 dialogStage.setScene(new Scene(box));
1.25 button.setCancelButton(true);
1.26 - button.setOnAction(new EventHandler<ActionEvent>() {
1.27 - @Override
1.28 - public void handle(ActionEvent t) {
1.29 - dialogStage.close();
1.30 - }
1.31 - });
1.32 + button.setOnAction(new CloseDialogHandler(dialogStage, null));
1.33 dialogStage.centerOnScreen();
1.34 dialogStage.showAndWait();
1.35 }
1.36 });
1.37 + view.getEngine().setConfirmHandler(new Callback<String, Boolean>() {
1.38 + @Override
1.39 + public Boolean call(String question) {
1.40 + final Stage dialogStage = new Stage();
1.41 + dialogStage.initModality(Modality.WINDOW_MODAL);
1.42 + dialogStage.initOwner(stage);
1.43 + ResourceBundle r = ResourceBundle.getBundle("org/netbeans/html/boot/fx/Bundle"); // NOI18N
1.44 + dialogStage.setTitle(r.getString("ConfirmTitle")); // NOI18N
1.45 + final Button ok = new Button(r.getString("ConfirmOKButton")); // NOI18N
1.46 + final Button cancel = new Button(r.getString("ConfirmCancelButton")); // NOI18N
1.47 + final Text text = new Text(question);
1.48 + final Insets ins = new Insets(10);
1.49 + final VBox box = new VBox();
1.50 + box.setAlignment(Pos.CENTER);
1.51 + box.setSpacing(10);
1.52 + box.setPadding(ins);
1.53 + final HBox buttons = new HBox(ok, cancel);
1.54 + buttons.setAlignment(Pos.CENTER);
1.55 + buttons.setSpacing(10);
1.56 + buttons.setPadding(ins);
1.57 + box.getChildren().addAll(text, buttons);
1.58 + dialogStage.setScene(new Scene(box));
1.59 + ok.setCancelButton(false);
1.60 +
1.61 + final boolean[] res = new boolean[1];
1.62 + ok.setOnAction(new CloseDialogHandler(dialogStage, res));
1.63 + cancel.setCancelButton(true);
1.64 + cancel.setOnAction(new CloseDialogHandler(dialogStage, null));
1.65 + dialogStage.centerOnScreen();
1.66 + dialogStage.showAndWait();
1.67 + return res[0];
1.68 + }
1.69 + });
1.70 root.setCenter(view);
1.71 final Worker<Void> w = view.getEngine().getLoadWorker();
1.72 w.stateProperty().addListener(new ChangeListener<Worker.State>() {
1.73 @@ -210,4 +241,22 @@
1.74 }
1.75 }
1.76
1.77 + private static final class CloseDialogHandler implements EventHandler<ActionEvent> {
1.78 + private final Stage dialogStage;
1.79 + private final boolean[] res;
1.80 +
1.81 + public CloseDialogHandler(Stage dialogStage, boolean[] res) {
1.82 + this.dialogStage = dialogStage;
1.83 + this.res = res;
1.84 + }
1.85 +
1.86 + @Override
1.87 + public void handle(ActionEvent t) {
1.88 + dialogStage.close();
1.89 + if (res != null) {
1.90 + res[0] = true;
1.91 + }
1.92 + }
1.93 + }
1.94 +
1.95 }
2.1 --- a/boot-fx/src/main/resources/org/netbeans/html/boot/fx/Bundle.properties Tue Jul 15 21:16:36 2014 +0200
2.2 +++ b/boot-fx/src/main/resources/org/netbeans/html/boot/fx/Bundle.properties Tue Jul 15 21:32:14 2014 +0200
2.3 @@ -40,3 +40,7 @@
2.4
2.5 AlertTitle=Warning
2.6 AlertCloseButton=Close
2.7 +
2.8 +ConfirmTitle=Question
2.9 +ConfirmOKButton=OK
2.10 +ConfirmCancelButton=Cancel