add: createFood

This commit is contained in:
Johannes Kantz 2023-02-01 07:21:59 +01:00
parent 5ee0288736
commit f71aba3505
2 changed files with 171 additions and 95 deletions

View File

@ -0,0 +1,71 @@
package com.bib.essensbestellungsverwaltung;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CreateFoodController {
@FXML
public TextField name;
@FXML
public TextArea description;
@FXML
public RadioButton isHauptgerichtRadio;
@FXML
public RadioButton isDessertRadio;
@FXML
public RadioButton isVegetarischRadio;
@FXML
public RadioButton isVeganRadio;
@FXML
public RadioButton isFleischRadio;
@FXML
public TextArea allergienTextBox;
@FXML
public Text responseText;
@FXML
public void onAbbrechen(ActionEvent actionEvent) {
clearInputs();
}
@FXML
public void onHinzufügen(ActionEvent actionEvent) {
String gerichtName = name.getText();
String beschreibung = description.getText();
if(!isHauptgerichtRadio.isSelected() && !isDessertRadio.isSelected()){
// art auswähelen
}
boolean isNachtisch = !isHauptgerichtRadio.isSelected();
if(!isVegetarischRadio.isSelected() && !isVeganRadio.isSelected() && isFleischRadio.isSelected()){
// Typ auswählen
}
int ft = isVeganRadio.isSelected() ? 1 : isVeganRadio.isSelected() ? 2 : 3;
FoodType foodType = new FoodType(ft, "Vegan");
List<Allergy> allergies = new ArrayList<>();
// TODO: allergien hinzufügen
long id = FoodMgr.createFood(new Food(gerichtName, beschreibung, isNachtisch, foodType, allergies));
System.out.println("Food created with id: " + id);
responseText.setText("New Food Created");
clearInputs();
}
private void clearInputs(){
name.setText("");
description.setText("");
isHauptgerichtRadio.setSelected(false);
isDessertRadio.setSelected(false);
isVeganRadio.setSelected(false);
isVegetarischRadio.setSelected(false);
isFleischRadio.setSelected(false);
allergienTextBox.setText("");
}
}

View File

@ -1,102 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.*?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.*?>
<?import javafx.scene.control.Label?> <?import javafx.scene.layout.*?>
<?import javafx.scene.control.RadioButton?> <?import javafx.scene.text.*?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="521.0" prefWidth="731.0" stylesheets="@createFood.css" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1"> <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="731.0" stylesheets="@createFood.css" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.bib.essensbestellungsverwaltung.CreateFoodController">
<children> <children>
<Label alignment="CENTER" layoutX="234.0" layoutY="29.0" prefHeight="44.0" prefWidth="237.0" text="Gericht hinzufügen"> <Label alignment="CENTER" layoutX="247.0" layoutY="29.0" prefHeight="44.0" prefWidth="237.0" text="Gericht hinzufügen">
<font> <font>
<Font size="18.0" /> <Font size="18.0" />
</font> </font>
</Label> </Label>
<VBox layoutX="112.0" layoutY="73.0" prefHeight="389.0" prefWidth="459.0"> <VBox layoutX="136.0" layoutY="73.0" prefHeight="388.0" prefWidth="459.0">
<children> <children>
<HBox prefHeight="75.0" prefWidth="459.0"> <HBox prefHeight="75.0" prefWidth="459.0">
<children> <children>
<Label prefHeight="33.0" prefWidth="121.0" text="Name des Gerichts" /> <Label prefHeight="33.0" prefWidth="121.0" text="Name des Gerichts" />
<TextField prefHeight="25.0" prefWidth="290.0"> <TextField fx:id="name" prefHeight="25.0" prefWidth="290.0">
<HBox.margin> <HBox.margin>
<Insets top="5.0" />
</HBox.margin>
</TextField>
</children>
</HBox>
<HBox prefHeight="75.0" prefWidth="459.0">
<children>
<Label prefHeight="33.0" prefWidth="121.0" text="Beschreibung" />
<TextArea fx:id="description" prefHeight="75.0" prefWidth="290.0" />
</children>
<padding>
<Insets top="5.0" /> <Insets top="5.0" />
</HBox.margin> </padding>
</TextField> </HBox>
</children> <HBox prefHeight="75.0" prefWidth="459.0">
</HBox> <children>
<HBox prefHeight="75.0" prefWidth="459.0"> <Label text="Art des Gerichts">
<children> <HBox.margin>
<Label prefHeight="33.0" prefWidth="121.0" text="Beschreibung" /> <Insets top="20.0" />
<TextArea prefHeight="75.0" prefWidth="290.0" /> </HBox.margin>
</children> </Label>
<padding> <RadioButton fx:id="isHauptgerichtRadio" mnemonicParsing="false" text="Hauptgericht">
<Insets top="5.0" /> <HBox.margin>
</padding> <Insets left="35.0" top="20.0" />
</HBox> </HBox.margin>
<HBox prefHeight="75.0" prefWidth="459.0"> <toggleGroup>
<children> <ToggleGroup fx:id="art" />
<Label text="Art des Gerichts"> </toggleGroup>
<HBox.margin> </RadioButton>
<Insets top="20.0" /> <RadioButton fx:id="isDessertRadio" mnemonicParsing="false" text="Dessert" toggleGroup="$art">
</HBox.margin> <HBox.margin>
</Label> <Insets left="50.0" top="20.0" />
<RadioButton mnemonicParsing="false" text="Dessert"> </HBox.margin>
<HBox.margin> </RadioButton>
<Insets left="35.0" top="20.0" /> </children>
</HBox.margin> <VBox.margin>
</RadioButton> <Insets />
<RadioButton mnemonicParsing="false" text="Kein Dessert"> </VBox.margin>
<HBox.margin> <padding>
<Insets left="50.0" top="20.0" /> <Insets top="5.0" />
</HBox.margin> </padding>
</RadioButton> </HBox>
</children> <HBox prefHeight="75.0" prefWidth="459.0">
<children>
<Label text="Typ">
<HBox.margin>
<Insets top="20.0" />
</HBox.margin>
</Label>
<RadioButton fx:id="isVegetarischRadio" mnemonicParsing="false" prefHeight="17.0" prefWidth="91.0" text="Vegetarisch">
<HBox.margin>
<Insets left="100.0" top="20.0" />
</HBox.margin>
<toggleGroup>
<ToggleGroup fx:id="typ" />
</toggleGroup>
</RadioButton>
<RadioButton fx:id="isVeganRadio" mnemonicParsing="false" text="Vegan" toggleGroup="$typ">
<HBox.margin>
<Insets left="20.0" top="20.0" />
</HBox.margin>
</RadioButton>
<RadioButton fx:id="isFleischRadio" mnemonicParsing="false" text="Fleisch" toggleGroup="$typ">
<HBox.margin>
<Insets left="40.0" top="20.0" />
</HBox.margin>
</RadioButton>
</children>
</HBox>
<HBox prefHeight="76.0" prefWidth="459.0">
<children>
<Label prefHeight="41.0" prefWidth="171.0" text="Allergien mit Komma getrennt" />
<TextArea fx:id="allergienTextBox" prefHeight="76.0" prefWidth="246.0" />
</children>
</HBox>
<Text fx:id="responseText" fill="RED" strokeType="OUTSIDE" strokeWidth="0.0" textAlignment="CENTER" wrappingWidth="459.13673400878906">
<VBox.margin> <VBox.margin>
<Insets /> <Insets top="20.0" />
</VBox.margin> </VBox.margin>
<padding> </Text>
<Insets top="5.0" /> </children>
</padding> </VBox>
</HBox> <Button id="btCreateFood" layoutX="484.0" layoutY="481.0" mnemonicParsing="false" onAction="#onHinzufügen" prefHeight="34.0" prefWidth="146.0" text="Hinzufügen" />
<HBox prefHeight="75.0" prefWidth="459.0"> <Button id="btCancelFood" layoutX="102.0" layoutY="473.0" mnemonicParsing="false" onAction="#onAbbrechen" prefHeight="50.0" prefWidth="162.0" text="Abbrechen" />
<children> </children>
<Label text="Typ">
<HBox.margin>
<Insets top="20.0" />
</HBox.margin>
</Label>
<RadioButton mnemonicParsing="false" prefHeight="17.0" prefWidth="91.0" text="Vegetarisch">
<HBox.margin>
<Insets left="100.0" top="20.0" />
</HBox.margin>
</RadioButton>
<RadioButton mnemonicParsing="false" text="Vegan">
<HBox.margin>
<Insets left="20.0" top="20.0" />
</HBox.margin>
</RadioButton>
<RadioButton mnemonicParsing="false" text="Fleisch">
<HBox.margin>
<Insets left="40.0" top="20.0" />
</HBox.margin>
</RadioButton>
</children>
</HBox>
<HBox prefHeight="76.0" prefWidth="459.0">
<children>
<Label prefHeight="41.0" prefWidth="171.0" text="Allergien mit Komma getrennt" />
<TextArea prefHeight="76.0" prefWidth="246.0" />
</children>
</HBox>
</children>
</VBox>
<Button id="btCreateFood" layoutX="106.0" layoutY="457.0" mnemonicParsing="false" prefHeight="50.0" prefWidth="145.0" text="Hinzufügen" />
<Button id="btCancelFood" layoutX="366.0" layoutY="457.0" mnemonicParsing="false" prefHeight="50.0" prefWidth="162.0" text="Abbrechen" />
</children>
</AnchorPane> </AnchorPane>