Added new improvements
This commit is contained in:
parent
32ebdb77b9
commit
007024b37e
@ -3,11 +3,13 @@ package org.nanoboot.utils.timecalc.gui.progress;
|
||||
import lombok.Getter;
|
||||
import org.nanoboot.utils.timecalc.gui.common.Widget;
|
||||
import org.nanoboot.utils.timecalc.main.TimeCalcConf;
|
||||
import org.nanoboot.utils.timecalc.utils.BooleanHolder;
|
||||
import org.nanoboot.utils.timecalc.utils.NumberFormats;
|
||||
import org.nanoboot.utils.timecalc.utils.Utils;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
@ -21,7 +23,15 @@ public class Battery extends Widget {
|
||||
public static final Color MEDIUM_HIGHLIGHTED = Color.ORANGE;
|
||||
public static final Color HIGH_HIGHLIGHTED = new Color(158, 227, 158);
|
||||
public static final Color HIGHEST_HIGHLIGHTED = Color.green;
|
||||
public static final double CRITICAL_LOW_ENERGY = 0.08;
|
||||
public static final double LOW_ENERGY = 0.15;
|
||||
public static final double HIGH_ENERGY = 0.75;
|
||||
public static final double VERY_HIGH_ENERGY = 0.9;
|
||||
public static boolean wavesOff = false;
|
||||
private static final Font bigFont = new Font("sans", Font.BOLD, 24);
|
||||
private BooleanHolder blinking = new BooleanHolder();
|
||||
private long tmpNanoTime = 0l;
|
||||
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
@ -47,6 +57,14 @@ public class Battery extends Widget {
|
||||
this.totalHeight = (int) (this.getHeight() / 10d * 7d);
|
||||
this.totalWidth = this.getWidth();
|
||||
}
|
||||
if(donePercent > 0 && donePercent < CRITICAL_LOW_ENERGY && (System.nanoTime() - tmpNanoTime) > 1000000000l / 2l) {
|
||||
blinking.flip();
|
||||
System.out.println(getName() + "donePercent=" + donePercent);
|
||||
tmpNanoTime = System.nanoTime();
|
||||
}
|
||||
if(donePercent <= 0 && blinking.get()){
|
||||
blinking.set(false);
|
||||
}
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
@ -56,22 +74,25 @@ public class Battery extends Widget {
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
if (!Utils.ultraLight.get()) {
|
||||
g2d.fillRect(1, 1, totalWidth, totalHeight - 2);
|
||||
g2d.fillRect(1, 1, totalWidth, totalHeight);
|
||||
}
|
||||
|
||||
if (Utils.highlighted.get() || mouseOver) {
|
||||
g2d.setColor(
|
||||
donePercent < 0.1 ? LOW_HIGHLIGHTED : (donePercent < 0.75 ?
|
||||
donePercent < LOW_ENERGY ? LOW_HIGHLIGHTED : (donePercent < HIGH_ENERGY ?
|
||||
MEDIUM_HIGHLIGHTED :
|
||||
(donePercent < 0.9 ? HIGH_HIGHLIGHTED :
|
||||
(donePercent < VERY_HIGH_ENERGY ? HIGH_HIGHLIGHTED :
|
||||
HIGHEST_HIGHLIGHTED)));
|
||||
} else {
|
||||
g2d.setColor(donePercent < 0.1 ? LOW : (donePercent < 0.75 ?
|
||||
MEDIUM : (donePercent < 0.9 ? HIGH : HIGHEST)));
|
||||
g2d.setColor(donePercent < LOW_ENERGY ? LOW : (donePercent < HIGH_ENERGY ?
|
||||
MEDIUM : (donePercent < VERY_HIGH_ENERGY ? HIGH : HIGHEST)));
|
||||
}
|
||||
if (Utils.ultraLight.get()) {
|
||||
g2d.setColor(Utils.ULTRA_LIGHT_GRAY);
|
||||
}
|
||||
if(blinking.get()) {
|
||||
g2d.setColor(BACKGROUND_COLOR);
|
||||
}
|
||||
int doneHeight = (int) (totalHeight * donePercent);
|
||||
int intX = 1;
|
||||
int todoHeight = totalHeight - doneHeight;
|
||||
@ -117,9 +138,47 @@ public class Battery extends Widget {
|
||||
5)),
|
||||
todoHeight + (waterSurfaceHeight * 1)},
|
||||
pointCount);
|
||||
|
||||
g2d.setColor((Utils.ultraLight.get() || !Utils.highlighted.get()) && !mouseOver ? Utils.ULTRA_LIGHT_GRAY : Color.DARK_GRAY);
|
||||
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
g2d.drawPolyline(
|
||||
new int[] {intX,
|
||||
(int) (intX + totalWidth / pointCount * 0.5),
|
||||
intX + totalWidth / pointCount * 3,
|
||||
intX + totalWidth / pointCount * 4,
|
||||
intX + totalWidth / pointCount * 5,
|
||||
intX + totalWidth / pointCount * 6,
|
||||
intX + totalWidth / pointCount * 7,
|
||||
intX + totalWidth / pointCount * 8},
|
||||
new int[] {todoHeight + (waterSurfaceHeight * 1),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
0, true)),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
1, true)),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
2, true)),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
3, true)),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
4, true)),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
5, true)),
|
||||
todoHeight + (waterSurfaceHeight * 1)},
|
||||
pointCount);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
}
|
||||
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK :
|
||||
Color.LIGHT_GRAY);
|
||||
|
||||
Font currentFont = g2d.getFont();
|
||||
g2d.setFont(bigFont);
|
||||
g2d.drawString("⚡", ((int) (totalWidth * 0.45)),(donePercent < 0.5 ? totalHeight / 4 * 3 :
|
||||
totalHeight / 4 * 1) + 10);
|
||||
g2d.setFont(currentFont);
|
||||
|
||||
g2d.drawString(
|
||||
NumberFormats.FORMATTER_THREE_DECIMAL_PLACES.format(donePercent * 100) + "%",
|
||||
((int) (totalWidth * 0.15)),
|
||||
@ -145,16 +204,15 @@ public class Battery extends Widget {
|
||||
}
|
||||
|
||||
private double getRandom(int index) {
|
||||
if (Math.random() > 0.7) {
|
||||
return getRandom(index, false);
|
||||
}
|
||||
private double getRandom(int index, boolean keepArray) {
|
||||
if (!keepArray && Math.random() > 0.95) {
|
||||
randomDoubles[index] = Math.random();
|
||||
}
|
||||
return randomDoubles[index];
|
||||
}
|
||||
|
||||
public int getTimerDelay() {
|
||||
return 250;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return this.label;
|
||||
}
|
||||
@ -166,4 +224,7 @@ public class Battery extends Widget {
|
||||
public void setBounds(int x, int y, int height) {
|
||||
setBounds(x, y, (int) (40d / 100d * ((double)height)), height);
|
||||
}
|
||||
public int getTimerDelay() {
|
||||
return 25;
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -15,6 +15,7 @@ public class Main {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
Utils.startApp();
|
||||
while (true) {
|
||||
boolean test = FileConstants.TEST_TXT.exists();
|
||||
String oldStartTime = Utils.readTextFromFile(
|
||||
|
@ -10,6 +10,7 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Base64;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
@ -18,7 +19,7 @@ import java.util.jar.Manifest;
|
||||
* @since 15.02.2024
|
||||
*/
|
||||
public class Utils {
|
||||
private static long startNanoTime;
|
||||
private static long startNanoTime = 0l;
|
||||
public static final BooleanHolder highlighted = new BooleanHolder();
|
||||
public static final BooleanHolder ultraLight = new BooleanHolder();
|
||||
public static final BooleanHolder everythingHidden = new BooleanHolder();
|
||||
@ -29,7 +30,7 @@ public class Utils {
|
||||
*/
|
||||
private static final int COUNT_OF_BYTES_PER_ONE_KILOBYTE = 1024;
|
||||
public static void startApp() {
|
||||
if(startNanoTime == 0) {
|
||||
if(startNanoTime != 0) {
|
||||
throw new TimeCalcException("App is already started.");
|
||||
}
|
||||
startNanoTime = System.nanoTime();
|
||||
@ -88,8 +89,17 @@ public class Utils {
|
||||
((int) (Math.random() * 256)), ((int) (Math.random() * 256)));
|
||||
}
|
||||
|
||||
public static int getCountOfMinutesSinceAppStarted() {
|
||||
return ((int)((System.nanoTime() - startNanoTime) / 1000000000 / 60));
|
||||
public static long getCountOfMinutesSinceAppStarted() {
|
||||
return getCountOfSecondsSinceAppStarted() / 60l;
|
||||
}
|
||||
public static long getCountOfSecondsSinceAppStarted() {
|
||||
return getCountOfMillisecondsSinceAppStarted() / 1000000000l;
|
||||
}
|
||||
public static long getCountOfMillisecondsSinceAppStarted() {
|
||||
if(startNanoTime == 0l) {
|
||||
throw new TimeCalcException("App was not yet started.");
|
||||
}
|
||||
return System.nanoTime() - startNanoTime;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -124,4 +134,9 @@ public class Utils {
|
||||
Attributes attr = manifest.getMainAttributes();
|
||||
return attr.getValue("Build-Date");
|
||||
}
|
||||
public static byte[] decodeBase64ToByteArray(String s) {
|
||||
Base64.Decoder base64Decoder = Base64.getDecoder();
|
||||
return base64Decoder
|
||||
.decode(s.getBytes());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user