implemented the analog watch
This commit is contained in:
parent
5fd9581670
commit
63ae5e2e1c
@ -40,38 +40,35 @@ public class FastWatchController {
|
|||||||
@FXML
|
@FXML
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
WatchTime wt = WatchTime.getInstance();
|
WatchTime wt = WatchTime.getInstance();
|
||||||
wt.setTime(4,1,DayOfWeek.FRIDAY);
|
wt.setTime(4, 1, DayOfWeek.FRIDAY);
|
||||||
cmbDayOfWeek.getItems().addAll(DayOfWeek.values());
|
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());
|
lblHours.textProperty().bind(wt.hoursProperty().asString());
|
||||||
lblMinutes.textProperty().bind(wt.minutesProperty().asString());
|
lblMinutes.textProperty().bind(wt.minutesProperty().asString());
|
||||||
lblDayOfWeek.textProperty().bind(wt.dayOfWeekShortProperty());
|
lblDayOfWeek.textProperty().bind(wt.dayOfWeekShortProperty());
|
||||||
|
|
||||||
|
|
||||||
//TODO: Bind slider (bidirectionally!) and slider label (one-way).
|
|
||||||
lblTickDelay.textProperty().bind(wt.tickDelayProperty().asString());
|
lblTickDelay.textProperty().bind(wt.tickDelayProperty().asString());
|
||||||
sldTickDelay.valueProperty().bindBidirectional(wt.tickDelayProperty());
|
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() {
|
private void updateAnalogClock() {
|
||||||
double length = 140; //Approx. half the container size.
|
WatchTime wt = WatchTime.getInstance();
|
||||||
|
double length = 140;
|
||||||
|
|
||||||
this.linHandHours.setStartX(0);
|
double hourAngle = (wt.hoursProperty().get() % 12 + wt.minutesProperty().get() / 60.0) * 30;
|
||||||
this.linHandHours.setStartY(0);
|
double hourRadians = Math.toRadians(hourAngle - 90);
|
||||||
this.linHandHours.setEndX(-0.866 * length * 0.6);
|
this.linHandHours.setEndX(Math.cos(hourRadians) * length * 0.6);
|
||||||
this.linHandHours.setEndY(0.49 * length * 0.6);
|
this.linHandHours.setEndY(Math.sin(hourRadians) * length * 0.6);
|
||||||
|
|
||||||
this.linHandMinutes.setStartX(0);
|
double minuteAngle = wt.minutesProperty().get() * 6;
|
||||||
this.linHandMinutes.setStartY(0);
|
double minuteRadians = Math.toRadians(minuteAngle - 90);
|
||||||
this.linHandMinutes.setEndX(0);
|
this.linHandMinutes.setEndX(Math.cos(minuteRadians) * length * 0.8);
|
||||||
this.linHandMinutes.setEndY(-1.0 * length * 0.8);
|
this.linHandMinutes.setEndY(Math.sin(minuteRadians) * length * 0.8);
|
||||||
|
|
||||||
//Hint: Use Point2D for storing coordinates - this makes using helper functions easier.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void btnAdjustOnAction(ActionEvent actionEvent) {
|
public void btnAdjustOnAction(ActionEvent actionEvent) {
|
||||||
@ -79,7 +76,7 @@ public class FastWatchController {
|
|||||||
.mapToInt(Integer::parseInt)
|
.mapToInt(Integer::parseInt)
|
||||||
.toArray();
|
.toArray();
|
||||||
DayOfWeek dayOfWeek = this.cmbDayOfWeek.getValue();
|
DayOfWeek dayOfWeek = this.cmbDayOfWeek.getValue();
|
||||||
WatchTime.getInstance().setTime(time[0],time[1], dayOfWeek);
|
WatchTime.getInstance().setTime(time[0], time[1], dayOfWeek);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user