From 6b7a6f095d4448fc21a431aa844560748e6ea291 Mon Sep 17 00:00:00 2001 From: giavaphi Date: Thu, 24 Nov 2022 23:18:14 +0100 Subject: [PATCH] dialog pane for location and area of crop --- .../CropDetailController.java | 40 +++++++++++++++++-- .../TextFieldFormularController.java | 27 +++++++++++++ .../gartenverwaltung/TextFieldFormular.fxml | 22 ++++++++++ 3 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 src/main/java/ch/zhaw/gartenverwaltung/TextFieldFormularController.java create mode 100644 src/main/resources/ch/zhaw/gartenverwaltung/TextFieldFormular.fxml diff --git a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java index 7ec8652..dd7e803 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java @@ -104,16 +104,16 @@ public class CropDetailController { * open dialog to set area */ @FXML - void setArea() { - + void setArea() throws IOException { + openTextFieldDialog("set Text Area", "Text Area", area_label.getText(), false); } /** * open dialog to set location */ @FXML - void setLocation() { - + void setLocation() throws IOException { + openTextFieldDialog("set Location", "Location", location_label.getText(), true); } /** @@ -300,4 +300,36 @@ public class CropDetailController { } } + + private void openTextFieldDialog(String title, String labelDescription, String value, boolean isLocation) throws IOException { + Dialog dialog = new Dialog<>(); + dialog.setTitle(title); + dialog.setHeaderText(title); + dialog.setResizable(false); + + DialogPane dialogPane = dialog.getDialogPane(); + + ButtonType save = new ButtonType("Save", ButtonBar.ButtonData.OK_DONE); + dialogPane.getButtonTypes().addAll(save, ButtonType.CANCEL); + + if (appLoader.loadPaneToDialog("TextFieldFormular.fxml", dialogPane) instanceof TextFieldFormularController controller) { + controller.setDescription_label(labelDescription); + controller.setValueTextArea(value); + + dialog.setResultConverter(button -> button.equals(save) ? controller.getValue() : null); + + dialog.showAndWait() + .ifPresent(string -> { + if (isLocation) { + System.out.println(string); + //ToDo method to set location + location_label.setText(string); + } else { + System.out.println(string); + //ToDo method to set area of crop in garden + area_label.setText(string); + } + }); + } + } } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/TextFieldFormularController.java b/src/main/java/ch/zhaw/gartenverwaltung/TextFieldFormularController.java new file mode 100644 index 0000000..ebbbfe2 --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/TextFieldFormularController.java @@ -0,0 +1,27 @@ +package ch.zhaw.gartenverwaltung; + +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; + +public class TextFieldFormularController { + + @FXML + private Label description_label; + + @FXML + private TextField text_area; + + + public void setDescription_label(String string) { + description_label.setText(string); + } + + public void setValueTextArea(String string) { + text_area.setText(string); + } + + public String getValue() { + return text_area.getText(); + } +} diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/TextFieldFormular.fxml b/src/main/resources/ch/zhaw/gartenverwaltung/TextFieldFormular.fxml new file mode 100644 index 0000000..2d4dfdc --- /dev/null +++ b/src/main/resources/ch/zhaw/gartenverwaltung/TextFieldFormular.fxml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + +