From 8ce268432dc28869bd6cae8bba27b6716b64a198 Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Sun, 3 Mar 2024 13:25:16 +0000 Subject: [PATCH] Added several improvements --- .gitignore | 1 + Readme.md | 24 ++++++++++++++++--- .../timecalc/app/TimeCalcKeyAdapter.java | 15 ++++++------ .../timecalc/app/TimeCalcProperties.java | 15 ++++++------ .../timecalc/utils/common/FileConstants.java | 11 +++++---- .../src/main/resources/help/Readme.md | 24 ++++++++++++++++--- 6 files changed, 66 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 199fbcd..1cd6181 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ focus.txt dist/* time-calc-current-profile.txt time-calc-profiles.txt +.tc/* \ No newline at end of file diff --git a/Readme.md b/Readme.md index 69f6cfd..2857a9d 100644 --- a/Readme.md +++ b/Readme.md @@ -31,19 +31,37 @@ You can stop the app, if you press the **"Exit"** button or click on the exit wi If these files are present, something special happens. -### starttime.txt +### .tc/starttime.txt This file contains the default start time - used during the previous run of the app. If file starttime.txt does not exist, then the default start time is 7:00. -### overtime.txt +### .tc/overtime.txt This file contains the default overtime - used during the previous run of the app. If file overtime.txt does not exist, then the default overtime is 0:00. -### test.txt +### .tc/test.txt If file test.txt exists, then user is not asked for start time and overtime. Instead, the values in files starttime.txt and overtime.txt are used. +This file can be also used to define custom current time - for testing purposes. + +### ./tc/timecalc.conf + +Configuration is stored here. + +### ./tc/timecalc.{profile name}.conf + +Configuration for a profile is stored here. + +### ./tc/time-calc-current-profile.txt + +Current profile is stored here. + +### time-calc-profiles.txt + +Optional assignments of profiles to numbers is stored here. + ## Features ### 3 Visibility modes diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcKeyAdapter.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcKeyAdapter.java index 8407724..01254aa 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcKeyAdapter.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcKeyAdapter.java @@ -3,6 +3,7 @@ package org.nanoboot.utils.timecalc.app; import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.swing.common.MainWindow; import org.nanoboot.utils.timecalc.swing.common.Toaster; +import org.nanoboot.utils.timecalc.utils.common.FileConstants; import org.nanoboot.utils.timecalc.utils.common.Jokes; import org.nanoboot.utils.timecalc.utils.common.Utils; @@ -23,7 +24,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter { private final TimeCalcConfiguration timeCalcConfiguration; private final TimeCalcApp timeCalcApp; private final MainWindow window; - private final File timeCalcProfilesTxtFile = new File("time-calc-profiles.txt"); + public TimeCalcKeyAdapter( TimeCalcConfiguration timeCalcConfiguration, TimeCalcApp timeCalcApp, @@ -174,14 +175,14 @@ public class TimeCalcKeyAdapter extends KeyAdapter { e.getKeyCode() == KeyEvent.VK_8 || e.getKeyCode() == KeyEvent.VK_9; - if(numberKeyWasPressed &&!timeCalcProfilesTxtFile.exists()) { + if(numberKeyWasPressed && !FileConstants.TIME_CALC_PROFILES_TXT_FILE.exists()) { JOptionPane.showMessageDialog(null, "Warning: There is no profile assigned to Key with number, you pressed.", "Warning", JOptionPane.WARNING_MESSAGE); } - if (numberKeyWasPressed && timeCalcProfilesTxtFile.exists()) { + if (numberKeyWasPressed && FileConstants.TIME_CALC_PROFILES_TXT_FILE.exists()) { Properties properties = new Properties(); try { - properties.load(new FileInputStream(timeCalcProfilesTxtFile)); + properties.load(new FileInputStream(FileConstants.TIME_CALC_PROFILES_TXT_FILE)); } catch (IOException ioException) { ioException.printStackTrace(); } @@ -220,15 +221,15 @@ public class TimeCalcKeyAdapter extends KeyAdapter { } if (e.getKeyCode() == KeyEvent.VK_F) { - if(timeCalcProfilesTxtFile.exists()) { + if(FileConstants.TIME_CALC_PROFILES_TXT_FILE.exists()) { try { - Utils.showNotification(Utils.readTextFromFile(timeCalcProfilesTxtFile), 200); + Utils.showNotification(Utils.readTextFromFile(FileConstants.TIME_CALC_PROFILES_TXT_FILE), 200); } catch (IOException ioException) { ioException.printStackTrace(); Utils.showNotification("Error: " + ioException.getMessage()); } } else { - Utils.showNotification("Warning: There are no numbers assigned to profiles. Update file: " + timeCalcProfilesTxtFile.getAbsolutePath() + "."); + Utils.showNotification("Warning: There are no numbers assigned to profiles. Update file: " + FileConstants.TIME_CALC_PROFILES_TXT_FILE.getAbsolutePath() + "."); } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperties.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperties.java index 174fe9e..b72357c 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperties.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperties.java @@ -1,6 +1,7 @@ package org.nanoboot.utils.timecalc.app; import org.nanoboot.utils.timecalc.entity.Visibility; +import org.nanoboot.utils.timecalc.utils.common.FileConstants; import org.nanoboot.utils.timecalc.utils.common.Utils; import java.io.File; @@ -18,9 +19,9 @@ import java.util.Properties; */ public class TimeCalcProperties { - public static final File FILE_WITHOUT_ANY_PROFILE = new File("timecalc.conf"); + private static TimeCalcProperties INSTANCE; - private static final File timeCalcCurrentProfileTxtFile = new File("time-calc-current-profile.txt"); + private final Properties properties = new Properties(); private final Map defaultProperties = new HashMap<>(); @@ -28,8 +29,8 @@ public class TimeCalcProperties { System.out.println("Loading configuration - start"); String profileName = ""; try { - profileName = timeCalcCurrentProfileTxtFile.exists() ? Utils.readTextFromFile( - timeCalcCurrentProfileTxtFile) : ""; + profileName = FileConstants.TIME_CALC_CURRENT_PROFILE_TXT_FILE.exists() ? Utils.readTextFromFile( + FileConstants.TIME_CALC_CURRENT_PROFILE_TXT_FILE) : ""; } catch (IOException e) { e.printStackTrace(); throw new TimeCalcException(e); @@ -152,13 +153,13 @@ public class TimeCalcProperties { "Saving to " + file + " failed: " + e.getMessage()); } - Utils.writeTextToFile(timeCalcCurrentProfileTxtFile, profileName); + Utils.writeTextToFile(FileConstants.TIME_CALC_CURRENT_PROFILE_TXT_FILE, profileName); } private File getFile(String profileName) { return profileName == null || profileName.isEmpty() ? - FILE_WITHOUT_ANY_PROFILE : - new File("timecalc." + profileName + ".conf"); + FileConstants.FILE_WITHOUT_ANY_PROFILE : + new File(FileConstants.FILE_WITHOUT_ANY_PROFILE.getParentFile(), "timecalc." + profileName + ".conf"); } public void loadProfile(String profileName) { diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/FileConstants.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/FileConstants.java index 6eb0b33..6d4b7f3 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/FileConstants.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/FileConstants.java @@ -7,10 +7,13 @@ import java.io.File; * @since 21.02.2024 */ public class FileConstants { - - public static final File STARTTIME_TXT = new File("starttime.txt"); - public static final File OVERTIME_TXT = new File("overtime.txt"); - public static final File TEST_TXT = new File("test.txt"); + public static final File TC_DIRECTORY = new File(".tc"); + public static final File STARTTIME_TXT = new File(TC_DIRECTORY, "starttime.txt"); + public static final File OVERTIME_TXT = new File(TC_DIRECTORY, "overtime.txt"); + public static final File TEST_TXT = new File(TC_DIRECTORY, "test.txt"); + public static final File TIME_CALC_PROFILES_TXT_FILE = new File(TC_DIRECTORY, "time-calc-profiles.txt"); + public static final File TIME_CALC_CURRENT_PROFILE_TXT_FILE = new File(TC_DIRECTORY, "time-calc-current-profile.txt"); + public static final File FILE_WITHOUT_ANY_PROFILE = new File(TC_DIRECTORY, "timecalc.conf"); private FileConstants() { //Not meant to be instantiated. diff --git a/modules/time-calc-app/src/main/resources/help/Readme.md b/modules/time-calc-app/src/main/resources/help/Readme.md index d8de907..f0b2f66 100644 --- a/modules/time-calc-app/src/main/resources/help/Readme.md +++ b/modules/time-calc-app/src/main/resources/help/Readme.md @@ -31,19 +31,37 @@ You can stop the app, if you press the **"Exit"** button or click on the exit wi If these files are present, something special happens. -### starttime.txt +### .tc/starttime.txt This file contains the default start time - used during the previous run of the app. If file starttime.txt does not exist, then the default start time is 7:00. -### overtime.txt +### .tc/overtime.txt This file contains the default overtime - used during the previous run of the app. If file overtime.txt does not exist, then the default overtime is 0:00. -### test.txt +### .tc/test.txt If file test.txt exists, then user is not asked for start time and overtime. Instead, the values in files starttime.txt and overtime.txt are used. +This file can be also used to define custom current time - for testing purposes. + +### ./tc/timecalc.conf + +Configuration is stored here. + +### ./tc/timecalc.{profile name}.conf + +Configuration for a profile is stored here. + +### ./tc/time-calc-current-profile.txt + +Current profile is stored here. + +### time-calc-profiles.txt + +Optional assignments of profiles to numbers is stored here. + ## Features ### 3 Visibility modes