mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
Added several improvements
This commit is contained in:
parent
e553ecb6a6
commit
8a36e47404
@ -515,7 +515,7 @@ public class ConfigWindow extends TWindow {
|
|||||||
boolean isInteger = Integer.class == timeCalcProperty.getClazz();
|
boolean isInteger = Integer.class == timeCalcProperty.getClazz();
|
||||||
timeCalcConfiguration
|
timeCalcConfiguration
|
||||||
.getProperty(timeCalcProperty).addListener(e -> {
|
.getProperty(timeCalcProperty).addListener(e -> {
|
||||||
System.out.println("JTextField was changed: " + timeCalcPropertyKey);
|
|
||||||
textField.setText(isInteger
|
textField.setText(isInteger
|
||||||
?
|
?
|
||||||
String.valueOf(timeCalcConfiguration
|
String.valueOf(timeCalcConfiguration
|
||||||
@ -535,15 +535,12 @@ public class ConfigWindow extends TWindow {
|
|||||||
textField.getDocument()
|
textField.getDocument()
|
||||||
.addDocumentListener(new DocumentListener() {
|
.addDocumentListener(new DocumentListener() {
|
||||||
public void changedUpdate(DocumentEvent e) {
|
public void changedUpdate(DocumentEvent e) {
|
||||||
System.out.println("changedUpdate");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeUpdate(DocumentEvent e) {
|
public void removeUpdate(DocumentEvent e) {
|
||||||
System.out.println("removeUpdate");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertUpdate(DocumentEvent e) {
|
public void insertUpdate(DocumentEvent e) {
|
||||||
System.out.println("insertUpdate");
|
|
||||||
update(e);
|
update(e);
|
||||||
}
|
}
|
||||||
private void update(DocumentEvent e) {
|
private void update(DocumentEvent e) {
|
||||||
|
@ -239,20 +239,27 @@ public class MainWindow extends TWindow {
|
|||||||
helpWindow.setVisible(true);
|
helpWindow.setVisible(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
time.yearCustomProperty.bindTo(timeCalcConfiguration.testYearCustomProperty);
|
time.yearCustomProperty
|
||||||
time.monthCustomProperty.bindTo(timeCalcConfiguration.testMonthCustomProperty);
|
.bindTo(timeCalcConfiguration.testYearCustomProperty);
|
||||||
time.dayCustomProperty.bindTo(timeCalcConfiguration.testDayCustomProperty);
|
time.monthCustomProperty
|
||||||
time.hourCustomProperty.bindTo(timeCalcConfiguration.testHourCustomProperty);
|
.bindTo(timeCalcConfiguration.testMonthCustomProperty);
|
||||||
time.minuteCustomProperty.bindTo(timeCalcConfiguration.testMinuteCustomProperty);
|
time.dayCustomProperty
|
||||||
time.secondCustomProperty.bindTo(timeCalcConfiguration.testSecondCustomProperty);
|
.bindTo(timeCalcConfiguration.testDayCustomProperty);
|
||||||
time.millisecondCustomProperty.bindTo(timeCalcConfiguration.testMillisecondCustomProperty);
|
time.hourCustomProperty
|
||||||
|
.bindTo(timeCalcConfiguration.testHourCustomProperty);
|
||||||
|
time.minuteCustomProperty
|
||||||
|
.bindTo(timeCalcConfiguration.testMinuteCustomProperty);
|
||||||
|
time.secondCustomProperty
|
||||||
|
.bindTo(timeCalcConfiguration.testSecondCustomProperty);
|
||||||
|
time.millisecondCustomProperty
|
||||||
|
.bindTo(timeCalcConfiguration.testMillisecondCustomProperty);
|
||||||
time.allowCustomValuesProperty.setValue(true);
|
time.allowCustomValuesProperty.setValue(true);
|
||||||
analogClock.dayProperty.bindTo(time.dayProperty);
|
analogClock.dayProperty.bindTo(time.dayProperty);
|
||||||
analogClock.monthProperty.bindTo(time.monthProperty);
|
analogClock.monthProperty.bindTo(time.monthProperty);
|
||||||
analogClock.yearProperty.bindTo(time.yearProperty);
|
analogClock.yearProperty.bindTo(time.yearProperty);
|
||||||
analogClock.hourProperty.bindTo(time.hourProperty);
|
analogClock.hourProperty.bindTo(time.hourProperty);
|
||||||
analogClock.minuteProperty.bindTo(time.minuteProperty);
|
analogClock.minuteProperty.bindTo(time.minuteProperty);
|
||||||
analogClock.secondProperty.bindTo( time.secondProperty);
|
analogClock.secondProperty.bindTo(time.secondProperty);
|
||||||
analogClock.millisecondProperty.bindTo(time.millisecondProperty);
|
analogClock.millisecondProperty.bindTo(time.millisecondProperty);
|
||||||
|
|
||||||
analogClock.dayOfWeekProperty.bindTo(time.dayOfWeekProperty);
|
analogClock.dayOfWeekProperty.bindTo(time.dayOfWeekProperty);
|
||||||
@ -317,37 +324,6 @@ public class MainWindow extends TWindow {
|
|||||||
140);
|
140);
|
||||||
add(weekBattery);
|
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(
|
Battery monthBattery = new MonthBattery(
|
||||||
weekBattery.getBounds().x + weekBattery.getWidth()
|
weekBattery.getBounds().x + weekBattery.getWidth()
|
||||||
+ SwingUtils.MARGIN,
|
+ SwingUtils.MARGIN,
|
||||||
@ -523,6 +499,11 @@ public class MainWindow extends TWindow {
|
|||||||
progressCircle.setDonePercent(done);
|
progressCircle.setDonePercent(done);
|
||||||
dayBattery.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();
|
int weekDayWhenMondayIsOne = analogClock.dayOfWeekProperty.getValue();
|
||||||
weekBattery.setDonePercent(
|
weekBattery.setDonePercent(
|
||||||
WeekBattery.getWeekProgress(weekDayWhenMondayIsOne, done));
|
WeekBattery.getWeekProgress(weekDayWhenMondayIsOne, done));
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -14,12 +14,18 @@ public class MonthBattery extends Battery {
|
|||||||
|
|
||||||
public static double getMonthProgress(int weekDayWhenMondayIsOne,
|
public static double getMonthProgress(int weekDayWhenMondayIsOne,
|
||||||
int workDaysDone, int workDaysTotal, double done) {
|
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) {
|
if (done > 1) {
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
return weekDayWhenMondayIsOne == 0
|
double result = weekDayWhenMondayIsOne == 0
|
||||||
|| weekDayWhenMondayIsOne == 6
|
|| weekDayWhenMondayIsOne == 6
|
||||||
? workDaysDone / workDaysTotal
|
? (double) workDaysDone / workDaysTotal
|
||||||
: (workDaysDone + done) / workDaysTotal;
|
: (workDaysDone + done) / workDaysTotal;
|
||||||
|
// System.out.println("result=" + result);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user