Added support for profiles II

This commit is contained in:
Robert Vokac 2024-03-03 13:20:38 +00:00
parent b7ef2119f3
commit 3b9805abed
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
3 changed files with 22 additions and 7 deletions

View File

@ -219,18 +219,16 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
}
}
if (e.getKeyCode() == KeyEvent.VK_F) {
Toaster toaster = new Toaster();
if(timeCalcProfilesTxtFile.exists()) {
toaster.setDisplayTime(15000);
try {
toaster.showToaster(Utils.readTextFromFile(timeCalcProfilesTxtFile));
Utils.showNotification(Utils.readTextFromFile(timeCalcProfilesTxtFile), 200);
} catch (IOException ioException) {
ioException.printStackTrace();
toaster.showToaster("Error: " + ioException.getMessage());
Utils.showNotification("Error: " + ioException.getMessage());
}
} else {
toaster.setDisplayTime(15000);
toaster.showToaster("Warning: There are no numbers assigned to profiles. Update file: " + timeCalcProfilesTxtFile.getAbsolutePath() + ".");
Utils.showNotification("Warning: There are no numbers assigned to profiles. Update file: " + timeCalcProfilesTxtFile.getAbsolutePath() + ".");
}
}

View File

@ -162,8 +162,13 @@ public class TimeCalcProperties {
}
public void loadProfile(String profileName) {
File file = getFile(profileName);
if(!file.exists()) {
Utils.showNotification("There is no profile with name: " + profileName);
return;
}
try {
this.properties.load( new FileInputStream(getFile(profileName)));
this.properties.load( new FileInputStream(file));
} catch (IOException e) {
System.err.println(e);
}

View File

@ -1,6 +1,7 @@
package org.nanoboot.utils.timecalc.utils.common;
import org.nanoboot.utils.timecalc.app.Main;
import org.nanoboot.utils.timecalc.swing.common.Toaster;
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
import java.awt.Color;
@ -140,4 +141,15 @@ public class Utils {
}
return sb.toString();
}
public static void showNotification(String message) {
showNotification(message, 0);
}
public static void showNotification(String message, int height) {
Toaster toaster = new Toaster();
toaster.setDisplayTime(15000);
if(height != 0) {
toaster.setToasterHeight(height);
}
toaster.showToaster(message);
}
}