dialog pane for location and area of crop
This commit is contained in:
parent
b0369e3174
commit
6b7a6f095d
|
@ -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<String> 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
|
||||
|
||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="64.0" prefWidth="298.0" xmlns="http://javafx.com/javafx/1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.TextFieldFormularController">
|
||||
<children>
|
||||
<HBox alignment="CENTER" layoutX="153.0" layoutY="33.0" prefHeight="100.0" prefWidth="200.0" spacing="10.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<children>
|
||||
<Label fx:id="description_label" maxWidth="1.7976931348623157E308" text="Label" HBox.hgrow="ALWAYS" />
|
||||
<TextField fx:id="text_area" HBox.hgrow="NEVER" />
|
||||
</children>
|
||||
<padding>
|
||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||
</padding>
|
||||
</HBox>
|
||||
</children>
|
||||
</AnchorPane>
|
Loading…
Reference in New Issue