Compare commits
No commits in common. "7a6a0eb66fa4003ecc52bea0d58498b2dee8413b" and "6c00b7f182f55b70bd829bacd39b508c692c9e9e" have entirely different histories.
7a6a0eb66f
...
6c00b7f182
|
@ -10,16 +10,10 @@ import javafx.scene.layout.AnchorPane;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
public class MainFXMLController implements Initializable {
|
public class MainFXMLController implements Initializable {
|
||||||
/**
|
|
||||||
* Caching the panes
|
|
||||||
*/
|
|
||||||
private final Map<String, AnchorPane> panes = new HashMap<>();
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button home_button;
|
private Button home_button;
|
||||||
|
@ -68,22 +62,15 @@ public class MainFXMLController implements Initializable {
|
||||||
* @throws IOException exception when file does not exist
|
* @throws IOException exception when file does not exist
|
||||||
*/
|
*/
|
||||||
public void loadPane(String fxmlFile) throws IOException {
|
public void loadPane(String fxmlFile) throws IOException {
|
||||||
|
//ToDo HGrow and VGrow of new node
|
||||||
AnchorPane anchorPane = panes.get(fxmlFile);
|
Node node;
|
||||||
if (anchorPane == null) {
|
FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(HelloApplication.class.getResource(fxmlFile)));
|
||||||
FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(HelloApplication.class.getResource(fxmlFile)));
|
node = (Node)loader.load();
|
||||||
anchorPane = loader.load();
|
if(fxmlFile.equals("MyPlants.fxml")) {
|
||||||
panes.put(fxmlFile, anchorPane);
|
MyPlantsController myPlantsController = loader.getController();
|
||||||
|
myPlantsController.getMainController(this);
|
||||||
if(fxmlFile.equals("MyPlants.fxml")) {
|
|
||||||
MyPlantsController myPlantsController = loader.getController();
|
|
||||||
myPlantsController.getMainController(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mainPane.getChildren().setAll(anchorPane);
|
mainPane.getChildren().setAll(node);
|
||||||
anchorPane.prefWidthProperty().bind(mainPane.widthProperty());
|
|
||||||
anchorPane.prefHeightProperty().bind(mainPane.heightProperty());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void styleChangeButton(Button button) {
|
private void styleChangeButton(Button button) {
|
||||||
|
|
|
@ -4,26 +4,19 @@ import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
|
||||||
import ch.zhaw.gartenverwaltung.plantList.PlantListModel;
|
import ch.zhaw.gartenverwaltung.plantList.PlantListModel;
|
||||||
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
import ch.zhaw.gartenverwaltung.types.HardinessZone;
|
||||||
import ch.zhaw.gartenverwaltung.types.Plant;
|
import ch.zhaw.gartenverwaltung.types.Plant;
|
||||||
import ch.zhaw.gartenverwaltung.types.Seasons;
|
|
||||||
import javafx.application.Platform;
|
|
||||||
import javafx.beans.property.ListProperty;
|
|
||||||
import javafx.beans.property.SimpleListProperty;
|
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.beans.value.ChangeListener;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.collections.FXCollections;
|
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
import javafx.geometry.Insets;
|
|
||||||
import javafx.geometry.Bounds;
|
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.image.Image;
|
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.InputMethodEvent;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
@ -32,12 +25,8 @@ public class PlantsController implements Initializable {
|
||||||
private Plant selectedPlant = null;
|
private Plant selectedPlant = null;
|
||||||
private final HardinessZone DEFAULT_HARDINESS_ZONE = HardinessZone.ZONE_8A;
|
private final HardinessZone DEFAULT_HARDINESS_ZONE = HardinessZone.ZONE_8A;
|
||||||
|
|
||||||
// TODO: move to model
|
|
||||||
|
|
||||||
private final ListProperty<Plant> plantListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private VBox seasons;
|
private CheckBox autum_filter;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private VBox climate_zones;
|
private VBox climate_zones;
|
||||||
|
@ -57,45 +46,79 @@ public class PlantsController implements Initializable {
|
||||||
@FXML
|
@FXML
|
||||||
private TextField search_plants;
|
private TextField search_plants;
|
||||||
|
|
||||||
/**
|
@FXML
|
||||||
* saves the current selected plant in new JSON database
|
private CheckBox sommer_filter;
|
||||||
* @param event event
|
|
||||||
*/
|
@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
|
@FXML
|
||||||
void saveToMyPlant(ActionEvent event) {
|
void saveToMyPlant(ActionEvent event) {
|
||||||
//ToDo model save selectedPlant to mySelectedPlant(IO)
|
//ToDo model save selectedPlant to mySelectedPlant(IO)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
void searchForPlant(InputMethodEvent event) {
|
||||||
|
viewFilteredListBySearch(search_plants.getText());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
setListCellFactory();
|
List<Plant> plantList = new LinkedList<>();
|
||||||
fillPlantListWithHardinessZone();
|
try {
|
||||||
list_plants.itemsProperty().bind(plantListProperty);
|
plantList = plantListModel.getPlantList(DEFAULT_HARDINESS_ZONE);
|
||||||
|
} catch (HardinessZoneNotSetException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
fillListViewWithData(plantList);
|
||||||
|
|
||||||
description_plant.setText("");
|
description_plant.setText("");
|
||||||
saveToMyPlant_button.setDisable(true);
|
saveToMyPlant_button.setDisable(true);
|
||||||
|
|
||||||
createFilterSeasons();
|
|
||||||
createFilterHardinessZone();
|
createFilterHardinessZone();
|
||||||
lookForSelectedListEntry();
|
lookForSelectedListEntry();
|
||||||
try {
|
|
||||||
viewFilteredListBySearch();
|
|
||||||
} catch (HardinessZoneNotSetException | IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set text of list view to plant name
|
* update the ListView according to the plant list provided
|
||||||
|
* Entry in ListView is plant name
|
||||||
|
* @param list plantList which fill the ListView
|
||||||
*/
|
*/
|
||||||
private void setListCellFactory() {
|
private void fillListViewWithData(List<Plant> list) {
|
||||||
|
clearListView();
|
||||||
|
for (Plant plant : list) {
|
||||||
|
list_plants.getItems().add(plant);
|
||||||
|
}
|
||||||
list_plants.setCellFactory(param -> new ListCell<Plant>() {
|
list_plants.setCellFactory(param -> new ListCell<Plant>() {
|
||||||
@Override
|
@Override
|
||||||
protected void updateItem(Plant plant, boolean empty) {
|
protected void updateItem(Plant plant, boolean empty) {
|
||||||
|
@ -110,139 +133,44 @@ public class PlantsController implements Initializable {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void viewFilteredListByFilters() {
|
||||||
* get plant list according to param season and hardiness zone
|
boolean springValue = spring_filter.isSelected();
|
||||||
* fill list view with plant list
|
boolean sommerValue = sommer_filter.isSelected();
|
||||||
* @param season enum of seasons
|
boolean autumValue = autum_filter.isSelected();
|
||||||
* @throws HardinessZoneNotSetException throws exception
|
boolean winterValue = winter_filter.isSelected();
|
||||||
* @throws IOException throws exception
|
//ToDo getFilteredPlantList with (plantListModel.getFilteredPlantList(DEFAULT_HARDINESS_ZONE, <predicate>))
|
||||||
*/
|
//List<Plant> plantList = new LinkedList<>();
|
||||||
private void viewFilteredListBySeason(Seasons season) throws HardinessZoneNotSetException, IOException {
|
//fillListViewWithData(plantList);
|
||||||
clearListView();
|
|
||||||
plantListProperty.addAll(plantListModel.getFilteredPlantListBySaisonWithoutGrowthPhase(plantListModel.getCurrentZone(), season.getStartDate(), season.getEndDate()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void viewFilteredListBySearch(String query) {
|
||||||
* get plant list filtered by search plant entry and hardiness zone
|
//ToDo getFilteredPlantList with (plantListModel.getFilteredPlantList(DEFAULT_HARDINESS_ZONE, <predicate>))
|
||||||
* fill list view with plant list
|
//List<Plant> plantList = new LinkedList<>();
|
||||||
* @throws HardinessZoneNotSetException throws exception when no hardiness zone is defined
|
//fillListViewWithData(plantList);
|
||||||
* @throws IOException throws exception
|
|
||||||
*/
|
|
||||||
private void viewFilteredListBySearch() throws HardinessZoneNotSetException, IOException {
|
|
||||||
search_plants.textProperty().addListener((observable, oldValue, newValue) -> {
|
|
||||||
if (newValue.isEmpty()) {
|
|
||||||
fillPlantListWithHardinessZone();
|
|
||||||
}else {
|
|
||||||
try {
|
|
||||||
List<Plant> filteredPlants = plantListModel.getFilteredPlantListByString(DEFAULT_HARDINESS_ZONE, newValue);
|
|
||||||
clearListView();
|
|
||||||
plantListProperty.addAll(filteredPlants);
|
|
||||||
} catch (HardinessZoneNotSetException | IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* get plant list of current hardiness zone
|
|
||||||
* fill list view with plant list
|
|
||||||
*/
|
|
||||||
private void fillPlantListWithHardinessZone() {
|
|
||||||
try {
|
|
||||||
clearListView();
|
|
||||||
plantListProperty.addAll(plantListModel.getPlantList(plantListModel.getCurrentZone()));
|
|
||||||
} catch (HardinessZoneNotSetException | IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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() {
|
private void createFilterHardinessZone() {
|
||||||
ToggleGroup hardinessGroup = new ToggleGroup();
|
//ToDo create radioList of hardinessZone in VBox climate_zones
|
||||||
for (HardinessZone zone : HardinessZone.values()) {
|
|
||||||
RadioButton radioButton = new RadioButton(zone.name());
|
|
||||||
radioButton.setToggleGroup(hardinessGroup);
|
|
||||||
radioButton.setPadding(new Insets(0,0,10,0));
|
|
||||||
if (zone.equals(DEFAULT_HARDINESS_ZONE)) {
|
|
||||||
radioButton.setSelected(true);
|
|
||||||
}
|
|
||||||
radioButton.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
|
||||||
@Override
|
|
||||||
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
|
|
||||||
plantListModel.setCurrentZone(zone);
|
|
||||||
fillPlantListWithHardinessZone();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
climate_zones.getChildren().add(radioButton);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates radio buttons for the seasons defined in enum Seasons
|
* observes changes in the selectedProperty of ListView and updates the description label
|
||||||
* defines default value as selected
|
|
||||||
* when selected filter viewList according to seasons
|
|
||||||
*/
|
|
||||||
private void createFilterSeasons() {
|
|
||||||
ToggleGroup seasonGroup = new ToggleGroup();
|
|
||||||
for (Seasons season : Seasons.values()) {
|
|
||||||
RadioButton radioButton = new RadioButton(season.name());
|
|
||||||
radioButton.setToggleGroup(seasonGroup);
|
|
||||||
radioButton.setPadding(new Insets(0,0,10,0));
|
|
||||||
if (season.equals(Seasons.AllSEASONS)) {
|
|
||||||
radioButton.setSelected(true);
|
|
||||||
}
|
|
||||||
radioButton.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
|
||||||
@Override
|
|
||||||
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
|
|
||||||
if (season.equals(Seasons.AllSEASONS)) {
|
|
||||||
fillPlantListWithHardinessZone();
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
viewFilteredListBySeason(season);
|
|
||||||
} catch (HardinessZoneNotSetException | IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
seasons.getChildren().add(radioButton);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* observes changes in the selectedProperty of ListView and updates:
|
|
||||||
* the description label
|
|
||||||
* image of the plant
|
|
||||||
*/
|
*/
|
||||||
private void lookForSelectedListEntry() {
|
private void lookForSelectedListEntry() {
|
||||||
list_plants.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Plant>() {
|
list_plants.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Plant>() {
|
||||||
@Override
|
@Override
|
||||||
public void changed(ObservableValue<? extends Plant> observable, Plant oldValue, Plant newValue) {
|
public void changed(ObservableValue<? extends Plant> observable, Plant oldValue, Plant newValue) {
|
||||||
|
//ToDo
|
||||||
if(newValue != null) {
|
if(newValue != null) {
|
||||||
selectedPlant = newValue;
|
selectedPlant = newValue;
|
||||||
description_plant.setText(selectedPlant.description());
|
description_plant.setText(selectedPlant.description());
|
||||||
saveToMyPlant_button.setDisable(false);
|
saveToMyPlant_button.setDisable(false);
|
||||||
Image img;
|
//update img plant
|
||||||
if(selectedPlant.image() != null) {
|
|
||||||
img = selectedPlant.image();
|
|
||||||
} else {
|
|
||||||
img = new Image(String.valueOf(PlantsController.class.getResource("placeholder.png")));
|
|
||||||
}
|
|
||||||
img_plant.setImage(img);
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
selectedPlant = null;
|
selectedPlant = null;
|
||||||
description_plant.setText("");
|
description_plant.setText("");
|
||||||
saveToMyPlant_button.setDisable(true);
|
saveToMyPlant_button.setDisable(true);
|
||||||
Image img = new Image(String.valueOf(PlantsController.class.getResource("placeholder.png")));
|
//update img when null placeholder PNG
|
||||||
img_plant.setImage(img);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -253,6 +181,6 @@ public class PlantsController implements Initializable {
|
||||||
* clears the ListView of entries
|
* clears the ListView of entries
|
||||||
*/
|
*/
|
||||||
private void clearListView() {
|
private void clearListView() {
|
||||||
plantListProperty.clear();
|
list_plants.getItems().clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,9 @@ import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
public class PlantImageDeserializer extends JsonDeserializer<Image> {
|
public class PlantImageDeserializer extends JsonDeserializer<Image> {
|
||||||
|
@ -20,9 +18,9 @@ public class PlantImageDeserializer extends JsonDeserializer<Image> {
|
||||||
Image result = null;
|
Image result = null;
|
||||||
URL imageUrl = PlantDatabase.class.getResource(String.format("images/%s", parser.getText()));
|
URL imageUrl = PlantDatabase.class.getResource(String.format("images/%s", parser.getText()));
|
||||||
if (imageUrl != null) {
|
if (imageUrl != null) {
|
||||||
try (InputStream is = new FileInputStream(new File(imageUrl.toURI()))) {
|
try (InputStream is = new FileInputStream(imageUrl.getFile())) {
|
||||||
result = new Image(is);
|
result = new Image(is);
|
||||||
} catch (IllegalArgumentException | URISyntaxException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// TODO: Log
|
// TODO: Log
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.err.printf("Cannot find Image \"%s\"\n", imageUrl.getFile());
|
System.err.printf("Cannot find Image \"%s\"\n", imageUrl.getFile());
|
||||||
|
|
|
@ -33,12 +33,12 @@ public class PlantListModel {
|
||||||
setDefaultZone();
|
setDefaultZone();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlantListModel(PlantDatabase plantDatabase) {
|
public PlantListModel(PlantDatabase plantDatabase){
|
||||||
this.plantDatabase = plantDatabase;
|
this.plantDatabase = plantDatabase;
|
||||||
setDefaultZone();
|
setDefaultZone();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDefaultZone() {
|
private void setDefaultZone(){
|
||||||
currentZone = HardinessZone.ZONE_8A; // TODO: get Default Zone from Config
|
currentZone = HardinessZone.ZONE_8A; // TODO: get Default Zone from Config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,6 @@ public class PlantListModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get actual Plant List in alphabetic Order
|
* Method to get actual Plant List in alphabetic Order
|
||||||
*
|
|
||||||
* @return actual Plant List in alphabetic Order
|
* @return actual Plant List in alphabetic Order
|
||||||
*/
|
*/
|
||||||
public List<Plant> getPlantList(HardinessZone zone) throws HardinessZoneNotSetException, IOException {
|
public List<Plant> getPlantList(HardinessZone zone) throws HardinessZoneNotSetException, IOException {
|
||||||
|
@ -63,11 +62,10 @@ public class PlantListModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get the actual Plant list in custom Order
|
* Method to get the actual Plant list in custom Order
|
||||||
*
|
* @param zone selected hardiness zone
|
||||||
* @param zone selected hardiness zone
|
|
||||||
* @param comparator comparator to sort the list
|
* @param comparator comparator to sort the list
|
||||||
* @return sorted list with plants in the given hardiness zone
|
* @return sorted list with plants in the given hardiness zone
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
||||||
*/
|
*/
|
||||||
public List<Plant> getSortedPlantList(HardinessZone zone, Comparator<Plant> comparator) throws HardinessZoneNotSetException, IOException {
|
public List<Plant> getSortedPlantList(HardinessZone zone, Comparator<Plant> comparator) throws HardinessZoneNotSetException, IOException {
|
||||||
|
@ -77,11 +75,10 @@ public class PlantListModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get Filtered plant list
|
* Method to get Filtered plant list
|
||||||
*
|
|
||||||
* @param predicate predicate to filter the list
|
* @param predicate predicate to filter the list
|
||||||
* @param zone selected hardiness zone
|
* @param zone selected hardiness zone
|
||||||
* @return filterd list with plants in the hardinness zone
|
* @return filterd list with plants in the hardinness zone
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
||||||
*/
|
*/
|
||||||
public List<Plant> getFilteredPlantList(HardinessZone zone, Predicate<Plant> predicate) throws HardinessZoneNotSetException, IOException {
|
public List<Plant> getFilteredPlantList(HardinessZone zone, Predicate<Plant> predicate) throws HardinessZoneNotSetException, IOException {
|
||||||
|
@ -91,11 +88,10 @@ public class PlantListModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to get Filtered plant list by id by exact match
|
* Method to get Filtered plant list by id by exact match
|
||||||
*
|
|
||||||
* @param zone selected hardiness zone
|
* @param zone selected hardiness zone
|
||||||
* @param id id of plant
|
* @param id id of plant
|
||||||
* @return if id doesn't exist: empty List, else list with 1 plant entry.
|
* @return if id doesn't exist: empty List, else list with 1 plant entry.
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
||||||
*/
|
*/
|
||||||
public List<Plant> getFilteredPlantListById(HardinessZone zone, Long id) throws HardinessZoneNotSetException, IOException {
|
public List<Plant> getFilteredPlantListById(HardinessZone zone, Long id) throws HardinessZoneNotSetException, IOException {
|
||||||
|
@ -106,68 +102,41 @@ public class PlantListModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param zone selected hardiness zone
|
*
|
||||||
|
* @param zone selected hardiness zone
|
||||||
* @param searchString the string to search plant List, set '#' as first char the search by id.
|
* @param searchString the string to search plant List, set '#' as first char the search by id.
|
||||||
* @return List of plants found in Plant List which contain the search String in the name or description
|
* @return List of plants found in Plant List which contain the search String in the name or description
|
||||||
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public List<Plant> getFilteredPlantListByString(HardinessZone zone, String searchString) throws HardinessZoneNotSetException, IOException {
|
public List<Plant> getFilteredPlantListByString(HardinessZone zone, String searchString) throws HardinessZoneNotSetException, IOException {
|
||||||
if (searchString.length() == 0) {
|
if(searchString.length() == 0){
|
||||||
return getPlantList(zone);
|
return getPlantList(zone);
|
||||||
} else if (searchString.charAt(0) == '#') {
|
} else if(searchString.charAt(0) == '#') {
|
||||||
try {
|
try {
|
||||||
return getFilteredPlantListById(zone, Long.parseLong(searchString.substring(1)));
|
return getFilteredPlantListById(zone, Long.parseLong(searchString.substring(1)));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String caseInsensitiveSearchString = searchString.toLowerCase();
|
return getFilteredPlantList(zone, plant -> plant.name().contains(searchString) || plant.description().contains(searchString));
|
||||||
return getFilteredPlantList(zone, plant ->
|
|
||||||
plant.name().toLowerCase().contains(caseInsensitiveSearchString) ||
|
|
||||||
plant.description().toLowerCase().contains(caseInsensitiveSearchString)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @param type GrowPhaseType to filter
|
* @param type GrowPhaseType to filter
|
||||||
* @param zone selected hardiness zone
|
* @param zone selected hardiness zone
|
||||||
* @param from the earliest date to for the filter
|
* @param from the earliest date to for the filter
|
||||||
* @param to the lastest date for the filter
|
* @param to the lastest date for the filter
|
||||||
* @return List of Plants with selected saison
|
* @return List of Plants with selected saison
|
||||||
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
private List<Plant> getFilteredPlantListBySaison(GrowthPhaseType type, HardinessZone zone, MonthDay from, MonthDay to) throws HardinessZoneNotSetException, IOException {
|
private List<Plant> getFilteredPlantListBySaison(GrowthPhaseType type, HardinessZone zone, MonthDay from, MonthDay to) throws HardinessZoneNotSetException, IOException {
|
||||||
return getFilteredPlantList(zone, plant -> plant.lifecycle().stream().anyMatch(growthPhase -> growthPhase.startDate().compareTo(from) >= 0 && (growthPhase.startDate().compareTo(to) <= 0) && growthPhase.type() == type));
|
return getFilteredPlantList(zone, plant -> plant.lifecycle().stream().anyMatch(growthPhase -> growthPhase.startDate().compareTo(from) >= 0 && (growthPhase.startDate().compareTo(to) <= 0) && growthPhase.type() == type));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param zone selected hardiness zone
|
|
||||||
* @param from the earliest date to for the filter
|
|
||||||
* @param to the lastest date for the filter
|
|
||||||
* @return List of Plants with selected saison
|
|
||||||
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
|
||||||
* @throws IOException If the database cannot be accessed
|
|
||||||
*/
|
|
||||||
public List<Plant> getFilteredPlantListByPlantingSaison(HardinessZone zone, MonthDay from, MonthDay to) throws HardinessZoneNotSetException, IOException {
|
|
||||||
return getFilteredPlantListBySaison(GrowthPhaseType.PLANT, zone, from, to);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param zone selected hardiness zone
|
|
||||||
* @param from the earliest date to for the filter
|
|
||||||
* @param to the lastest date for the filter
|
|
||||||
* @return List of Plants with selected saison
|
|
||||||
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
|
||||||
* @throws IOException If the database cannot be accessed
|
|
||||||
*/
|
|
||||||
public List<Plant> getFilteredPlantListByHarvestSaison(HardinessZone zone, MonthDay from, MonthDay to) throws HardinessZoneNotSetException, IOException {
|
|
||||||
return getFilteredPlantListBySaison(GrowthPhaseType.HARVEST, zone, from, to);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param zone selected hardiness zone
|
* @param zone selected hardiness zone
|
||||||
|
@ -177,7 +146,20 @@ public class PlantListModel {
|
||||||
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
||||||
* @throws IOException If the database cannot be accessed
|
* @throws IOException If the database cannot be accessed
|
||||||
*/
|
*/
|
||||||
public List<Plant> getFilteredPlantListBySaisonWithoutGrowthPhase(HardinessZone zone, MonthDay from, MonthDay to) throws HardinessZoneNotSetException, IOException {
|
public List<Plant> getFilteredPlantListByPlantingSaison(HardinessZone zone, MonthDay from, MonthDay to) throws HardinessZoneNotSetException, IOException {
|
||||||
return getFilteredPlantList(zone, plant -> plant.lifecycle().stream().anyMatch(growthPhase -> growthPhase.startDate().compareTo(from) >= 0 && (growthPhase.startDate().compareTo(to) <= 0)));
|
return getFilteredPlantListBySaison(GrowthPhaseType.PLANT, zone, from, to);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param zone selected hardiness zone
|
||||||
|
* @param from the earliest date to for the filter
|
||||||
|
* @param to the lastest date for the filter
|
||||||
|
* @return List of Plants with selected saison
|
||||||
|
* @throws HardinessZoneNotSetException If no {@link HardinessZone} was specified
|
||||||
|
* @throws IOException If the database cannot be accessed
|
||||||
|
*/
|
||||||
|
public List<Plant> getFilteredPlantListByHarvestSaison(HardinessZone zone, MonthDay from, MonthDay to) throws HardinessZoneNotSetException, IOException {
|
||||||
|
return getFilteredPlantListBySaison(GrowthPhaseType.HARVEST, zone, from, to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
package ch.zhaw.gartenverwaltung.types;
|
|
||||||
|
|
||||||
import java.time.MonthDay;
|
|
||||||
|
|
||||||
public enum Seasons {
|
|
||||||
AllSEASONS("--01-01", "--12-31"),
|
|
||||||
SPRING("--03-01", "--05-30"),
|
|
||||||
SOMMER("--06-01", "--08-30"),
|
|
||||||
AUTUM("--09-01", "--11-30"),
|
|
||||||
WINTER("--12-01", "--02-28");
|
|
||||||
|
|
||||||
public final String startDate;
|
|
||||||
public final String endDate;
|
|
||||||
|
|
||||||
Seasons(String startDate, String endDate) {
|
|
||||||
this.startDate = startDate;
|
|
||||||
this.endDate = endDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MonthDay getStartDate() {
|
|
||||||
return MonthDay.parse(this.startDate);
|
|
||||||
}
|
|
||||||
public MonthDay getEndDate() {
|
|
||||||
return MonthDay.parse(this.endDate);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,6 +3,7 @@
|
||||||
<?import javafx.geometry.Insets?>
|
<?import javafx.geometry.Insets?>
|
||||||
<?import javafx.geometry.Rectangle2D?>
|
<?import javafx.geometry.Rectangle2D?>
|
||||||
<?import javafx.scene.control.Button?>
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.CheckBox?>
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.control.ListView?>
|
<?import javafx.scene.control.ListView?>
|
||||||
<?import javafx.scene.control.SplitPane?>
|
<?import javafx.scene.control.SplitPane?>
|
||||||
|
@ -15,9 +16,8 @@
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?import javafx.scene.text.Font?>
|
||||||
|
|
||||||
<AnchorPane maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="1000.0" prefHeight="853.0"
|
<AnchorPane maxHeight="-Infinity" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="1000.0" prefHeight="853.0" prefWidth="1219.0"
|
||||||
prefWidth="1219.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1"
|
xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.gartenverwaltung.PlantsController">
|
||||||
fx:controller="ch.zhaw.gartenverwaltung.PlantsController">
|
|
||||||
<children>
|
<children>
|
||||||
<SplitPane dividerPositions="0.7377363661277062" layoutX="539.0" layoutY="266.0" prefHeight="853.0" prefWidth="1219.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
<SplitPane dividerPositions="0.7377363661277062" layoutX="539.0" layoutY="266.0" prefHeight="853.0" prefWidth="1219.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
<items>
|
<items>
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
<Font name="System Bold" size="30.0" />
|
<Font name="System Bold" size="30.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<TextField fx:id="search_plants" promptText="Search for Plant Name" />
|
<TextField fx:id="search_plants" onInputMethodTextChanged="#searchForPlant" promptText="Search for Plant Name" />
|
||||||
<HBox alignment="CENTER_LEFT" prefHeight="480.0" prefWidth="881.0" VBox.vgrow="ALWAYS">
|
<HBox alignment="CENTER_LEFT" prefHeight="480.0" prefWidth="881.0" VBox.vgrow="ALWAYS">
|
||||||
<children>
|
<children>
|
||||||
<ListView fx:id="list_plants" maxWidth="1.7976931348623157E308" prefHeight="497.0" prefWidth="580.0" HBox.hgrow="ALWAYS" />
|
<ListView fx:id="list_plants" maxWidth="1.7976931348623157E308" prefHeight="497.0" prefWidth="580.0" HBox.hgrow="ALWAYS" />
|
||||||
|
@ -75,7 +75,30 @@
|
||||||
<content>
|
<content>
|
||||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||||
<children>
|
<children>
|
||||||
<VBox fx:id="seasons" layoutX="37.0" layoutY="-19.0" prefHeight="180.66666666666666" prefWidth="310.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
<VBox layoutX="37.0" layoutY="-19.0" prefHeight="180.66666666666666" prefWidth="310.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
|
<children>
|
||||||
|
<CheckBox fx:id="spring_filter" mnemonicParsing="false" onAction="#filterSpring" text="Spring">
|
||||||
|
<padding>
|
||||||
|
<Insets top="10.0" />
|
||||||
|
</padding>
|
||||||
|
</CheckBox>
|
||||||
|
<CheckBox fx:id="sommer_filter" mnemonicParsing="false" onAction="#filterSommer" text="Sommer">
|
||||||
|
<padding>
|
||||||
|
<Insets top="10.0" />
|
||||||
|
</padding>
|
||||||
|
</CheckBox>
|
||||||
|
<CheckBox fx:id="autum_filter" mnemonicParsing="false" onAction="#filterAutum" text="Autum">
|
||||||
|
<padding>
|
||||||
|
<Insets top="10.0" />
|
||||||
|
</padding>
|
||||||
|
</CheckBox>
|
||||||
|
<CheckBox fx:id="winter_filter" mnemonicParsing="false" onAction="#filterWinter" text="Winter">
|
||||||
|
<padding>
|
||||||
|
<Insets top="10.0" />
|
||||||
|
</padding>
|
||||||
|
</CheckBox>
|
||||||
|
</children>
|
||||||
|
</VBox>
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
</content>
|
</content>
|
||||||
|
|
Loading…
Reference in New Issue