|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * Year Month Calendar Add-on |
| 4 | + * %% |
| 5 | + * Copyright (C) 2021 - 2024 Flowing Code |
| 6 | + * %% |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + * #L% |
| 19 | + */ |
| 20 | +package com.flowingcode.addons.ycalendar; |
| 21 | + |
| 22 | +import com.flowingcode.vaadin.addons.demo.DemoSource; |
| 23 | +import com.vaadin.flow.component.datepicker.DatePicker.DatePickerI18n; |
| 24 | +import com.vaadin.flow.component.dependency.CssImport; |
| 25 | +import com.vaadin.flow.component.html.Div; |
| 26 | +import com.vaadin.flow.router.PageTitle; |
| 27 | +import com.vaadin.flow.router.Route; |
| 28 | +import java.text.DateFormatSymbols; |
| 29 | +import java.time.DayOfWeek; |
| 30 | +import java.time.temporal.WeekFields; |
| 31 | +import java.util.List; |
| 32 | +import java.util.Locale; |
| 33 | + |
| 34 | +@CssImport(value = "./styles/test_year-month-calendar.css", themeFor = "vaadin-month-calendar") |
| 35 | +@PageTitle("i18n") |
| 36 | +@DemoSource |
| 37 | +@Route(value = "year-month-calendar/year-i18n", layout = YearMonthCalendarDemoView.class) |
| 38 | +public class YearI18NDemo extends Div { |
| 39 | + |
| 40 | + public YearI18NDemo() { |
| 41 | + |
| 42 | + Locale locale = Locale.GERMAN; |
| 43 | + |
| 44 | + DatePickerI18n i18n = new DatePickerI18n(); |
| 45 | + DateFormatSymbols dfs = DateFormatSymbols.getInstance(locale); |
| 46 | + i18n.setMonthNames(List.of(dfs.getMonths())); |
| 47 | + i18n.setWeekdays(List.of(dfs.getWeekdays()).stream().skip(1).toList()); |
| 48 | + i18n.setWeekdaysShort(List.of(dfs.getShortWeekdays()).stream().skip(1).toList()); |
| 49 | + |
| 50 | + DayOfWeek firstDayOfWeek = WeekFields.of(locale).getFirstDayOfWeek(); |
| 51 | + i18n.setFirstDayOfWeek(firstDayOfWeek.getValue() % 7); |
| 52 | + |
| 53 | + YearCalendar calendar = new YearCalendar(); |
| 54 | + // #if vaadin eq 0 |
| 55 | + calendar.setClassNameGenerator(date -> { |
| 56 | + if (date.getDayOfWeek() == DayOfWeek.SATURDAY || date.getDayOfWeek() == DayOfWeek.SUNDAY) { |
| 57 | + return "weekend"; |
| 58 | + } |
| 59 | + return null; |
| 60 | + }); |
| 61 | + // #endif |
| 62 | + calendar.setI18n(i18n); |
| 63 | + add(calendar); |
| 64 | + } |
| 65 | + |
| 66 | +} |
0 commit comments