浏览代码

Fixes issue 3440: Textpane needs to cache fontsize/fontname settings

Change-Id: I4e66f4b51d9990fdcd3aef4127ebbe8cdee1c68b
Reviewed-on: http://gerrit.dmdirc.com/364
Reviewed-by: Chris Smith <chris@dmdirc.com>
Tested-by: Chris Smith <chris@dmdirc.com>
tags/0.6.3
Gregory Holmes 14 年前
父节点
当前提交
3e6224e94b
共有 1 个文件被更改,包括 31 次插入9 次删除
  1. 31
    9
      src/com/dmdirc/addons/ui_swing/textpane/Line.java

+ 31
- 9
src/com/dmdirc/addons/ui_swing/textpane/Line.java 查看文件

@@ -23,9 +23,11 @@
23 23
 package com.dmdirc.addons.ui_swing.textpane;
24 24
 
25 25
 import com.dmdirc.config.ConfigManager;
26
+import com.dmdirc.interfaces.ConfigChangeListener;
26 27
 import com.dmdirc.ui.core.util.ExtendedAttributedString;
27 28
 import com.dmdirc.ui.core.util.Utils;
28 29
 import com.dmdirc.ui.messages.Styliser;
30
+import java.awt.Font;
29 31
 
30 32
 import java.text.AttributedString;
31 33
 import java.util.Arrays;
@@ -35,11 +37,12 @@ import javax.swing.UIManager;
35 37
 /**
36 38
  * Represents a line of text in IRC.
37 39
  */
38
-class Line {
40
+class Line implements ConfigChangeListener {
39 41
 
40 42
     private final String[] lineParts;
41 43
     private final ConfigManager config;
42 44
     private int lineHeight;
45
+    private String fontName;
43 46
 
44 47
     /**
45 48
      * Creates a new line.
@@ -50,12 +53,9 @@ class Line {
50 53
     public Line(final String[] lineParts, final ConfigManager config) {
51 54
         this.lineParts = lineParts;
52 55
         this.config = config;
53
-        this.lineHeight = -1;
54
-        if (config.hasOptionString("ui", "textPaneFontSize")) {
55
-            this.lineHeight = config.getOptionInt("ui", "textPaneFontSize");
56
-        } else {
57
-            this.lineHeight = UIManager.getFont("TextPane.font").getSize();
58
-        }
56
+        setCachedSettings();
57
+        config.addChangeListener("ui", "textPaneFontSize", this);
58
+        config.addChangeListener("ui", "textPaneFontName", this);
59 59
     }
60 60
 
61 61
     /**
@@ -69,7 +69,9 @@ class Line {
69 69
             final int lineHeight) {
70 70
         this.lineParts = lineParts;
71 71
         this.config = config;
72
-        this.lineHeight = lineHeight;
72
+        setCachedSettings();
73
+        config.addChangeListener("ui", "textPaneFontSize", this);
74
+        config.addChangeListener("ui", "textPaneFontName", this);
73 75
     }
74 76
 
75 77
     /**
@@ -138,7 +140,7 @@ class Line {
138 140
      */
139 141
     public AttributedString getStyled() {
140 142
         final ExtendedAttributedString string = Utils.getAttributedString(lineParts,
141
-                config);
143
+                fontName, lineHeight);
142 144
         lineHeight = string.getMaxLineHeight();
143 145
         return string.getAttributedString();
144 146
     }
@@ -157,4 +159,24 @@ class Line {
157 159
     public int hashCode() {
158 160
         return getLineParts().hashCode();
159 161
     }
162
+
163
+    /** {@inheritDoc} */
164
+    @Override
165
+    public void configChanged(final String domain, final String key) {
166
+        setCachedSettings();
167
+    }
168
+
169
+    private void setCachedSettings() {
170
+        final Font defaultFont = UIManager.getFont("TextPane.font");
171
+        if (config.hasOptionString("ui", "textPaneFontName")) {
172
+            fontName = config.getOption("ui", "textPaneFontName");
173
+        } else {
174
+            fontName = defaultFont.getName();
175
+        }
176
+        if (config.hasOptionString("ui", "textPaneFontSize")) {
177
+            lineHeight = config.getOptionInt("ui", "textPaneFontSize");
178
+        } else {
179
+            lineHeight = defaultFont.getSize();
180
+        }
181
+    }
160 182
 }

正在加载...
取消
保存