use of eu.hansolo.tilesfx.TimeSection in project tilesfx by HanSolo.
the class TimerControlTileSkin method updateTime.
public void updateTime(final ZonedDateTime TIME) {
if (tile.isDiscreteHours()) {
hourRotate.setAngle(TIME.getHour() * 30);
} else {
hourRotate.setAngle(0.5 * (60 * TIME.getHour() + TIME.getMinute()));
}
if (tile.isDiscreteMinutes()) {
minuteRotate.setAngle(TIME.getMinute() * 6);
} else {
minuteRotate.setAngle(TIME.getMinute() * 6 + TIME.getSecond() * 0.1);
}
if (second.isVisible()) {
if (tile.isDiscreteSeconds()) {
secondRotate.setAngle(TIME.getSecond() * 6);
} else {
secondRotate.setAngle(TIME.getSecond() * 6 + TIME.get(ChronoField.MILLI_OF_SECOND) * 0.006);
}
}
if (sectionsVisible) {
for (TimeSection section : sectionMap.keySet()) {
if (highlightSections) {
sectionMap.get(section).setStroke(section.contains(TIME.toLocalTime()) ? section.getHighlightColor() : section.getColor());
} else {
sectionMap.get(section).setStroke(section.getColor());
}
}
}
amPmText.setText(TIME.get(ChronoField.AMPM_OF_DAY) == 0 ? "AM" : "PM");
Helper.adjustTextSize(amPmText, 0.2 * size, size * 0.05);
amPmText.setX((width - amPmText.getLayoutBounds().getWidth()) * 0.5);
amPmText.setY(height * 0.5 - size * 0.1);
dateText.setText(dateFormatter.format(TIME).toUpperCase());
Helper.adjustTextSize(dateText, 0.3 * size, size * 0.05);
dateText.setX((width - dateText.getLayoutBounds().getWidth()) * 0.5);
dateText.setY(height * 0.5 + size * 0.15);
}
use of eu.hansolo.tilesfx.TimeSection in project tilesfx by HanSolo.
the class TimerControlTileSkin method initGraphics.
// ******************** Initialization ************************************
@Override
protected void initGraphics() {
super.initGraphics();
currentValueListener = o -> {
// Update time only if clock is not already running
if (tile.isRunning()) {
return;
}
updateTime(ZonedDateTime.ofInstant(Instant.ofEpochSecond(tile.getCurrentTime()), ZoneId.of(ZoneId.systemDefault().getId())));
};
timeListener = o -> updateTime(tile.getTime());
dateFormatter = DateTimeFormatter.ofPattern("EE d", tile.getLocale());
sectionMap = new HashMap<>(tile.getTimeSections().size());
for (TimeSection section : tile.getTimeSections()) {
sectionMap.put(section, new Arc());
}
minuteRotate = new Rotate();
hourRotate = new Rotate();
secondRotate = new Rotate();
sectionsPane = new Pane();
sectionsPane.getChildren().addAll(sectionMap.values());
Helper.enableNode(sectionsPane, tile.getSectionsVisible());
minuteTickMarks = new Path();
minuteTickMarks.setFillRule(FillRule.EVEN_ODD);
minuteTickMarks.setFill(null);
minuteTickMarks.setStroke(tile.getMinuteColor());
minuteTickMarks.setStrokeLineCap(StrokeLineCap.ROUND);
hourTickMarks = new Path();
hourTickMarks.setFillRule(FillRule.EVEN_ODD);
hourTickMarks.setFill(null);
hourTickMarks.setStroke(tile.getHourColor());
hourTickMarks.setStrokeLineCap(StrokeLineCap.ROUND);
hour = new Rectangle(3, 60);
hour.setArcHeight(3);
hour.setArcWidth(3);
hour.setStroke(tile.getHourColor());
hour.getTransforms().setAll(hourRotate);
minute = new Rectangle(3, 96);
minute.setArcHeight(3);
minute.setArcWidth(3);
minute.setStroke(tile.getMinuteColor());
minute.getTransforms().setAll(minuteRotate);
second = new Rectangle(1, 96);
second.setArcHeight(1);
second.setArcWidth(1);
second.setStroke(tile.getSecondColor());
second.getTransforms().setAll(secondRotate);
second.setVisible(tile.isSecondsVisible());
second.setManaged(tile.isSecondsVisible());
knob = new Circle(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, 4.5);
knob.setStroke(Color.web("#282a3280"));
dropShadow = new DropShadow();
dropShadow.setColor(Color.rgb(0, 0, 0, 0.25));
dropShadow.setBlurType(BlurType.TWO_PASS_BOX);
dropShadow.setRadius(0.015 * PREFERRED_WIDTH);
dropShadow.setOffsetY(0.015 * PREFERRED_WIDTH);
shadowGroupHour = new Group(hour);
shadowGroupMinute = new Group(minute);
shadowGroupSecond = new Group(second, knob);
shadowGroupHour.setEffect(tile.isShadowsEnabled() ? dropShadow : null);
shadowGroupMinute.setEffect(tile.isShadowsEnabled() ? dropShadow : null);
shadowGroupSecond.setEffect(tile.isShadowsEnabled() ? dropShadow : null);
titleText = new Text("");
titleText.setTextOrigin(VPos.TOP);
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
amPmText = new Text(tile.getTime().get(ChronoField.AMPM_OF_DAY) == 0 ? "AM" : "PM");
dateText = new Text("");
Helper.enableNode(dateText, tile.isDateVisible());
text = new Text("");
Helper.enableNode(text, tile.isTextVisible());
getPane().getChildren().addAll(sectionsPane, hourTickMarks, minuteTickMarks, titleText, amPmText, dateText, text, shadowGroupHour, shadowGroupMinute, shadowGroupSecond);
}
use of eu.hansolo.tilesfx.TimeSection in project tilesfx by HanSolo.
the class TimerControlTileSkin method drawTimeSections.
private void drawTimeSections() {
if (sectionMap.isEmpty())
return;
ZonedDateTime time = tile.getTime();
DayOfWeek day = time.getDayOfWeek();
boolean isAM = time.get(ChronoField.AMPM_OF_DAY) == 0;
double offset = 90;
double angleStep = 360.0 / 60.0;
boolean highlightSections = tile.isHighlightSections();
for (TimeSection section : sectionMap.keySet()) {
LocalTime start = section.getStart();
LocalTime stop = section.getStop();
boolean isStartAM = start.get(ChronoField.AMPM_OF_DAY) == 0;
boolean isStopAM = stop.get(ChronoField.AMPM_OF_DAY) == 0;
boolean draw = isAM ? (isStartAM || isStopAM) : (!isStartAM || !isStopAM);
if (!section.getDays().contains(day)) {
draw = false;
}
if (!section.isActive()) {
draw = false;
}
if (draw) {
double sectionStartAngle = (start.getHour() % 12 * 5.0 + start.getMinute() / 12.0 + start.getSecond() / 300.0) * angleStep + 180;
double sectionAngleExtend = ((stop.getHour() - start.getHour()) % 12 * 5.0 + (stop.getMinute() - start.getMinute()) / 12.0 + (stop.getSecond() - start.getSecond()) / 300.0) * angleStep;
if (start.getHour() > stop.getHour()) {
sectionAngleExtend = (360.0 - Math.abs(sectionAngleExtend));
}
Arc arc = sectionMap.get(section);
arc.setCenterX(clockSize * 0.5);
arc.setCenterY(clockSize * 0.5);
arc.setRadiusX(clockSize * 0.45);
arc.setRadiusY(clockSize * 0.45);
arc.setStartAngle(-(offset + sectionStartAngle));
arc.setLength(-sectionAngleExtend);
arc.setType(ArcType.OPEN);
arc.setStrokeWidth(clockSize * 0.04);
arc.setStrokeLineCap(StrokeLineCap.BUTT);
arc.setFill(null);
if (highlightSections) {
arc.setStroke(section.contains(time.toLocalTime()) ? section.getHighlightColor() : section.getColor());
} else {
arc.setStroke(section.getColor());
}
}
}
}
Aggregations