From 0f92aa9b7637d4d937d135de758dc6efe5beb4f6 Mon Sep 17 00:00:00 2001 From: Cole Manning // RVRX Date: Thu, 15 Jul 2021 21:04:07 -0400 Subject: [PATCH 01/27] add timer end field, #72 --- .../goistreamtoolredux/controller/TimerPane.java | 12 ++++++------ .../resources/goistreamtoolredux/fxml/TimerPane.fxml | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/goistreamtoolredux/controller/TimerPane.java b/src/main/java/goistreamtoolredux/controller/TimerPane.java index 38ec322..4d40cb4 100644 --- a/src/main/java/goistreamtoolredux/controller/TimerPane.java +++ b/src/main/java/goistreamtoolredux/controller/TimerPane.java @@ -1,9 +1,6 @@ package goistreamtoolredux.controller; -import com.jfoenix.controls.JFXButton; -import com.jfoenix.controls.JFXSnackbar; -import com.jfoenix.controls.JFXSnackbarLayout; -import com.jfoenix.controls.JFXToggleButton; +import com.jfoenix.controls.*; import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView; import goistreamtoolredux.App; import goistreamtoolredux.algorithm.FileManager; @@ -56,6 +53,9 @@ public class TimerPane { @FXML // fx:id="timerToggler" private JFXToggleButton timerToggler; // Value injected by FXMLLoader + @FXML // fx:id="timerEndTextField" + private JFXTextField timerEndTextField; // Value injected by FXMLLoader + @FXML // fx:id="timerOneSpinner" private Spinner timerOneSpinner; // Value injected by FXMLLoader @@ -73,8 +73,6 @@ public class TimerPane { - - @FXML void lobbyPauseClicked(MouseEvent event) { LobbyTimer.getInstance().pause(); @@ -226,6 +224,8 @@ public void save(ActionEvent actionEvent) { //todo exception.printStackTrace(); } + + //todo update the finished preference } } diff --git a/src/main/resources/goistreamtoolredux/fxml/TimerPane.fxml b/src/main/resources/goistreamtoolredux/fxml/TimerPane.fxml index f987d9f..666709c 100644 --- a/src/main/resources/goistreamtoolredux/fxml/TimerPane.fxml +++ b/src/main/resources/goistreamtoolredux/fxml/TimerPane.fxml @@ -1,6 +1,7 @@ + @@ -36,6 +37,11 @@ + + + + + From 233a3299dd22d91a12bf4c92923e5a6cdac8668c Mon Sep 17 00:00:00 2001 From: Cole Manning // RVRX Date: Thu, 15 Jul 2021 21:10:51 -0400 Subject: [PATCH 02/27] set timer end text in preference API --- .../java/goistreamtoolredux/controller/TimerPane.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/goistreamtoolredux/controller/TimerPane.java b/src/main/java/goistreamtoolredux/controller/TimerPane.java index 4d40cb4..534ce29 100644 --- a/src/main/java/goistreamtoolredux/controller/TimerPane.java +++ b/src/main/java/goistreamtoolredux/controller/TimerPane.java @@ -70,6 +70,7 @@ public class TimerPane { private static final String TIMER_ONE_LENGTH = "timer_one_length"; private static final String TIMER_TWO_LENGTH = "timer_two_length"; private static final String IS_TIMER_ONE = "is_timer_one"; + private static final String TIMER_END_TEXT = "timer_end_text"; @@ -165,6 +166,9 @@ void initialize() { //init timer 2 spinner initTimerSpinner(timerTwoSpinner, prefs.getInt(TIMER_TWO_LENGTH, 240)); + //init value for end text TextField + timerEndTextField.setText(prefs.get(TIMER_END_TEXT, "0:00")); + } static void initTimerSpinner(Spinner timerSpinner, int initialLength) { @@ -225,7 +229,9 @@ public void save(ActionEvent actionEvent) { exception.printStackTrace(); } - //todo update the finished preference + //update timer end text + prefs.put(TIMER_END_TEXT, timerEndTextField.getText()); + System.out.println("updating end preference: " + prefs.get(TIMER_END_TEXT, "NOT THERE?")); } } From e60c2be1c56f7d4ffc2de5342ebdfb1a40a35aba Mon Sep 17 00:00:00 2001 From: Cole Manning // RVRX Date: Thu, 15 Jul 2021 21:36:50 -0400 Subject: [PATCH 03/27] timer can now resume from custom finished state #72 --- .../goistreamtoolredux/algorithm/LobbyTimer.java | 8 ++++++++ .../java/goistreamtoolredux/algorithm/Timers.java | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/goistreamtoolredux/algorithm/LobbyTimer.java b/src/main/java/goistreamtoolredux/algorithm/LobbyTimer.java index e26e2e7..da4bb11 100644 --- a/src/main/java/goistreamtoolredux/algorithm/LobbyTimer.java +++ b/src/main/java/goistreamtoolredux/algorithm/LobbyTimer.java @@ -4,10 +4,13 @@ import goistreamtoolredux.controller.TimerPane; import java.io.FileNotFoundException; +import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; import java.util.NoSuchElementException; import java.util.Timer; import java.util.TimerTask; +import java.util.prefs.Preferences; /** * Singleton timer class. @@ -136,6 +139,11 @@ public void run() { System.out.println("Timer Finished!\n>"); LobbyTimer.getInstance().isTimerRunning = false; timer.getCurrentTimer().cancel(); + + //set timer text to be the preferred text upon ending + Writer fileWriter = new FileWriter(FileManager.outputPath + "Timer.txt"); + fileWriter.write(Preferences.userRoot().node("/goistreamtoolredux/algorithm").get("timer_end_text","0:00")); + fileWriter.close(); } else { timer.set(currentTime - 1); TimerPane timerPaneController = (TimerPane) App.getMasterController().getTimerPaneController(); diff --git a/src/main/java/goistreamtoolredux/algorithm/Timers.java b/src/main/java/goistreamtoolredux/algorithm/Timers.java index 98003b7..6c5de48 100644 --- a/src/main/java/goistreamtoolredux/algorithm/Timers.java +++ b/src/main/java/goistreamtoolredux/algorithm/Timers.java @@ -82,6 +82,9 @@ public void set(int seconds) throws IOException { * Gets the current value of the timer. * If the timer file is empty or invalid, the file will be fixed, * and the default length (TimerLength.txt will be returned) + * + * @// TODO: 7/15/21 remove TimerLength.txt logic! Depreciated and unexpected + * * @return time left in seconds. * @throws FileNotFoundException timer.txt cannot be found * @throws InvalidDataException incorrect values in TimerLength.txt @@ -91,7 +94,14 @@ public int get() throws IOException, InvalidDataException { File timerSettings = new File(timerTXT); Scanner scanner = new Scanner(timerSettings); try { - return convertFromMinuteFormat(scanner.nextLine()); + int foo = convertFromMinuteFormat(scanner.nextLine()); + return foo; + } catch (NumberFormatException exception) { + //occurs when timer.txt does not contain int - this can be because of user input + // but more commonly due to user setting their own end text in the file. + // in this case, we just return the preferred length. + return getInitialTimerLength(); + } catch (NoSuchElementException e) { //timer file is empty or invalid. //write value of "TimerLength.txt" to "Timer.txt", and return such From 8c78e1e81229add4e84f89778773f4371e5cc36a Mon Sep 17 00:00:00 2001 From: Cole Manning // RVRX Date: Thu, 15 Jul 2021 21:46:16 -0400 Subject: [PATCH 04/27] fix forgotten change --- src/main/java/goistreamtoolredux/algorithm/Timers.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/goistreamtoolredux/algorithm/Timers.java b/src/main/java/goistreamtoolredux/algorithm/Timers.java index 6c5de48..7a13e9a 100644 --- a/src/main/java/goistreamtoolredux/algorithm/Timers.java +++ b/src/main/java/goistreamtoolredux/algorithm/Timers.java @@ -94,8 +94,7 @@ public int get() throws IOException, InvalidDataException { File timerSettings = new File(timerTXT); Scanner scanner = new Scanner(timerSettings); try { - int foo = convertFromMinuteFormat(scanner.nextLine()); - return foo; + return convertFromMinuteFormat(scanner.nextLine()); } catch (NumberFormatException exception) { //occurs when timer.txt does not contain int - this can be because of user input // but more commonly due to user setting their own end text in the file. From b9b8a6063bdd67acd685708490a820902d0a8711 Mon Sep 17 00:00:00 2001 From: Cole Manning // RVRX Date: Fri, 16 Jul 2021 10:37:00 -0400 Subject: [PATCH 05/27] remove old timerLength logic --- .../goistreamtoolredux/algorithm/Timers.java | 41 +++++++------------ 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/src/main/java/goistreamtoolredux/algorithm/Timers.java b/src/main/java/goistreamtoolredux/algorithm/Timers.java index 7a13e9a..c09bfc5 100644 --- a/src/main/java/goistreamtoolredux/algorithm/Timers.java +++ b/src/main/java/goistreamtoolredux/algorithm/Timers.java @@ -48,11 +48,9 @@ public void setInitialTimerTwoLength(int seconds) { * Gotten from the preferences API, defaults to 240 if no preference set yet. * * @return timer length in seconds - * @throws IOException - * @throws NoSuchElementException TimerLength.txt contains an unexpected character. * @see #setInitialTimerLength(int) */ - public int getInitialTimerLength() throws IOException, NoSuchElementException, InvalidDataException { + public int getInitialTimerLength() { if (prefs.getBoolean(IS_TIMER_ONE, true)) { //if timer one is selected, or must be defaulted to return prefs.getInt(TIMER_ONE_LENGTH, 240); @@ -80,42 +78,31 @@ public void set(int seconds) throws IOException { /** * Gets the current value of the timer. - * If the timer file is empty or invalid, the file will be fixed, - * and the default length (TimerLength.txt will be returned) - * - * @// TODO: 7/15/21 remove TimerLength.txt logic! Depreciated and unexpected + * If the timer file is empty or invalid, the default timer will be retrieved * * @return time left in seconds. * @throws FileNotFoundException timer.txt cannot be found - * @throws InvalidDataException incorrect values in TimerLength.txt */ - public int get() throws IOException, InvalidDataException { + public int get() throws IOException { //open Timer.txt and scan first integer File timerSettings = new File(timerTXT); Scanner scanner = new Scanner(timerSettings); try { return convertFromMinuteFormat(scanner.nextLine()); - } catch (NumberFormatException exception) { - //occurs when timer.txt does not contain int - this can be because of user input - // but more commonly due to user setting their own end text in the file. - // in this case, we just return the preferred length. + } catch (NumberFormatException | NoSuchElementException exception) { + /* + NumberFormatException: + occurs when timer.txt does not contain int - this can be because of user input + but more commonly due to user setting their own end text in the file. + in this case, we just return the preferred length. + NoSuchElementException: + timer file is empty (no line found) + return preferred timer start value + */ + return getInitialTimerLength(); - } catch (NoSuchElementException e) { - //timer file is empty or invalid. - //write value of "TimerLength.txt" to "Timer.txt", and return such - Writer fileWriter = new FileWriter(timerTXT); - try { - fileWriter.write(convertToMinuteFormat(getInitialTimerLength())); - } catch (NoSuchElementException | InvalidDataException exception) { - //getInitial error, so write new value to getInitial - Writer fileWriterInitial = new FileWriter(FileManager.inputPath + "TimerLength.txt"); - fileWriterInitial.write(240); - fileWriterInitial.close(); - } - fileWriter.close(); } - return 240; } /** From ea0638d7dd2d5caea135660715a96ec19b1305e3 Mon Sep 17 00:00:00 2001 From: Cole Manning // RVRX Date: Fri, 16 Jul 2021 13:30:11 -0400 Subject: [PATCH 06/27] remove non-thrown exception, was causing build to fail --- src/main/java/goistreamtoolredux/algorithm/CustomTimer.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/goistreamtoolredux/algorithm/CustomTimer.java b/src/main/java/goistreamtoolredux/algorithm/CustomTimer.java index b4e0249..6d62025 100644 --- a/src/main/java/goistreamtoolredux/algorithm/CustomTimer.java +++ b/src/main/java/goistreamtoolredux/algorithm/CustomTimer.java @@ -141,8 +141,6 @@ public void run() { exception.printStackTrace(); } catch (IOException exception) { exception.printStackTrace(); - } catch (InvalidDataException exception) { - exception.printStackTrace(); } } } From eb177ac09db321ee1f7d806df007dc326a8cdabd Mon Sep 17 00:00:00 2001 From: RVRX Date: Sun, 18 Jul 2021 11:47:55 -0400 Subject: [PATCH 07/27] remove broken catch block --- src/main/java/goistreamtoolredux/algorithm/LobbyTimer.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/goistreamtoolredux/algorithm/LobbyTimer.java b/src/main/java/goistreamtoolredux/algorithm/LobbyTimer.java index da4bb11..a1faeee 100644 --- a/src/main/java/goistreamtoolredux/algorithm/LobbyTimer.java +++ b/src/main/java/goistreamtoolredux/algorithm/LobbyTimer.java @@ -153,8 +153,6 @@ public void run() { exception.printStackTrace(); } catch (IOException exception) { exception.printStackTrace(); - } catch (InvalidDataException exception) { - exception.printStackTrace(); } } } From 1c45641e8721940847a0e0ba6d30cd00808ee31e Mon Sep 17 00:00:00 2001 From: RVRX Date: Sun, 18 Jul 2021 11:53:33 -0400 Subject: [PATCH 08/27] Delete CustomTimer.java --- .../algorithm/CustomTimer.java | 147 ------------------ 1 file changed, 147 deletions(-) delete mode 100644 src/main/java/goistreamtoolredux/algorithm/CustomTimer.java diff --git a/src/main/java/goistreamtoolredux/algorithm/CustomTimer.java b/src/main/java/goistreamtoolredux/algorithm/CustomTimer.java deleted file mode 100644 index 6d62025..0000000 --- a/src/main/java/goistreamtoolredux/algorithm/CustomTimer.java +++ /dev/null @@ -1,147 +0,0 @@ -package goistreamtoolredux.algorithm; - -import goistreamtoolredux.App; -import goistreamtoolredux.controller.TimerPane; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.NoSuchElementException; -import java.util.Timer; -import java.util.TimerTask; - -public class CustomTimer extends Timers { - - private static CustomTimer singleton = new CustomTimer(); - private Timer currentTimer; - protected boolean isTimerRunning = false; - - public Timer getCurrentTimer() { - return currentTimer; - } - - private CustomTimer() {} - - /* Static 'instance' method */ - public static CustomTimer getInstance() { - return singleton; - } - - //File paths -// String timerLength = FileManager.inputPath + "TimerLength.txt"; -// String timerTXT = FileManager.outputPath + "Timer.txt"; - - - /*--- Methods ---*/ - - /** - * Start the timer (initial or after a pause) - * @throws IOException - * @throws NoSuchElementException - * @see #stop() - * @see #pause() - * @see #restart() - */ - public void start() throws IOException, NoSuchElementException, InvalidDataException { - if (!isTimerRunning) { //prevent starting when there is already a timer. no doubling up! - if (get() <= 0) { //if timer is currently at 0, restart - restart(); - } else { //otherwise, resume from last position by starting goistreamtoolredux.algorithm.CountdownTimer task - isTimerRunning = true; - currentTimer = new Timer(); - TimerTask task = new CountdownTimerCustom(); - currentTimer.schedule(task,0, 1000); - } - } else System.err.println("Timer already running!"); - } - - /** - * Completely stops and cancels the timer. NOT EQUIVALENT TO A PAUSE. - * Starting after this state will restart the timer. - * - * @throws NullPointerException there is no current timer or {@link TimerTask} running - * @throws IOException if I/O error is encountered when writing to Timer.txt - * @see #start() - * @see #pause() - * @see #restart() - */ - public void stop() throws NullPointerException, IOException { - //stop the current TimerTask - if (currentTimer != null) { - currentTimer.cancel(); - isTimerRunning = false; - } - //set Timer.txt to nothing [will cause start() to restart timer if called next] - set(0); - } - - /** - * Pauses the current timer state. Starting from this after this state will - * continue the timer from where the timer left off. - * Does nothing if there is no active timer - * - * @see #start() - * @see #stop() - * @see #restart() - */ - public void pause() { - //cancel TimerTask to stop countdown. Keeps value, so start() can resume from it - if (currentTimer != null) { - currentTimer.cancel(); - isTimerRunning = false; - } - } - - /** - * Resets the timer back to beginning value and starts it again - * @see #start() - * @see #stop() - * @see #pause() - */ - public void restart() throws IOException, InvalidDataException { - //stop timer - if (currentTimer != null) { - currentTimer.cancel(); - isTimerRunning = false; - } - - //write initial timer length to Timer.txt - set(getInitialTimerLength()); - - //start - start(); - } -} - -/** - * Begins countdown from current value in the Timer.txt file. {@link TimerTask} to be scheduled in {@link Timer#schedule(TimerTask, long, long)} for the countdown timer system. - * @implNote Be careful with scheduling this function too fast/often, it doesn't implement any - * file locks and is not atomic as of the current version. - * @implNote Does not use system clock (or at least efficiently. Timer will start to lag behind if more system resources are used or application is active with other tasks - */ -class CountdownTimerCustom extends TimerTask { - - public void run() { - - /*todo, implement lock*/ - - LobbyTimer timer = LobbyTimer.getInstance(); - - try { - int currentTime = timer.get(); - if (currentTime <= 0) { - System.out.println("Timer Finished!\n>"); - LobbyTimer.getInstance().isTimerRunning = false; - timer.getCurrentTimer().cancel(); - } else { - timer.set(currentTime - 1); - TimerPane timerPaneController = (TimerPane) App.getMasterController().getTimerPaneController(); - timerPaneController.setLobbyTimerText(String.valueOf(currentTime - 1)); - } - } catch (FileNotFoundException exception) { - exception.printStackTrace(); - } catch (IOException exception) { - exception.printStackTrace(); - } - } -} - From 90b79b293f31dd2ca9f36ffe3551351079f5e449 Mon Sep 17 00:00:00 2001 From: RVRX Date: Sun, 18 Jul 2021 11:53:55 -0400 Subject: [PATCH 09/27] remove broken catch in TimerPane --- src/main/java/goistreamtoolredux/controller/TimerPane.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/goistreamtoolredux/controller/TimerPane.java b/src/main/java/goistreamtoolredux/controller/TimerPane.java index 534ce29..c380e90 100644 --- a/src/main/java/goistreamtoolredux/controller/TimerPane.java +++ b/src/main/java/goistreamtoolredux/controller/TimerPane.java @@ -149,9 +149,6 @@ void initialize() { e.printStackTrace(); //todo, handle failed file creation } - } catch (InvalidDataException invalidDataException) { - invalidDataException.printStackTrace(); - //todo handle } catch (IOException exception) { exception.printStackTrace(); //todo handle From a19aa1927b677f6a62172482be620e78c0897cf3 Mon Sep 17 00:00:00 2001 From: RVRX Date: Sun, 18 Jul 2021 12:00:33 -0400 Subject: [PATCH 10/27] rename LobbyTimer > AppTimer --- src/main/java/goistreamtoolredux/App.java | 6 ++-- .../{LobbyTimer.java => AppTimer.java} | 12 +++---- .../algorithm/FileManager.java | 10 +++--- .../goistreamtoolredux/algorithm/Timers.java | 7 ---- .../controller/TimerPane.java | 14 ++++---- .../goistreamtoolredux/AlgorithmTest.java | 34 +++++++++---------- 6 files changed, 38 insertions(+), 45 deletions(-) rename src/main/java/goistreamtoolredux/algorithm/{LobbyTimer.java => AppTimer.java} (94%) diff --git a/src/main/java/goistreamtoolredux/App.java b/src/main/java/goistreamtoolredux/App.java index 0a892ad..61146ee 100644 --- a/src/main/java/goistreamtoolredux/App.java +++ b/src/main/java/goistreamtoolredux/App.java @@ -1,7 +1,7 @@ package goistreamtoolredux; +import goistreamtoolredux.algorithm.AppTimer; import goistreamtoolredux.algorithm.FileManager; -import goistreamtoolredux.algorithm.LobbyTimer; import goistreamtoolredux.controller.Master; import javafx.application.Application; import javafx.application.Platform; @@ -99,8 +99,8 @@ public void handle(WorkerStateEvent event) { public void stop() { System.out.println("Shutting Down"); //cancel the current TimerTask so the app doesn't hang on quit - if (LobbyTimer.getInstance().getCurrentTimer() != null) { - LobbyTimer.getInstance().getCurrentTimer().cancel(); + if (AppTimer.getInstance().getCurrentTimer() != null) { + AppTimer.getInstance().getCurrentTimer().cancel(); } } diff --git a/src/main/java/goistreamtoolredux/algorithm/LobbyTimer.java b/src/main/java/goistreamtoolredux/algorithm/AppTimer.java similarity index 94% rename from src/main/java/goistreamtoolredux/algorithm/LobbyTimer.java rename to src/main/java/goistreamtoolredux/algorithm/AppTimer.java index a1faeee..f7be553 100644 --- a/src/main/java/goistreamtoolredux/algorithm/LobbyTimer.java +++ b/src/main/java/goistreamtoolredux/algorithm/AppTimer.java @@ -16,9 +16,9 @@ * Singleton timer class. * Warning: gets confusing with all the uses of timer as a word, vs the actual JDK Timer class. */ -public class LobbyTimer extends Timers { +public class AppTimer extends Timers { - private static LobbyTimer singleton = new LobbyTimer(); + private static AppTimer singleton = new AppTimer(); private Timer currentTimer; protected boolean isTimerRunning = false; @@ -26,10 +26,10 @@ public Timer getCurrentTimer() { return currentTimer; } - private LobbyTimer() {} + private AppTimer() {} /* Static 'instance' method */ - public static LobbyTimer getInstance() { + public static AppTimer getInstance() { return singleton; } @@ -131,13 +131,13 @@ public void run() { /*todo, implement lock*/ - LobbyTimer timer = LobbyTimer.getInstance(); + AppTimer timer = AppTimer.getInstance(); try { int currentTime = timer.get(); if (currentTime <= 0) { System.out.println("Timer Finished!\n>"); - LobbyTimer.getInstance().isTimerRunning = false; + AppTimer.getInstance().isTimerRunning = false; timer.getCurrentTimer().cancel(); //set timer text to be the preferred text upon ending diff --git a/src/main/java/goistreamtoolredux/algorithm/FileManager.java b/src/main/java/goistreamtoolredux/algorithm/FileManager.java index 2144baf..36cd45c 100644 --- a/src/main/java/goistreamtoolredux/algorithm/FileManager.java +++ b/src/main/java/goistreamtoolredux/algorithm/FileManager.java @@ -239,7 +239,7 @@ private static void CLIParse(String input) { break; case "timer set": - LobbyTimer timer = LobbyTimer.getInstance(); + AppTimer timer = AppTimer.getInstance(); try { System.out.println("How many seconds would you like to set the timer for"); int setTime = scanner.nextInt(); @@ -259,7 +259,7 @@ private static void CLIParse(String input) { case "timer start": try { - LobbyTimer.getInstance().start(); + AppTimer.getInstance().start(); } catch (IOException exception) { exception.printStackTrace(); } catch (NoSuchElementException exception) { @@ -271,7 +271,7 @@ private static void CLIParse(String input) { case "timer stop": try { - LobbyTimer.getInstance().stop(); + AppTimer.getInstance().stop(); System.out.println("Stopped!"); } catch (IOException exception) { exception.printStackTrace(); @@ -279,12 +279,12 @@ private static void CLIParse(String input) { break; case "timer pause": - LobbyTimer.getInstance().pause(); + AppTimer.getInstance().pause(); break; case "timer restart": case "timer reset": try { - LobbyTimer.getInstance().restart(); + AppTimer.getInstance().restart(); } catch (IOException | InvalidDataException exception) { exception.printStackTrace(); } diff --git a/src/main/java/goistreamtoolredux/algorithm/Timers.java b/src/main/java/goistreamtoolredux/algorithm/Timers.java index c09bfc5..f173455 100644 --- a/src/main/java/goistreamtoolredux/algorithm/Timers.java +++ b/src/main/java/goistreamtoolredux/algorithm/Timers.java @@ -7,8 +7,6 @@ public class Timers { -// private Timer currentTimer; -// protected boolean isTimerRunning = false; private static Preferences prefs = Preferences.userRoot().node("/goistreamtoolredux/algorithm"); private static final String TIMER_ONE_LENGTH = "timer_one_length"; @@ -28,11 +26,6 @@ public class Timers { * @see #getInitialTimerLength() */ public void setInitialTimerLength(int seconds) throws IOException, IllegalArgumentException { -// if (seconds <= 0) throw new IllegalArgumentException("Cannot set initial timer value to 0"); -// //open TimerLength file and set a new value -// Writer fileWriter = new FileWriter(timerLength); -// fileWriter.write(String.valueOf(seconds)); -// fileWriter.close(); prefs.putInt(TIMER_TWO_LENGTH, seconds); } diff --git a/src/main/java/goistreamtoolredux/controller/TimerPane.java b/src/main/java/goistreamtoolredux/controller/TimerPane.java index c380e90..e235793 100644 --- a/src/main/java/goistreamtoolredux/controller/TimerPane.java +++ b/src/main/java/goistreamtoolredux/controller/TimerPane.java @@ -3,9 +3,9 @@ import com.jfoenix.controls.*; import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView; import goistreamtoolredux.App; +import goistreamtoolredux.algorithm.AppTimer; import goistreamtoolredux.algorithm.FileManager; import goistreamtoolredux.algorithm.InvalidDataException; -import goistreamtoolredux.algorithm.LobbyTimer; import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.fxml.FXML; @@ -76,13 +76,13 @@ public class TimerPane { @FXML void lobbyPauseClicked(MouseEvent event) { - LobbyTimer.getInstance().pause(); + AppTimer.getInstance().pause(); } @FXML void lobbyPlayClicked(MouseEvent event) { try { - LobbyTimer.getInstance().start(); + AppTimer.getInstance().start(); } catch (IOException exception) { exception.printStackTrace(); //todo handle @@ -95,7 +95,7 @@ void lobbyPlayClicked(MouseEvent event) { @FXML void lobbyRestartClicked(MouseEvent event) { try { - LobbyTimer.getInstance().restart(); + AppTimer.getInstance().restart(); } catch (IOException exception) { exception.printStackTrace(); //todo handle @@ -109,7 +109,7 @@ void lobbyRestartClicked(MouseEvent event) { @FXML void lobbyStopClicked(MouseEvent event) { try { - LobbyTimer.getInstance().stop(); + AppTimer.getInstance().stop(); lobbyTimerText.setText("0"); } catch (IOException exception) { exception.printStackTrace(); @@ -136,7 +136,7 @@ void initialize() { //get initial lobby timer length try { - lobbyTimerText.setText(String.valueOf(LobbyTimer.getInstance().get())); + lobbyTimerText.setText(String.valueOf(AppTimer.getInstance().get())); } catch (FileNotFoundException exception) { //if file is not found - then there is no current timer, so the default '00:00' is what we want // so no changes need to be made @@ -217,7 +217,7 @@ public void save(ActionEvent actionEvent) { anchorPane.requestFocus(); //pulls focus away from spinners - allowing them to update their values JFXSnackbar bar = new JFXSnackbar(anchorPane); try { - LobbyTimer.getInstance().setInitialTimerLength(timerOneSpinner.getValue()); + AppTimer.getInstance().setInitialTimerLength(timerOneSpinner.getValue()); prefs.putInt(TIMER_ONE_LENGTH, timerOneSpinner.getValue()); prefs.putInt(TIMER_TWO_LENGTH, timerTwoSpinner.getValue()); bar.enqueue(new JFXSnackbar.SnackbarEvent(new JFXSnackbarLayout("Saving Timers"),new Duration(1000))); diff --git a/src/test/java/goistreamtoolredux/AlgorithmTest.java b/src/test/java/goistreamtoolredux/AlgorithmTest.java index c6730dc..f6a53bd 100644 --- a/src/test/java/goistreamtoolredux/AlgorithmTest.java +++ b/src/test/java/goistreamtoolredux/AlgorithmTest.java @@ -2,7 +2,7 @@ import goistreamtoolredux.algorithm.FileManager; import goistreamtoolredux.algorithm.InvalidDataException; -import goistreamtoolredux.algorithm.LobbyTimer; +import goistreamtoolredux.algorithm.AppTimer; import goistreamtoolredux.algorithm.Team; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -25,16 +25,16 @@ public class AlgorithmTest { @Test public void settingAndGettingInitialTimerTest() throws IOException, InvalidDataException { - LobbyTimer lobbyTimer = LobbyTimer.getInstance(); + AppTimer appTimer = AppTimer.getInstance(); //10 - lobbyTimer.setInitialTimerLength(10); - assertEquals(10, lobbyTimer.getInitialTimerLength()); + appTimer.setInitialTimerLength(10); + assertEquals(10, appTimer.getInitialTimerLength()); //120 - lobbyTimer.setInitialTimerLength(120); - assertEquals(120, lobbyTimer.getInitialTimerLength()); + appTimer.setInitialTimerLength(120); + assertEquals(120, appTimer.getInitialTimerLength()); Exception exception = assertThrows(NumberFormatException.class, () -> { Integer.parseInt("1a"); @@ -53,7 +53,7 @@ public void exceptionSetInitialTimerInvalidTest() { // due to start calling restart if timer is 0, and restart starting from the initial value (which would be 0) // then calling start Exception exception = assertThrows(IllegalArgumentException.class, () -> { - LobbyTimer.getInstance().setInitialTimerLength(0); + AppTimer.getInstance().setInitialTimerLength(0); }); } @@ -75,20 +75,20 @@ public void readTeamsFromDiskTest() throws IOException { @Test public void convertToMinTest() { - assertEquals("3:20", LobbyTimer.convertToMinuteFormat(200)); - assertEquals("0:59", LobbyTimer.convertToMinuteFormat(59)); - assertEquals("1:00", LobbyTimer.convertToMinuteFormat(60)); - assertEquals("34:12", LobbyTimer.convertToMinuteFormat(2052)); + assertEquals("3:20", AppTimer.convertToMinuteFormat(200)); + assertEquals("0:59", AppTimer.convertToMinuteFormat(59)); + assertEquals("1:00", AppTimer.convertToMinuteFormat(60)); + assertEquals("34:12", AppTimer.convertToMinuteFormat(2052)); } @Test public void convertFromMinTest() { - assertEquals(60, LobbyTimer.convertFromMinuteFormat("01:00")); - assertEquals(60, LobbyTimer.convertFromMinuteFormat("1:00")); - assertEquals(200, LobbyTimer.convertFromMinuteFormat("03:20")); - assertEquals(200, LobbyTimer.convertFromMinuteFormat("3:20")); - assertEquals(0, LobbyTimer.convertFromMinuteFormat("00:00")); - assertEquals(0, LobbyTimer.convertFromMinuteFormat("0:00")); + assertEquals(60, AppTimer.convertFromMinuteFormat("01:00")); + assertEquals(60, AppTimer.convertFromMinuteFormat("1:00")); + assertEquals(200, AppTimer.convertFromMinuteFormat("03:20")); + assertEquals(200, AppTimer.convertFromMinuteFormat("3:20")); + assertEquals(0, AppTimer.convertFromMinuteFormat("00:00")); + assertEquals(0, AppTimer.convertFromMinuteFormat("0:00")); } @Test From 1dd1730cf9f584d6d554a85d343870947f59b3ae Mon Sep 17 00:00:00 2001 From: RVRX Date: Sun, 18 Jul 2021 12:05:57 -0400 Subject: [PATCH 11/27] update JavaDoc --- docs/javadoc/allclasses-frame.html | 3 +- docs/javadoc/allclasses-noframe.html | 3 +- docs/javadoc/goistreamtoolredux/App.html | 8 +- docs/javadoc/goistreamtoolredux/Main.html | 4 +- .../{CustomTimer.html => AppTimer.html} | 82 ++-- .../algorithm/FileManager.html | 8 +- .../algorithm/InvalidDataException.html | 8 +- .../algorithm/LobbyTimer.html | 405 ------------------ .../goistreamtoolredux/algorithm/Team.html | 8 +- .../goistreamtoolredux/algorithm/Timers.html | 22 +- .../algorithm/package-frame.html | 5 +- .../algorithm/package-summary.html | 28 +- .../algorithm/package-tree.html | 19 +- .../controller/MapPane.html | 4 +- .../goistreamtoolredux/controller/Master.html | 12 +- .../controller/SettingsPane.html | 10 +- .../controller/SplashScreenLoader.html | 8 +- .../controller/TeamPane.html | 8 +- .../controller/TimerPane.html | 8 +- .../controller/TournamentPane.html | 4 +- .../controller/package-frame.html | 2 +- .../controller/package-summary.html | 18 +- .../controller/package-tree.html | 18 +- .../goistreamtoolredux/package-frame.html | 2 +- .../goistreamtoolredux/package-summary.html | 8 +- .../goistreamtoolredux/package-tree.html | 8 +- docs/javadoc/index-all.html | 56 +-- docs/javadoc/overview-tree.html | 3 +- docs/javadoc/package-list | 3 + 29 files changed, 163 insertions(+), 612 deletions(-) rename docs/javadoc/goistreamtoolredux/algorithm/{CustomTimer.html => AppTimer.html} (69%) delete mode 100644 docs/javadoc/goistreamtoolredux/algorithm/LobbyTimer.html diff --git a/docs/javadoc/allclasses-frame.html b/docs/javadoc/allclasses-frame.html index 42b027a..e4500b8 100644 --- a/docs/javadoc/allclasses-frame.html +++ b/docs/javadoc/allclasses-frame.html @@ -12,10 +12,9 @@

All Classes

  • App
  • -
  • CustomTimer
  • +
  • AppTimer
  • FileManager
  • InvalidDataException
  • -
  • LobbyTimer
  • Main
  • MapPane
  • Master
  • diff --git a/docs/javadoc/allclasses-noframe.html b/docs/javadoc/allclasses-noframe.html index cb3c7c0..c5bda47 100644 --- a/docs/javadoc/allclasses-noframe.html +++ b/docs/javadoc/allclasses-noframe.html @@ -12,10 +12,9 @@

    All Classes

    • App
    • -
    • CustomTimer
    • +
    • AppTimer
    • FileManager
    • InvalidDataException
    • -
    • LobbyTimer
    • Main
    • MapPane
    • Master
    • diff --git a/docs/javadoc/goistreamtoolredux/App.html b/docs/javadoc/goistreamtoolredux/App.html index d07a9bd..0947652 100644 --- a/docs/javadoc/goistreamtoolredux/App.html +++ b/docs/javadoc/goistreamtoolredux/App.html @@ -48,7 +48,7 @@