Compare commits
No commits in common. "96fdc641058653a8acf28301066a5476ca28836c" and "efc95dbcc6233bc657a9d33603c038438ae4f918" have entirely different histories.
96fdc64105
...
efc95dbcc6
|
@ -20,6 +20,7 @@ import javafx.scene.Scene;
|
|||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
|
@ -54,17 +55,17 @@ public class PlantsController implements Initializable {
|
|||
private ListView<Plant> list_plants;
|
||||
|
||||
@FXML
|
||||
private Button selectSowDay_button;
|
||||
private Button saveToMyPlant_button;
|
||||
|
||||
@FXML
|
||||
private TextField search_plants;
|
||||
|
||||
/**
|
||||
* open new window to select sow or harvest day to save the crop
|
||||
* saves the current selected plant in new JSON database
|
||||
* @param event event
|
||||
*/
|
||||
@FXML
|
||||
void selectSowDate(ActionEvent event) throws IOException {
|
||||
void saveToMyPlant(ActionEvent event) throws IOException {
|
||||
Parent root;
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(Objects.requireNonNull(getClass().getResource("SelectSowDay.fxml")));
|
||||
root = fxmlLoader.load();
|
||||
|
@ -91,7 +92,7 @@ public class PlantsController implements Initializable {
|
|||
list_plants.itemsProperty().bind(plantListProperty);
|
||||
|
||||
description_plant.setText("");
|
||||
selectSowDay_button.setDisable(true);
|
||||
saveToMyPlant_button.setDisable(true);
|
||||
|
||||
createFilterSeasons();
|
||||
createFilterHardinessZone();
|
||||
|
@ -201,7 +202,7 @@ public class PlantsController implements Initializable {
|
|||
private void createFilterSeasons() {
|
||||
ToggleGroup seasonGroup = new ToggleGroup();
|
||||
for (Seasons season : Seasons.values()) {
|
||||
RadioButton radioButton = new RadioButton(season.getName());
|
||||
RadioButton radioButton = new RadioButton(season.name());
|
||||
radioButton.setToggleGroup(seasonGroup);
|
||||
radioButton.setPadding(new Insets(0,0,10,0));
|
||||
if (season.equals(Seasons.AllSEASONS)) {
|
||||
|
@ -232,18 +233,13 @@ public class PlantsController implements Initializable {
|
|||
* image of the plant
|
||||
*/
|
||||
private void lookForSelectedListEntry() {
|
||||
selectedPlant = null;
|
||||
description_plant.setText("");
|
||||
selectSowDay_button.setDisable(true);
|
||||
Image img = new Image(String.valueOf(PlantsController.class.getResource("placeholder.png")));
|
||||
img_plant.setImage(img);
|
||||
list_plants.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Plant>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Plant> observable, Plant oldValue, Plant newValue) {
|
||||
if(newValue != null) {
|
||||
selectedPlant = newValue;
|
||||
description_plant.setText(selectedPlant.description());
|
||||
selectSowDay_button.setDisable(false);
|
||||
saveToMyPlant_button.setDisable(false);
|
||||
Image img;
|
||||
if(selectedPlant.image() != null) {
|
||||
img = selectedPlant.image();
|
||||
|
@ -251,10 +247,12 @@ public class PlantsController implements Initializable {
|
|||
img = new Image(String.valueOf(PlantsController.class.getResource("placeholder.png")));
|
||||
}
|
||||
img_plant.setImage(img);
|
||||
|
||||
|
||||
} else {
|
||||
selectedPlant = null;
|
||||
description_plant.setText("");
|
||||
selectSowDay_button.setDisable(true);
|
||||
saveToMyPlant_button.setDisable(true);
|
||||
Image img = new Image(String.valueOf(PlantsController.class.getResource("placeholder.png")));
|
||||
img_plant.setImage(img);
|
||||
}
|
||||
|
|
|
@ -31,50 +31,31 @@ public class SelectSowDayController implements Initializable {
|
|||
@FXML
|
||||
private RadioButton sow_radio;
|
||||
|
||||
/**
|
||||
* close the date selector window
|
||||
* @param event event
|
||||
*/
|
||||
@FXML
|
||||
void cancel(ActionEvent event) {
|
||||
closeWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
* get sow date from datePicker or calculate sow date from harvest date
|
||||
* save selected plant and sow date
|
||||
* @param event event
|
||||
*/
|
||||
@FXML
|
||||
void save(ActionEvent event) {
|
||||
//ToDo save plant and sow date to crop/gardenplan model
|
||||
LocalDate sowDate;
|
||||
System.out.println(selectedPlant);
|
||||
if (sow_radio.isSelected()) {
|
||||
sowDate = datepicker.getValue();
|
||||
System.out.println(datepicker.getValue());
|
||||
} else {
|
||||
//ToDo method to get current lifecycle group in plant
|
||||
sowDate = selectedPlant.sowDateFromHarvestDate(datepicker.getValue(), 0);
|
||||
//ToDo error when
|
||||
//what's up with that group thing in life_cycle we have hardiness zone for that
|
||||
System.out.println(selectedPlant.sowDateFromHarvestDate(datepicker.getValue(), 0));
|
||||
}
|
||||
System.out.println(sowDate);
|
||||
System.out.println(selectedPlant);
|
||||
closeWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
* save the plant which will be planted and update label
|
||||
* @param plant Plant
|
||||
*/
|
||||
public void getSelectedPlant(Plant plant) {
|
||||
selectedPlant = plant;
|
||||
popup_label.setText("Select Harvest/Sow Date for" + selectedPlant.name());
|
||||
}
|
||||
|
||||
/**
|
||||
* add listener and set default values
|
||||
* {@inheritDoc}
|
||||
* @param location location
|
||||
* @param resources resources
|
||||
*/
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
clearDatePickerEntries();
|
||||
|
@ -86,9 +67,6 @@ public class SelectSowDayController implements Initializable {
|
|||
enableDisableSaveButton();
|
||||
}
|
||||
|
||||
/**
|
||||
* clear date picker editor when radio button is changed
|
||||
*/
|
||||
private void clearDatePickerEntries() {
|
||||
sow_radio.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||
@Override
|
||||
|
@ -98,10 +76,6 @@ public class SelectSowDayController implements Initializable {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* date picker disable/enable dates according to selected plant: sow or harvest day
|
||||
* @return cellFactory of datePicker
|
||||
*/
|
||||
private Callback<DatePicker, DateCell> getDayCellFactory() {
|
||||
|
||||
final Callback<DatePicker, DateCell> dayCellFactory = new Callback<DatePicker, DateCell>() {
|
||||
|
@ -129,10 +103,6 @@ public class SelectSowDayController implements Initializable {
|
|||
setStyle("-fx-background-color: #32CD32;");
|
||||
}
|
||||
}
|
||||
if ((!sow_radio.isSelected() && selectedPlant.sowDateFromHarvestDate(item, 0).compareTo(today) < 0)) {
|
||||
setDisable(true);
|
||||
setStyle("-fx-background-color: #ffc0cb;");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -140,17 +110,11 @@ public class SelectSowDayController implements Initializable {
|
|||
return dayCellFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* close date picker window
|
||||
*/
|
||||
private void closeWindow() {
|
||||
Stage stage = (Stage) save_button.getScene().getWindow();
|
||||
stage.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* disable save button, when there is no date selected in date picker
|
||||
*/
|
||||
private void enableDisableSaveButton() {
|
||||
save_button.setDisable(true);
|
||||
datepicker.getEditor().textProperty().addListener(new ChangeListener<String>() {
|
||||
|
|
|
@ -20,40 +20,20 @@ public record Plant(
|
|||
List<Pest> pests,
|
||||
List<GrowthPhase> lifecycle) {
|
||||
|
||||
/**
|
||||
* remove all growthPhase which do not belong to the hardiness zone
|
||||
* @param zone hardiness zone
|
||||
*/
|
||||
public void inZone(HardinessZone zone) {
|
||||
lifecycle.removeIf(growthPhase -> !growthPhase.zone().equals(zone));
|
||||
}
|
||||
|
||||
/**
|
||||
* get all growthPhases of lifecycle group
|
||||
* @param group lifecycle group
|
||||
* @return list of growthPhases
|
||||
*/
|
||||
public List<GrowthPhase> lifecycleForGroup(int group) {
|
||||
return lifecycle.stream()
|
||||
.filter(growthPhase -> growthPhase.group() == group)
|
||||
.filter(growthPhase -> growthPhase.group() != group)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* get sow date from given harvest day from lifecycle group
|
||||
* @param harvestDate date of the harvest
|
||||
* @param group lifecycle group
|
||||
* @return LocaleDate of sow date
|
||||
*/
|
||||
public LocalDate sowDateFromHarvestDate(LocalDate harvestDate, int group) {
|
||||
return harvestDate.minusDays(timeToHarvest(group));
|
||||
}
|
||||
|
||||
/**
|
||||
* calculate the days between sow and harvest day for lifecycle group
|
||||
* @param group the lifecycle group
|
||||
* @return Integer number of dates between sow and harvest day
|
||||
*/
|
||||
public int timeToHarvest(int group) {
|
||||
List<GrowthPhase> activeLifecycle = lifecycleForGroup(group);
|
||||
GrowthPhase sow = activeLifecycle.stream()
|
||||
|
@ -69,12 +49,6 @@ public record Plant(
|
|||
return (int) DAYS.between(harvest.startDate().atYear(currentYear), sow.startDate().atYear(currentYear));
|
||||
}
|
||||
|
||||
/**
|
||||
* filter out the given growthPhase out of the lifecycle
|
||||
* create list of dates for this growthPhase and return it
|
||||
* @param growthPhase the wanted growthPhase
|
||||
* @return a list of dates of the current year
|
||||
*/
|
||||
public List<LocalDate> getDateListOfGrowthPhase(GrowthPhaseType growthPhase) {
|
||||
List<LocalDate> dates = new LinkedList<>();
|
||||
for (GrowthPhase growth : lifecycle) {
|
||||
|
@ -82,15 +56,12 @@ public record Plant(
|
|||
dates = addDatesFromMonthDay(growth);
|
||||
}
|
||||
}
|
||||
if (growthPhase.equals(GrowthPhaseType.HARVEST)) {
|
||||
return removeDatesForPassedSowDates(dates);
|
||||
}
|
||||
return dates;
|
||||
}
|
||||
|
||||
/**
|
||||
* transform monthDay value of the given growthPhase to localDate
|
||||
* return a list of dates from start to end of growth phase
|
||||
* @param growthPhase the current growthPhase
|
||||
* @return a list of dates of the current year
|
||||
*/
|
||||
private List<LocalDate> addDatesFromMonthDay(GrowthPhase growthPhase) {
|
||||
List<LocalDate> dates = new LinkedList<>();
|
||||
LocalDate today = LocalDate.now();
|
||||
|
@ -102,4 +73,9 @@ public record Plant(
|
|||
}
|
||||
return dates;
|
||||
}
|
||||
|
||||
private List<LocalDate> removeDatesForPassedSowDates(List<LocalDate> dates) {
|
||||
//ToDo Remove harvest dates where sow dates have already passed current day
|
||||
return dates;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,20 +3,18 @@ package ch.zhaw.gartenverwaltung.types;
|
|||
import java.time.MonthDay;
|
||||
|
||||
public enum Seasons {
|
||||
AllSEASONS("--01-01", "--12-31", "All Seasons"),
|
||||
SPRING("--03-01", "--05-30", "Spring"),
|
||||
SUMMER("--06-01", "--08-30", "Summer"),
|
||||
AUTUMN("--09-01", "--11-30", "Autumn"),
|
||||
WINTER("--12-01", "--02-28", "Winter");
|
||||
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;
|
||||
public final String name;
|
||||
|
||||
Seasons(String startDate, String endDate, String name) {
|
||||
Seasons(String startDate, String endDate) {
|
||||
this.startDate = startDate;
|
||||
this.endDate = endDate;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public MonthDay getStartDate() {
|
||||
|
@ -25,7 +23,4 @@ public enum Seasons {
|
|||
public MonthDay getEndDate() {
|
||||
return MonthDay.parse(this.endDate);
|
||||
}
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.geometry.Rectangle2D?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.scene.control.SplitPane?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.control.TitledPane?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
|
@ -31,8 +33,15 @@
|
|||
<TextField fx:id="search_plants" promptText="Search for Plant Name" />
|
||||
<HBox alignment="CENTER_LEFT" prefHeight="480.0" prefWidth="881.0" VBox.vgrow="ALWAYS">
|
||||
<children>
|
||||
<ListView fx:id="list_plants" maxWidth="1.7976931348623157E308" prefHeight="497.0" prefWidth="400.0" HBox.hgrow="ALWAYS" />
|
||||
<ImageView fx:id="img_plant" fitWidth="300" pickOnBounds="true" preserveRatio="true" HBox.hgrow="NEVER" />
|
||||
<ListView fx:id="list_plants" maxWidth="1.7976931348623157E308" prefHeight="497.0" prefWidth="580.0" HBox.hgrow="ALWAYS" />
|
||||
<ImageView fx:id="img_plant" fitHeight="322.0" fitWidth="861.0" pickOnBounds="true" preserveRatio="true" HBox.hgrow="NEVER">
|
||||
<viewport>
|
||||
<Rectangle2D height="300.0" width="300.0" />
|
||||
</viewport>
|
||||
<image>
|
||||
<Image url="@placeholder.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
</children>
|
||||
</HBox>
|
||||
<Label prefHeight="33.0" prefWidth="919.0" text="Plant Information:">
|
||||
|
@ -48,7 +57,7 @@
|
|||
<Insets bottom="10.0" top="10.0" />
|
||||
</padding>
|
||||
</Label>
|
||||
<Button fx:id="selectSowDay_button" alignment="CENTER" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#selectSowDate" prefHeight="38.0" prefWidth="917.0" text="Select Harvest/Sow Day" />
|
||||
<Button fx:id="saveToMyPlant_button" alignment="CENTER" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#saveToMyPlant" prefHeight="38.0" prefWidth="917.0" text="Save to MyPlants" />
|
||||
</children>
|
||||
</VBox>
|
||||
</children>
|
||||
|
|
|
@ -94,7 +94,6 @@
|
|||
"endDate": "03-10",
|
||||
"zone": "ZONE_8A",
|
||||
"type": "SOW",
|
||||
"group": 0,
|
||||
"wateringCycle": {
|
||||
"litersPerSqM": 15,
|
||||
"interval": 3,
|
||||
|
@ -116,7 +115,6 @@
|
|||
"endDate": "05-10",
|
||||
"zone": "ZONE_8A",
|
||||
"type": "PLANT",
|
||||
"group": 0,
|
||||
"wateringCycle": {
|
||||
"litersPerSqM": 25,
|
||||
"interval": 3,
|
||||
|
@ -140,7 +138,6 @@
|
|||
"endDate": "05-20",
|
||||
"zone": "ZONE_8A",
|
||||
"type": "HARVEST",
|
||||
"group": 0,
|
||||
"wateringCycle": {
|
||||
"litersPerSqM": 0,
|
||||
"interval": null,
|
||||
|
|
Loading…
Reference in New Issue