diff --git a/pom.xml b/pom.xml
index 07b074f..3d7569e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,6 +20,7 @@
UTF-8
${basedir}/lib
${maven.build.timestamp}
+ 1.18.22
@@ -77,6 +78,32 @@
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+
+
+ org.projectlombok
+ lombok
+ ${lombok.version}
+
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+
+
+
+
+ org.projectlombok
+ lombok
+ 1.18.22
+ provided
+
+
\ No newline at end of file
diff --git a/src/main/java/org/nanoboot/utils/timecalc/gui/common/Widget.java b/src/main/java/org/nanoboot/utils/timecalc/gui/common/Widget.java
index 3236b5b..703338e 100644
--- a/src/main/java/org/nanoboot/utils/timecalc/gui/common/Widget.java
+++ b/src/main/java/org/nanoboot/utils/timecalc/gui/common/Widget.java
@@ -59,6 +59,9 @@ public class Widget extends JPanel {
if (donePercent > 1) {
donePercent = 1;
}
+ if (donePercent < 0) {
+ donePercent = 0;
+ }
this.donePercent = donePercent;
}
diff --git a/src/main/java/org/nanoboot/utils/timecalc/main/TimeCalcException.java b/src/main/java/org/nanoboot/utils/timecalc/main/TimeCalcException.java
index 14b9169..74d02df 100644
--- a/src/main/java/org/nanoboot/utils/timecalc/main/TimeCalcException.java
+++ b/src/main/java/org/nanoboot/utils/timecalc/main/TimeCalcException.java
@@ -4,7 +4,7 @@ package org.nanoboot.utils.timecalc.main;
* @author Robert
* @since 21.02.2024
*/
-public class TimeCalcException extends RuntimeException {
+public class TimeCalcException extends RuntimeException{
public TimeCalcException(String msg) {
super(msg);
}
diff --git a/src/main/java/org/nanoboot/utils/timecalc/main/TimeCalcWindow.java b/src/main/java/org/nanoboot/utils/timecalc/main/TimeCalcWindow.java
index f695f22..549ee48 100644
--- a/src/main/java/org/nanoboot/utils/timecalc/main/TimeCalcWindow.java
+++ b/src/main/java/org/nanoboot/utils/timecalc/main/TimeCalcWindow.java
@@ -10,6 +10,7 @@ import org.nanoboot.utils.timecalc.gui.progress.ProgressSquare;
import org.nanoboot.utils.timecalc.utils.Constants;
import org.nanoboot.utils.timecalc.utils.DateFormats;
import org.nanoboot.utils.timecalc.utils.Jokes;
+import org.nanoboot.utils.timecalc.utils.NumberFormats;
import org.nanoboot.utils.timecalc.utils.Utils;
import javax.imageio.ImageIO;
@@ -26,8 +27,6 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
-import java.text.DecimalFormat;
-import java.text.NumberFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
@@ -45,14 +44,8 @@ import static org.nanoboot.utils.timecalc.utils.FileConstants.FOCUS_TXT;
*/
public class TimeCalcWindow {
public static final String WALL = "||";
-
- private static final int WORKING_HOURS_LENGTH = 8;
- private static final int WORKING_MINUTES_LENGTH = 30;
- private static final String NEW_LINE = "\n";
-
private static final int MARGIN = 10;
- private final String startTime;
private final String windowTitle;
private final int startHour;
private final int startMinute;
@@ -60,7 +53,6 @@ public class TimeCalcWindow {
private final int overtimeMinute;
private final int totalMinutes;
private final Set alreadyShownPercents = new HashSet<>();
- private String overTime;
private int endHour;
private int endMinute;
private boolean stopBeforeEnd = false;
@@ -72,25 +64,24 @@ public class TimeCalcWindow {
Utils.toastsAreEnabled
.set(TimeCalcConf.getInstance().areToastsEnabled());
- this.startTime = startTimeIn;
- this.overTime = (overTimeIn == null || overTimeIn.isEmpty()) ?
+ overTimeIn = (overTimeIn == null || overTimeIn.isEmpty()) ?
Constants.DEFAULT_OVERTIME : overTimeIn;
- String[] startTimeAsArray = startTime.split(":");
+ String[] startTimeAsArray = startTimeIn.split(":");
this.startHour = Integer.valueOf(startTimeAsArray[0]);
this.startMinute = Integer.valueOf(startTimeAsArray[1]);
- boolean overtimeIsNegative = overTime.startsWith("-");
+ boolean overtimeIsNegative = overTimeIn.startsWith("-");
if (overtimeIsNegative) {
- overTime = overTime.replace("-", "");
+ overTimeIn = overTimeIn.replace("-", "");
}
this.overtimeHour = (overtimeIsNegative ? (-1) : 1) * Integer
- .valueOf(overTime.split(":")[0]);
+ .valueOf(overTimeIn.split(":")[0]);
this.overtimeMinute = (overtimeIsNegative ? (-1) : 1) * Integer
- .valueOf(overTime.split(":")[1]);
+ .valueOf(overTimeIn.split(":")[1]);
- this.endHour = startHour + WORKING_HOURS_LENGTH + overtimeHour;
- this.endMinute = startMinute + WORKING_MINUTES_LENGTH + overtimeMinute;
+ this.endHour = startHour + Constants.WORKING_HOURS_LENGTH + overtimeHour;
+ this.endMinute = startMinute + Constants.WORKING_MINUTES_LENGTH + overtimeMinute;
while (endMinute >= 60) {
endMinute = endMinute - 60;
endHour = endHour + 1;
@@ -100,8 +91,7 @@ public class TimeCalcWindow {
int totalSeconds = totalMinutes * 60;
int totalMilliseconds = totalSeconds * 1000;
- NumberFormat formatter5 = new DecimalFormat("#0.00000");
- NumberFormat formatter3 = new DecimalFormat("#0.000");
+
JFrame window = new JFrame();
@@ -451,8 +441,8 @@ public class TimeCalcWindow {
int secondsRemains = 60 - secondNow;
int millisecondsRemains = 1000 - millisecondNow;
- int hourDone = WORKING_HOURS_LENGTH + overtimeHour - hourRemains;
- int minutesDone = 30 + overtimeMinute - minuteRemains;
+ int hourDone = Constants.WORKING_HOURS_LENGTH + overtimeHour - hourRemains;
+ int minutesDone = Constants.WORKING_MINUTES_LENGTH + overtimeMinute - minuteRemains;
int secondsDone = secondNow;
int millisecondsDone = millisecondNow;
@@ -461,13 +451,6 @@ public class TimeCalcWindow {
int totalMillisecondsDone =
totalSecondsDone * 1000 + millisecondsDone;
- // System.out.println(hourNow + " " + minuteNow + " " + secondNow + " " + millisecondNow);
- // System.out.println(hourRemains + " " + minuteRemains + " " + secondsRemains + " " + millisecondsRemains);
- // System.out.println(hourDone + " " + minutesDone + " " + secondsDone + " " + totalMillisecondsDone + "\n");
- // System.out.println("totalSecondsDone=" + totalSecondsDone);
- // System.out.println("totalMillisecondsDone=" + totalMillisecondsDone);
-
- // double done = ((double)totalMinutesDone)/((double)totalMinutes);
double done = ((double) totalMillisecondsDone)
/ ((double) totalMilliseconds);
progressSquare.setDonePercent(done);
@@ -519,11 +502,11 @@ public class TimeCalcWindow {
totalSecondsRemains * 1000 + millisecondsRemains;
double totalSecondsRemainsDouble =
((double) totalMillisecondsRemains) / 1000;
- String msg = "Done=" + formatter5.format(done * 100) + "% Remains="
+ String msg = "Done=" + NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES.format(done * 100) + "% Remains="
+ String.format("%02d", hourRemains) + ":" + String
.format("%02d", minuteRemains)
+ /*":" + String.format("%02d", secondsRemains)+ */ " ("
- + formatter3
+ + NumberFormats.FORMATTER_THREE_DECIMAL_PLACES
.format(totalSecondsRemainsDouble - 60)
+ " s" + ")" + " End=" + String
.format("%02d", endHour) + ":" + String
@@ -601,11 +584,6 @@ public class TimeCalcWindow {
private void printPercentToAscii(double percent,
String msg, StringBuilder sb) {
- NumberFormat formatter = new DecimalFormat("#00.00");
- NumberFormat formatter2 = new DecimalFormat("##.##");
- String s = formatter.format(percent * 100);
- s = s.replace(",", "");
-
int percentInt = (int) (percent * 100);
if (!alreadyShownPercents.contains((int) (percent * 100))) {
alreadyShownPercents.add((int) (percent * 100));
@@ -649,27 +627,27 @@ public class TimeCalcWindow {
}
int spacesTodo = spacesTotal - (spacesDone < 0 ? 0 : spacesDone);
- sb.append("||" + createSpaces(spacesTotal + 6 - 2) + (spacesTodo == 0 ?
+ sb.append(WALL + createSpaces(spacesTotal + 6 - 2) + (spacesTodo == 0 ?
" \n" : "||======||\n"));
- sb.append("||").append(createSpaces(spacesTotal + 4))
+ sb.append(WALL).append(createSpaces(spacesTotal + 4))
.append(spacesTodo == 0 ? "" : "| |").append("\n");
- NumberFormat formatter3 = new DecimalFormat("#0.00000");
+
sb.append(
WALL + createSpaces(spacesDone) + " () " + createSpaces(
- spacesTodo) + /*WALL +*/ (spacesTodo == 0 ?
+ spacesTodo) + (spacesTodo == 0 ?
" \\☼☼☼☼/ " :
- "| _ |") + /*WALL +*/ NEW_LINE +
+ "| _ |") + Constants.NEW_LINE +
WALL + createSpaces(spacesDone) + "/||\\" + createSpaces(
- spacesTodo) + /*WALL +*/ (spacesTodo == 0 ?
+ spacesTodo) + (spacesTodo == 0 ?
" ☼☼☼☼☼☼ " :
- "| | |") + /*WALL +*/ NEW_LINE +
+ "| | |") + Constants.NEW_LINE +
WALL + createSpaces(spacesDone) + " /\\ " + createSpaces(
- spacesTodo) + /*WALL +*/ (spacesTodo == 0 ?
+ spacesTodo) + (spacesTodo == 0 ?
" /☼☼☼☼\\ " :
- "| |") + /*WALL +*/ NEW_LINE +
+ "| |") + Constants.NEW_LINE +
"================================================================"
- + NEW_LINE + "Steps: " + formatter3
+ + Constants.NEW_LINE + "Steps: " + NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES
.format(percent * ((double) spacesTotal)) + "/"
+ spacesTotal
);
diff --git a/src/main/java/org/nanoboot/utils/timecalc/utils/Constants.java b/src/main/java/org/nanoboot/utils/timecalc/utils/Constants.java
index 316bb1c..b25190f 100644
--- a/src/main/java/org/nanoboot/utils/timecalc/utils/Constants.java
+++ b/src/main/java/org/nanoboot/utils/timecalc/utils/Constants.java
@@ -7,6 +7,9 @@ package org.nanoboot.utils.timecalc.utils;
public class Constants {
public static final String DEFAULT_START_TIME = "7:00";
public static final String DEFAULT_OVERTIME = "0:00";
+ public static final int WORKING_HOURS_LENGTH = 8;
+ public static final int WORKING_MINUTES_LENGTH = 30;
+ public static final String NEW_LINE = "\n";
private Constants() {
//Not meant to be instantiated.
diff --git a/src/main/java/org/nanoboot/utils/timecalc/utils/DateFormats.java b/src/main/java/org/nanoboot/utils/timecalc/utils/DateFormats.java
index ae28410..642080c 100644
--- a/src/main/java/org/nanoboot/utils/timecalc/utils/DateFormats.java
+++ b/src/main/java/org/nanoboot/utils/timecalc/utils/DateFormats.java
@@ -7,10 +7,9 @@ import java.time.format.DateTimeFormatter;
* @since 21.02.2024
*/
public class DateFormats {
- public final static DateTimeFormatter DATE_TIME_FORMATTER_HHmmssSSS =
- DateTimeFormatter.ofPattern("HH:mm:ss:SSS");
-
private DateFormats() {
//Not meant to be instantiated.
}
+ public final static DateTimeFormatter DATE_TIME_FORMATTER_HHmmssSSS =
+ DateTimeFormatter.ofPattern("HH:mm:ss:SSS");
}
diff --git a/src/main/java/org/nanoboot/utils/timecalc/utils/FileConstants.java b/src/main/java/org/nanoboot/utils/timecalc/utils/FileConstants.java
index 67bff6e..85c4cd2 100644
--- a/src/main/java/org/nanoboot/utils/timecalc/utils/FileConstants.java
+++ b/src/main/java/org/nanoboot/utils/timecalc/utils/FileConstants.java
@@ -7,11 +7,11 @@ import java.io.File;
* @since 21.02.2024
*/
public class FileConstants {
+ private FileConstants() {
+ //Not meant to be instantiated.
+ }
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 FOCUS_TXT = new File("focus.txt");
- private FileConstants() {
- //Not meant to be instantiated.
- }
}
diff --git a/src/main/java/org/nanoboot/utils/timecalc/utils/Jokes.java b/src/main/java/org/nanoboot/utils/timecalc/utils/Jokes.java
index 7534e51..7402e1f 100644
--- a/src/main/java/org/nanoboot/utils/timecalc/utils/Jokes.java
+++ b/src/main/java/org/nanoboot/utils/timecalc/utils/Jokes.java
@@ -63,7 +63,7 @@ public class Jokes {
}
public static void showRandom() {
- if (!TimeCalcConf.getInstance().isJokeVisible()) {
+ if(!TimeCalcConf.getInstance().isJokeVisible()) {
//nothing to do
return;
}
diff --git a/src/main/java/org/nanoboot/utils/timecalc/utils/NumberFormats.java b/src/main/java/org/nanoboot/utils/timecalc/utils/NumberFormats.java
index c966cc4..5250cc1 100644
--- a/src/main/java/org/nanoboot/utils/timecalc/utils/NumberFormats.java
+++ b/src/main/java/org/nanoboot/utils/timecalc/utils/NumberFormats.java
@@ -1,5 +1,8 @@
package org.nanoboot.utils.timecalc.utils;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+
/**
* @author Robert
* @since 21.02.2024
@@ -8,4 +11,7 @@ public class NumberFormats {
private NumberFormats() {
//Not meant to be instantiated.
}
+ public static final NumberFormat FORMATTER_TWO_DECIMAL_PLACES = new DecimalFormat("#00.00");
+ public static final NumberFormat FORMATTER_FIVE_DECIMAL_PLACES = new DecimalFormat("#0.00000");
+ public static final NumberFormat FORMATTER_THREE_DECIMAL_PLACES = new DecimalFormat("#0.000");
}
diff --git a/src/main/java/org/nanoboot/utils/timecalc/utils/TimeHoursMinutes.java b/src/main/java/org/nanoboot/utils/timecalc/utils/TimeHoursMinutes.java
new file mode 100644
index 0000000..fd5ff73
--- /dev/null
+++ b/src/main/java/org/nanoboot/utils/timecalc/utils/TimeHoursMinutes.java
@@ -0,0 +1,17 @@
+package org.nanoboot.utils.timecalc.utils;
+
+/**
+ * @author Robert
+ * @since 21.02.2024
+ */
+public class TimeHoursMinutes {
+
+ private final Integer hour;
+ private final Integer minute;
+
+ public TimeHoursMinutes(String string) {
+ String[] array = string.split(":");
+ this.hour = Integer.valueOf(array[0]);
+ this.minute = Integer.valueOf(array[1]);
+ }
+}
diff --git a/src/main/java/org/nanoboot/utils/timecalc/utils/Utils.java b/src/main/java/org/nanoboot/utils/timecalc/utils/Utils.java
index 7ec01d1..880bd99 100644
--- a/src/main/java/org/nanoboot/utils/timecalc/utils/Utils.java
+++ b/src/main/java/org/nanoboot/utils/timecalc/utils/Utils.java
@@ -18,28 +18,25 @@ import java.util.jar.Manifest;
* @since 15.02.2024
*/
public class Utils {
+ private static long startNanoTime;
public static final BooleanHolder highlighted = new BooleanHolder();
public static final BooleanHolder ultraLight = new BooleanHolder();
public static final BooleanHolder everythingHidden = new BooleanHolder();
- public static final BooleanHolder toastsAreEnabled =
- new BooleanHolder(true);
- public static final Color ULTRA_LIGHT_GRAY = new Color(216, 216, 216);
+ public static final BooleanHolder toastsAreEnabled = new BooleanHolder(true);
+ public static final Color ULTRA_LIGHT_GRAY = new Color(216,216,216);
/**
* Count of bytes per one kilobyte.
*/
private static final int COUNT_OF_BYTES_PER_ONE_KILOBYTE = 1024;
- private static long startNanoTime;
-
- private Utils() {
- //Not meant to be instantiated.
- }
-
public static void startApp() {
- if (startNanoTime == 0) {
+ if(startNanoTime == 0) {
throw new TimeCalcException("App is already started.");
}
startNanoTime = System.nanoTime();
}
+ private Utils() {
+ //Not meant to be instantiated.
+ }
/**
* Writes text to a file.
@@ -92,22 +89,20 @@ public class Utils {
}
public static int getCountOfMinutesSinceAppStarted() {
- return ((int) ((System.nanoTime() - startNanoTime) / 1000000000 / 60));
+ return ((int)((System.nanoTime() - startNanoTime) / 1000000000 / 60));
}
/**
* Returns version of "Time Calc" from jar file.
- *
* @return version
*/
public static String getVersion() {
String version = Main.class.getPackage().getImplementationVersion();
- return version;
+ return version == null ? "" : version;
}
/**
* Returns build date of "Time Calc" from jar file.
- *
* @return build date
*/
public static String getBuildDate() {
@@ -117,9 +112,8 @@ public class Utils {
if (!classPath.startsWith("jar")) {
return null;
}
- String manifestPath =
- classPath.substring(0, classPath.lastIndexOf("!") + 1)
- + "/META-INF/MANIFEST.MF";
+ String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1)
+ + "/META-INF/MANIFEST.MF";
Manifest manifest;
try {
manifest = new Manifest(new URL(manifestPath).openStream());