package greenfoot.guifx;

import bluej.utility.javafx.FXPlatformConsumer;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import threadchecker.OnThread;
import threadchecker.Tag;


| This is the JavaFX-based Greenfoot.ask GUI which is shown in the IDE | when Greenfoot.ask is called. Not to be confused with AskPanel, which | is the Swing version shown when running as a standalone application. | @OnThread(Tag.FXPlatform) public class AskPaneFX extends BorderPane{ private final Text promptText; private final TextField textField; private FXPlatformConsumer<String> withAnswer; public AskPaneFX() { promptText = new Text(); textField = new TextField(); textField.setOnAction(e -> enter()); Button enterButton = new Button("OK"); enterButton.setOnAction(e -> enter()); TextFlow promptTextFlow = new TextFlow(promptText); promptTextFlow.setPadding(new Insets(0,10,10,10)); BorderPane borderPane = new BorderPane(textField, promptTextFlow, enterButton, null, null); borderPane.getStyleClass().add("ask-pane"); setBottom(borderPane); setVisible(false); } private void enter() { if (withAnswer != null) { withAnswer.accept(textField.getText()); withAnswer = null; } }
| Focuses the text field in the pane | public void focusTextEntry() { textField.requestFocus(); }
| Sets the text above the text field (usually a question to the user) | public void setPrompt(String prompt) { promptText.setText(prompt); }
| Sets the handler for the answer, once the user has input it and pressed enter/clicked OK. | public void setWithAnswer(FXPlatformConsumer<String> withAnswer) { this.withAnswer = withAnswer; } }
top, use, map, class AskPaneFX

.   AskPaneFX
.   enter
.   focusTextEntry
.   setPrompt
.   setWithAnswer




84 neLoCode + 6 LoComm