JavaDoc for controller classes

This commit is contained in:
giavaphi 2022-12-05 01:56:15 +01:00
parent 0257dd9bf0
commit d725367f4d
11 changed files with 178 additions and 0 deletions

View File

@ -31,6 +31,9 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Controller class for the CropDetail.fxml file
*/
public class CropDetailController {
private Crop crop;
@ -141,6 +144,9 @@ public class CropDetailController {
setCellFactoryTasks();
}
/**
* cell Factory for TaskListView
*/
private void setCellFactoryTasks() {
taskList_listView.setCellFactory(param -> new ListCell<>() {
@Override
@ -158,6 +164,9 @@ public class CropDetailController {
});
}
/**
* cell Factory for PestListView
*/
private void setCellFactoryPests() {
pests_listView.setCellFactory(param -> new ListCell<>() {
@Override
@ -175,6 +184,10 @@ public class CropDetailController {
});
}
/**
* update task list
* @param crop {@link Crop} that is selected
*/
private void setTaskListProperty(Crop crop) {
crop.getCropId().ifPresent(id -> {
List<Task> taskList;
@ -189,6 +202,11 @@ public class CropDetailController {
});
}
/**
* Creates a {@link HBox} for the given {@link Task}.
* @param task {@link Task} which is selected
* @return {@link HBox} that was created
*/
private HBox createTaskHBox(Task task) {
HBox hBox = new HBox(10);
Label taskName = new Label(task.getName()+": ");
@ -215,6 +233,11 @@ public class CropDetailController {
return hBox;
}
/**
* Creates a {@link HBox} for the given {@link Pest}.
* @param pest {@link Pest} which is selected
* @return {@link HBox} that was created
*/
private HBox createPestHBox(Pest pest) {
Label label = new Label(pest.name() + ": ");
label.setStyle("-fx-font-weight: bold");
@ -241,6 +264,11 @@ public class CropDetailController {
button.setGraphic(imageView);
}
/**
* opens dialog of {@link Task} edit.
* @param task {@link Task}
* @return {@link EventHandler} for the case of editing a {@link Task}
*/
private EventHandler<ActionEvent> getEditTaskEvent(Task task) {
return (event) -> {
try {
@ -251,12 +279,24 @@ public class CropDetailController {
};
}
/**
* opens alert of {@link Task} deletion.
* @param task {@link Task}
* @return {@link EventHandler} for the case of deleting a {@link Task}
*/
private EventHandler<ActionEvent> deleteTask(Task task) {
return (event) -> {
showDeleteTask(task);
};
}
/**
* opens a dialog to create a new Task or edit the given Task
* @param newTask boolean if it is a new Task
* @param givenTask {@link Task} which was selected
* @throws IOException Exception
* @throws HardinessZoneNotSetException Exception
*/
private void createTaskDialog(boolean newTask, Task givenTask) throws IOException, HardinessZoneNotSetException {
Dialog<Task> dialog = new Dialog<>();
dialog.setTitle("Set Task");
@ -299,6 +339,10 @@ public class CropDetailController {
}
/**
* opens TextField Dialog to enter the plant area.
* @throws IOException Exception
*/
private void openTextFieldDialog() throws IOException {
Dialog<String> dialog = new Dialog<>();
dialog.setTitle("set Text Area");
@ -329,6 +373,10 @@ public class CropDetailController {
}
}
/**
* Alert to delete Task.
* @param task {@link Task} which is being deleted
*/
private void showDeleteTask(Task task) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Delete " + task.getName());

View File

@ -8,6 +8,9 @@ import javafx.scene.image.ImageView;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Controller class for the Home.fxml file
*/
public class HomeController implements Initializable {
@FXML
@ -34,6 +37,11 @@ public class HomeController implements Initializable {
setImages(imageViewPhilippe, "");
}
/**
* set image to image view
* @param imageView the imageView to update
* @param photoName the file name of the photo
*/
private void setImages(ImageView imageView, String photoName) {
Image img;
if (photoName.equals("")) {

View File

@ -19,6 +19,9 @@ import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Controller class for the MainFXML.fxml file
*/
public class MainFXMLController {
private static final Logger LOG = Logger.getLogger(MainFXMLController.class.getName());
@ -176,6 +179,10 @@ public class MainFXMLController {
tutorial_button.visibleProperty().bind(Settings.getInstance().getShowTutorialProperty());
}
/**
* close Tutorial Window
* @param windowEvent event
*/
private void closeWindowHandler(WindowEvent windowEvent) {
tutorialModal.close();
}

View File

@ -27,6 +27,9 @@ import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Controller class for the MyGarden.fxml file
*/
public class MyGardenController {
private static final Logger LOG = Logger.getLogger(MyGardenController.class.getName());
@Inject

View File

@ -27,6 +27,9 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Controller class for the MySchedule.fxml file
*/
public class MyScheduleController {
private static final Logger LOG = Logger.getLogger(MyScheduleController.class.getName());
private final ListProperty<List<Task>> taskListProperty = new SimpleListProperty<>(FXCollections.observableArrayList());
@ -65,6 +68,9 @@ public class MyScheduleController {
}
}
/**
* sort scheduler to selected crop
*/
private void lookForSelectedListEntries() {
scheduledPlants_listview.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
selectedCrop = newValue;
@ -76,6 +82,9 @@ public class MyScheduleController {
});
}
/**
* set cellFactory for the crops.
*/
private void setCellFactoryCropListView() {
scheduledPlants_listview.setCellFactory(param -> new ListCell<>() {
@Override
@ -98,6 +107,9 @@ public class MyScheduleController {
});
}
/**
* set CallFactory for the given Tasks
*/
private void setCellFactoryTaskListView() {
week_listView.setCellFactory(param -> new ListCell<>() {
@Override
@ -115,6 +127,10 @@ public class MyScheduleController {
});
}
/**
* update task list
* @throws IOException exception
*/
private void loadTaskList() throws IOException {
List<List<Task>> taskLists;
if (selectedCrop != null) {
@ -126,6 +142,12 @@ public class MyScheduleController {
taskListProperty.addAll(taskLists);
}
/**
* Create a {@link VBox} of the given TaskList.
* @param tasks List of {@link Task}s
* @param dayIndex index of the day
* @return {@link VBox} of the given Task of the day
*/
private VBox weekTaskVBox(List<Task> tasks, int dayIndex) {
VBox vBox = new VBox(10);
LocalDate today = LocalDate.now();

View File

@ -28,6 +28,9 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Controller class for the Plants.fxml file
*/
public class PlantsController {
private static final Logger LOG = Logger.getLogger(PlantsController.class.getName());

View File

@ -8,6 +8,10 @@ import javafx.util.Callback;
import java.time.LocalDate;
/**
* Controller class for the SelectSowDay.fxml file
* Gets opened with a dialog.
*/
public class SelectSowDayController {
private Plant selectedPlant;

View File

@ -14,6 +14,9 @@ import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
/**
* Controller class for the Settings.fxml file
*/
public class SettingsController implements Initializable {
Settings settings = Settings.getInstance();
@ -31,6 +34,11 @@ public class SettingsController implements Initializable {
@FXML
private Label location_label;
/**
* open dialog to set location
* @param event event
* @throws IOException exception
*/
@FXML
void setLocation(ActionEvent event) throws IOException {
openTextFieldDialog();
@ -71,6 +79,10 @@ public class SettingsController implements Initializable {
button.setGraphic(imageView);
}
/**
* opens Dialog to set exception
* @throws IOException exception
*/
private void openTextFieldDialog() throws IOException {
Dialog<String> dialog = new Dialog<>();
dialog.setTitle("Set Location of your Garden");

View File

@ -19,6 +19,9 @@ import java.net.URL;
import java.time.LocalDate;
import java.util.ResourceBundle;
/**
* Controller class for the TaskFormular.fxml file
*/
public class TaskFormularController implements Initializable {
private Crop crop;
private Plant plant;
@ -49,6 +52,11 @@ public class TaskFormularController implements Initializable {
@AfterInject
@SuppressWarnings("unused")
/**
* returns the edited or added {@link Task}
* @param crop {@link Crop} which was selected
* @return {@link Task} which was edited or added
*/
public Task returnResult(Crop crop) {
int interval = 0;
if (!(interval_field.getText().isEmpty() || interval_field.getText().equals(""))) {
@ -61,11 +69,21 @@ public class TaskFormularController implements Initializable {
return task;
}
/**
* set selected crop and get the plant from the crop.
* @param crop {@link Crop} which was selected
* @throws HardinessZoneNotSetException exception
* @throws IOException exception
*/
public void setCorp(Crop crop) throws HardinessZoneNotSetException, IOException {
this.crop = crop;
this.plant = plantList.getPlantById(Settings.getInstance().getCurrentHardinessZone(), crop.getPlantId()).get();
}
/**
* set the values of task into the labels and datePicker.
* @param task {@link Task} which was given
*/
public void setTaskValue(Task task) {
this.task = task;
taskName_field.setText(task.getName());
@ -79,6 +97,10 @@ public class TaskFormularController implements Initializable {
}
}
/**
* dayCellFactory of the start date
* @return {@link Callback} of the dayCellFactory
*/
private Callback<DatePicker, DateCell> getDayCellFactoryStartDate() {
return (datePicker) -> new DateCell() {
@ -103,6 +125,10 @@ public class TaskFormularController implements Initializable {
};
}
/**
* dayCellFactory of the end date
* @return {@link Callback} of the dayCellFactory
*/
private Callback<DatePicker, DateCell> getDayCellFactoryEndDate() {
return (datePicker) -> new DateCell() {
@ -127,6 +153,10 @@ public class TaskFormularController implements Initializable {
};
}
/**
* disable button until condition meet.
* @param button {@link Button} which was given
*/
public void initSaveButton(Button button) {
interval_field.textProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue.matches("\\d*")) {
@ -139,6 +169,16 @@ public class TaskFormularController implements Initializable {
.or(description_area.textProperty().isEmpty()));
}
/**
* initialize dayCellFactories
* @param location
* The location used to resolve relative paths for the root object, or
* {@code null} if the location is not known.
*
* @param resources
* The resources used to localize the root object, or {@code null} if
* the root object was not localized.
*/
@Override
public void initialize(URL location, ResourceBundle resources) {
start_datePicker.setDayCellFactory(getDayCellFactoryStartDate());

View File

@ -5,6 +5,9 @@ import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
/**
* Controller class for the TexFieldFormular.fxml file
*/
public class TextFieldFormularController {
@FXML
@ -14,18 +17,34 @@ public class TextFieldFormularController {
private TextField text_area;
/**
* set description label
* @param string string of the description
*/
public void setDescription_label(String string) {
description_label.setText(string);
}
/**
* set text area value
* @param string string of text area value
*/
public void setValueTextArea(String string) {
text_area.setText(string);
}
/**
* return value of text area
* @return string of the tex area
*/
public String getValue() {
return text_area.getText();
}
/**
* Disable Button until condition meet
* @param button {@link Button} which is gets dissabled
*/
public void initSaveButton(Button button) {
text_area.textProperty().addListener((observable, oldValue, newValue) -> {
if (newValue.matches("\\d*\\.?\\d*")) {

View File

@ -8,6 +8,9 @@ import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
* Controller class for the Tutorial.fxml file
*/
public class TutorialController {
@FXML
@ -44,16 +47,25 @@ public class TutorialController {
setButtonAbilities();
}
/**
* disable next or close button according to the location of button
*/
private void setButtonAbilities() {
previousPageButton.setDisable(page <= 0);
nextPageButton.setDisable(page >= tourPages.getChildren().size() - 1);
}
/**
* switch to next view
*/
private void switchViews() {
tourPages.getChildren().forEach(node -> node.setOpacity(0));
tourPages.getChildren().get(page).setOpacity(1);
}
/**
* close Tutorial
*/
public void closeTutorial() {
Stage root = (Stage) tourPages.getScene().getWindow();
root.close();