Parcourir la source

Fixes issue 3096: SSD/CSD take a long time to open for the first time

Change-Id: Ifed3538723b27c49589dbcc275fa190239a6ea61
Reviewed-on: http://gerrit.dmdirc.com/385
Reviewed-by: Chris Smith <chris@dmdirc.com>
Tested-by: Chris Smith <chris@dmdirc.com>
tags/0.6.3
Gregory Holmes il y a 14 ans
Parent
révision
85c23bf482

+ 48
- 7
src/com/dmdirc/addons/ui_swing/components/FontPicker.java Voir le fichier

@@ -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
 }

+ 1
- 3
src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/ChannelSettingsDialog.java Voir le fichier

@@ -78,15 +78,13 @@ public final class ChannelSettingsDialog extends StandardDialog implements
78 78
     private ChannelSettingsDialog(final Channel newChannel,
79 79
             final Window parentWindow) {
80 80
         super(parentWindow, ModalityType.MODELESS);
81
-        final long time = System.currentTimeMillis();
82
-
81
+        
83 82
         channel = newChannel;
84 83
         identity = IdentityManager.getChannelConfig(channel.getServer().
85 84
                 getNetwork(), channel.getChannelInfo().getName());
86 85
 
87 86
         initComponents();
88 87
         initListeners();
89
-        System.out.println(System.currentTimeMillis() - time);
90 88
     }
91 89
 
92 90
     /**

Chargement…
Annuler
Enregistrer