Javadocs and code cleanup

This commit is contained in:
schrom01 2022-12-11 14:57:59 +01:00
parent 27b8d1754e
commit 7741569659
6 changed files with 32 additions and 12 deletions

View File

@ -13,30 +13,46 @@ import javafx.stage.Stage;
import java.io.IOException; import java.io.IOException;
import java.util.Timer; import java.util.Timer;
/**
* Main class of the Application
*/
public class Main extends Application { public class Main extends Application {
Timer backGroundTaskTimer = new Timer(); Timer backGroundTaskTimer = new Timer();
BackgroundTasks backgroundTasks; 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 @Override
public void start(Stage stage) throws IOException { public void start(Stage stage) throws IOException {
AppLoader appLoader = new AppLoader(); 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); appLoader.loadSceneToStage("MainFXML.fxml", stage);
stage.setTitle("Gartenverwaltung"); stage.setTitle("Gartenverwaltung");
stage.show(); 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); 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 @Override
public void stop(){ public void stop(){
backGroundTaskTimer.cancel(); backGroundTaskTimer.cancel();
} }
/**
* The Main method launches the application
* @param args There are no arguments needed.
*/
public static void main(String[] args) { public static void main(String[] args) {
launch(); launch();
} }

View File

@ -55,19 +55,19 @@ public class BackgroundTasks extends TimerTask {
movePastTasks(); movePastTasks();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); 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 { try {
weatherGardenTaskPlaner.refreshTasks(); weatherGardenTaskPlaner.refreshTasks();
} catch (IOException | HardinessZoneNotSetException | PlantNotFoundException e) { } catch (IOException | HardinessZoneNotSetException | PlantNotFoundException e) {
e.printStackTrace(); 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 { try {
notifier.sendNotifications(); notifier.sendNotifications();
} catch (IOException | MessagingException | HardinessZoneNotSetException e) { } catch (IOException | MessagingException | HardinessZoneNotSetException e) {
e.printStackTrace(); 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());
} }
} }
} }

View File

@ -1,5 +1,6 @@
package ch.zhaw.gartenverwaltung.bootstrap; package ch.zhaw.gartenverwaltung.bootstrap;
import ch.zhaw.gartenverwaltung.CropDetailController;
import ch.zhaw.gartenverwaltung.Main; import ch.zhaw.gartenverwaltung.Main;
import ch.zhaw.gartenverwaltung.io.*; import ch.zhaw.gartenverwaltung.io.*;
import ch.zhaw.gartenverwaltung.models.Garden; import ch.zhaw.gartenverwaltung.models.Garden;
@ -17,12 +18,15 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Class responsible for bootstrapping the application wide dependencies * Class responsible for bootstrapping the application wide dependencies
* and injecting them into JavaFX Controllers. * and injecting them into JavaFX Controllers.
*/ */
public class AppLoader { public class AppLoader {
private static final Logger LOG = Logger.getLogger(CropDetailController.class.getName());
/** /**
* Caching the panes * Caching the panes
*/ */
@ -146,7 +150,7 @@ public class AppLoader {
try { try {
afterInjectMethod.invoke(controller); afterInjectMethod.invoke(controller);
} catch (IllegalAccessException | InvocationTargetException e) { } catch (IllegalAccessException | InvocationTargetException e) {
// TODO: Log LOG.log(Level.SEVERE, "Could not invoke afterInjectMethod", e.getCause());
e.printStackTrace(); e.printStackTrace();
} }
}); });

View File

@ -1,5 +1,6 @@
package ch.zhaw.gartenverwaltung.models; package ch.zhaw.gartenverwaltung.models;
import ch.zhaw.gartenverwaltung.Settings;
import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException; import ch.zhaw.gartenverwaltung.io.HardinessZoneNotSetException;
import ch.zhaw.gartenverwaltung.io.PlantList; import ch.zhaw.gartenverwaltung.io.PlantList;
import ch.zhaw.gartenverwaltung.types.GrowthPhaseType; import ch.zhaw.gartenverwaltung.types.GrowthPhaseType;
@ -16,7 +17,6 @@ import java.util.stream.Collectors;
public class PlantListModel { public class PlantListModel {
private final PlantList plantList; private final PlantList plantList;
private HardinessZone currentZone;
/** /**
* Comparators to create sorted Plant List * Comparators to create sorted Plant List
@ -33,15 +33,15 @@ public class PlantListModel {
} }
private void setDefaultZone() { private void setDefaultZone() {
currentZone = HardinessZone.ZONE_8A; // TODO: get Default Zone from Settings Settings.getInstance().setCurrentHardinessZone(null);
} }
public void setCurrentZone(HardinessZone currentZone) { public void setCurrentZone(HardinessZone currentZone) {
this.currentZone = currentZone; Settings.getInstance().setCurrentHardinessZone(currentZone);
} }
public HardinessZone getCurrentZone() { public HardinessZone getCurrentZone() {
return currentZone; return Settings.getInstance().getCurrentHardinessZone();
} }
/** /**

View File

@ -68,7 +68,7 @@ public record Plant(
return growthPhase.group(); return growthPhase.group();
} }
} }
return 0; // TODO implement return 0;
} }
/** /**

View File

@ -101,7 +101,7 @@ class PlantListModelTest {
@Test @Test
void setCurrentZone() { void setCurrentZone() {
checkCurrentZone(HardinessZone.ZONE_8A); // TODO change to get default zone from config checkCurrentZone(HardinessZone.ZONE_8A);
model.setCurrentZone(HardinessZone.ZONE_1A); model.setCurrentZone(HardinessZone.ZONE_1A);
checkCurrentZone(HardinessZone.ZONE_1A); checkCurrentZone(HardinessZone.ZONE_1A);
model.setCurrentZone(HardinessZone.ZONE_8A); model.setCurrentZone(HardinessZone.ZONE_8A);