#12 small changes and java doc

This commit is contained in:
giavaphi 2022-10-31 09:23:44 +01:00
parent c83b8695ab
commit 5b039eb762
1 changed files with 52 additions and 11 deletions

View File

@ -14,7 +14,6 @@ import javafx.geometry.Insets;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.InputMethodEvent;
import javafx.scene.layout.VBox;
import java.io.IOException;
@ -49,18 +48,25 @@ public class PlantsController implements Initializable {
@FXML
private TextField search_plants;
/**
* saves the current selected plant in new JSON database
* @param event event
*/
@FXML
void saveToMyPlant(ActionEvent event) {
//ToDo model save selectedPlant to mySelectedPlant(IO)
}
/**
* fill list view with current hardiness zone
* set default values
* create filter of season and hardiness zone
* create event listener for selected list entry and search by query
* {@inheritDoc}
*/
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
fillPlantListWithDefaultValues();
fillPlantListWithHardinessZone();
description_plant.setText("");
saveToMyPlant_button.setDisable(true);
@ -99,15 +105,28 @@ public class PlantsController implements Initializable {
});
}
/**
* get plant list according to param season and hardiness zone
* fill list view with plant list
* @param season enum of seasons
* @throws HardinessZoneNotSetException throws exception
* @throws IOException throws exception
*/
private void viewFilteredListBySeason(Seasons season) throws HardinessZoneNotSetException, IOException {
List<Plant> plantList = plantListModel.getFilteredPlantListBySaisonWithoutGrowthPhase(plantListModel.getCurrentZone(), season.getStartDate(), season.getEndDate());
fillListViewWithData(plantList);
}
/**
* get plant list filtered by search plant entry and hardiness zone
* fill list view with plant list
* @throws HardinessZoneNotSetException throws exception when no hardiness zone is defined
* @throws IOException throws exception
*/
private void viewFilteredListBySearch() throws HardinessZoneNotSetException, IOException {
search_plants.textProperty().addListener((observable, oldValue, newValue) -> {
if (newValue.isEmpty()) {
fillPlantListWithDefaultValues();
fillPlantListWithHardinessZone();
}else {
List<Plant> plantList = new LinkedList<>();
try {
@ -120,7 +139,11 @@ public class PlantsController implements Initializable {
});
}
private void fillPlantListWithDefaultValues() {
/**
* get plant list of current hardiness zone
* fill list view with plant list
*/
private void fillPlantListWithHardinessZone() {
List<Plant> plantList = new LinkedList<>();
try {
plantList = plantListModel.getPlantList(plantListModel.getCurrentZone());
@ -130,6 +153,11 @@ public class PlantsController implements Initializable {
fillListViewWithData(plantList);
}
/**
* creates radio buttons for the hardiness zones defined in enum HardinessZone
* defines default value as selected
* when selected filter viewList according to hardiness zone
*/
private void createFilterHardinessZone() {
ToggleGroup hardinessGroup = new ToggleGroup();
for (HardinessZone zone : HardinessZone.values()) {
@ -143,13 +171,18 @@ public class PlantsController implements Initializable {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
plantListModel.setCurrentZone(zone);
fillPlantListWithDefaultValues();
fillPlantListWithHardinessZone();
}
});
climate_zones.getChildren().add(radioButton);
}
}
/**
* creates radio buttons for the seasons defined in enum Seasons
* defines default value as selected
* when selected filter viewList according to seasons
*/
private void createFilterSeasons() {
ToggleGroup seasonGroup = new ToggleGroup();
for (Seasons season : Seasons.values()) {
@ -163,7 +196,7 @@ public class PlantsController implements Initializable {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if (season.equals(Seasons.AllSEASONS)) {
fillPlantListWithDefaultValues();
fillPlantListWithHardinessZone();
} else {
try {
viewFilteredListBySeason(season);
@ -179,7 +212,9 @@ public class PlantsController implements Initializable {
}
/**
* observes changes in the selectedProperty of ListView and updates the description label
* observes changes in the selectedProperty of ListView and updates:
* the description label
* image of the plant
*/
private void lookForSelectedListEntry() {
list_plants.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Plant>() {
@ -189,9 +224,15 @@ public class PlantsController implements Initializable {
selectedPlant = newValue;
description_plant.setText(selectedPlant.description());
saveToMyPlant_button.setDisable(false);
//ToDo Uncomment if plant.java can load img
//Image img = selectedPlant.image();
//img_plant.setImage(img);
Image img;
if(selectedPlant.image() != null) {
img = selectedPlant.image();
} else {
img = new Image(String.valueOf(PlantsController.class.getResource("placeholder.png")));
}
img_plant.setImage(img);
} else {
selectedPlant = null;
description_plant.setText("");