Added new improvements
This commit is contained in:
parent
a10faea532
commit
ff211e391e
27
pom.xml
27
pom.xml
@ -20,6 +20,7 @@
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<lib.dir>${basedir}/lib</lib.dir>
|
||||
<timestamp>${maven.build.timestamp}</timestamp>
|
||||
<lombok.version>1.18.22</lombok.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
@ -77,6 +78,32 @@
|
||||
<!-- </execution>-->
|
||||
<!-- </executions>-->
|
||||
<!-- </plugin>-->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<!--<compilerArgs>
|
||||
-|-enable-preview
|
||||
</compilerArgs>-->
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.22</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -59,6 +59,9 @@ public class Widget extends JPanel {
|
||||
if (donePercent > 1) {
|
||||
donePercent = 1;
|
||||
}
|
||||
if (donePercent < 0) {
|
||||
donePercent = 0;
|
||||
}
|
||||
this.donePercent = donePercent;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<Integer> 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
|
||||
);
|
||||
|
@ -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.
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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.
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class Jokes {
|
||||
}
|
||||
|
||||
public static void showRandom() {
|
||||
if (!TimeCalcConf.getInstance().isJokeVisible()) {
|
||||
if(!TimeCalcConf.getInstance().isJokeVisible()) {
|
||||
//nothing to do
|
||||
return;
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
@ -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());
|
||||
|
Loading…
x
Reference in New Issue
Block a user