Dialog to handle input of text invoked via window.prompt
authorJaroslav Tulach <jtulach@netbeans.org>
Tue, 15 Jul 2014 21:45:23 +0200
changeset 73339d767857334
parent 732 f6c0850b49b9
child 734 a1b7b481fa42
Dialog to handle input of text invoked via window.prompt
boot-fx/src/main/java/org/netbeans/html/boot/fx/FXBrwsr.java
boot-fx/src/main/resources/org/netbeans/html/boot/fx/Bundle.properties
     1.1 --- a/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXBrwsr.java	Tue Jul 15 21:32:14 2014 +0200
     1.2 +++ b/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXBrwsr.java	Tue Jul 15 21:45:23 2014 +0200
     1.3 @@ -60,10 +60,13 @@
     1.4  import javafx.scene.Group;
     1.5  import javafx.scene.Scene;
     1.6  import javafx.scene.control.Button;
     1.7 +import javafx.scene.control.TextField;
     1.8 +import javafx.scene.control.TextInputControl;
     1.9  import javafx.scene.layout.BorderPane;
    1.10  import javafx.scene.layout.HBox;
    1.11  import javafx.scene.layout.VBox;
    1.12  import javafx.scene.text.Text;
    1.13 +import javafx.scene.web.PromptData;
    1.14  import javafx.scene.web.WebEvent;
    1.15  import javafx.scene.web.WebView;
    1.16  import javafx.stage.Modality;
    1.17 @@ -199,6 +202,40 @@
    1.18                  return res[0];
    1.19              }
    1.20          });
    1.21 +        view.getEngine().setPromptHandler(new Callback<PromptData, String>() {
    1.22 +            @Override
    1.23 +            public String call(PromptData prompt) {
    1.24 +                final Stage dialogStage = new Stage();
    1.25 +                dialogStage.initModality(Modality.WINDOW_MODAL);
    1.26 +                dialogStage.initOwner(stage);
    1.27 +                ResourceBundle r = ResourceBundle.getBundle("org/netbeans/html/boot/fx/Bundle"); // NOI18N
    1.28 +                dialogStage.setTitle(r.getString("PromptTitle")); // NOI18N
    1.29 +                final Button ok = new Button(r.getString("PromptOKButton")); // NOI18N
    1.30 +                final Button cancel = new Button(r.getString("PromptCancelButton")); // NOI18N
    1.31 +                final Text text = new Text(prompt.getMessage());
    1.32 +                final TextField line = new TextField();
    1.33 +                final Insets ins = new Insets(10);
    1.34 +                final VBox box = new VBox();
    1.35 +                box.setAlignment(Pos.CENTER);
    1.36 +                box.setSpacing(10);
    1.37 +                box.setPadding(ins);
    1.38 +                final HBox buttons = new HBox(ok, cancel);
    1.39 +                buttons.setAlignment(Pos.CENTER);
    1.40 +                buttons.setSpacing(10);
    1.41 +                buttons.setPadding(ins);
    1.42 +                box.getChildren().addAll(text, line, buttons);
    1.43 +                dialogStage.setScene(new Scene(box));
    1.44 +                ok.setCancelButton(false);
    1.45 +                
    1.46 +                final boolean[] res = new boolean[1];
    1.47 +                ok.setOnAction(new CloseDialogHandler(dialogStage, res));
    1.48 +                cancel.setCancelButton(true);
    1.49 +                cancel.setOnAction(new CloseDialogHandler(dialogStage, null));
    1.50 +                dialogStage.centerOnScreen();
    1.51 +                dialogStage.showAndWait();
    1.52 +                return res[0] ? line.getText() : null;
    1.53 +            }
    1.54 +        });
    1.55          root.setCenter(view);
    1.56          final Worker<Void> w = view.getEngine().getLoadWorker();
    1.57          w.stateProperty().addListener(new ChangeListener<Worker.State>() {
     2.1 --- a/boot-fx/src/main/resources/org/netbeans/html/boot/fx/Bundle.properties	Tue Jul 15 21:32:14 2014 +0200
     2.2 +++ b/boot-fx/src/main/resources/org/netbeans/html/boot/fx/Bundle.properties	Tue Jul 15 21:45:23 2014 +0200
     2.3 @@ -44,3 +44,7 @@
     2.4  ConfirmTitle=Question
     2.5  ConfirmOKButton=OK
     2.6  ConfirmCancelButton=Cancel
     2.7 +
     2.8 +PromptTitle=Question
     2.9 +PromptOKButton=OK
    2.10 +PromptCancelButton=Cancel