From 3077e02b3242c041973f29ded806bbad685dd901 Mon Sep 17 00:00:00 2001 From: giavaphi Date: Sat, 5 Nov 2022 23:50:45 +0100 Subject: [PATCH 1/2] #48 and #47 basics of gui --- .../gartenverwaltung/MyPlantsController.java | 79 +++++++++++++++--- .../MyScheduleController.java | 81 +++++++++++++------ 2 files changed, 122 insertions(+), 38 deletions(-) diff --git a/src/main/java/ch/zhaw/gartenverwaltung/MyPlantsController.java b/src/main/java/ch/zhaw/gartenverwaltung/MyPlantsController.java index e223e8b..2fe9139 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/MyPlantsController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/MyPlantsController.java @@ -1,16 +1,23 @@ package ch.zhaw.gartenverwaltung; +import ch.zhaw.gartenverwaltung.types.Crop; import ch.zhaw.gartenverwaltung.types.Plant; import javafx.event.ActionEvent; +import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.fxml.Initializable; +import javafx.scene.control.Alert; import javafx.scene.control.Button; +import javafx.scene.control.ButtonType; +import javafx.scene.control.Label; +import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import java.io.IOException; import java.net.URL; import java.util.LinkedList; import java.util.List; +import java.util.Optional; import java.util.ResourceBundle; public class MyPlantsController implements Initializable { @@ -30,14 +37,14 @@ public class MyPlantsController implements Initializable { @Override public void initialize(URL url, ResourceBundle resourceBundle) { //ToDo - List myPlants = getMyPlants(); - createPlantView(myPlants); + List cropList = getCropList(); + createPlantView(cropList); } - private void createPlantView(List myPlants) { - //ToDo - for(Plant plant : myPlants) { - createPlantView(); + private void createPlantView(List crops) { + for(Crop crop : crops) { + HBox hBox = createPlantView(crop); + myPlants_vbox.getChildren().add(hBox); } } @@ -45,14 +52,60 @@ public class MyPlantsController implements Initializable { mainController = controller; } - private List getMyPlants() { - //ToDo method to get myPlantList(scheduled) - //Method to call all Plants saved - List myPlantList = new LinkedList<>(); - return myPlantList; + private List getCropList() { + //ToDo method to get cropList + //Method to get Crop List + List cropList = new LinkedList<>(); + return cropList; } - private void createPlantView() { - //ToDo FXML Panel with Plant data + private HBox createPlantView(Crop crop) { + //ToDo add dynamic design + HBox hBox = new HBox(); + Label label = new Label("Placeholder"); + Button details = new Button("Details"); + Button delete = new Button("delete"); + details.setOnAction(getGoToCropDetailEvent(crop)); + delete.setOnAction(getDeleteCropEvent(crop)); + hBox.getChildren().addAll(label, details, delete); + return hBox; + } + + private EventHandler getGoToCropDetailEvent(Crop crop) { + EventHandler event = new EventHandler() { + @Override + public void handle(ActionEvent event) { + //ToDo uncomment when new FXML exists + /*try { + mainController.loadPane(""); + } catch (IOException e) { + e.printStackTrace(); + }*/ + } + }; + return event; + } + + private EventHandler getDeleteCropEvent(Crop crop) { + EventHandler event = new EventHandler() { + @Override + public void handle(ActionEvent event) { + showConfirmation(crop); + } + }; + return event; + } + + private void showConfirmation(Crop crop) { + Alert alert = new Alert(Alert.AlertType.CONFIRMATION); + alert.setTitle("Delete Crop"); + alert.setHeaderText("Are you sure want to delete this Crop?"); + alert.setContentText("placeholder"); + + Optional option = alert.showAndWait(); + + if (option.get() == ButtonType.OK) { + //ToDo Method to remove crop + } } } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java b/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java index b16445a..173c0ec 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java @@ -1,14 +1,19 @@ package ch.zhaw.gartenverwaltung; -import ch.zhaw.gartenverwaltung.types.Plant; +import ch.zhaw.gartenverwaltung.types.Crop; +import ch.zhaw.gartenverwaltung.types.Task; +import javafx.beans.property.ListProperty; +import javafx.beans.property.SimpleListProperty; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Label; import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.layout.Pane; +import javafx.scene.layout.VBox; import java.net.URL; import java.time.LocalDate; @@ -17,7 +22,9 @@ import java.util.List; import java.util.ResourceBundle; public class MyScheduleController implements Initializable { - private Plant selectedPlant = null; + private Crop selectedCrop = null; + + private final ListProperty cropListProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); @FXML private Label day1_label; @@ -65,28 +72,26 @@ public class MyScheduleController implements Initializable { private Label information_label; @FXML - private ListView scheduledPlants_listview; + private ListView scheduledPlants_listview; @Override public void initialize(URL location, ResourceBundle resources) { - List plantList = new LinkedList<>(); - fillListViewMyPlantsInSchedule(plantList); - getSelectedPlantTask(); + //ToDo method to load crop list + List cropList = new LinkedList<>(); + setCellFactoryListView(); + scheduledPlants_listview.itemsProperty().bind(cropListProperty); + lookForSelectedListEntries(); setDayLabels(); information_label.setText(""); + loadTaskList(); } - private void getSelectedPlantTask() { - scheduledPlants_listview.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { + private void lookForSelectedListEntries() { + scheduledPlants_listview.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { @Override - public void changed(ObservableValue observable, Plant oldValue, Plant newValue) { - if(newValue != null) { - selectedPlant = newValue; - //ToDo update day_panel with task for the day - } else { - selectedPlant = null; - //ToDo update day_panel with task for the day (all plants) - } + public void changed(ObservableValue observable, Crop oldValue, Crop newValue) { + selectedCrop = newValue; + loadTaskList(); } }); } @@ -102,23 +107,49 @@ public class MyScheduleController implements Initializable { day7_label.setText(today.plusDays(6).getDayOfWeek().toString()); } - private void fillListViewMyPlantsInSchedule(List list) { - for (Plant plant : list) { - scheduledPlants_listview.getItems().add(plant); - } - scheduledPlants_listview.setCellFactory(param -> new ListCell() { + private void setCellFactoryListView() { + scheduledPlants_listview.setCellFactory(param -> new ListCell() { @Override - protected void updateItem(Plant plant, boolean empty) { - super.updateItem(plant, empty); + protected void updateItem(Crop crop, boolean empty) { + super.updateItem(crop, empty); - if (empty || plant == null || plant.name() == null) { + if (empty || crop == null) { setText(null); } else { - setText(plant.name()); + setText("placeholder"); } } }); } + private void loadTaskList() { + //ToDo load task list according to selectedCrop + List> taskLists = new LinkedList<>(); + if (selectedCrop != null) { + + } else { + + } + if (!taskLists.isEmpty()) { + viewTaskListOfDay(day1_pane, taskLists.get(0)); + viewTaskListOfDay(day2_pane, taskLists.get(1)); + viewTaskListOfDay(day3_pane, taskLists.get(2)); + viewTaskListOfDay(day4_pane, taskLists.get(3)); + viewTaskListOfDay(day5_pane, taskLists.get(4)); + viewTaskListOfDay(day6_pane, taskLists.get(5)); + viewTaskListOfDay(day7_pane, taskLists.get(6)); + } + } + + private void viewTaskListOfDay(Pane pane, List tasks) { + //ToDo update pane with task list + VBox vBox = new VBox(); + for (Task task : tasks) { + Label label = new Label("placeholder"); + vBox.getChildren().add(label); + } + pane.getChildren().add(vBox); + } + } From ea4a1ecc6a893c0322b8b7c2f43aa8f092eb3699 Mon Sep 17 00:00:00 2001 From: giavaphi Date: Sun, 6 Nov 2022 17:46:35 +0100 Subject: [PATCH 2/2] gui details of crop basics --- .../CropDetailController.java | 64 ++++++++ .../gartenverwaltung/MyPlantsController.java | 10 +- .../ch/zhaw/gartenverwaltung/CropDetail.fxml | 142 ++++++++++++++++++ 3 files changed, 209 insertions(+), 7 deletions(-) create mode 100644 src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java create mode 100644 src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml diff --git a/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java new file mode 100644 index 0000000..e34f743 --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/CropDetailController.java @@ -0,0 +1,64 @@ +package ch.zhaw.gartenverwaltung; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.layout.VBox; + +public class CropDetailController { + + @FXML + private Button area_button; + + @FXML + private Label area_label; + + @FXML + private Label cropName_label; + + @FXML + private Label description_label; + + @FXML + private VBox growthPahses_vbox; + + @FXML + private Label lacation_label; + + @FXML + private Label light_label; + + @FXML + private Button location_button; + + @FXML + private VBox pests_vbox; + + @FXML + private Label soil_label; + + @FXML + private Label spacing_label; + + @FXML + void editTaskList(ActionEvent event) { + + } + + @FXML + void goBack(ActionEvent event) { + + } + + @FXML + void setArea(ActionEvent event) { + + } + + @FXML + void setLocation(ActionEvent event) { + + } + +} diff --git a/src/main/java/ch/zhaw/gartenverwaltung/MyPlantsController.java b/src/main/java/ch/zhaw/gartenverwaltung/MyPlantsController.java index 2fe9139..9bbd3a8 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/MyPlantsController.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/MyPlantsController.java @@ -1,7 +1,6 @@ package ch.zhaw.gartenverwaltung; import ch.zhaw.gartenverwaltung.types.Crop; -import ch.zhaw.gartenverwaltung.types.Plant; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXML; @@ -23,9 +22,6 @@ import java.util.ResourceBundle; public class MyPlantsController implements Initializable { MainFXMLController mainController; - @FXML - private Button addPlant_button; - @FXML private VBox myPlants_vbox; @@ -76,11 +72,11 @@ public class MyPlantsController implements Initializable { @Override public void handle(ActionEvent event) { //ToDo uncomment when new FXML exists - /*try { - mainController.loadPane(""); + try { + mainController.loadPane("CropDetail.fxml"); } catch (IOException e) { e.printStackTrace(); - }*/ + } } }; return event; diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml b/src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml new file mode 100644 index 0000000..c0cd65a --- /dev/null +++ b/src/main/resources/ch/zhaw/gartenverwaltung/CropDetail.fxml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +