diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ConfigWindow.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ConfigWindow.java index a7c0699..0fcefe7 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ConfigWindow.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ConfigWindow.java @@ -515,7 +515,7 @@ public class ConfigWindow extends TWindow { boolean isInteger = Integer.class == timeCalcProperty.getClazz(); timeCalcConfiguration .getProperty(timeCalcProperty).addListener(e -> { - System.out.println("JTextField was changed: " + timeCalcPropertyKey); + textField.setText(isInteger ? String.valueOf(timeCalcConfiguration @@ -535,15 +535,12 @@ public class ConfigWindow extends TWindow { textField.getDocument() .addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { - System.out.println("changedUpdate"); } public void removeUpdate(DocumentEvent e) { - System.out.println("removeUpdate"); } public void insertUpdate(DocumentEvent e) { - System.out.println("insertUpdate"); update(e); } private void update(DocumentEvent e) { diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java index 755b139..4330d09 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java @@ -239,20 +239,27 @@ public class MainWindow extends TWindow { helpWindow.setVisible(true); }); - time.yearCustomProperty.bindTo(timeCalcConfiguration.testYearCustomProperty); - time.monthCustomProperty.bindTo(timeCalcConfiguration.testMonthCustomProperty); - time.dayCustomProperty.bindTo(timeCalcConfiguration.testDayCustomProperty); - time.hourCustomProperty.bindTo(timeCalcConfiguration.testHourCustomProperty); - time.minuteCustomProperty.bindTo(timeCalcConfiguration.testMinuteCustomProperty); - time.secondCustomProperty.bindTo(timeCalcConfiguration.testSecondCustomProperty); - time.millisecondCustomProperty.bindTo(timeCalcConfiguration.testMillisecondCustomProperty); + time.yearCustomProperty + .bindTo(timeCalcConfiguration.testYearCustomProperty); + time.monthCustomProperty + .bindTo(timeCalcConfiguration.testMonthCustomProperty); + time.dayCustomProperty + .bindTo(timeCalcConfiguration.testDayCustomProperty); + time.hourCustomProperty + .bindTo(timeCalcConfiguration.testHourCustomProperty); + time.minuteCustomProperty + .bindTo(timeCalcConfiguration.testMinuteCustomProperty); + time.secondCustomProperty + .bindTo(timeCalcConfiguration.testSecondCustomProperty); + time.millisecondCustomProperty + .bindTo(timeCalcConfiguration.testMillisecondCustomProperty); time.allowCustomValuesProperty.setValue(true); analogClock.dayProperty.bindTo(time.dayProperty); analogClock.monthProperty.bindTo(time.monthProperty); analogClock.yearProperty.bindTo(time.yearProperty); analogClock.hourProperty.bindTo(time.hourProperty); analogClock.minuteProperty.bindTo(time.minuteProperty); - analogClock.secondProperty.bindTo( time.secondProperty); + analogClock.secondProperty.bindTo(time.secondProperty); analogClock.millisecondProperty.bindTo(time.millisecondProperty); analogClock.dayOfWeekProperty.bindTo(time.dayOfWeekProperty); @@ -317,37 +324,6 @@ public class MainWindow extends TWindow { 140); add(weekBattery); - int currentDayOfMonth = analogClock.dayProperty.getValue(); - - int workDaysDone = 0; - int workDaysTodo = 0; - int workDaysTotal; - for (int dayOfMonth = 1; - dayOfMonth <= time.asCalendar().getActualMaximum(Calendar.DAY_OF_MONTH); - dayOfMonth++) { - DayOfWeek dayOfWeek = - LocalDate.of(analogClock.yearProperty.getValue(), - analogClock.monthProperty.getValue(), dayOfMonth) - .getDayOfWeek(); - boolean weekend - = dayOfWeek.toString().equals("SATURDAY") || dayOfWeek - .toString().equals("SUNDAY"); - if (dayOfMonth < currentDayOfMonth && !weekend) { - ++workDaysDone; - } - if (dayOfMonth > currentDayOfMonth && !weekend) { - ++workDaysTodo; - } - } - String currentDayOfWeekAsString = LocalDate - .of(analogClock.yearProperty.getValue(), - analogClock.monthProperty.getValue(), - analogClock.dayOfWeekProperty.getValue()).getDayOfWeek() - .toString(); - boolean nowIsWeekend = currentDayOfWeekAsString.equals("SATURDAY") - || currentDayOfWeekAsString.equals("SUNDAY"); - workDaysTotal = workDaysDone + (nowIsWeekend ? 0 : 1) + workDaysTodo; - Battery monthBattery = new MonthBattery( weekBattery.getBounds().x + weekBattery.getWidth() + SwingUtils.MARGIN, @@ -523,6 +499,11 @@ public class MainWindow extends TWindow { progressCircle.setDonePercent(done); dayBattery.setDonePercent(done); + WeekStatistics weekStatistics = new WeekStatistics(analogClock, time); + final boolean nowIsWeekend = weekStatistics.isNowIsWeekend(); + final int workDaysDone = weekStatistics.getWorkDaysDone(); + final int workDaysTotal = weekStatistics.getWorkDaysTotal(); + int weekDayWhenMondayIsOne = analogClock.dayOfWeekProperty.getValue(); weekBattery.setDonePercent( WeekBattery.getWeekProgress(weekDayWhenMondayIsOne, done)); diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/WeekStatistics.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/WeekStatistics.java new file mode 100644 index 0000000..e6a76b8 --- /dev/null +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/WeekStatistics.java @@ -0,0 +1,61 @@ +package org.nanoboot.utils.timecalc.swing.common; + +import lombok.Getter; +import org.nanoboot.utils.timecalc.swing.progress.AnalogClock; +import org.nanoboot.utils.timecalc.swing.progress.Time; + +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.util.Calendar; + +/** + * @author Robert + * @since 06.03.2024 + */ +@Getter +public class WeekStatistics { + private final boolean nowIsWeekend; + private final int workDaysDone; + private final int workDaysTotal; + + public WeekStatistics(AnalogClock analogClock, Time time) { + int workDaysDoneTmp = 0; + int workDaysTodoTmp = 0; + int workDaysTotalTmp; + { + int currentDayOfMonth = analogClock.dayProperty.getValue(); + + for (int dayOfMonth = 1; + dayOfMonth <= time.asCalendar() + .getActualMaximum(Calendar.DAY_OF_MONTH); + dayOfMonth++) { + DayOfWeek dayOfWeek = + LocalDate.of(analogClock.yearProperty.getValue(), + analogClock.monthProperty.getValue(), + dayOfMonth) + .getDayOfWeek(); + boolean weekend + = dayOfWeek.toString().equals("SATURDAY") || dayOfWeek + .toString().equals("SUNDAY"); + if (dayOfMonth < currentDayOfMonth && !weekend) { + ++workDaysDoneTmp; + } + if (dayOfMonth > currentDayOfMonth && !weekend) { + ++workDaysTodoTmp; + } + } + + } + String currentDayOfWeekAsString = LocalDate + .of(analogClock.yearProperty.getValue(), + analogClock.monthProperty.getValue(), + analogClock.dayOfWeekProperty.getValue()).getDayOfWeek() + .toString(); + this.nowIsWeekend = currentDayOfWeekAsString.equals("SATURDAY") + || currentDayOfWeekAsString.equals("SUNDAY"); + workDaysTotalTmp = + workDaysDoneTmp + (nowIsWeekend ? 0 : 1) + workDaysTodoTmp; + this.workDaysDone = workDaysDoneTmp; + this.workDaysTotal = workDaysTotalTmp; + } +} diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/MonthBattery.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/MonthBattery.java index cab8e6e..e8ca13e 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/MonthBattery.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/MonthBattery.java @@ -14,12 +14,18 @@ public class MonthBattery extends Battery { public static double getMonthProgress(int weekDayWhenMondayIsOne, int workDaysDone, int workDaysTotal, double done) { +// System.out.println("weekDayWhenMondayIsOne=" + weekDayWhenMondayIsOne); +// System.out.println("workDaysDone=" + workDaysDone); +// System.out.println("workDaysTotal=" + workDaysTotal); +// System.out.println("done=" + done); if (done > 1) { done = 1; } - return weekDayWhenMondayIsOne == 0 - || weekDayWhenMondayIsOne == 6 - ? workDaysDone / workDaysTotal + double result = weekDayWhenMondayIsOne == 0 + || weekDayWhenMondayIsOne == 6 + ? (double) workDaysDone / workDaysTotal : (workDaysDone + done) / workDaysTotal; +// System.out.println("result=" + result); + return result; } }