Browse Source

Remove requirement for FrameContainer in Styliser.

Issue CLIENT-24

Change-Id: Ia561f2b92cc4f007f7fefb24a28231fff927bc36
Reviewed-on: http://gerrit.dmdirc.com/1694
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.5b1
Greg Holmes 13 years ago
parent
commit
23076224c3
1 changed files with 35 additions and 21 deletions
  1. 35
    21
      src/com/dmdirc/ui/messages/Styliser.java

+ 35
- 21
src/com/dmdirc/ui/messages/Styliser.java View File

@@ -23,8 +23,10 @@
23 23
 package com.dmdirc.ui.messages;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
+import com.dmdirc.Server;
26 27
 import com.dmdirc.actions.ActionManager;
27 28
 import com.dmdirc.actions.CoreActionType;
29
+import com.dmdirc.config.ConfigManager;
28 30
 import com.dmdirc.interfaces.ConfigChangeListener;
29 31
 import com.dmdirc.logger.ErrorLevel;
30 32
 import com.dmdirc.logger.Logger;
@@ -44,7 +46,6 @@ import javax.swing.text.StyledDocument;
44 46
 /**
45 47
  * The styliser applies IRC styles to text. Styles are indicated by various
46 48
  * control codes which are a de-facto IRC standard.
47
- * @author chris
48 49
  */
49 50
 public class Styliser implements ConfigChangeListener {
50 51
 
@@ -139,26 +140,39 @@ public class Styliser implements ConfigChangeListener {
139 140
     /** Colours to use for URI and channel links. */
140 141
     private Color uriColour, channelColour;
141 142
 
142
-    /** The container that owns this styliser. */
143
-    private final FrameContainer<?> owner;
143
+    /** Server to get channel prefixes from, or null if not applicable. */
144
+    private final Server server;
145
+    /** Config manager to retrive settings from. */
146
+    private final ConfigManager configManager;
144 147
 
145 148
     /**
146 149
      * Creates a new instance of Styliser.
147 150
      *
148 151
      * @param owner The {@link FrameContainer} that owns this styliser.
149
-     * @since 0.6.3
150 152
      */
151 153
     public Styliser(final FrameContainer<?> owner) {
152
-        this.owner = owner;
153
-
154
-        owner.getConfigManager().addChangeListener("ui", "linkcolour", this);
155
-        owner.getConfigManager().addChangeListener("ui", "channelcolour", this);
156
-        owner.getConfigManager().addChangeListener("ui", "stylelinks", this);
157
-        owner.getConfigManager().addChangeListener("ui", "stylechannels", this);
158
-        styleURIs = owner.getConfigManager().getOptionBool("ui", "stylelinks");
159
-        styleChannels = owner.getConfigManager().getOptionBool("ui", "stylechannels");
160
-        uriColour = owner.getConfigManager().getOptionColour("ui", "linkcolour");
161
-        channelColour = owner.getConfigManager().getOptionColour("ui", "channelcolour");
154
+        this(owner.getServer(), owner.getConfigManager());
155
+    }
156
+
157
+    /**
158
+     * Creates a new instance of Styliser.
159
+     *
160
+     * @param server The {@link Server} that owns this styliser or null if n/a.
161
+     * @param configManager the {@link ConfigManager} to get settings from.
162
+     * @since 0.6.3
163
+     */
164
+    public Styliser(final Server server, final ConfigManager configManager) {
165
+        this.server = server;
166
+        this.configManager = configManager;
167
+
168
+        configManager.addChangeListener("ui", "linkcolour", this);
169
+        configManager.addChangeListener("ui", "channelcolour", this);
170
+        configManager.addChangeListener("ui", "stylelinks", this);
171
+        configManager.addChangeListener("ui", "stylechannels", this);
172
+        styleURIs = configManager.getOptionBool("ui", "stylelinks");
173
+        styleChannels = configManager.getOptionBool("ui", "stylechannels");
174
+        uriColour = configManager.getOptionColour("ui", "linkcolour");
175
+        channelColour = configManager.getOptionColour("ui", "channelcolour");
162 176
     }
163 177
 
164 178
     /**
@@ -289,8 +303,8 @@ public class Styliser implements ConfigChangeListener {
289 303
      */
290 304
     public String doLinks(final String string) {
291 305
         String target = string;
292
-        final String prefixes = owner.getServer() == null ? null
293
-                : owner.getServer().getChannelPrefixes();
306
+        final String prefixes = server == null ? null
307
+                : server.getChannelPrefixes();
294 308
 
295 309
         String target2 = target;
296 310
         target = target.replaceAll(URL_REGEXP, CODE_HYPERLINK + "$0" + CODE_HYPERLINK);
@@ -326,7 +340,7 @@ public class Styliser implements ConfigChangeListener {
326 340
         final StringBuilder smilies = new StringBuilder();
327 341
 
328 342
         for (Map.Entry<String, String> icon
329
-                : owner.getConfigManager().getOptions("icon").entrySet()) {
343
+                : configManager.getOptions("icon").entrySet()) {
330 344
             if (icon.getKey().startsWith("smilie-")) {
331 345
                 if (smilies.length() > 0) {
332 346
                     smilies.append('|');
@@ -861,13 +875,13 @@ public class Styliser implements ConfigChangeListener {
861 875
     @Override
862 876
     public void configChanged(final String domain, final String key) {
863 877
         if ("stylelinks".equals(key)) {
864
-            styleURIs = owner.getConfigManager().getOptionBool("ui", "stylelinks");
878
+            styleURIs = configManager.getOptionBool("ui", "stylelinks");
865 879
         } else if ("stylechannels".equals(key)) {
866
-            styleChannels = owner.getConfigManager().getOptionBool("ui", "stylechannels");
880
+            styleChannels = configManager.getOptionBool("ui", "stylechannels");
867 881
         } else if ("linkcolour".equals(key)) {
868
-            uriColour = owner.getConfigManager().getOptionColour("ui", "linkcolour");
882
+            uriColour = configManager.getOptionColour("ui", "linkcolour");
869 883
         } else if ("channelcolour".equals(key)) {
870
-            channelColour = owner.getConfigManager().getOptionColour("ui", "channelcolour");
884
+            channelColour = configManager.getOptionColour("ui", "channelcolour");
871 885
         }
872 886
     }
873 887
 

Loading…
Cancel
Save