Procházet zdrojové kódy

Fixes issue 4007

Wow, thats ugly code, bonus feature discovery (its up to you to figure out the
 crazy IPv6 FTP stuff it's doing if you care)

Change-Id: I67ca079365ad40891f5cefab18f36f2ff68d1a30
Reviewed-on: http://gerrit.dmdirc.com/1121
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.4
Greboid před 14 roky
rodič
revize
c758701a6d

+ 44
- 12
src/com/dmdirc/addons/ui_swing/textpane/TextPaneCanvas.java Zobrazit soubor

@@ -25,9 +25,12 @@ import com.dmdirc.ui.messages.LinePosition;
25 25
 import com.dmdirc.ui.messages.IRCDocument;
26 26
 import com.dmdirc.addons.ui_swing.BackgroundOption;
27 27
 import com.dmdirc.addons.ui_swing.UIUtilities;
28
+import com.dmdirc.addons.ui_swing.components.LoggingSwingWorker;
28 29
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
29 30
 import com.dmdirc.config.ConfigManager;
30 31
 import com.dmdirc.interfaces.ConfigChangeListener;
32
+import com.dmdirc.logger.ErrorLevel;
33
+import com.dmdirc.logger.Logger;
31 34
 import com.dmdirc.ui.messages.IRCTextAttribute;
32 35
 import com.dmdirc.util.ListenerList;
33 36
 import com.dmdirc.util.URLBuilder;
@@ -55,6 +58,7 @@ import java.text.AttributedCharacterIterator;
55 58
 import java.text.AttributedString;
56 59
 import java.util.HashMap;
57 60
 import java.util.Map;
61
+import java.util.concurrent.ExecutionException;
58 62
 
59 63
 import javax.imageio.ImageIO;
60 64
 import javax.swing.JPanel;
@@ -172,21 +176,49 @@ class TextPaneCanvas extends JPanel implements MouseInputListener,
172 176
     private void updateCachedSettings() {
173 177
         final String backgroundPath = manager.getOption(domain,
174 178
                 "textpanebackground");
175
-        UIUtilities.invokeAndWait(new Runnable() {
179
+        if (!backgroundPath.isEmpty()) {
180
+            UIUtilities.invokeAndWait(new Runnable() {
176 181
 
177
-            /** {@inheritDoc} */
178
-            @Override
179
-            public void run() {
180
-                try {
182
+                /** {@inheritDoc} */
183
+                @Override
184
+                public void run() {
181 185
                     final URL url = URLBuilder.buildURL(backgroundPath);
182
-                    if (url != null) {
183
-                        backgroundImage = ImageIO.read(url);
184
-                    }
185
-                } catch (IOException ex) {
186
-                    backgroundImage = null;
186
+                    new LoggingSwingWorker<Image, Void>() {
187
+
188
+                        /** {@inheritDoc} */
189
+                        @Override
190
+                        protected Image doInBackground() throws Exception {
191
+                            Image returnValue = null;
192
+                            try {
193
+                                if (url != null) {
194
+                                    returnValue = ImageIO.read(url);
195
+                                }
196
+                            } catch (IOException ex) {
197
+                                returnValue = null;
198
+                            }
199
+                            return returnValue;
200
+                        }
201
+
202
+                        /** {@inheritDoc} */
203
+                        @Override
204
+                        protected void done() {
205
+                            if (isCancelled()) {
206
+                                return;
207
+                            }
208
+                            try {
209
+                                backgroundImage = get();
210
+                                recalc();
211
+                            } catch (InterruptedException ex) {
212
+                            //Ignore
213
+                            } catch (ExecutionException ex) {
214
+                                Logger.appError(ErrorLevel.MEDIUM,
215
+                                        ex.getMessage(), ex);
216
+                            }
217
+                        }
218
+                    }.execute();
187 219
                 }
188
-            }
189
-        });
220
+            });
221
+        }
190 222
         try {
191 223
             backgroundOption = BackgroundOption.valueOf(manager.getOption(domain,
192 224
                     "textpanebackgroundoption"));

Načítá se…
Zrušit
Uložit