|
@@ -23,12 +23,16 @@
|
23
|
23
|
package com.dmdirc.addons.ui_swing.components;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.addons.ui_swing.components.renderers.FontListCellRenderer;
|
|
26
|
+import com.dmdirc.logger.ErrorLevel;
|
|
27
|
+import com.dmdirc.logger.Logger;
|
26
|
28
|
|
27
|
29
|
import java.awt.Font;
|
28
|
30
|
import java.awt.GraphicsEnvironment;
|
|
31
|
+import java.util.concurrent.ExecutionException;
|
29
|
32
|
|
30
|
33
|
import javax.swing.DefaultComboBoxModel;
|
31
|
34
|
import javax.swing.JComboBox;
|
|
35
|
+import javax.swing.SwingUtilities;
|
32
|
36
|
|
33
|
37
|
/**
|
34
|
38
|
* System font picking component.
|
|
@@ -36,6 +40,7 @@ import javax.swing.JComboBox;
|
36
|
40
|
public class FontPicker extends JComboBox {
|
37
|
41
|
|
38
|
42
|
private static final long serialVersionUID = -9054812588033935839L;
|
|
43
|
+ private String fontFamily;
|
39
|
44
|
|
40
|
45
|
/**
|
41
|
46
|
* Creates a new Font picker for the specified font family.
|
|
@@ -44,16 +49,52 @@ public class FontPicker extends JComboBox {
|
44
|
49
|
*/
|
45
|
50
|
public FontPicker(final String fontFamily) {
|
46
|
51
|
super(new DefaultComboBoxModel());
|
|
52
|
+ this.fontFamily = fontFamily;
|
47
|
53
|
|
48
|
|
- final String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().
|
49
|
|
- getAvailableFontFamilyNames();
|
|
54
|
+ setRenderer(new FontListCellRenderer());
|
|
55
|
+ new LoggingSwingWorker<String[], String[]>() {
|
|
56
|
+
|
|
57
|
+ /** {@inheritDoc} */
|
|
58
|
+ @Override
|
|
59
|
+ protected String[] doInBackground() throws Exception {
|
|
60
|
+ return GraphicsEnvironment.getLocalGraphicsEnvironment().
|
|
61
|
+ getAvailableFontFamilyNames();
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ /** {@inheritDoc} */
|
|
65
|
+ @Override
|
|
66
|
+ protected void done() {
|
|
67
|
+ try {
|
|
68
|
+ loadFonts(get());
|
|
69
|
+ } catch (InterruptedException ex) {
|
|
70
|
+ //Ignore
|
|
71
|
+ } catch (ExecutionException ex) {
|
|
72
|
+ Logger.appError(ErrorLevel.MEDIUM, ex.getMessage(), ex);
|
|
73
|
+ }
|
|
74
|
+ }
|
|
75
|
+ }.execute();
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ private void loadFonts(final String[] fonts) {
|
50
|
79
|
final int size = getFont().getSize();
|
51
|
|
- for (String font : fonts) {
|
52
|
|
- ((DefaultComboBoxModel) getModel()).addElement(new Font(font,
|
53
|
|
- Font.PLAIN, size));
|
|
80
|
+ for (final String font : fonts) {
|
|
81
|
+ SwingUtilities.invokeLater(new Runnable() {
|
|
82
|
+
|
|
83
|
+ /** {@inheritDoc} */
|
|
84
|
+ @Override
|
|
85
|
+ public void run() {
|
|
86
|
+ ((DefaultComboBoxModel) getModel()).addElement(new Font(
|
|
87
|
+ font, Font.PLAIN, size));
|
|
88
|
+ }
|
|
89
|
+ });
|
54
|
90
|
}
|
55
|
|
- setSelectedItem(new Font(fontFamily, Font.PLAIN, size));
|
|
91
|
+ SwingUtilities.invokeLater(new Runnable() {
|
56
|
92
|
|
57
|
|
- setRenderer(new FontListCellRenderer());
|
|
93
|
+ /** {@inheritDoc} */
|
|
94
|
+ @Override
|
|
95
|
+ public void run() {
|
|
96
|
+ setSelectedItem(new Font(fontFamily, Font.PLAIN, size));
|
|
97
|
+ }
|
|
98
|
+ });
|
58
|
99
|
}
|
59
|
100
|
}
|