Added several improvements

This commit is contained in:
Robert Vokac 2024-03-03 13:25:16 +00:00
parent 3b9805abed
commit 8ce268432d
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
6 changed files with 66 additions and 24 deletions

1
.gitignore vendored
View File

@ -18,3 +18,4 @@ focus.txt
dist/*
time-calc-current-profile.txt
time-calc-profiles.txt
.tc/*

View File

@ -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

View File

@ -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() + ".");
}
}

View File

@ -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<String, String> 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) {

View File

@ -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.

View File

@ -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