WalkingHumanProgress was refactored

This commit is contained in:
Robert Vokac 2024-03-09 14:27:33 +00:00
parent 50142440c8
commit 7d97b71617
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
2 changed files with 11 additions and 67 deletions

View File

@ -601,9 +601,6 @@ public class MainWindow extends TWindow {
setTitle(currentVisibility.isNone() ? "" : getWindowTitle()); setTitle(currentVisibility.isNone() ? "" : getWindowTitle());
int hourNow = analogClock.hourProperty.getValue();
int minuteNow = analogClock.minuteProperty.getValue();
int secondNow = analogClock.secondProperty.getValue(); int secondNow = analogClock.secondProperty.getValue();
int millisecondNow = analogClock.millisecondProperty.getValue(); int millisecondNow = analogClock.millisecondProperty.getValue();
@ -691,25 +688,14 @@ public class MainWindow extends TWindow {
yearBattery yearBattery
.setDonePercent(YearBattery.getYearProgress(analogClock)); .setDonePercent(YearBattery.getYearProgress(analogClock));
yearBattery.setLabel(""); yearBattery.setLabel("");
//yearBattery.setDonePercent(YearBattery.getYearProgress(2024,0,1,0,0,0,0));
int totalSecondsRemains
= (int) (timeRemains.getHour() * 60 * 60
+ timeRemains.getMinute() * 60
+ secondsRemains);
int totalMillisecondsRemains
= totalSecondsRemains * 1000 + millisecondsRemains;
double totalSecondsRemainsDouble
= ((double) totalMillisecondsRemains) / 1000;
if (timeRemains.getHour() <= 0 && timeRemains.getMinute() <= 0) { if (timeRemains.getHour() <= 0 && timeRemains.getMinute() <= 0) {
Toaster toasterManager = new Toaster(); Toaster toasterManager = new Toaster();
toasterManager.setDisplayTime(30000); toasterManager.setDisplayTime(30000);
toasterManager.showToaster( toasterManager.showToaster(
"Congratulation :-) It is the time to go home."); "Congratulation :-) It is the time to go home.");
walkingHumanProgress walkingHumanProgress
.printPercentToAscii(done, timeRemains.getHour(), .setDonePercent(done);
timeRemains.getMinute(), done,
totalSecondsRemainsDouble, endTime);
try { try {
Thread.sleep(10000); Thread.sleep(10000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -724,9 +710,7 @@ public class MainWindow extends TWindow {
} }
} else { } else {
walkingHumanProgress walkingHumanProgress
.printPercentToAscii(done, timeRemains.getHour(), .setDonePercent(done);
timeRemains.getMinute(), done,
totalSecondsRemainsDouble, endTime);
} }
try { try {

View File

@ -8,7 +8,6 @@ import org.nanoboot.utils.timecalc.swing.common.Toaster;
import org.nanoboot.utils.timecalc.swing.common.Widget; import org.nanoboot.utils.timecalc.swing.common.Widget;
import org.nanoboot.utils.timecalc.utils.common.Constants; import org.nanoboot.utils.timecalc.utils.common.Constants;
import org.nanoboot.utils.timecalc.utils.common.NumberFormats; import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
import org.nanoboot.utils.timecalc.utils.common.TTime;
import org.nanoboot.utils.timecalc.utils.common.Utils; import org.nanoboot.utils.timecalc.utils.common.Utils;
import org.nanoboot.utils.timecalc.utils.property.Property; import org.nanoboot.utils.timecalc.utils.property.Property;
@ -35,13 +34,6 @@ public class WalkingHumanProgress extends Widget implements
private static final String WALL = "||"; private static final String WALL = "||";
private final Set<Integer> alreadyShownPercents = new HashSet<>(); private final Set<Integer> alreadyShownPercents = new HashSet<>();
private double percent;
private int hourRemains;
private int minuteRemains;
private double done;
private double totalSecondsRemainsDouble;
private TTime endTime;
public WalkingHumanProgress() { public WalkingHumanProgress() {
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11)); setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11));
putClientProperty("mouseEntered", "false"); putClientProperty("mouseEntered", "false");
@ -111,7 +103,7 @@ public class WalkingHumanProgress extends Widget implements
@Override @Override
public void paintWidget(Graphics brush) { public void paintWidget(Graphics brush) {
String string = printPercentToAscii(); String string = createAsciiString();
if (string.isEmpty()) { if (string.isEmpty()) {
//nothing to do //nothing to do
} else { } else {
@ -133,7 +125,7 @@ public class WalkingHumanProgress extends Widget implements
} }
} }
private String printPercentToAscii() { private String createAsciiString() {
if (visibleProperty.isDisabled()) { if (visibleProperty.isDisabled()) {
//nothing to do //nothing to do
return ""; return "";
@ -143,11 +135,10 @@ public class WalkingHumanProgress extends Widget implements
this.setVisible(visibility != Visibility.NONE); this.setVisible(visibility != Visibility.NONE);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String msg = createMessage(hourRemains, minuteRemains, done,
totalSecondsRemainsDouble, endTime); int percentInt = (int) (donePercent * 100);
int percentInt = (int) (percent * 100); if (!alreadyShownPercents.contains((int) (donePercent * 100))) {
if (!alreadyShownPercents.contains((int) (percent * 100))) { alreadyShownPercents.add((int) (donePercent * 100));
alreadyShownPercents.add((int) (percent * 100));
Toaster toasterManager = new Toaster(); Toaster toasterManager = new Toaster();
Font font = new Font("sans", Font.PLAIN, 16); Font font = new Font("sans", Font.PLAIN, 16);
toasterManager.setToasterMessageFont(font); toasterManager.setToasterMessageFont(font);
@ -177,11 +168,8 @@ public class WalkingHumanProgress extends Widget implements
} }
} }
sb.append(msg + "\n\n");
int spacesTotal = 40; int spacesTotal = 40;
int spacesDone = (int) (percent * spacesTotal); int spacesDone = (int) (donePercent * spacesTotal);
if (spacesDone > spacesTotal) { if (spacesDone > spacesTotal) {
spacesDone = spacesTotal; spacesDone = spacesTotal;
} }
@ -208,40 +196,12 @@ public class WalkingHumanProgress extends Widget implements
+ createRepeatedString(spacesTotal + 16, '=') + createRepeatedString(spacesTotal + 16, '=')
+ Constants.NEW_LINE + "Steps: " + Constants.NEW_LINE + "Steps: "
+ NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES + NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES
.format(percent * ((double) spacesTotal)) + "/" .format(donePercent * ((double) spacesTotal)) + "/"
+ spacesTotal + spacesTotal
); );
return sb.toString(); return sb.toString();
} }
public void printPercentToAscii(double percent, long hourRemains,
long minuteRemains, double done,
double totalSecondsRemainsDouble, TTime endTime) {
this.percent = percent;
this.hourRemains = (int) hourRemains;
this.minuteRemains = (int) minuteRemains;
this.done = done;
this.totalSecondsRemainsDouble = totalSecondsRemainsDouble;
this.endTime = endTime;
}
private String createMessage(int hourRemains, int minuteRemains,
double done,
double totalSecondsRemainsDouble, TTime endTime) {
String msg
= "Done=" + NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES.format(
done * 100) + "% Remains="
+ String.format("%02d", hourRemains) + ":" + String
.format("%02d", minuteRemains)
+ /*":" + String.format("%02d", secondsRemains)+ */ " ("
+ NumberFormats.FORMATTER_THREE_DECIMAL_PLACES
.format(totalSecondsRemainsDouble - 60)
+ " s" + ")" + " End=" + String
.format("%02d", endTime.getHour()) + ":" + String
.format("%02d", endTime.getMinute());
return msg;
}
@Override @Override
public Property getVisibilityProperty() { public Property getVisibilityProperty() {
return visibilityProperty; return visibilityProperty;