Search in sources :

Example 1 with DAY_OF_MONTH

use of java.time.temporal.ChronoField.DAY_OF_MONTH in project tilesfx by HanSolo.

the class CalendarTileSkin method drawCells.

private void drawCells() {
    List<ChartData> dataList = tile.getChartData();
    ZonedDateTime time = tile.getTime();
    Locale locale = tile.getLocale();
    int day = time.getDayOfMonth();
    int startDay = time.withDayOfMonth(1).getDayOfWeek().getValue();
    long lastDay = time.range(DAY_OF_MONTH).getMaximum();
    Color textColor = tile.getTextColor();
    Color bkgColor = tile.getBackgroundColor();
    Font regFont = Fonts.latoRegular(size * 0.045);
    Font bldFont = Fonts.latoBold(size * 0.045);
    Background bkgToday = new Background(new BackgroundFill(tile.getBarColor(), new CornerRadii(size * 0.0125), new Insets(2)));
    Border appmntBorder = new Border(new BorderStroke(tile.getAlarmColor(), tile.getAlarmColor(), tile.getAlarmColor(), tile.getAlarmColor(), BorderStrokeStyle.SOLID, BorderStrokeStyle.SOLID, BorderStrokeStyle.SOLID, BorderStrokeStyle.SOLID, new CornerRadii(size * 0.0125), BorderWidths.DEFAULT, new Insets(1)));
    boolean counting = false;
    int dayCounter = 1;
    for (int y = 0; y < 7; y++) {
        for (int x = 0; x < 8; x++) {
            int index = y * 8 + x;
            Label label = labels.get(index);
            String text;
            if (x == 0 && y == 0) {
                text = "";
                label.setManaged(false);
                label.setVisible(false);
            } else if (y == 0) {
                text = DayOfWeek.of(x).getDisplayName(TextStyle.SHORT, locale);
                // label.setTextFill(x == 7 ? Tile.RED : textColor);
                label.setTextFill(textColor);
                label.setFont(bldFont);
            } else if (x == 0) {
                text = Integer.toString(time.withDayOfMonth(1).plusDays((y - 1) * 7).get(IsoFields.WEEK_OF_WEEK_BASED_YEAR));
                label.setTextFill(Tile.GRAY);
                label.setFont(regFont);
                label.setBorder(weekBorder);
            } else {
                if (index - 7 > startDay) {
                    counting = true;
                    text = Integer.toString(dayCounter);
                    LocalDate currentDay = time.toLocalDate().plusDays(dayCounter - 1);
                    long appointments = dataList.stream().filter(data -> data.getTimestampAsLocalDate().isEqual(currentDay)).count();
                    if (x == 7) {
                        if (appointments > 0) {
                            label.setBorder(appmntBorder);
                        } else {
                            label.setBorder(null);
                        }
                        label.setTextFill(Tile.RED);
                        label.setFont(regFont);
                    } else if (dayCounter == day) {
                        if (appointments > 0) {
                            label.setBorder(appmntBorder);
                        } else {
                            label.setBorder(null);
                        }
                        label.setBackground(bkgToday);
                        label.setTextFill(bkgColor);
                        label.setFont(bldFont);
                    } else {
                        if (appointments > 0) {
                            label.setBorder(appmntBorder);
                        } else {
                            label.setBorder(null);
                        }
                        label.setTextFill(textColor);
                        label.setFont(regFont);
                    }
                } else {
                    text = "";
                    label.setManaged(false);
                    label.setVisible(false);
                }
                if (dayCounter > lastDay) {
                    text = "";
                    label.setManaged(false);
                    label.setVisible(false);
                }
                if (counting) {
                    dayCounter++;
                }
            }
            label.setText(text);
            label.setVisible(true);
            label.setManaged(true);
            label.setPrefSize(cellWidth, cellHeight);
            label.relocate(x * cellWidth + cellOffsetX, y * cellHeight + cellOffsetY);
        }
    }
}
Also used : Locale(java.util.Locale) EventHandler(javafx.event.EventHandler) Pos(javafx.geometry.Pos) Fonts(eu.hansolo.tilesfx.fonts.Fonts) MouseEvent(javafx.scene.input.MouseEvent) ZonedDateTime(java.time.ZonedDateTime) EventType(eu.hansolo.tilesfx.events.TileEvent.EventType) ArrayList(java.util.ArrayList) ChartData(eu.hansolo.tilesfx.chart.ChartData) Insets(javafx.geometry.Insets) Helper(eu.hansolo.tilesfx.tools.Helper) BorderWidths(javafx.scene.layout.BorderWidths) BackgroundFill(javafx.scene.layout.BackgroundFill) Locale(java.util.Locale) Tile(eu.hansolo.tilesfx.Tile) Color(javafx.scene.paint.Color) Label(javafx.scene.control.Label) TextStyle(java.time.format.TextStyle) Border(javafx.scene.layout.Border) Font(javafx.scene.text.Font) Background(javafx.scene.layout.Background) DAY_OF_MONTH(java.time.temporal.ChronoField.DAY_OF_MONTH) BorderStrokeStyle(javafx.scene.layout.BorderStrokeStyle) BorderStroke(javafx.scene.layout.BorderStroke) Text(javafx.scene.text.Text) List(java.util.List) TileEvent(eu.hansolo.tilesfx.events.TileEvent) IsoFields(java.time.temporal.IsoFields) DayOfWeek(java.time.DayOfWeek) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) CornerRadii(javafx.scene.layout.CornerRadii) ChartData(eu.hansolo.tilesfx.chart.ChartData) Insets(javafx.geometry.Insets) Background(javafx.scene.layout.Background) Color(javafx.scene.paint.Color) BackgroundFill(javafx.scene.layout.BackgroundFill) Label(javafx.scene.control.Label) LocalDate(java.time.LocalDate) Font(javafx.scene.text.Font) ZonedDateTime(java.time.ZonedDateTime) BorderStroke(javafx.scene.layout.BorderStroke) CornerRadii(javafx.scene.layout.CornerRadii) Border(javafx.scene.layout.Border)

Aggregations

Tile (eu.hansolo.tilesfx.Tile)1 ChartData (eu.hansolo.tilesfx.chart.ChartData)1 TileEvent (eu.hansolo.tilesfx.events.TileEvent)1 EventType (eu.hansolo.tilesfx.events.TileEvent.EventType)1 Fonts (eu.hansolo.tilesfx.fonts.Fonts)1 Helper (eu.hansolo.tilesfx.tools.Helper)1 DayOfWeek (java.time.DayOfWeek)1 LocalDate (java.time.LocalDate)1 ZonedDateTime (java.time.ZonedDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 TextStyle (java.time.format.TextStyle)1 DAY_OF_MONTH (java.time.temporal.ChronoField.DAY_OF_MONTH)1 IsoFields (java.time.temporal.IsoFields)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 Optional (java.util.Optional)1 EventHandler (javafx.event.EventHandler)1 Insets (javafx.geometry.Insets)1 Pos (javafx.geometry.Pos)1