diff --git a/src/main/java/ch/zhaw/gartenverwaltung/HelloApplication.java b/src/main/java/ch/zhaw/gartenverwaltung/HelloApplication.java index 0d70b44..fd31017 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/HelloApplication.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/HelloApplication.java @@ -10,9 +10,9 @@ import java.io.IOException; public class HelloApplication extends Application { @Override public void start(Stage stage) throws IOException { - FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml")); - Scene scene = new Scene(fxmlLoader.load(), 320, 240); - stage.setTitle("Hello!"); + FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("MainFXML.fxml")); + Scene scene = new Scene(fxmlLoader.load()); + stage.setTitle("Gartenverwaltung"); stage.setScene(scene); stage.show(); } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/HomeController.java b/src/main/java/ch/zhaw/gartenverwaltung/HomeController.java new file mode 100644 index 0000000..7df4661 --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/HomeController.java @@ -0,0 +1,5 @@ +package ch.zhaw.gartenverwaltung; + +public class HomeController +{ +} diff --git a/src/main/java/ch/zhaw/gartenverwaltung/MainFXMLController.java b/src/main/java/ch/zhaw/gartenverwaltung/MainFXMLController.java new file mode 100644 index 0000000..c3fe04d --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/MainFXMLController.java @@ -0,0 +1,94 @@ +package ch.zhaw.gartenverwaltung; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.Initializable; +import javafx.scene.Node; +import javafx.scene.control.Button; +import javafx.scene.layout.AnchorPane; + +import java.io.IOException; +import java.net.URL; +import java.util.Objects; +import java.util.ResourceBundle; + +public class MainFXMLController implements Initializable { + + @FXML + private Button home_button; + + @FXML + private AnchorPane mainPane; + + @FXML + private Button myPlants_button; + + @FXML + private Button mySchedule_button; + + @FXML + private Button plants_button; + + @FXML + void goToHome(ActionEvent event) throws IOException { + loadPane("Home.fxml"); + styleChangeButton(home_button); + } + + @FXML + void goToMyPlants(ActionEvent event) throws IOException { + loadPane("MyPlants.fxml"); + styleChangeButton(myPlants_button); + } + + @FXML + void goToMySchedule(ActionEvent event) throws IOException { + loadPane("MySchedule.fxml"); + styleChangeButton(mySchedule_button); + } + + @FXML + void goToPlants(ActionEvent event) throws IOException { + loadPane("Plants.fxml"); + styleChangeButton(plants_button); + } + + /** + * Updates the mainPane with the selected fxml file. + * set HGrow and VGrow to parent AnchorPane. + * Sends MainController to other Controllers. + * @param fxmlFile string of fxml file + * @throws IOException exception when file does not exist + */ + public void loadPane(String fxmlFile) throws IOException { + //ToDo HGrow and VGrow of new node + Node node; + FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(HelloApplication.class.getResource(fxmlFile))); + node = (Node)loader.load(); + if(fxmlFile.equals("MyPlants.fxml")) { + MyPlantsController myPlantsController = loader.getController(); + myPlantsController.getMainController(this); + } + mainPane.getChildren().setAll(node); + } + + private void styleChangeButton(Button button) { + //ToDo changeStyle of the menu buttons + } + + /** + * loads the default FXML File + * {@inheritDoc} + */ + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + try { + loadPane("Home.fxml"); + styleChangeButton(home_button); + } catch (IOException e) { + e.printStackTrace(); + } + } +} + diff --git a/src/main/java/ch/zhaw/gartenverwaltung/MyPlantsController.java b/src/main/java/ch/zhaw/gartenverwaltung/MyPlantsController.java new file mode 100644 index 0000000..e223e8b --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/MyPlantsController.java @@ -0,0 +1,58 @@ +package ch.zhaw.gartenverwaltung; + +import ch.zhaw.gartenverwaltung.types.Plant; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.Button; +import javafx.scene.layout.VBox; + +import java.io.IOException; +import java.net.URL; +import java.util.LinkedList; +import java.util.List; +import java.util.ResourceBundle; + +public class MyPlantsController implements Initializable { + MainFXMLController mainController; + + @FXML + private Button addPlant_button; + + @FXML + private VBox myPlants_vbox; + + @FXML + void addPlant(ActionEvent event) throws IOException { + mainController.loadPane("Plants.fxml"); + } + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + //ToDo + List myPlants = getMyPlants(); + createPlantView(myPlants); + } + + private void createPlantView(List myPlants) { + //ToDo + for(Plant plant : myPlants) { + createPlantView(); + } + } + + public void getMainController(MainFXMLController controller) { + mainController = controller; + } + + private List getMyPlants() { + //ToDo method to get myPlantList(scheduled) + //Method to call all Plants saved + List myPlantList = new LinkedList<>(); + return myPlantList; + } + + private void createPlantView() { + //ToDo FXML Panel with Plant data + } +} diff --git a/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java b/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java new file mode 100644 index 0000000..b16445a --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/MyScheduleController.java @@ -0,0 +1,124 @@ +package ch.zhaw.gartenverwaltung; + +import ch.zhaw.gartenverwaltung.types.Plant; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +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 java.net.URL; +import java.time.LocalDate; +import java.util.LinkedList; +import java.util.List; +import java.util.ResourceBundle; + +public class MyScheduleController implements Initializable { + private Plant selectedPlant = null; + + @FXML + private Label day1_label; + + @FXML + private Pane day1_pane; + + @FXML + private Label day2_label; + + @FXML + private Pane day2_pane; + + @FXML + private Label day3_label; + + @FXML + private Pane day3_pane; + + @FXML + private Label day4_label; + + @FXML + private Pane day4_pane; + + @FXML + private Label day5_label; + + @FXML + private Pane day5_pane; + + @FXML + private Label day6_label; + + @FXML + private Pane day6_pane; + + @FXML + private Label day7_label; + + @FXML + private Pane day7_pane; + + @FXML + private Label information_label; + + @FXML + private ListView scheduledPlants_listview; + + @Override + public void initialize(URL location, ResourceBundle resources) { + List plantList = new LinkedList<>(); + fillListViewMyPlantsInSchedule(plantList); + getSelectedPlantTask(); + setDayLabels(); + information_label.setText(""); + } + + private void getSelectedPlantTask() { + 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) + } + } + }); + } + + private void setDayLabels() { + LocalDate today = LocalDate.now(); + day1_label.setText(today.getDayOfWeek().toString()); + day2_label.setText(today.plusDays(1).getDayOfWeek().toString()); + day3_label.setText(today.plusDays(2).getDayOfWeek().toString()); + day4_label.setText(today.plusDays(3).getDayOfWeek().toString()); + day5_label.setText(today.plusDays(4).getDayOfWeek().toString()); + day6_label.setText(today.plusDays(5).getDayOfWeek().toString()); + 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() { + @Override + protected void updateItem(Plant plant, boolean empty) { + super.updateItem(plant, empty); + + if (empty || plant == null || plant.name() == null) { + setText(null); + } else { + setText(plant.name()); + } + } + }); + } + + +} diff --git a/src/main/java/ch/zhaw/gartenverwaltung/PlantsController.java b/src/main/java/ch/zhaw/gartenverwaltung/PlantsController.java new file mode 100644 index 0000000..a8c8d93 --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/PlantsController.java @@ -0,0 +1,186 @@ +package ch.zhaw.gartenverwaltung; + +import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException; +import ch.zhaw.gartenverwaltung.plantList.PlantListModel; +import ch.zhaw.gartenverwaltung.types.HardinessZone; +import ch.zhaw.gartenverwaltung.types.Plant; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.*; +import javafx.scene.image.ImageView; +import javafx.scene.input.InputMethodEvent; +import javafx.scene.layout.VBox; + +import java.io.IOException; +import java.net.URL; +import java.util.LinkedList; +import java.util.List; +import java.util.ResourceBundle; + +public class PlantsController implements Initializable { + private final PlantListModel plantListModel = new PlantListModel(); + private Plant selectedPlant = null; + private final HardinessZone DEFAULT_HARDINESS_ZONE = HardinessZone.ZONE_8A; + + @FXML + private CheckBox autum_filter; + + @FXML + private VBox climate_zones; + + @FXML + private Label description_plant; + + @FXML + private ImageView img_plant; + + @FXML + private ListView list_plants; + + @FXML + private Button saveToMyPlant_button; + + @FXML + private TextField search_plants; + + @FXML + private CheckBox sommer_filter; + + @FXML + private CheckBox spring_filter; + + @FXML + private CheckBox winter_filter; + + @FXML + void filterAutum(ActionEvent event) { + //ToDo + + } + + @FXML + void filterSommer(ActionEvent event) { + //ToDo + + } + + @FXML + void filterSpring(ActionEvent event) { + //ToDo + + } + + @FXML + void filterWinter(ActionEvent event) { + //ToDo + + } + + @FXML + void saveToMyPlant(ActionEvent event) { + //ToDo model save selectedPlant to mySelectedPlant(IO) + } + + @FXML + void searchForPlant(InputMethodEvent event) { + viewFilteredListBySearch(search_plants.getText()); + } + + /** + * {@inheritDoc} + */ + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + List plantList = new LinkedList<>(); + try { + plantList = plantListModel.getPlantList(DEFAULT_HARDINESS_ZONE); + } catch (HardinessZoneNotSetException | IOException e) { + e.printStackTrace(); + } + fillListViewWithData(plantList); + + description_plant.setText(""); + saveToMyPlant_button.setDisable(true); + + createFilterHardinessZone(); + lookForSelectedListEntry(); + } + + /** + * update the ListView according to the plant list provided + * Entry in ListView is plant name + * @param list plantList which fill the ListView + */ + private void fillListViewWithData(List list) { + clearListView(); + for (Plant plant : list) { + list_plants.getItems().add(plant); + } + list_plants.setCellFactory(param -> new ListCell() { + @Override + protected void updateItem(Plant plant, boolean empty) { + super.updateItem(plant, empty); + + if (empty || plant == null || plant.name() == null) { + setText(null); + } else { + setText(plant.name()); + } + } + }); + } + + private void viewFilteredListByFilters() { + boolean springValue = spring_filter.isSelected(); + boolean sommerValue = sommer_filter.isSelected(); + boolean autumValue = autum_filter.isSelected(); + boolean winterValue = winter_filter.isSelected(); + //ToDo getFilteredPlantList with (plantListModel.getFilteredPlantList(DEFAULT_HARDINESS_ZONE, )) + //List plantList = new LinkedList<>(); + //fillListViewWithData(plantList); + } + + private void viewFilteredListBySearch(String query) { + //ToDo getFilteredPlantList with (plantListModel.getFilteredPlantList(DEFAULT_HARDINESS_ZONE, )) + //List plantList = new LinkedList<>(); + //fillListViewWithData(plantList); + } + + private void createFilterHardinessZone() { + //ToDo create radioList of hardinessZone in VBox climate_zones + } + + /** + * observes changes in the selectedProperty of ListView and updates the description label + */ + private void lookForSelectedListEntry() { + list_plants.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, Plant oldValue, Plant newValue) { + //ToDo + if(newValue != null) { + selectedPlant = newValue; + description_plant.setText(selectedPlant.description()); + saveToMyPlant_button.setDisable(false); + //update img plant + } else { + selectedPlant = null; + description_plant.setText(""); + saveToMyPlant_button.setDisable(true); + //update img when null placeholder PNG + } + } + }); + } + + + /** + * clears the ListView of entries + */ + private void clearListView() { + list_plants.getItems().clear(); + } +} diff --git a/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java b/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java index bd12a28..8217962 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/plantList/PlantListModel.java @@ -11,6 +11,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.function.Predicate; +import java.util.stream.Collectors; public class PlantListModel { private PlantDatabase plantDatabase; @@ -67,7 +68,7 @@ public class PlantListModel { */ public List getSortedPlantList(HardinessZone zone, Comparator comparator) throws HardinessZoneNotSetException, IOException { setCurrentZone(zone); - return plantDatabase.getPlantList(zone).stream().sorted(comparator).toList(); + return plantDatabase.getPlantList(zone).stream().sorted(comparator).collect(Collectors.toList()); } /** @@ -80,7 +81,7 @@ public class PlantListModel { */ public List getFilteredPlantList(HardinessZone zone, Predicate predicate) throws HardinessZoneNotSetException, IOException { setCurrentZone(zone); - return getPlantList(zone).stream().filter(predicate).toList(); + return getPlantList(zone).stream().filter(predicate).collect(Collectors.toList()); } /** diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java index 13652a6..ee90a6e 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java @@ -2,6 +2,7 @@ package ch.zhaw.gartenverwaltung.types; import java.time.LocalDate; import java.util.List; +import java.util.stream.Collectors; import static java.time.temporal.ChronoUnit.DAYS; @@ -22,7 +23,7 @@ public record Plant( public List lifecycleForGroup(int group) { return lifecycle.stream() .filter(growthPhase -> growthPhase.group() != group) - .toList(); + .collect(Collectors.toList()); } public LocalDate sowDateFromHarvestDate(LocalDate harvestDate, int group) { diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/Home.fxml b/src/main/resources/ch/zhaw/gartenverwaltung/Home.fxml new file mode 100644 index 0000000..65ee774 --- /dev/null +++ b/src/main/resources/ch/zhaw/gartenverwaltung/Home.fxml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/MainFXML.fxml b/src/main/resources/ch/zhaw/gartenverwaltung/MainFXML.fxml new file mode 100644 index 0000000..75ff18b --- /dev/null +++ b/src/main/resources/ch/zhaw/gartenverwaltung/MainFXML.fxml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/MySchedule.fxml b/src/main/resources/ch/zhaw/gartenverwaltung/MySchedule.fxml new file mode 100644 index 0000000..0a75e12 --- /dev/null +++ b/src/main/resources/ch/zhaw/gartenverwaltung/MySchedule.fxml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/ch/zhaw/gartenverwaltung/Plants.fxml b/src/main/resources/ch/zhaw/gartenverwaltung/Plants.fxml new file mode 100644 index 0000000..80abd33 --- /dev/null +++ b/src/main/resources/ch/zhaw/gartenverwaltung/Plants.fxml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +