Kaynağa Gözat

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 yıl önce
ebeveyn
işleme
3e6224e94b

+ 31
- 9
src/com/dmdirc/addons/ui_swing/textpane/Line.java Dosyayı Görüntüle

23
 package com.dmdirc.addons.ui_swing.textpane;
23
 package com.dmdirc.addons.ui_swing.textpane;
24
 
24
 
25
 import com.dmdirc.config.ConfigManager;
25
 import com.dmdirc.config.ConfigManager;
26
+import com.dmdirc.interfaces.ConfigChangeListener;
26
 import com.dmdirc.ui.core.util.ExtendedAttributedString;
27
 import com.dmdirc.ui.core.util.ExtendedAttributedString;
27
 import com.dmdirc.ui.core.util.Utils;
28
 import com.dmdirc.ui.core.util.Utils;
28
 import com.dmdirc.ui.messages.Styliser;
29
 import com.dmdirc.ui.messages.Styliser;
30
+import java.awt.Font;
29
 
31
 
30
 import java.text.AttributedString;
32
 import java.text.AttributedString;
31
 import java.util.Arrays;
33
 import java.util.Arrays;
35
 /**
37
 /**
36
  * Represents a line of text in IRC.
38
  * Represents a line of text in IRC.
37
  */
39
  */
38
-class Line {
40
+class Line implements ConfigChangeListener {
39
 
41
 
40
     private final String[] lineParts;
42
     private final String[] lineParts;
41
     private final ConfigManager config;
43
     private final ConfigManager config;
42
     private int lineHeight;
44
     private int lineHeight;
45
+    private String fontName;
43
 
46
 
44
     /**
47
     /**
45
      * Creates a new line.
48
      * Creates a new line.
50
     public Line(final String[] lineParts, final ConfigManager config) {
53
     public Line(final String[] lineParts, final ConfigManager config) {
51
         this.lineParts = lineParts;
54
         this.lineParts = lineParts;
52
         this.config = config;
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
             final int lineHeight) {
69
             final int lineHeight) {
70
         this.lineParts = lineParts;
70
         this.lineParts = lineParts;
71
         this.config = config;
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
      */
140
      */
139
     public AttributedString getStyled() {
141
     public AttributedString getStyled() {
140
         final ExtendedAttributedString string = Utils.getAttributedString(lineParts,
142
         final ExtendedAttributedString string = Utils.getAttributedString(lineParts,
141
-                config);
143
+                fontName, lineHeight);
142
         lineHeight = string.getMaxLineHeight();
144
         lineHeight = string.getMaxLineHeight();
143
         return string.getAttributedString();
145
         return string.getAttributedString();
144
     }
146
     }
157
     public int hashCode() {
159
     public int hashCode() {
158
         return getLineParts().hashCode();
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
 }

Loading…
İptal
Kaydet