Added theme fix to calendar

This commit is contained in:
Nikolay Borodin 2024-06-13 20:20:36 +02:00
parent 5b021b6997
commit 0e48a87cea

View file

@ -18,6 +18,8 @@
*/
package org.p2pvpn.gui;
import com.github.lgooddatepicker.components.CalendarPanel;
import com.github.lgooddatepicker.components.DatePickerSettings;
import com.github.lgooddatepicker.components.DatePickerSettings.DateArea;
import com.github.lgooddatepicker.zinternaltools.CustomPopup;
import com.github.lgooddatepicker.zinternaltools.CalendarSelectionEvent;
import com.github.lgooddatepicker.zinternaltools.YearMonthChangeEvent;
@ -30,6 +32,7 @@ import java.time.ZoneId;
import java.util.Date;
import javax.swing.JSpinner;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
/**
* Calendar widget for the date entry field in InviteWindow.
@ -47,10 +50,13 @@ public class CalendarPopup implements CalendarListener {
inputField = field;
calendarPanel = new CalendarPanel();
DatePickerSettings settings = new DatePickerSettings();
applyTheme(settings);
calendarPanel.setSettings(settings);
calendarPanel.addCalendarListener(this);
}
void show() {
public void show() {
Date originalDate = (Date) inputField.getModel().getValue();
calendarPanel.setSelectedDate(originalDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
@ -68,6 +74,24 @@ public class CalendarPopup implements CalendarListener {
calendarPopup.show();
calendarPanel.requestFocus();
}
// fixme: remove this function when this is fixed
// https://github.com/LGoodDatePicker/LGoodDatePicker/issues/195
private void applyTheme(DatePickerSettings settings) {
settings.setColor(DateArea.CalendarBackgroundNormalDates, UIManager.getColor("Panel.background"));
settings.setColor(DateArea.BackgroundOverallCalendarPanel, UIManager.getColor("Panel.background"));
settings.setColor(DateArea.TextFieldBackgroundValidDate, UIManager.getColor("TextField.background"));
settings.setColor(DateArea.CalendarBackgroundSelectedDate, UIManager.getColor("Table.selectionBackground"));
settings.setColor(DateArea.BackgroundTopLeftLabelAboveWeekNumbers, UIManager.getColor("Label.background"));
settings.setColor(DateArea.BackgroundMonthAndYearMenuLabels, UIManager.getColor("Label.background"));
settings.setColor(DateArea.BackgroundTodayLabel, UIManager.getColor("Label.background"));
settings.setColor(DateArea.BackgroundClearLabel, UIManager.getColor("Button.background"));
settings.setColor(DateArea.CalendarTextNormalDates, UIManager.getColor("Label.foreground"));
settings.setColor(DateArea.CalendarBorderSelectedDate, UIManager.getColor("Table.selectionBackground").darker());
settings.setColor(DateArea.BackgroundCalendarPanelLabelsOnHover, UIManager.getColor("ComboBox.buttonHighlight"));
settings.setColor(DateArea.CalendarTextWeekdays, UIManager.getColor("Button.foreground"));
settings.setColorBackgroundWeekdayLabels(UIManager.getColor("Button.background"), true);
}
@Override
public void selectedDateChanged(CalendarSelectionEvent event) {