diff --git a/src/main/java/ch/zhaw/gartenverwaltung/Main.java b/src/main/java/ch/zhaw/gartenverwaltung/Main.java index f757926..65aed31 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/Main.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/Main.java @@ -13,30 +13,46 @@ import javafx.stage.Stage; import java.io.IOException; import java.util.Timer; +/** + * Main class of the Application + */ public class Main extends Application { Timer backGroundTaskTimer = new Timer(); BackgroundTasks backgroundTasks; + /** + * Method which is automatically called if Application is starting. It loads the scenes to stage and shows the stage. + * It creates a new Instance of BackgroundTasks and schedules them with a Timer instance to execute them every minute. + * @param stage Stage to show + * @throws IOException If loading Scenes can not access the fxml Resource File + */ @Override public void start(Stage stage) throws IOException { AppLoader appLoader = new AppLoader(); - backgroundTasks = new BackgroundTasks((TaskList) appLoader.getAppDependency(TaskList.class),(CropList) appLoader.getAppDependency(CropList.class), (PlantList) appLoader.getAppDependency(PlantList.class)); - appLoader.loadSceneToStage("MainFXML.fxml", stage); stage.setTitle("Gartenverwaltung"); stage.show(); + backgroundTasks = new BackgroundTasks((TaskList) appLoader.getAppDependency(TaskList.class),(CropList) appLoader.getAppDependency(CropList.class), (PlantList) appLoader.getAppDependency(PlantList.class)); backGroundTaskTimer.scheduleAtFixedRate(backgroundTasks, 0, 60000); } + /** + * Method which is automatically called when application is stopped. + * It cancels the timer to not execute the background tasks anymore. + */ @Override public void stop(){ backGroundTaskTimer.cancel(); } + /** + * The Main method launches the application + * @param args There are no arguments needed. + */ public static void main(String[] args) { launch(); } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java index 261f675..e0071a0 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/backgroundtasks/BackgroundTasks.java @@ -55,19 +55,19 @@ public class BackgroundTasks extends TimerTask { movePastTasks(); } catch (IOException e) { e.printStackTrace(); - LOG.log(Level.SEVERE, "Could not execute Background Task: move past Tasks ", e.getCause()); + LOG.log(Level.WARNING, "Could not execute Background Task: move past Tasks ", e.getCause()); } try { weatherGardenTaskPlaner.refreshTasks(); } catch (IOException | HardinessZoneNotSetException | PlantNotFoundException e) { e.printStackTrace(); - LOG.log(Level.SEVERE, "Could not execute Background Task: Refresh Tasks by WeatherGardenTaskPlaner ", e.getCause()); + LOG.log(Level.WARNING, "Could not execute Background Task: Refresh Tasks by WeatherGardenTaskPlaner ", e.getCause()); } try { notifier.sendNotifications(); } catch (IOException | MessagingException | HardinessZoneNotSetException e) { e.printStackTrace(); - LOG.log(Level.SEVERE, "Could not execute Background Task: send Notification for due Tasks", e.getCause()); + LOG.log(Level.WARNING, "Could not execute Background Task: send Notification for due Tasks", e.getCause()); } } } diff --git a/src/main/java/ch/zhaw/gartenverwaltung/bootstrap/AppLoader.java b/src/main/java/ch/zhaw/gartenverwaltung/bootstrap/AppLoader.java index 9397a3c..b6c8d6a 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/bootstrap/AppLoader.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/bootstrap/AppLoader.java @@ -1,5 +1,6 @@ package ch.zhaw.gartenverwaltung.bootstrap; +import ch.zhaw.gartenverwaltung.CropDetailController; import ch.zhaw.gartenverwaltung.Main; import ch.zhaw.gartenverwaltung.io.*; import ch.zhaw.gartenverwaltung.models.Garden; @@ -17,12 +18,15 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Class responsible for bootstrapping the application wide dependencies * and injecting them into JavaFX Controllers. */ public class AppLoader { + private static final Logger LOG = Logger.getLogger(CropDetailController.class.getName()); /** * Caching the panes */ @@ -146,7 +150,7 @@ public class AppLoader { try { afterInjectMethod.invoke(controller); } catch (IllegalAccessException | InvocationTargetException e) { - // TODO: Log + LOG.log(Level.SEVERE, "Could not invoke afterInjectMethod", e.getCause()); e.printStackTrace(); } }); diff --git a/src/main/java/ch/zhaw/gartenverwaltung/models/PlantListModel.java b/src/main/java/ch/zhaw/gartenverwaltung/models/PlantListModel.java index 19cce96..33627c9 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/models/PlantListModel.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/models/PlantListModel.java @@ -1,5 +1,6 @@ package ch.zhaw.gartenverwaltung.models; +import ch.zhaw.gartenverwaltung.Settings; import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException; import ch.zhaw.gartenverwaltung.io.PlantList; import ch.zhaw.gartenverwaltung.types.GrowthPhaseType; @@ -16,7 +17,6 @@ import java.util.stream.Collectors; public class PlantListModel { private final PlantList plantList; - private HardinessZone currentZone; /** * Comparators to create sorted Plant List @@ -33,15 +33,15 @@ public class PlantListModel { } private void setDefaultZone() { - currentZone = HardinessZone.ZONE_8A; // TODO: get Default Zone from Settings + Settings.getInstance().setCurrentHardinessZone(null); } public void setCurrentZone(HardinessZone currentZone) { - this.currentZone = currentZone; + Settings.getInstance().setCurrentHardinessZone(currentZone); } public HardinessZone getCurrentZone() { - return currentZone; + return Settings.getInstance().getCurrentHardinessZone(); } /** diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java index dd92412..d1a0905 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Plant.java @@ -68,7 +68,7 @@ public record Plant( return growthPhase.group(); } } - return 0; // TODO implement + return 0; } /** diff --git a/src/test/java/ch/zhaw/gartenverwaltung/models/PlantListModelTest.java b/src/test/java/ch/zhaw/gartenverwaltung/models/PlantListModelTest.java index 5f71e1f..19b68e8 100644 --- a/src/test/java/ch/zhaw/gartenverwaltung/models/PlantListModelTest.java +++ b/src/test/java/ch/zhaw/gartenverwaltung/models/PlantListModelTest.java @@ -101,7 +101,7 @@ class PlantListModelTest { @Test void setCurrentZone() { - checkCurrentZone(HardinessZone.ZONE_8A); // TODO change to get default zone from config + checkCurrentZone(HardinessZone.ZONE_8A); model.setCurrentZone(HardinessZone.ZONE_1A); checkCurrentZone(HardinessZone.ZONE_1A); model.setCurrentZone(HardinessZone.ZONE_8A);