|
29 | 29 |
|
30 | 30 | package org.scijava.ui.swing.widget; |
31 | 31 |
|
| 32 | +import java.awt.Color; |
32 | 33 | import java.awt.event.ActionEvent; |
33 | 34 | import java.awt.event.ActionListener; |
34 | 35 | import java.util.Date; |
35 | 36 |
|
36 | 37 | import javax.swing.JPanel; |
| 38 | +import javax.swing.UIManager; |
37 | 39 |
|
38 | | -import net.sourceforge.jdatepicker.impl.JDatePanelImpl; |
39 | | -import net.sourceforge.jdatepicker.impl.JDatePickerImpl; |
40 | | -import net.sourceforge.jdatepicker.impl.UtilDateModel; |
| 40 | +import org.jdatepicker.ComponentColorDefaults; |
| 41 | +import org.jdatepicker.ComponentColorDefaults.Key; |
| 42 | +import org.jdatepicker.JDatePicker; |
| 43 | +import org.jdatepicker.UtilDateModel; |
41 | 44 |
|
42 | 45 | import org.scijava.log.LogService; |
43 | 46 | import org.scijava.plugin.Parameter; |
@@ -75,15 +78,49 @@ public void set(final WidgetModel model) { |
75 | 78 | super.set(model); |
76 | 79 |
|
77 | 80 | dateModel = new UtilDateModel(); |
78 | | - final JDatePickerImpl datePicker = |
79 | | - new JDatePickerImpl(new JDatePanelImpl(dateModel), null); |
| 81 | + applyThemeColors(); |
| 82 | + // NB: the picker must be built on our model, or user picks never reach it |
| 83 | + final JDatePicker datePicker = new JDatePicker(dateModel); |
80 | 84 | setToolTip(datePicker); |
81 | 85 | getComponent().add(datePicker); |
82 | 86 | datePicker.addActionListener(this); |
83 | 87 |
|
84 | 88 | refreshWidget(); |
85 | 89 | } |
86 | 90 |
|
| 91 | + // -- Helper methods -- |
| 92 | + |
| 93 | + /** |
| 94 | + * Maps the picker colors to the current look and feel. Note that |
| 95 | + * {@link ComponentColorDefaults} is a global singleton read when a picker |
| 96 | + * is created, so existing pickers keep their colors on a theme change |
| 97 | + */ |
| 98 | + private static void applyThemeColors() { |
| 99 | + setColor(Key.BG_MONTH_SELECTOR, "TableHeader.background"); |
| 100 | + setColor(Key.FG_MONTH_SELECTOR, "TableHeader.foreground"); |
| 101 | + setColor(Key.BG_GRID_HEADER, "TableHeader.background"); |
| 102 | + setColor(Key.FG_GRID_HEADER, "TableHeader.foreground"); |
| 103 | + setColor(Key.BG_GRID, "Table.background"); |
| 104 | + setColor(Key.BG_GRID_NOT_SELECTABLE, "Panel.background"); |
| 105 | + setColor(Key.FG_GRID_THIS_MONTH, "Table.foreground"); |
| 106 | + setColor(Key.FG_GRID_OTHER_MONTH, "Label.disabledForeground"); |
| 107 | + setColor(Key.FG_GRID_TODAY, "Component.accentColor"); |
| 108 | + setColor(Key.FG_GRID_SELECTED, "Table.selectionForeground"); |
| 109 | + setColor(Key.BG_GRID_SELECTED, "Table.selectionBackground"); |
| 110 | + setColor(Key.FG_GRID_TODAY_SELECTED, "Table.selectionForeground"); |
| 111 | + setColor(Key.BG_GRID_TODAY_SELECTED, "Table.selectionBackground"); |
| 112 | + setColor(Key.BG_TODAY_SELECTOR, "Panel.background"); |
| 113 | + setColor(Key.FG_TODAY_SELECTOR_ENABLED, "Label.foreground"); |
| 114 | + setColor(Key.FG_TODAY_SELECTOR_DISABLED, "Label.disabledForeground"); |
| 115 | + setColor(Key.POPUP_BORDER, "Component.borderColor"); |
| 116 | + } |
| 117 | + |
| 118 | + /** Sets a picker color from a UIManager key, if the key is defined */ |
| 119 | + private static void setColor(final Key key, final String uiKey) { |
| 120 | + final Color color = UIManager.getColor(uiKey); |
| 121 | + if (color != null) ComponentColorDefaults.getInstance().setColor(key, color); |
| 122 | + } |
| 123 | + |
87 | 124 | // -- Typed methods -- |
88 | 125 |
|
89 | 126 | @Override |
|
0 commit comments