Time improvements - wip2

This commit is contained in:
Robert Vokac 2024-02-10 12:22:23 +00:00
parent 4ab6553c11
commit 5bd75ddd70
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
2 changed files with 51 additions and 26 deletions

View File

@ -244,11 +244,55 @@ public class TimeCalcManager {
stopBeforeEnd = true;
});
Calendar calNow = Calendar.getInstance();
calNow.setTime(new Date());
AnalogClock analogClock = new AnalogClock(startTime, endTime);
analogClock.setBounds(MARGIN, MARGIN, 200);
Properties testProperties = new Properties();
File testPropertiesFile = new File("test.txt");
try {
if(testPropertiesFile.exists()) {
testProperties.load(new FileInputStream(testPropertiesFile));
}
} catch (FileNotFoundException ex) {
Logger.getLogger(TimeCalcManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException rex) {
Logger.getLogger(TimeCalcManager.class.getName()).log(Level.SEVERE, null, rex);
}
System.out.println("current dir=" + new File(".").getAbsolutePath());
if(testProperties.containsKey("current.day")) {
calNow.set(Calendar.DAY_OF_MONTH, Integer.parseInt((String) testProperties.get("current.day")));
analogClock.dayProperty.setValue(Integer.valueOf((String) testProperties.get("current.day")));
} else {
analogClock.dayProperty.bindTo(time.dayProperty);
}
if(testProperties.containsKey("current.month")) {
calNow.set(Calendar.MONTH, Integer.parseInt((String) testProperties.get("current.month")) - 1);
analogClock.monthProperty.setValue(Integer.valueOf((String) testProperties.get("current.month")));
} else {
analogClock.monthProperty.bindTo(time.monthProperty);
}
if(testProperties.containsKey("current.year")) {
calNow.set(Calendar.YEAR, Integer.parseInt((String) testProperties.get("current.year")));
analogClock.yearProperty.setValue(Integer.valueOf((String) testProperties.get("current.year")));
} else {
analogClock.yearProperty.bindTo(time.yearProperty);
}
if(testProperties.containsKey("current.year") || testProperties.containsKey("current.month") ||testProperties.containsKey("current.day")) {
analogClock.dayOfWeekProperty.setValue(calNow.get(Calendar.DAY_OF_WEEK));
} else {
analogClock.dayOfWeekProperty.bindTo(time.dayOfWeek);
}
analogClock.hourProperty.bindTo(time.hourProperty);
analogClock.minuteProperty.bindTo(time.minuteProperty);
analogClock.secondProperty.bindTo(time.secondProperty);
analogClock.millisecondProperty.bindTo(time.millisecondProperty);
window.add(analogClock);
@ -277,30 +321,6 @@ public class TimeCalcManager {
dayBattery.getY(), 140);
window.add(weekBattery);
Calendar calNow = Calendar.getInstance();
calNow.setTime(new Date());
Properties testProperties = new Properties();
File testPropertiesFile = new File("test.txt");
try {
if(testPropertiesFile.exists()) {
testProperties.load(new FileInputStream(testPropertiesFile));
}
} catch (FileNotFoundException ex) {
Logger.getLogger(TimeCalcManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException rex) {
Logger.getLogger(TimeCalcManager.class.getName()).log(Level.SEVERE, null, rex);
}
System.out.println("current dir=" + new File(".").getAbsolutePath());
if(testProperties.containsKey("current.day")) {
calNow.set(Calendar.DAY_OF_MONTH, Integer.parseInt((String) testProperties.get("current.day")));
}
if(testProperties.containsKey("current.month")) {
calNow.set(Calendar.MONTH, Integer.parseInt((String) testProperties.get("current.month")) - 1);
}
if(testProperties.containsKey("current.year")) {
calNow.set(Calendar.YEAR, Integer.parseInt((String) testProperties.get("current.year")));
}
int currentDayOfMonth = calNow.get(Calendar.DAY_OF_MONTH);
int workDaysDone = 0;

View File

@ -204,9 +204,14 @@ public class AnalogClock extends Widget {
if(this.mouseOver)
{
g2d.drawString(DateFormats.DATE_TIME_FORMATTER_LONG.format(new Date()), ((int) (side * 0.25)),
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, yearProperty.getValue());
cal.set(Calendar.MONTH, monthProperty.getValue() -1);
cal.set(Calendar.DAY_OF_MONTH, dayProperty.getValue());
Date date = cal.getTime();
g2d.drawString(DateFormats.DATE_TIME_FORMATTER_LONG.format(date), ((int) (side * 0.25)),
((int) (side * 0.35)));
g2d.drawString(DateFormats.DATE_TIME_FORMATTER_TIME.format(new Date()),
g2d.drawString(DateFormats.DATE_TIME_FORMATTER_TIME.format(date),
((int) (side * 0.25) + 30),
((int) (side * 0.35)) + 60);
}