Package belotetime.core.dialog

Source Code of belotetime.core.dialog.InputBox

package belotetime.core.dialog;

import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

@SuppressWarnings("rawtypes")
public class InputBox extends Stage implements EventHandler {
  private Button _validateButton;
  private TextField _inputTextField;
  private static String _input;

  public static String Show(String title, String message) {
    _input = null;
    (new InputBox(title, message)).showDialog();
    return _input;
  }

  @SuppressWarnings("unchecked")
  public InputBox(String title, String message) {
    setTitle(title);
    initStyle(StageStyle.UTILITY);
    initModality(Modality.APPLICATION_MODAL);

    setResizable(false);
   
    setOnCloseRequest(new EventHandler()
    {
      @Override
      public void handle(Event event)
      {
        _input = null;
      }
    });

    Insets insets = new Insets(5, 5, 5, 5);

    BorderPane border = new BorderPane();

    Label _messageLabel = new Label();
    _messageLabel.setText(message);
    BorderPane.setMargin(_messageLabel, insets);
    border.setTop(_messageLabel);
   
    _inputTextField = new TextField();
    BorderPane.setMargin(_inputTextField, insets);
    border.setCenter(_inputTextField);

    _validateButton = new Button("OK");
    _validateButton.setOnAction(this);
    BorderPane.setMargin(_validateButton, insets);
    BorderPane.setAlignment(_validateButton, Pos.CENTER);
    border.setBottom(_validateButton);

    Scene scene = new Scene(border);
    setScene(scene);
  }

  public void showDialog() {
    sizeToScene();
    centerOnScreen();
    showAndWait();
  }

  @Override
  public void handle(Event arg0) {
    if (arg0.getSource() == _validateButton) {
      _input = _inputTextField.getText();
      hide();
    }
  }

}
TOP

Related Classes of belotetime.core.dialog.InputBox

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.