#12 small changes and java doc
This commit is contained in:
parent
c83b8695ab
commit
5b039eb762
|
@ -14,7 +14,6 @@ import javafx.geometry.Insets;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.input.InputMethodEvent;
|
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -49,18 +48,25 @@ public class PlantsController implements Initializable {
|
||||||
@FXML
|
@FXML
|
||||||
private TextField search_plants;
|
private TextField search_plants;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saves the current selected plant in new JSON database
|
||||||
|
* @param event event
|
||||||
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
void saveToMyPlant(ActionEvent event) {
|
void saveToMyPlant(ActionEvent event) {
|
||||||
//ToDo model save selectedPlant to mySelectedPlant(IO)
|
//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}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
fillPlantListWithDefaultValues();
|
fillPlantListWithHardinessZone();
|
||||||
|
|
||||||
description_plant.setText("");
|
description_plant.setText("");
|
||||||
saveToMyPlant_button.setDisable(true);
|
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 {
|
private void viewFilteredListBySeason(Seasons season) throws HardinessZoneNotSetException, IOException {
|
||||||
List<Plant> plantList = plantListModel.getFilteredPlantListBySaisonWithoutGrowthPhase(plantListModel.getCurrentZone(), season.getStartDate(), season.getEndDate());
|
List<Plant> plantList = plantListModel.getFilteredPlantListBySaisonWithoutGrowthPhase(plantListModel.getCurrentZone(), season.getStartDate(), season.getEndDate());
|
||||||
fillListViewWithData(plantList);
|
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 {
|
private void viewFilteredListBySearch() throws HardinessZoneNotSetException, IOException {
|
||||||
search_plants.textProperty().addListener((observable, oldValue, newValue) -> {
|
search_plants.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
if (newValue.isEmpty()) {
|
if (newValue.isEmpty()) {
|
||||||
fillPlantListWithDefaultValues();
|
fillPlantListWithHardinessZone();
|
||||||
}else {
|
}else {
|
||||||
List<Plant> plantList = new LinkedList<>();
|
List<Plant> plantList = new LinkedList<>();
|
||||||
try {
|
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<>();
|
List<Plant> plantList = new LinkedList<>();
|
||||||
try {
|
try {
|
||||||
plantList = plantListModel.getPlantList(plantListModel.getCurrentZone());
|
plantList = plantListModel.getPlantList(plantListModel.getCurrentZone());
|
||||||
|
@ -130,6 +153,11 @@ public class PlantsController implements Initializable {
|
||||||
fillListViewWithData(plantList);
|
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() {
|
private void createFilterHardinessZone() {
|
||||||
ToggleGroup hardinessGroup = new ToggleGroup();
|
ToggleGroup hardinessGroup = new ToggleGroup();
|
||||||
for (HardinessZone zone : HardinessZone.values()) {
|
for (HardinessZone zone : HardinessZone.values()) {
|
||||||
|
@ -143,13 +171,18 @@ public class PlantsController implements Initializable {
|
||||||
@Override
|
@Override
|
||||||
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
|
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
|
||||||
plantListModel.setCurrentZone(zone);
|
plantListModel.setCurrentZone(zone);
|
||||||
fillPlantListWithDefaultValues();
|
fillPlantListWithHardinessZone();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
climate_zones.getChildren().add(radioButton);
|
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() {
|
private void createFilterSeasons() {
|
||||||
ToggleGroup seasonGroup = new ToggleGroup();
|
ToggleGroup seasonGroup = new ToggleGroup();
|
||||||
for (Seasons season : Seasons.values()) {
|
for (Seasons season : Seasons.values()) {
|
||||||
|
@ -163,7 +196,7 @@ public class PlantsController implements Initializable {
|
||||||
@Override
|
@Override
|
||||||
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
|
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
|
||||||
if (season.equals(Seasons.AllSEASONS)) {
|
if (season.equals(Seasons.AllSEASONS)) {
|
||||||
fillPlantListWithDefaultValues();
|
fillPlantListWithHardinessZone();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
viewFilteredListBySeason(season);
|
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() {
|
private void lookForSelectedListEntry() {
|
||||||
list_plants.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Plant>() {
|
list_plants.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Plant>() {
|
||||||
|
@ -189,9 +224,15 @@ public class PlantsController implements Initializable {
|
||||||
selectedPlant = newValue;
|
selectedPlant = newValue;
|
||||||
description_plant.setText(selectedPlant.description());
|
description_plant.setText(selectedPlant.description());
|
||||||
saveToMyPlant_button.setDisable(false);
|
saveToMyPlant_button.setDisable(false);
|
||||||
//ToDo Uncomment if plant.java can load img
|
Image img;
|
||||||
//Image img = selectedPlant.image();
|
if(selectedPlant.image() != null) {
|
||||||
//img_plant.setImage(img);
|
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("");
|
||||||
|
|
Loading…
Reference in New Issue