Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package guifx;
- import application.controller.Controller;
- import application.model.Companion;
- import application.model.Registration;
- import javafx.geometry.HPos;
- 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.ListView;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.HBox;
- import javafx.stage.Modality;
- import javafx.stage.Stage;
- import javafx.stage.StageStyle;
- public class CreateCompanionWindow extends Stage {
- private Registration registration;
- public CreateCompanionWindow(String title, Registration registration) {
- initStyle(StageStyle.UTILITY);
- initModality(Modality.APPLICATION_MODAL);
- setResizable(false);
- System.out.println( "tjek reg11"+registration);
- this.registration = registration;
- setTitle(title);
- GridPane pane = new GridPane();
- initContent(pane);
- Scene scene = new Scene(pane);
- setScene(scene);
- }
- public CreateCompanionWindow(String title) {
- this(title, null);
- }
- //-----------------------------------------------------------------------------------------------------
- private TextField txfName, txfAddress, txfCountry, txfPhoneNumber, txfCity;
- private ListView<Companion> lvwCompanions;
- private Label lblError;
- private void initContent(GridPane pane) {
- pane.setPadding(new Insets(10));
- pane.setHgap(10);
- pane.setVgap(10);
- pane.setGridLinesVisible(false);
- // Labels oprettes
- Label lblName = new Label("Name:");
- pane.add(lblName, 0, 0);
- Label lblAddress = new Label("Address:");
- pane.add(lblAddress, 0, 2);
- Label lblCity = new Label("City:");
- pane.add(lblCity, 0, 4);
- Label lblPhoneNumber = new Label("Phone number:");
- pane.add(lblPhoneNumber, 1, 0);
- Label lblCountry = new Label("Country:");
- pane.add(lblCountry, 1, 2);
- lblError = new Label();
- pane.add(lblError, 0, 5);
- lblError.setStyle("-fx-text-fill: red");
- // Tekstfelter oprettes
- txfName = new TextField();
- pane.add(txfName, 0, 1);
- txfAddress = new TextField();
- pane.add(txfAddress, 0, 3);
- txfCountry = new TextField();
- pane.add(txfCountry, 1, 3);
- txfPhoneNumber = new TextField();
- pane.add(txfPhoneNumber, 1, 1);
- txfCity = new TextField();
- pane.add(txfCity, 0, 5);
- // Kanpper oprettes
- HBox hbxButtons = new HBox(40);
- pane.add(hbxButtons, 0, 6, 3, 1);
- hbxButtons.setPadding(new Insets(10, 0, 0, 0));
- hbxButtons.setAlignment(Pos.BASELINE_RIGHT);
- Button btnCancel = new Button("Cancel");
- hbxButtons.getChildren().add(btnCancel);
- GridPane.setHalignment(btnCancel, HPos.LEFT);
- btnCancel.setOnAction(event -> this.cancelAction());
- Button btnOk = new Button("Ok");
- hbxButtons.getChildren().add(btnOk);
- GridPane.setHalignment(btnOk, HPos.LEFT);
- btnOk.setOnAction(event -> this.okAction());
- }
- // private void initControls() {
- // if (registartion != null) {
- // txfName.setText(registartion.getName());
- // } else {
- // txfName.clear();
- // }
- // }
- //--------------------------------------------------------------------------------------------------------
- private void cancelAction() {
- this.hide();
- }
- private void okAction() {
- String name = txfName.getText().trim();
- String address = txfAddress.getText().trim();
- String country = txfCountry.getText().trim();
- String city = txfCity.getText().trim();
- String phoneNumber = txfPhoneNumber.getText().trim();
- if(name == null && address == null && country == null && city == null && phoneNumber == null) {
- showReceiptAction();
- }else {
- Controller.createCompanion(registration, name, address, country, city, phoneNumber);
- showReceiptAction();
- }
- hide();
- }
- private void showReceiptAction() {
- ReceiptWindow dia = new ReceiptWindow("Receipt", registration);
- dia.showAndWait();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement