mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
Added several improvements
This commit is contained in:
parent
3b9805abed
commit
8ce268432d
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,3 +18,4 @@ focus.txt
|
|||||||
dist/*
|
dist/*
|
||||||
time-calc-current-profile.txt
|
time-calc-current-profile.txt
|
||||||
time-calc-profiles.txt
|
time-calc-profiles.txt
|
||||||
|
.tc/*
|
24
Readme.md
24
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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
|
## Features
|
||||||
|
|
||||||
### 3 Visibility modes
|
### 3 Visibility modes
|
||||||
|
@ -3,6 +3,7 @@ package org.nanoboot.utils.timecalc.app;
|
|||||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||||
import org.nanoboot.utils.timecalc.swing.common.MainWindow;
|
import org.nanoboot.utils.timecalc.swing.common.MainWindow;
|
||||||
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
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.Jokes;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
|
|||||||
private final TimeCalcConfiguration timeCalcConfiguration;
|
private final TimeCalcConfiguration timeCalcConfiguration;
|
||||||
private final TimeCalcApp timeCalcApp;
|
private final TimeCalcApp timeCalcApp;
|
||||||
private final MainWindow window;
|
private final MainWindow window;
|
||||||
private final File timeCalcProfilesTxtFile = new File("time-calc-profiles.txt");
|
|
||||||
public TimeCalcKeyAdapter(
|
public TimeCalcKeyAdapter(
|
||||||
TimeCalcConfiguration timeCalcConfiguration,
|
TimeCalcConfiguration timeCalcConfiguration,
|
||||||
TimeCalcApp timeCalcApp,
|
TimeCalcApp timeCalcApp,
|
||||||
@ -174,14 +175,14 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
|
|||||||
e.getKeyCode() == KeyEvent.VK_8 ||
|
e.getKeyCode() == KeyEvent.VK_8 ||
|
||||||
e.getKeyCode() == KeyEvent.VK_9;
|
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);
|
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();
|
Properties properties = new Properties();
|
||||||
try {
|
try {
|
||||||
properties.load(new FileInputStream(timeCalcProfilesTxtFile));
|
properties.load(new FileInputStream(FileConstants.TIME_CALC_PROFILES_TXT_FILE));
|
||||||
} catch (IOException ioException) {
|
} catch (IOException ioException) {
|
||||||
ioException.printStackTrace();
|
ioException.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -220,15 +221,15 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
|
|||||||
}
|
}
|
||||||
if (e.getKeyCode() == KeyEvent.VK_F) {
|
if (e.getKeyCode() == KeyEvent.VK_F) {
|
||||||
|
|
||||||
if(timeCalcProfilesTxtFile.exists()) {
|
if(FileConstants.TIME_CALC_PROFILES_TXT_FILE.exists()) {
|
||||||
try {
|
try {
|
||||||
Utils.showNotification(Utils.readTextFromFile(timeCalcProfilesTxtFile), 200);
|
Utils.showNotification(Utils.readTextFromFile(FileConstants.TIME_CALC_PROFILES_TXT_FILE), 200);
|
||||||
} catch (IOException ioException) {
|
} catch (IOException ioException) {
|
||||||
ioException.printStackTrace();
|
ioException.printStackTrace();
|
||||||
Utils.showNotification("Error: " + ioException.getMessage());
|
Utils.showNotification("Error: " + ioException.getMessage());
|
||||||
}
|
}
|
||||||
} else {
|
} 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() + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.nanoboot.utils.timecalc.app;
|
package org.nanoboot.utils.timecalc.app;
|
||||||
|
|
||||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||||
|
import org.nanoboot.utils.timecalc.utils.common.FileConstants;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -18,9 +19,9 @@ import java.util.Properties;
|
|||||||
*/
|
*/
|
||||||
public class TimeCalcProperties {
|
public class TimeCalcProperties {
|
||||||
|
|
||||||
public static final File FILE_WITHOUT_ANY_PROFILE = new File("timecalc.conf");
|
|
||||||
private static TimeCalcProperties INSTANCE;
|
private static TimeCalcProperties INSTANCE;
|
||||||
private static final File timeCalcCurrentProfileTxtFile = new File("time-calc-current-profile.txt");
|
|
||||||
private final Properties properties = new Properties();
|
private final Properties properties = new Properties();
|
||||||
private final Map<String, String> defaultProperties = new HashMap<>();
|
private final Map<String, String> defaultProperties = new HashMap<>();
|
||||||
|
|
||||||
@ -28,8 +29,8 @@ public class TimeCalcProperties {
|
|||||||
System.out.println("Loading configuration - start");
|
System.out.println("Loading configuration - start");
|
||||||
String profileName = "";
|
String profileName = "";
|
||||||
try {
|
try {
|
||||||
profileName = timeCalcCurrentProfileTxtFile.exists() ? Utils.readTextFromFile(
|
profileName = FileConstants.TIME_CALC_CURRENT_PROFILE_TXT_FILE.exists() ? Utils.readTextFromFile(
|
||||||
timeCalcCurrentProfileTxtFile) : "";
|
FileConstants.TIME_CALC_CURRENT_PROFILE_TXT_FILE) : "";
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new TimeCalcException(e);
|
throw new TimeCalcException(e);
|
||||||
@ -152,13 +153,13 @@ public class TimeCalcProperties {
|
|||||||
"Saving to " + file + " failed: " + e.getMessage());
|
"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) {
|
private File getFile(String profileName) {
|
||||||
return profileName == null || profileName.isEmpty() ?
|
return profileName == null || profileName.isEmpty() ?
|
||||||
FILE_WITHOUT_ANY_PROFILE :
|
FileConstants.FILE_WITHOUT_ANY_PROFILE :
|
||||||
new File("timecalc." + profileName + ".conf");
|
new File(FileConstants.FILE_WITHOUT_ANY_PROFILE.getParentFile(), "timecalc." + profileName + ".conf");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadProfile(String profileName) {
|
public void loadProfile(String profileName) {
|
||||||
|
@ -7,10 +7,13 @@ import java.io.File;
|
|||||||
* @since 21.02.2024
|
* @since 21.02.2024
|
||||||
*/
|
*/
|
||||||
public class FileConstants {
|
public class FileConstants {
|
||||||
|
public static final File TC_DIRECTORY = new File(".tc");
|
||||||
public static final File STARTTIME_TXT = new File("starttime.txt");
|
public static final File STARTTIME_TXT = new File(TC_DIRECTORY, "starttime.txt");
|
||||||
public static final File OVERTIME_TXT = new File("overtime.txt");
|
public static final File OVERTIME_TXT = new File(TC_DIRECTORY, "overtime.txt");
|
||||||
public static final File TEST_TXT = new File("test.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() {
|
private FileConstants() {
|
||||||
//Not meant to be instantiated.
|
//Not meant to be instantiated.
|
||||||
|
@ -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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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
|
## Features
|
||||||
|
|
||||||
### 3 Visibility modes
|
### 3 Visibility modes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user