implemented the analog watch

This commit is contained in:
Jonas Hinterdorfer 2025-03-20 12:02:58 +01:00
parent 5fd9581670
commit 63ae5e2e1c

View File

@ -40,38 +40,35 @@ public class FastWatchController {
@FXML
private void initialize() {
WatchTime wt = WatchTime.getInstance();
wt.setTime(4,1,DayOfWeek.FRIDAY);
wt.setTime(4, 1, DayOfWeek.FRIDAY);
cmbDayOfWeek.getItems().addAll(DayOfWeek.values());
//TODO: Bind labels of digital watch (one-way). Use StringBinding for the minutes to format them (leading 0s).
lblHours.textProperty().bind(wt.hoursProperty().asString());
lblMinutes.textProperty().bind(wt.minutesProperty().asString());
lblDayOfWeek.textProperty().bind(wt.dayOfWeekShortProperty());
//TODO: Bind slider (bidirectionally!) and slider label (one-way).
lblTickDelay.textProperty().bind(wt.tickDelayProperty().asString());
sldTickDelay.valueProperty().bindBidirectional(wt.tickDelayProperty());
//TODO: Add listener to redraw analog hands.
wt.hoursProperty().addListener((_) -> updateAnalogClock());
wt.minutesProperty().addListener((_) -> updateAnalogClock());
demonstrateSettingHands();
updateAnalogClock();
}
private void demonstrateSettingHands() {
double length = 140; //Approx. half the container size.
private void updateAnalogClock() {
WatchTime wt = WatchTime.getInstance();
double length = 140;
this.linHandHours.setStartX(0);
this.linHandHours.setStartY(0);
this.linHandHours.setEndX(-0.866 * length * 0.6);
this.linHandHours.setEndY(0.49 * length * 0.6);
double hourAngle = (wt.hoursProperty().get() % 12 + wt.minutesProperty().get() / 60.0) * 30;
double hourRadians = Math.toRadians(hourAngle - 90);
this.linHandHours.setEndX(Math.cos(hourRadians) * length * 0.6);
this.linHandHours.setEndY(Math.sin(hourRadians) * length * 0.6);
this.linHandMinutes.setStartX(0);
this.linHandMinutes.setStartY(0);
this.linHandMinutes.setEndX(0);
this.linHandMinutes.setEndY(-1.0 * length * 0.8);
//Hint: Use Point2D for storing coordinates - this makes using helper functions easier.
double minuteAngle = wt.minutesProperty().get() * 6;
double minuteRadians = Math.toRadians(minuteAngle - 90);
this.linHandMinutes.setEndX(Math.cos(minuteRadians) * length * 0.8);
this.linHandMinutes.setEndY(Math.sin(minuteRadians) * length * 0.8);
}
public void btnAdjustOnAction(ActionEvent actionEvent) {
@ -79,7 +76,7 @@ public class FastWatchController {
.mapToInt(Integer::parseInt)
.toArray();
DayOfWeek dayOfWeek = this.cmbDayOfWeek.getValue();
WatchTime.getInstance().setTime(time[0],time[1], dayOfWeek);
WatchTime.getInstance().setTime(time[0], time[1], dayOfWeek);
}
}