This commit is contained in:
Robert Vokac 2024-03-23 08:20:03 +01:00
parent 8e9b90d622
commit 3c4cdcbfec
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
10 changed files with 106 additions and 73 deletions

View File

@ -9,9 +9,9 @@ import org.nanoboot.utils.timecalc.app.TimeCalcException;
public class Progress {
private final double[] array = new double[6];
public void set(WidgetType type, double value) {
array[WidgetType.DAY.getIndex()] = value;
array[type.getIndex()] = value > 1 ? 1 : (value < 0 ? 0 : value);
}
public double get(WidgetType type) {
return array[WidgetType.DAY.getIndex()];
return array[type.getIndex()];
}
}

View File

@ -2,6 +2,7 @@ package org.nanoboot.utils.timecalc.swing.common;
import org.nanoboot.utils.timecalc.app.GetProperty;
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
import org.nanoboot.utils.timecalc.entity.Progress;
import org.nanoboot.utils.timecalc.entity.Visibility;
import org.nanoboot.utils.timecalc.entity.WidgetType;
import org.nanoboot.utils.timecalc.swing.progress.Battery;
@ -64,7 +65,7 @@ public class Widget extends JPanel implements
public StringProperty typeProperty
= new StringProperty("widget.typeProperty", WidgetType.DAY.name().toLowerCase());
protected int side = 0;
protected double donePercent = 0;
private Progress progress = null;
protected boolean mouseOver = false;
private boolean mouseOverCloseButton = false;
protected JLabel smileyIcon;
@ -153,20 +154,24 @@ public class Widget extends JPanel implements
// }
//
// }
public final void setDonePercent(double newDonePercent) {
if (newDonePercent > 1) {
newDonePercent = 1;
}
if (newDonePercent < 0) {
newDonePercent = 0;
}
double oldDonePercent = this.donePercent;
public final void setProgress(Progress newProgress) {
double oldDonePercent = this.progress == null ? 0 : this.progress.get(WidgetType.DAY);
int oldDonePercentInt1000Mil = (int) (oldDonePercent * 1000000000);
this.donePercent = newDonePercent;
int newDonePercentInt1000Mil = (int) (newDonePercent * 1000000000);
int newDonePercentInt1000Mil = (int) (newProgress.get(WidgetType.DAY) * 1000000000);
if (newDonePercentInt1000Mil != oldDonePercentInt1000Mil) {
lastUpdate = System.nanoTime();
}
this.progress = newProgress;
}
protected double donePercent() {
if(progress == null) {
return 0;
}
return progress.get(WidgetType.valueOf(typeProperty.getValue().toUpperCase(
Locale.ROOT)));
}
public void setBounds(int x, int y, int side) {
@ -300,7 +305,7 @@ public class Widget extends JPanel implements
brush.setColor(currentColor);
brush.setFont(MEDIUM_FONT);
brush.drawString(
ProgressSmiley.forProgress(customDonePercent >= 0 ? customDonePercent : donePercent).getCharacter(),
ProgressSmiley.forProgress(customDonePercent >= 0 ? customDonePercent : donePercent()).getCharacter(),
x + 1 + (getClass() == ProgressSwing.class ? -8 : 0), y + 16
);
brush.setFont(currentFont);
@ -309,7 +314,7 @@ public class Widget extends JPanel implements
if (colored) {
x = x + 2;
ImageIcon imageIcon = ProgressSmileyIcon
.forSmiley(ProgressSmiley.forProgress(customDonePercent >= 0 ? customDonePercent : donePercent))
.forSmiley(ProgressSmiley.forProgress(customDonePercent >= 0 ? customDonePercent : donePercent()))
.getIcon();
if(smileyNumber < 2) {
if (this.smileyIcon != null) {
@ -359,8 +364,8 @@ public class Widget extends JPanel implements
//Color currentBackgroundColor = brush.getBackground();
Font currentFont = brush.getFont();
brush.setFont(BIG_FONT);
int q = donePercent < 0.25 ? 0 : (donePercent < 0.5 ? 1 :
(donePercent < 0.75 ? 2 : (donePercent < 1.0 ? 3 : 4)));
int q = donePercent() < 0.25 ? 0 : (donePercent() < 0.5 ? 1 :
(donePercent() < 0.75 ? 2 : (donePercent() < 1.0 ? 3 : 4)));
Color color;
Color backgroundColor;
switch (visibility) {
@ -400,7 +405,7 @@ public class Widget extends JPanel implements
brush.setColor(backgroundColor);
if(x< 0 || y < 0) {
brush.fillRect(((int) (totalWidth * 0.08)),
(donePercent < 0.5 ? totalHeight / 4 * 3
(donePercent() < 0.5 ? totalHeight / 4 * 3
: (totalHeight / 4 * 1) + 10) + -8, 20, 20);
} else {
brush.fillRect(x, y, 20, 20);
@ -409,7 +414,7 @@ public class Widget extends JPanel implements
if(x< 0 || y < 0) {
brush.drawString(
String.valueOf(q), ((int) (totalWidth * 0.13)),
(donePercent < 0.5 ? totalHeight / 4 * 3
(donePercent() < 0.5 ? totalHeight / 4 * 3
: (totalHeight / 4 * 1) + 10) + 10
);
} else {

View File

@ -2,6 +2,7 @@ package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
import org.nanoboot.utils.timecalc.entity.Visibility;
import org.nanoboot.utils.timecalc.entity.WidgetType;
import org.nanoboot.utils.timecalc.swing.common.SwingUtils;
import org.nanoboot.utils.timecalc.swing.common.Widget;
import org.nanoboot.utils.timecalc.utils.common.DateFormats;
@ -21,6 +22,7 @@ import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
//https://kodejava.org/how-do-i-write-a-simple-analog-clock-using-java-2d/
public class AnalogClock extends Widget {
@ -96,8 +98,10 @@ public class AnalogClock extends Widget {
public final BooleanProperty smileyVisibleProperty = new BooleanProperty("smileyVisibleProperty");
public final BooleanProperty percentProgressVisibleProperty = new BooleanProperty("percentProgressVisibleProperty");
private Color customCircleColor = null;
private double dayProgress;
public AnalogClock() {
typeProperty.setValue(WidgetType.DAY.name().toLowerCase(Locale.ROOT));
setPreferredSize(new Dimension(200, 200));
@ -181,7 +185,7 @@ public class AnalogClock extends Widget {
int total = endMS - startMS;
int done = nowMS - startMS;
double progress = ((double)done) / ((double)total);
setDonePercent(progress);
this.dayProgress = progress;
//System.out.println("clock.handsLongProperty=" + handsLongProperty.isEnabled());
Visibility visibility
@ -380,7 +384,7 @@ public class AnalogClock extends Widget {
}
if(percentProgressVisibleProperty.isEnabled()) {
brush.drawString(((int) Math.floor(donePercent * 100)) + "%",
brush.drawString(((int) Math.floor(dayProgress * 100)) + "%",
((int) (side * 0.25)),
((int) (side * 0.35)) + 35);
}

View File

@ -15,6 +15,7 @@ import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class Battery extends Widget {
@ -171,6 +172,8 @@ public class Battery extends Widget {
protected Battery(String name) {
this.name = name;
setPreferredSize(new Dimension(40, 100));
this.typeProperty.setValue(getClass().getSimpleName().replace("Battery", "").toLowerCase(
Locale.ROOT));
}
protected Battery(String name, int i, int y, int height) {
@ -184,9 +187,10 @@ public class Battery extends Widget {
this.totalHeight = (int) (this.getHeight() / 10d * 7d);
this.totalWidth = this.getWidth();
}
double donePercent = donePercent();
if (blinkingIfCriticalLowVisibleProperty.isEnabled()) {
if (donePercent > 0 && donePercent <= CRITICAL_LOW_ENERGY
&& (System.nanoTime() - tmpNanoTime) > (1000000000l) / 2l) {
&& (System.nanoTime() - tmpNanoTime) > (1000000000l) / 2l) {
blinking.flip();
tmpNanoTime = System.nanoTime();
}
@ -239,7 +243,7 @@ public class Battery extends Widget {
? doneHeight : doneHeight - waterSurfaceHeight + 1);
int pointCount = 8;
if (doneHeight >= waterSurfaceHeight
&& donePercent < 1) {// && todoHeight > waterSurfaceHeight) {
&& donePercent < 1) {// && todoHeight > waterSurfaceHeight) {
//g2d.fillArc(intX, intY, width_, intHeight - waterSurfaceHeight, 30, 60);
brush.fillPolygon(
@ -367,7 +371,7 @@ public class Battery extends Widget {
public void paintChargingCharacter(Graphics2D brush) {
brush.drawString(
CHARCHING, ((int) (totalWidth * 0.45)),
(donePercent < 0.5 ? totalHeight / 4 * 3
(donePercent() < 0.5 ? totalHeight / 4 * 3
: (totalHeight / 4 * 1) + 10) + 10
);
}
@ -379,7 +383,7 @@ public class Battery extends Widget {
: (visibility.isWeaklyColored() ? HIGH_WEAKLY_COLORED
: Color.lightGray));
double angleDouble = donePercent * 360;
double angleDouble = donePercent() * 360;
brush.fillArc(((int) (totalWidth * 0.45)) + 15,
totalHeight / 4 * 3 + 28,

View File

@ -30,7 +30,7 @@ public class ProgressCircle extends Widget {
brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
double angleDouble = donePercent * 360;
double angleDouble = donePercent() * 360;
double angleDouble2 = (angleDouble - (int) (angleDouble)) * 360;
// System.out.println("remainingAngle=" + angleDouble2);
@ -45,7 +45,7 @@ public class ProgressCircle extends Widget {
brush.drawString(
NumberFormats.FORMATTER_ZERO_DECIMAL_PLACES
.format(donePercent * 100) + "%",
.format(donePercent() * 100) + "%",
(int) (side / 8d * 0d), (int) (side / 8d * 7.5d));
paintSmiley(visibility, brush, (int) (side / 8d * 0d) + 30,
(int) (side / 8d * 7.5d - 16d));

View File

@ -75,7 +75,7 @@ public class ProgressLife extends Widget implements GetProperty {
Date now = time.asCalendar().getTime();
long diff = now.getTime() - birthDate.getTime();
Date result = new Date(
(long) (birthDate.getTime() + diff * donePercent));
(long) (birthDate.getTime() + diff * donePercent()));
String date =
DateFormats.DATE_TIME_FORMATTER_YYYYMMDD.format(result);
@ -97,6 +97,9 @@ public class ProgressLife extends Widget implements GetProperty {
brush.drawString(time, SwingUtils.MARGIN, (int) (SwingUtils.MARGIN
+ (getHeight() - SwingUtils.MARGIN)
* 0.6d));
brush.drawString(typeProperty.getValue(), SwingUtils.MARGIN, (int) (SwingUtils.MARGIN
+ (getHeight() - SwingUtils.MARGIN)
* 0.6d) + 20);
}
}

View File

@ -30,7 +30,7 @@ public class ProgressSquare extends Widget {
brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
int dotNumber = (int) (donePercent * square);
int dotNumber = (int) (donePercent() * square);
int y = dotNumber / side;
int yOrig = y;
int x = dotNumber - y * side;
@ -78,11 +78,11 @@ public class ProgressSquare extends Widget {
: BACKGROUND_COLOR);
brush.drawString(NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES
.format(donePercent * 100) + "%",
.format(donePercent() * 100) + "%",
(int) (side / 8d * 3d),
(int) (side / 8d * (donePercent > 0.5 ? 3d : 5d)));
(int) (side / 8d * (donePercent() > 0.5 ? 3d : 5d)));
paintSmiley(visibility, brush, (int) (side / 8d * 3d),
(int) ((side / 8d * (donePercent > 0.5 ? 3d : 5d)) - 32d));
(int) ((side / 8d * (donePercent() > 0.5 ? 3d : 5d)) - 32d));
}

View File

@ -45,6 +45,7 @@ public class ProgressSwing extends Widget {
(int) (getHeight() * 0.66) - 10 - 3, 6, 6);
brush.drawLine(1, getHeight() - 2, getWidth(), getHeight() - 2);
int startX = (int) (getWidth() * 0.10);
double donePercent = donePercent();
int startY = (int) (getHeight() - getHeight() * 0.66 * (1 - donePercent)) - 10;
int endX = (int) (getWidth() * 0.90);
int endY = (int) (getHeight() - getHeight() * 0.66 * donePercent) - 10;

View File

@ -92,7 +92,7 @@ public class WalkingHumanProgress extends Widget implements
paintSmiley(visibility,
(Graphics2D) brush,
//29 309
29 + ((int) (280 * donePercent)),
29 + ((int) (280 * donePercent())),
y - 4, true);
}
y = y + SwingUtils.MARGIN;
@ -112,7 +112,7 @@ public class WalkingHumanProgress extends Widget implements
this.setVisible(visibility != Visibility.NONE);
StringBuilder sb = new StringBuilder();
final int donePercentInt = (int) (Math.floor(donePercent * 100));
final int donePercentInt = (int) (Math.floor(donePercent() * 100));
int percentInt = donePercentInt;
if (donePercentInt % 5 == 0 && !alreadyShownPercents.contains(donePercentInt)) {
@ -147,7 +147,7 @@ public class WalkingHumanProgress extends Widget implements
}
int spacesTotal = 40;
int spacesDone = (int) (donePercent * spacesTotal);
int spacesDone = (int) (donePercent() * spacesTotal);
if (spacesDone > spacesTotal) {
spacesDone = spacesTotal;
}
@ -174,9 +174,9 @@ public class WalkingHumanProgress extends Widget implements
+ createRepeatedString(spacesTotal + 14, '=')
+ Constants.NEW_LINE + "Steps: "
+ NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES
.format(donePercent * ((double) spacesTotal)) + "/"
.format(donePercent() * ((double) spacesTotal)) + "/"
+ spacesTotal + " Done: " + NumberFormats.FORMATTER_EIGHT_DECIMAL_PLACES
.format(donePercent * 100d) + "%"
.format(donePercent() * 100d) + "%"
);
return sb.toString();
}

View File

@ -7,7 +7,9 @@ import org.nanoboot.utils.timecalc.app.TimeCalcConfiguration;
import org.nanoboot.utils.timecalc.app.TimeCalcKeyAdapter;
import org.nanoboot.utils.timecalc.app.TimeCalcProperties;
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
import org.nanoboot.utils.timecalc.entity.Progress;
import org.nanoboot.utils.timecalc.entity.Visibility;
import org.nanoboot.utils.timecalc.entity.WidgetType;
import org.nanoboot.utils.timecalc.entity.WorkingDay;
import org.nanoboot.utils.timecalc.persistence.api.ActivityRepositoryApi;
import org.nanoboot.utils.timecalc.persistence.impl.sqlite.ActivityRepositorySQLiteImpl;
@ -328,7 +330,7 @@ public class MainWindow extends TWindow {
progressSwing.typeProperty
.bindTo(timeCalcConfiguration.swingTypeProperty);
progressLife.typeProperty
.bindTo(timeCalcConfiguration.squareTypeProperty);
.bindTo(timeCalcConfiguration.lifeTypeProperty);
progressLife.birthDateProperty
.bindTo(timeCalcConfiguration.lifeBirthDateProperty);
}
@ -974,52 +976,66 @@ public class MainWindow extends TWindow {
if (done > 1) {
done = 1;
}
progressSquare.setDonePercent(done);
progressCircle.setDonePercent(done);
progressSwing.setDonePercent(done);
progressLife.setDonePercent(done);
dayBattery.setDonePercent(done);
try {
WeekStatistics weekStatisticsTmp = new WeekStatistics(clock, time);
weekStatistics = weekStatisticsTmp;
} catch (DateTimeException e) {
e.printStackTrace();
Progress progress = new Progress();
progress.set(WidgetType.DAY, done);
try {
Thread.sleep(1000);
} catch (InterruptedException interruptedException) {
interruptedException.printStackTrace();
WeekStatistics weekStatisticsTmp = new WeekStatistics(clock, time);
weekStatistics = weekStatisticsTmp;
} catch (DateTimeException e) {
e.printStackTrace();
try {
Thread.sleep(1000);
} catch (InterruptedException interruptedException) {
interruptedException.printStackTrace();
}
// return false;
}
// return false;
}
final boolean nowIsWeekend = weekStatistics.isNowIsWeekend();
final int workDaysDone = weekStatistics.getWorkDaysDone();
final int workDaysTotal = weekStatistics.getWorkDaysTotal();
final boolean nowIsWeekend = weekStatistics.isNowIsWeekend();
final int workDaysDone = weekStatistics.getWorkDaysDone();
final int workDaysTotal = weekStatistics.getWorkDaysTotal();
int weekDayWhenMondayIsOne = clock.dayOfWeekProperty.getValue();
weekBattery.setDonePercent(
WeekBattery.getWeekProgress(weekDayWhenMondayIsOne, done));
weekBattery.setLabel(
nowIsWeekend ? "5/5" : (weekDayWhenMondayIsOne + "/5"));
int weekDayWhenMondayIsOne = clock.dayOfWeekProperty.getValue();
double weekProgress = WeekBattery.getWeekProgress(weekDayWhenMondayIsOne, done);
weekBattery.setProgress(progress);
weekBattery.setLabel(
nowIsWeekend ? "5/5" : (weekDayWhenMondayIsOne + "/5"));
monthBattery.setDonePercent(MonthBattery
.getMonthProgress(weekDayWhenMondayIsOne, workDaysDone,
workDaysTotal, done));
double monthProgress = MonthBattery
.getMonthProgress(weekDayWhenMondayIsOne, workDaysDone,
workDaysTotal, done);
progress.set(WidgetType.MONTH, monthProgress);
double hourProgress =
HourBattery.getHourProgress(timeRemains, secondsRemains,
millisecondsRemains);
double minuteProgress =
MinuteBattery.getMinuteProgress(secondNow, millisecondNow);
double yearProgress = YearBattery.getYearProgress(clock);
progress.set(WidgetType.HOUR, hourProgress);
progress.set(WidgetType.WEEK, weekProgress);
progress.set(WidgetType.MINUTE, minuteProgress);
progress.set(WidgetType.YEAR, yearProgress);
progressSquare.setProgress(progress);
progressCircle.setProgress(progress);
progressSwing.setProgress(progress);
progressLife.setProgress(progress);
dayBattery.setProgress(progress);
monthBattery.setProgress(progress);
monthBattery.setLabel(
(nowIsWeekend ? workDaysDone : workDaysDone + 1) + "/"
+ (workDaysTotal));
hourBattery.setDonePercent(
HourBattery.getHourProgress(timeRemains, secondsRemains,
millisecondsRemains));
hourBattery.setProgress(progress);
if (!nowIsWeekend) {
hourBattery.setLabel(
totalHoursDone + "/" + (totalMinutes / 60));
}
minuteBattery.setDonePercent(
MinuteBattery.getMinuteProgress(secondNow, millisecondNow));
yearBattery
.setDonePercent(YearBattery.getYearProgress(clock));
minuteBattery.setProgress(progress);
yearBattery.setProgress(progress);
yearBattery.setLabel("");
if (timeRemains.getHour() <= 0 && timeRemains.getMinute() <= 0 && timeRemains.getSecond() <= 0 && timeRemains.getMillisecond() <= 0) {
@ -1028,7 +1044,7 @@ public class MainWindow extends TWindow {
toasterManager.showToaster(
"Congratulation :-) It is the time to go home.");
walkingHumanProgress
.setDonePercent(done);
.setProgress(progress);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
@ -1042,7 +1058,7 @@ public class MainWindow extends TWindow {
}
}
} else {
walkingHumanProgress.setDonePercent(done);
walkingHumanProgress.setProgress(progress);
}
try {