如何更改 ICalendarFX 的组

How to change the groups of ICalendarFX

我正在使用 JFXtras 的日历,默认情况下事件有 24 个组(类别),我想更改它们。 这是默认代码:

public final static List<AppointmentGroup> DEFAULT_APPOINTMENT_GROUPS = IntStream.range(0, 24)
        .mapToObj(i -> new Agenda.AppointmentGroupImpl()
              .withStyleClass("group" + i)
              .withDescription("group" + (i < 10 ? "0" : "") + i))
        .collect(Collectors.toList());

final public static List<String> CATEGORIES = IntStream.range(0, 24)
        .mapToObj(i -> new String("group" + (i < 10 ? "0" : "") + i))
        .collect(Collectors.toList());

好吧,Appointment 告诉 Agenda 它属于哪个组。该 AppointmentGroup 提供 CSS class 以供使用(用于设置组中所有约会的样式)。所以 24 个预定义组就在那里,因为 Agenda.css.

中存在关联定义

https://github.com/JFXtras/jfxtras/blob/8.0/jfxtras-agenda/src/main/resources/jfxtras/internal/scene/control/skin/agenda/Agenda.css 第 71 行

.group0 { -fx-background-color: #AC725E; -fx-fill: #AC725E; }
.group1 { -fx-background-color: #D06B64; -fx-fill: #D06B64; }
.group2 { -fx-background-color: #F83A22; -fx-fill: #F83A22; }
...

因此,如果您创建一个新的 AppointmentGroup class,请设置样式 class id(不要使用现有的 id,如 "group0",如上面的代码中所做的那样,即有点没用),然后将该 AppointmentGroup 分配给一个 Appointment,Agenda 将使用 class 样式呈现它。然后你当然需要在 CSS 文件中定义它。

您还可以覆盖现有组 0、组 1 的样式...

给个想法..

1:加载您的 css-文件

vbox_root.getStylesheets().add("/styles/styles.css");

2:新增AppointmentGroups

agenda.appointmentGroups().add(new Agenda.AppointmentGroupImpl().withDescription("group24").withStyleClass("group24"));
agenda.appointmentGroups().add(new Agenda.AppointmentGroupImpl().withDescription("group25").withStyleClass("group25"));
agenda.appointmentGroups().add(new Agenda.AppointmentGroupImpl().withDescription("group26").withStyleClass("group26"));
agenda.appointmentGroups().add(new Agenda.AppointmentGroupImpl().withDescription("group27").withStyleClass("group27"));

3:在 styles/styles.css 中定义您的样式

.group24 {
    -fx-background-color: #424242;
    -fx-fill: #424242;
}

.group25 {
    -fx-background-color: #CDCDCD;
    -fx-fill: #CDCDCD;
}

.group26 {
    -fx-background-color: #000000;
    -fx-fill: #000000;
}

.group27 {
    -fx-background-color: #000000;
    -fx-fill: #000000;
}