Browse Source

Merge pull request #712 from csmith/master

Move IRC control codes to their own class.
pull/713/head
Greg Holmes 7 years ago
parent
commit
d103b5ae92

+ 4
- 4
src/main/java/com/dmdirc/commandparser/commands/Command.java View File

@@ -28,7 +28,7 @@ import com.dmdirc.events.CommandErrorEvent;
28 28
 import com.dmdirc.events.CommandOutputEvent;
29 29
 import com.dmdirc.interfaces.CommandController;
30 30
 import com.dmdirc.interfaces.WindowModel;
31
-import com.dmdirc.ui.messages.Styliser;
31
+import com.dmdirc.ui.messages.IRCControlCodes;
32 32
 
33 33
 import javax.annotation.Nonnull;
34 34
 import javax.annotation.Nullable;
@@ -104,8 +104,8 @@ public abstract class Command {
104 104
      */
105 105
     protected static String doTable(final String[] headers, final String[][] data) {
106 106
         final StringBuilder res = new StringBuilder();
107
-        res.append(Styliser.CODE_FIXED);
108
-        res.append(Styliser.CODE_BOLD);
107
+        res.append(IRCControlCodes.FIXED);
108
+        res.append(IRCControlCodes.BOLD);
109 109
 
110 110
         final int[] maxsizes = new int[headers.length];
111 111
 
@@ -121,7 +121,7 @@ public abstract class Command {
121 121
 
122 122
         for (String[] source : data) {
123 123
             res.append('\n');
124
-            res.append(Styliser.CODE_FIXED);
124
+            res.append(IRCControlCodes.FIXED);
125 125
 
126 126
             for (int i = 0; i < source.length; i++) {
127 127
                 doPadding(res, source[i], maxsizes[i]);

+ 10
- 10
src/main/java/com/dmdirc/commandparser/commands/global/Help.java View File

@@ -33,7 +33,7 @@ import com.dmdirc.interfaces.CommandController;
33 33
 import com.dmdirc.interfaces.WindowModel;
34 34
 import com.dmdirc.ui.input.AdditionalTabTargets;
35 35
 import com.dmdirc.ui.input.TabCompletionType;
36
-import com.dmdirc.ui.messages.Styliser;
36
+import com.dmdirc.ui.messages.IRCControlCodes;
37 37
 
38 38
 import java.util.ArrayList;
39 39
 import java.util.Collections;
@@ -87,14 +87,14 @@ public class Help extends Command implements IntelligentCommand {
87 87
 
88 88
         Collections.sort(commands);
89 89
 
90
-        showOutput(origin, isSilent, Styliser.CODE_FIXED
90
+        showOutput(origin, isSilent, IRCControlCodes.FIXED
91 91
                 + "----------------------- Available commands -------");
92 92
 
93 93
         final StringBuilder builder = new StringBuilder();
94 94
 
95 95
         for (String command : commands) {
96 96
             if (builder.length() + command.length() + 1 > 50) {
97
-                showOutput(origin, isSilent, Styliser.CODE_FIXED + builder.toString());
97
+                showOutput(origin, isSilent, IRCControlCodes.FIXED + builder.toString());
98 98
                 builder.delete(0, builder.length());
99 99
             } else if (builder.length() > 0) {
100 100
                 builder.append(' ');
@@ -104,10 +104,10 @@ public class Help extends Command implements IntelligentCommand {
104 104
         }
105 105
 
106 106
         if (builder.length() > 0) {
107
-            showOutput(origin, isSilent, Styliser.CODE_FIXED + builder.toString());
107
+            showOutput(origin, isSilent, IRCControlCodes.FIXED + builder.toString());
108 108
         }
109 109
 
110
-        showOutput(origin, isSilent, Styliser.CODE_FIXED
110
+        showOutput(origin, isSilent, IRCControlCodes.FIXED
111 111
                 + "--------------------------------------------------");
112 112
     }
113 113
 
@@ -131,15 +131,15 @@ public class Help extends Command implements IntelligentCommand {
131 131
         if (command == null) {
132 132
             showError(origin, isSilent, "Command '" + name + "' not found.");
133 133
         } else {
134
-            showOutput(origin, isSilent, Styliser.CODE_FIXED
134
+            showOutput(origin, isSilent, IRCControlCodes.FIXED
135 135
                     + "---------------------- Command information -------");
136
-            showOutput(origin, isSilent, Styliser.CODE_FIXED
136
+            showOutput(origin, isSilent, IRCControlCodes.FIXED
137 137
                     + " Name: " + name);
138
-            showOutput(origin, isSilent, Styliser.CODE_FIXED
138
+            showOutput(origin, isSilent, IRCControlCodes.FIXED
139 139
                     + " Type: " + command.getKey().getType());
140
-            showOutput(origin, isSilent, Styliser.CODE_FIXED
140
+            showOutput(origin, isSilent, IRCControlCodes.FIXED
141 141
                     + "Usage: " + command.getKey().getHelp());
142
-            showOutput(origin, isSilent, Styliser.CODE_FIXED
142
+            showOutput(origin, isSilent, IRCControlCodes.FIXED
143 143
                     + "--------------------------------------------------");
144 144
         }
145 145
     }

+ 4
- 4
src/main/java/com/dmdirc/commandparser/commands/server/OpenQuery.java View File

@@ -38,7 +38,7 @@ import com.dmdirc.interfaces.PrivateChat;
38 38
 import com.dmdirc.interfaces.WindowModel;
39 39
 import com.dmdirc.ui.input.AdditionalTabTargets;
40 40
 import com.dmdirc.ui.input.TabCompletionType;
41
-import com.dmdirc.ui.messages.Styliser;
41
+import com.dmdirc.ui.messages.IRCControlCodes;
42 42
 
43 43
 import javax.annotation.Nonnull;
44 44
 import javax.inject.Inject;
@@ -76,12 +76,12 @@ public class OpenQuery extends Command implements IntelligentCommand,
76 76
         final Connection connection = ((ServerCommandContext) context).getConnection();
77 77
         if (connection.getParser().get().isValidChannelName(args.getArguments()[0])) {
78 78
             showError(origin, args.isSilent(), "You can't open a query "
79
-                    + "with a channel; maybe you meant " + Styliser.CODE_FIXED
80
-                    + Styliser.CODE_BOLD
79
+                    + "with a channel; maybe you meant " + IRCControlCodes.FIXED
80
+                    + IRCControlCodes.BOLD
81 81
                     + getController().getCommandChar()
82 82
                     + (args.getArguments().length > 1 ? "msg" : "join") + ' '
83 83
                     + args.getArgumentsAsString()
84
-                    + Styliser.CODE_BOLD + Styliser.CODE_FIXED + '?');
84
+                    + IRCControlCodes.BOLD + IRCControlCodes.FIXED + '?');
85 85
             return;
86 86
         }
87 87
 

+ 10
- 10
src/main/java/com/dmdirc/ui/input/InputHandler.java View File

@@ -40,7 +40,7 @@ import com.dmdirc.parser.common.CompositionState;
40 40
 import com.dmdirc.plugins.ServiceManager;
41 41
 import com.dmdirc.ui.input.tabstyles.TabCompletionResult;
42 42
 import com.dmdirc.ui.input.tabstyles.TabCompletionStyle;
43
-import com.dmdirc.ui.messages.Styliser;
43
+import com.dmdirc.ui.messages.IRCControlCodes;
44 44
 import com.dmdirc.util.collections.ListenerList;
45 45
 import com.dmdirc.util.collections.RollingList;
46 46
 import com.dmdirc.util.validators.ValidationResponse;
@@ -250,9 +250,9 @@ public abstract class InputHandler implements ConfigChangeListener {
250 250
             // or control code with a comma (so they can pick a background)
251 251
             final String partialLine = line.substring(0, caretPosition - 1);
252 252
 
253
-            if (partialLine.matches("^.*" + Styliser.CODE_COLOUR + "[0-9]{0,2}$")) {
253
+            if (partialLine.matches("^.*" + IRCControlCodes.COLOUR + "[0-9]{0,2}$")) {
254 254
                 target.showColourPicker(true, false);
255
-            } else if (partialLine.matches("^.*" + Styliser.CODE_HEXCOLOUR + "[0-9A-Z]{6}?$")) {
255
+            } else if (partialLine.matches("^.*" + IRCControlCodes.COLOUR_HEX + "[0-9A-Z]{6}?$")) {
256 256
                 target.showColourPicker(false, true);
257 257
             }
258 258
         }
@@ -399,33 +399,33 @@ public abstract class InputHandler implements ConfigChangeListener {
399 399
             final boolean shiftPressed) {
400 400
         switch (keyCode) {
401 401
             case KeyEvent.VK_B:
402
-                addControlCode(Styliser.CODE_BOLD, POSITION_END);
402
+                addControlCode(IRCControlCodes.BOLD, POSITION_END);
403 403
                 break;
404 404
 
405 405
             case KeyEvent.VK_U:
406
-                addControlCode(Styliser.CODE_UNDERLINE, POSITION_END);
406
+                addControlCode(IRCControlCodes.UNDERLINE, POSITION_END);
407 407
                 break;
408 408
 
409 409
             case KeyEvent.VK_O:
410
-                addControlCode(Styliser.CODE_STOP, POSITION_END);
410
+                addControlCode(IRCControlCodes.STOP, POSITION_END);
411 411
                 break;
412 412
 
413 413
             case KeyEvent.VK_I:
414
-                addControlCode(Styliser.CODE_ITALIC, POSITION_END);
414
+                addControlCode(IRCControlCodes.ITALIC, POSITION_END);
415 415
                 break;
416 416
 
417 417
             case KeyEvent.VK_F:
418 418
                 if (shiftPressed) {
419
-                    addControlCode(Styliser.CODE_FIXED, POSITION_END);
419
+                    addControlCode(IRCControlCodes.FIXED, POSITION_END);
420 420
                 }
421 421
                 break;
422 422
 
423 423
             case KeyEvent.VK_K:
424 424
                 if (shiftPressed) {
425
-                    addControlCode(Styliser.CODE_HEXCOLOUR, POSITION_START);
425
+                    addControlCode(IRCControlCodes.COLOUR_HEX, POSITION_START);
426 426
                     target.showColourPicker(false, true);
427 427
                 } else {
428
-                    addControlCode(Styliser.CODE_COLOUR, POSITION_START);
428
+                    addControlCode(IRCControlCodes.COLOUR, POSITION_START);
429 429
                     target.showColourPicker(true, false);
430 430
                 }
431 431
                 break;

+ 47
- 0
src/main/java/com/dmdirc/ui/messages/IRCControlCodes.java View File

@@ -0,0 +1,47 @@
1
+/*
2
+ * Copyright (c) 2006-2016 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.ui.messages;
24
+
25
+/**
26
+ * Contains constants for IRC 'control codes' that modify text styles.
27
+ */
28
+public interface IRCControlCodes {
29
+
30
+  /** The character used for marking up bold text. */
31
+  char BOLD = 2;
32
+  /** The character used for marking up coloured text. */
33
+  char COLOUR = 3;
34
+  /** The character used for marking up coloured text (using hex). */
35
+  char COLOUR_HEX = 4;
36
+  /** The character used for stopping all formatting. */
37
+  char STOP = 15;
38
+  /** The character used for marking up fixed pitch text. */
39
+  char FIXED = 17;
40
+  /** The character used for negating control codes. */
41
+  char NEGATE = 18;
42
+  /** The character used for marking up italic text. */
43
+  char ITALIC = 29;
44
+  /** The character used for marking up underlined text. */
45
+  char UNDERLINE = 31;
46
+
47
+}

+ 2
- 1
src/main/java/com/dmdirc/ui/messages/IRCLine.java View File

@@ -105,7 +105,8 @@ public class IRCLine implements Line {
105 105
     @Override
106 106
     public <T> T getStyled(final StyledMessageMaker<T> maker) {
107 107
         maker.setDefaultFont(fontName, fontSize);
108
-        final T styledString = styliser.getStyledString(getLineParts(), maker);
108
+        styliser.addStyledString(maker, getLineParts());;
109
+        final T styledString = maker.getStyledMessage();
109 110
         fontSize = maker.getMaximumFontSize();
110 111
         maker.clear();
111 112
         return styledString;

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

@@ -22,59 +22,42 @@
22 22
 
23 23
 package com.dmdirc.ui.messages;
24 24
 
25
+import static com.google.common.base.Preconditions.checkArgument;
26
+
25 27
 import com.dmdirc.interfaces.Connection;
26 28
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
27 29
 import com.dmdirc.interfaces.config.ConfigChangeListener;
28 30
 import com.dmdirc.util.colours.Colour;
29
-
30 31
 import java.util.Locale;
31 32
 import java.util.regex.Pattern;
32
-
33 33
 import javax.annotation.Nullable;
34 34
 
35
-import static com.google.common.base.Preconditions.checkArgument;
36
-
37 35
 /**
38 36
  * The styliser applies IRC styles to text. Styles are indicated by various control codes which are
39 37
  * a de-facto IRC standard.
40 38
  */
41 39
 public class Styliser implements ConfigChangeListener {
42 40
 
43
-    /** The character used for marking up bold text. */
44
-    public static final char CODE_BOLD = 2;
45
-    /** The character used for marking up coloured text. */
46
-    public static final char CODE_COLOUR = 3;
47
-    /** The character used for marking up coloured text (using hex). */
48
-    public static final char CODE_HEXCOLOUR = 4;
49 41
     /** Character used to indicate hyperlinks. */
50 42
     public static final char CODE_HYPERLINK = 5;
51 43
     /** Character used to indicate channel links. */
52 44
     public static final char CODE_CHANNEL = 6;
53 45
     /** Character used to indicate smilies. */
54 46
     public static final char CODE_SMILIE = 7;
55
-    /** The character used for stopping all formatting. */
56
-    public static final char CODE_STOP = 15;
57 47
     /** Character used to indicate nickname links. */
58 48
     public static final char CODE_NICKNAME = 16;
59
-    /** The character used for marking up fixed pitch text. */
60
-    public static final char CODE_FIXED = 17;
61
-    /** The character used for negating control codes. */
62
-    public static final char CODE_NEGATE = 18;
63 49
     /** The character used for tooltips. */
64 50
     public static final char CODE_TOOLTIP = 19;
65
-    /** The character used for marking up italic text. */
66
-    public static final char CODE_ITALIC = 29;
67
-    /** The character used for marking up underlined text. */
68
-    public static final char CODE_UNDERLINE = 31;
69 51
     /** Internal chars. */
70 52
     private static final String INTERNAL_CHARS = String.valueOf(CODE_HYPERLINK)
71 53
             + CODE_NICKNAME + CODE_CHANNEL + CODE_SMILIE + CODE_TOOLTIP;
72 54
     /** Characters used for hyperlinks. */
73 55
     private static final String HYPERLINK_CHARS = Character.toString(CODE_HYPERLINK) + CODE_CHANNEL;
74 56
     /** Regexp to match characters which shouldn't be used in channel links. */
75
-    private static final String RESERVED_CHARS = "[^\\s" + CODE_BOLD + CODE_COLOUR
76
-            + CODE_STOP + CODE_HEXCOLOUR + CODE_FIXED + CODE_ITALIC
77
-            + CODE_UNDERLINE + CODE_CHANNEL + CODE_NICKNAME + CODE_NEGATE + "\",]";
57
+    private static final String RESERVED_CHARS = "[^\\s" + IRCControlCodes.BOLD + IRCControlCodes.COLOUR
58
+            + IRCControlCodes.STOP + IRCControlCodes.COLOUR_HEX + IRCControlCodes.FIXED + IRCControlCodes.ITALIC
59
+            + IRCControlCodes.UNDERLINE + CODE_CHANNEL + CODE_NICKNAME + IRCControlCodes.NEGATE
60
+        + "\",]";
78 61
     /** Defines all characters treated as trailing punctuation that are illegal in URLs. */
79 62
     private static final String URL_PUNCT_ILLEGAL = "\"";
80 63
     /** Defines all characters treated as trailing punctuation that're legal in URLs. */
@@ -87,7 +70,7 @@ public class Styliser implements ConfigChangeListener {
87 70
     private static final String URL_CHARS = '[' + URL_PUNCT_LEGAL + URL_NOPUNCT
88 71
             + "]*[" + URL_NOPUNCT + "]+[" + URL_PUNCT_LEGAL + URL_NOPUNCT + "]*";
89 72
     /** The regular expression to use for marking up URLs. */
90
-    private static final String URL_REGEXP = "(?i)((?>(?<!" + CODE_HEXCOLOUR
73
+    private static final String URL_REGEXP = "(?i)((?>(?<!" + IRCControlCodes.COLOUR_HEX
91 74
             + "[a-f0-9]{5})[a-f]|[g-z+])+://" + URL_CHARS
92 75
             + "|(?<![a-z0-9:/])www\\." + URL_CHARS + ')';
93 76
     /** Regular expression for intelligent handling of closing brackets. */
@@ -191,18 +174,6 @@ public class Styliser implements ConfigChangeListener {
191 174
         }
192 175
     }
193 176
 
194
-    /**
195
-     * Stylises the specified string.
196
-     *
197
-     * @param strings The line to be stylised
198
-     *
199
-     * @return StyledDocument for the inputted strings
200
-     */
201
-    public <T> T getStyledString(final String[] strings, final StyledMessageMaker<T> maker) {
202
-        addStyledString(maker, strings);
203
-        return maker.getStyledMessage();
204
-    }
205
-
206 177
     /**
207 178
      * Retrieves the styled String contained within the unstyled offsets specified. That is, the
208 179
      * <code>from</code> and <code>to</code> arguments correspond to indexes in an unstyled version
@@ -293,7 +264,7 @@ public class Styliser implements ConfigChangeListener {
293 264
      *
294 265
      * @since 0.6.3m1
295 266
      */
296
-    public String doSmilies(final String string) {
267
+    private String doSmilies(final String string) {
297 268
         // TODO: Check if they're enabled.
298 269
         // TODO: Store the list instead of building it every line
299 270
 
@@ -320,11 +291,11 @@ public class Styliser implements ConfigChangeListener {
320 291
      * @return a copy of the input with control codes removed
321 292
      */
322 293
     public static String stipControlCodes(final String input) {
323
-        return input.replaceAll("[" + CODE_BOLD + CODE_CHANNEL + CODE_FIXED
324
-                + CODE_HYPERLINK + CODE_ITALIC + CODE_NEGATE + CODE_NICKNAME
325
-                + CODE_SMILIE + CODE_STOP + CODE_UNDERLINE + "]|"
326
-                + CODE_HEXCOLOUR + "([A-Za-z0-9]{6}(,[A-Za-z0-9]{6})?)?|"
327
-                + CODE_COLOUR + "([0-9]{1,2}(,[0-9]{1,2})?)?", "")
294
+        return input.replaceAll("[" + IRCControlCodes.BOLD + CODE_CHANNEL + IRCControlCodes.FIXED
295
+                + CODE_HYPERLINK + IRCControlCodes.ITALIC + IRCControlCodes.NEGATE + CODE_NICKNAME
296
+                + CODE_SMILIE + IRCControlCodes.STOP + IRCControlCodes.UNDERLINE + "]|"
297
+                + IRCControlCodes.COLOUR_HEX + "([A-Za-z0-9]{6}(,[A-Za-z0-9]{6})?)?|"
298
+                + IRCControlCodes.COLOUR + "([0-9]{1,2}(,[0-9]{1,2})?)?", "")
328 299
                 .replaceAll(CODE_TOOLTIP + ".*?" + CODE_TOOLTIP + "(.*?)" + CODE_TOOLTIP, "$1");
329 300
     }
330 301
 
@@ -337,9 +308,9 @@ public class Styliser implements ConfigChangeListener {
337 308
      *
338 309
      * @since 0.6.5
339 310
      */
340
-    public static String stipInternalControlCodes(final String input) {
311
+    private static String stipInternalControlCodes(final String input) {
341 312
         return input.replaceAll("[" + CODE_CHANNEL + CODE_HYPERLINK + CODE_NICKNAME
342
-                + CODE_SMILIE + CODE_STOP + CODE_UNDERLINE + ']', "")
313
+                + CODE_SMILIE + IRCControlCodes.STOP + IRCControlCodes.UNDERLINE + ']', "")
343 314
                 .replaceAll(CODE_TOOLTIP + ".*?" + CODE_TOOLTIP + "(.*?)"
344 315
                         + CODE_TOOLTIP, "$1");
345 316
     }
@@ -356,18 +327,18 @@ public class Styliser implements ConfigChangeListener {
356 327
     public static String readUntilControl(final String input) {
357 328
         int pos = input.length();
358 329
 
359
-        pos = checkChar(pos, input.indexOf(CODE_BOLD));
360
-        pos = checkChar(pos, input.indexOf(CODE_UNDERLINE));
361
-        pos = checkChar(pos, input.indexOf(CODE_STOP));
362
-        pos = checkChar(pos, input.indexOf(CODE_COLOUR));
363
-        pos = checkChar(pos, input.indexOf(CODE_HEXCOLOUR));
364
-        pos = checkChar(pos, input.indexOf(CODE_ITALIC));
365
-        pos = checkChar(pos, input.indexOf(CODE_FIXED));
330
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.BOLD));
331
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.UNDERLINE));
332
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.STOP));
333
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.COLOUR));
334
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.COLOUR_HEX));
335
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.ITALIC));
336
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.FIXED));
366 337
         pos = checkChar(pos, input.indexOf(CODE_HYPERLINK));
367 338
         pos = checkChar(pos, input.indexOf(CODE_NICKNAME));
368 339
         pos = checkChar(pos, input.indexOf(CODE_CHANNEL));
369 340
         pos = checkChar(pos, input.indexOf(CODE_SMILIE));
370
-        pos = checkChar(pos, input.indexOf(CODE_NEGATE));
341
+        pos = checkChar(pos, input.indexOf(IRCControlCodes.NEGATE));
371 342
         pos = checkChar(pos, input.indexOf(CODE_TOOLTIP));
372 343
 
373 344
         return input.substring(0, pos);
@@ -404,7 +375,7 @@ public class Styliser implements ConfigChangeListener {
404 375
         final boolean isNegated = state.isNegated;
405 376
 
406 377
         // Bold
407
-        if (string.charAt(0) == CODE_BOLD) {
378
+        if (string.charAt(0) == IRCControlCodes.BOLD) {
408 379
             if (!isNegated) {
409 380
                 maker.toggleBold();
410 381
             }
@@ -413,7 +384,7 @@ public class Styliser implements ConfigChangeListener {
413 384
         }
414 385
 
415 386
         // Underline
416
-        if (string.charAt(0) == CODE_UNDERLINE) {
387
+        if (string.charAt(0) == IRCControlCodes.UNDERLINE) {
417 388
             if (!isNegated) {
418 389
                 maker.toggleUnderline();
419 390
             }
@@ -422,7 +393,7 @@ public class Styliser implements ConfigChangeListener {
422 393
         }
423 394
 
424 395
         // Italic
425
-        if (string.charAt(0) == CODE_ITALIC) {
396
+        if (string.charAt(0) == IRCControlCodes.ITALIC) {
426 397
             if (!isNegated) {
427 398
                 maker.toggleItalic();
428 399
             }
@@ -475,7 +446,7 @@ public class Styliser implements ConfigChangeListener {
475 446
         }
476 447
 
477 448
         // Fixed pitch
478
-        if (string.charAt(0) == CODE_FIXED) {
449
+        if (string.charAt(0) == IRCControlCodes.FIXED) {
479 450
             if (!isNegated) {
480 451
                 maker.toggleFixedWidth();
481 452
             }
@@ -484,7 +455,7 @@ public class Styliser implements ConfigChangeListener {
484 455
         }
485 456
 
486 457
         // Stop formatting
487
-        if (string.charAt(0) == CODE_STOP) {
458
+        if (string.charAt(0) == IRCControlCodes.STOP) {
488 459
             if (!isNegated) {
489 460
                 maker.resetAllStyles();
490 461
             }
@@ -493,7 +464,7 @@ public class Styliser implements ConfigChangeListener {
493 464
         }
494 465
 
495 466
         // Colours
496
-        if (string.charAt(0) == CODE_COLOUR) {
467
+        if (string.charAt(0) == IRCControlCodes.COLOUR) {
497 468
             int count = 1;
498 469
             // This isn't too nice!
499 470
             if (string.length() > count && isInt(string.charAt(count))) {
@@ -542,7 +513,7 @@ public class Styliser implements ConfigChangeListener {
542 513
         }
543 514
 
544 515
         // Hex colours
545
-        if (string.charAt(0) == CODE_HEXCOLOUR) {
516
+        if (string.charAt(0) == IRCControlCodes.COLOUR_HEX) {
546 517
             int count = 1;
547 518
             if (hasHexString(string, 1)) {
548 519
                 if (!isNegated) {
@@ -583,7 +554,7 @@ public class Styliser implements ConfigChangeListener {
583 554
         }
584 555
 
585 556
         // Control code negation
586
-        if (string.charAt(0) == CODE_NEGATE) {
557
+        if (string.charAt(0) == IRCControlCodes.NEGATE) {
587 558
             state.isNegated = !state.isNegated;
588 559
             return 1;
589 560
         }
@@ -692,10 +663,10 @@ public class Styliser implements ConfigChangeListener {
692 663
 
693 664
     private static class StyliserState {
694 665
 
695
-        public boolean isNegated;
696
-        public boolean isInLink;
697
-        public boolean isInSmilie;
698
-        public boolean isInToolTip;
666
+        boolean isNegated;
667
+        boolean isInLink;
668
+        boolean isInSmilie;
669
+        boolean isInToolTip;
699 670
 
700 671
     }
701 672
 

+ 7
- 7
src/test/java/com/dmdirc/ui/messages/StyliserIndicesTest.java View File

@@ -55,14 +55,14 @@ public class StyliserIndicesTest {
55 55
             // No style
56 56
             {"Blah blah blah", 0, 1, "B"},
57 57
             {"Blah blah blah", 0, 4, "Blah"},
58
-            {Styliser.CODE_BOLD + "Blah blah blah", 0, 4, Styliser.CODE_BOLD + "Blah"},
59
-            {Styliser.CODE_BOLD + "Bl" + Styliser.CODE_BOLD + "ah blah blah",
60
-                     0, 4, Styliser.CODE_BOLD + "Bl" + Styliser.CODE_BOLD + "ah"},
61
-            {"Blah" + Styliser.CODE_BOLD + " blah blah",
58
+            {IRCControlCodes.BOLD + "Blah blah blah", 0, 4, IRCControlCodes.BOLD + "Blah"},
59
+            {IRCControlCodes.BOLD + "Bl" + IRCControlCodes.BOLD + "ah blah blah",
60
+                     0, 4, IRCControlCodes.BOLD + "Bl" + IRCControlCodes.BOLD + "ah"},
61
+            {"Blah" + IRCControlCodes.BOLD + " blah blah",
62 62
                      0, 4, "Blah"},
63
-            {"Blah" + Styliser.CODE_COLOUR + "4,0RED blah blah",
64
-                     4, 7, Styliser.CODE_COLOUR + "4,0RED"},
65
-            {"Blah" + Styliser.CODE_COLOUR + "4,0RED blah blah",
63
+            {"Blah" + IRCControlCodes.COLOUR + "4,0RED blah blah",
64
+                     4, 7, IRCControlCodes.COLOUR + "4,0RED"},
65
+            {"Blah" + IRCControlCodes.COLOUR + "4,0RED blah blah",
66 66
                      5, 7, "ED"},
67 67
             {Styliser.CODE_TOOLTIP + "Annoying internal tooltip text"
68 68
                      + Styliser.CODE_TOOLTIP + "Blah" + Styliser.CODE_TOOLTIP + "Blah",

Loading…
Cancel
Save