|
@@ -26,13 +26,19 @@ import com.dmdirc.DMDircMBassador;
|
26
|
26
|
import com.dmdirc.addons.ui_swing.UIUtilities;
|
27
|
27
|
import com.dmdirc.addons.ui_swing.components.renderers.FontListCellRenderer;
|
28
|
28
|
|
|
29
|
+import com.google.common.collect.Lists;
|
|
30
|
+
|
29
|
31
|
import java.awt.Font;
|
30
|
32
|
import java.awt.GraphicsEnvironment;
|
|
33
|
+import java.util.ArrayList;
|
|
34
|
+import java.util.List;
|
31
|
35
|
|
32
|
36
|
import javax.swing.DefaultComboBoxModel;
|
33
|
37
|
import javax.swing.JComboBox;
|
34
|
38
|
import javax.swing.MutableComboBoxModel;
|
35
|
39
|
|
|
40
|
+import static com.google.common.base.Preconditions.checkNotNull;
|
|
41
|
+
|
36
|
42
|
/**
|
37
|
43
|
* System font picking component.
|
38
|
44
|
*/
|
|
@@ -54,9 +60,7 @@ public class FontPicker extends JComboBox<Object> {
|
54
|
60
|
this.fontFamily = fontFamily;
|
55
|
61
|
|
56
|
62
|
setRenderer(new FontListCellRenderer(getRenderer()));
|
57
|
|
- UIUtilities.<String[]>invokeOffEDT(eventBus,
|
58
|
|
- () -> GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(),
|
59
|
|
- this::loadFonts);
|
|
63
|
+ UIUtilities.invokeOffEDT(eventBus, this::getFonts, this::loadFonts);
|
60
|
64
|
}
|
61
|
65
|
|
62
|
66
|
/**
|
|
@@ -64,12 +68,22 @@ public class FontPicker extends JComboBox<Object> {
|
64
|
68
|
*
|
65
|
69
|
* @param fonts Fonts to load
|
66
|
70
|
*/
|
67
|
|
- private void loadFonts(final String... fonts) {
|
68
|
|
- final int size = getFont().getSize();
|
|
71
|
+ private void loadFonts(final List<String> fonts) {
|
|
72
|
+ checkNotNull(fonts);
|
|
73
|
+ final int size = getFont() == null ? 12 : getFont().getSize();
|
69
|
74
|
for (final String font : fonts) {
|
70
|
75
|
((MutableComboBoxModel<Object>) getModel()).addElement(new Font(font, Font.PLAIN, size));
|
71
|
76
|
}
|
72
|
77
|
setSelectedItem(new Font(fontFamily, Font.PLAIN, size));
|
73
|
78
|
}
|
74
|
79
|
|
|
80
|
+ private List<String> getFonts() {
|
|
81
|
+ final String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment()
|
|
82
|
+ .getAvailableFontFamilyNames();
|
|
83
|
+ if (fonts == null) {
|
|
84
|
+ return new ArrayList<>();
|
|
85
|
+ }
|
|
86
|
+ return Lists.newArrayList(fonts);
|
|
87
|
+ }
|
|
88
|
+
|
75
|
89
|
}
|