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 e26e2c5..8407724 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 @@ -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() + "."); } } 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 6583d81..174fe9e 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 @@ -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); } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/Utils.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/Utils.java index ae5bb6c..ccba3db 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/Utils.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/Utils.java @@ -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); + } }