Sfoglia il codice sorgente

Add an interface for ColourManager.

pull/736/head
Chris Smith 7 anni fa
parent
commit
82f897f85e

+ 41
- 0
api/src/main/java/com/dmdirc/ui/messages/ColourManager.java Vedi File

1
+package com.dmdirc.ui.messages;
2
+
3
+import com.dmdirc.util.colours.Colour;
4
+
5
+/**
6
+ * Created by Chris on 30/12/2016.
7
+ */
8
+public interface ColourManager {
9
+    /**
10
+     * Parses either a 1-2 digit IRC colour, or a 6 digit hex colour from the target string, and
11
+     * returns the corresponding colour. Returns the specified fallback colour if the spec can't be
12
+     * parsed.
13
+     *
14
+     * @param spec     The string to parse
15
+     * @param fallback The colour to use if the spec isn't valid
16
+     *
17
+     * @return A colour representation of the specified string
18
+     */
19
+    Colour getColourFromString(String spec, Colour fallback);
20
+
21
+    /**
22
+     * Returns a Colour object that corresponds to the specified 6-digit hex string. If the string
23
+     * is invalid, logs a warning and returns white.
24
+     *
25
+     * @param hex The hex string to convert into a Colour
26
+     *
27
+     * @return A Colour object corresponding to the hex input
28
+     */
29
+    Colour getColourFromHex(String hex);
30
+
31
+    /**
32
+     * Returns a Colour object that represents the colour associated with the specified IRC colour
33
+     * code. If the code is not found, a warning is logged with the client's Logger class, and white
34
+     * is returned.
35
+     *
36
+     * @param number The IRC colour code to look up
37
+     *
38
+     * @return The corresponding Colour object
39
+     */
40
+    Colour getColourFromIrcCode(int number);
41
+}

+ 1
- 1
src/main/java/com/dmdirc/ui/messages/ColourManagerFactory.java Vedi File

38
     }
38
     }
39
 
39
 
40
     public ColourManager getColourManager(final AggregateConfigProvider configManager) {
40
     public ColourManager getColourManager(final AggregateConfigProvider configManager) {
41
-        return new ColourManager(configManager);
41
+        return new ColourManagerImpl(configManager);
42
     }
42
     }
43
 
43
 
44
 }
44
 }

src/main/java/com/dmdirc/ui/messages/ColourManager.java → src/main/java/com/dmdirc/ui/messages/ColourManagerImpl.java Vedi File

39
  * The colour manager manages the colour scheme for the IRC client. It allows other components to
39
  * The colour manager manages the colour scheme for the IRC client. It allows other components to
40
  * use IRC colour codes instead of absolute colours.
40
  * use IRC colour codes instead of absolute colours.
41
  */
41
  */
42
-public class ColourManager {
42
+public class ColourManagerImpl implements ColourManager {
43
 
43
 
44
-    private static final Logger LOG = LoggerFactory.getLogger(ColourManager.class);
44
+    private static final Logger LOG = LoggerFactory.getLogger(ColourManagerImpl.class);
45
     /** Default colours used for the standard 16 IRC colours. */
45
     /** Default colours used for the standard 16 IRC colours. */
46
     private static final Colour[] DEFAULT_COLOURS = {
46
     private static final Colour[] DEFAULT_COLOURS = {
47
         Colour.WHITE, Colour.BLACK, new Colour(0, 0, 127), new Colour(0, 141, 0),
47
         Colour.WHITE, Colour.BLACK, new Colour(0, 0, 127), new Colour(0, 141, 0),
56
     private final Colour[] ircColours = DEFAULT_COLOURS.clone();
56
     private final Colour[] ircColours = DEFAULT_COLOURS.clone();
57
 
57
 
58
     /**
58
     /**
59
-     * Creates a new instance of {@link ColourManager}.
59
+     * Creates a new instance of {@link ColourManagerImpl}.
60
      *
60
      *
61
      * @param configManager The manager to read config settings from.
61
      * @param configManager The manager to read config settings from.
62
      */
62
      */
63
-    public ColourManager(final AggregateConfigProvider configManager) {
63
+    public ColourManagerImpl(final AggregateConfigProvider configManager) {
64
         this.configManager = configManager;
64
         this.configManager = configManager;
65
 
65
 
66
         configManager.addChangeListener("colour", (domain, key) -> initColours());
66
         configManager.addChangeListener("colour", (domain, key) -> initColours());
85
         }
85
         }
86
     }
86
     }
87
 
87
 
88
-    /**
89
-     * Parses either a 1-2 digit IRC colour, or a 6 digit hex colour from the target string, and
90
-     * returns the corresponding colour. Returns the specified fallback colour if the spec can't be
91
-     * parsed.
92
-     *
93
-     * @param spec     The string to parse
94
-     * @param fallback The colour to use if the spec isn't valid
95
-     *
96
-     * @return A colour representation of the specified string
97
-     */
88
+    @Override
98
     public Colour getColourFromString(final String spec, final Colour fallback) {
89
     public Colour getColourFromString(final String spec, final Colour fallback) {
99
         if (colourCache.containsKey(spec)) {
90
         if (colourCache.containsKey(spec)) {
100
             return colourCache.get(spec);
91
             return colourCache.get(spec);
130
         return res;
121
         return res;
131
     }
122
     }
132
 
123
 
133
-    /**
134
-     * Returns a Colour object that corresponds to the specified 6-digit hex string. If the string
135
-     * is invalid, logs a warning and returns white.
136
-     *
137
-     * @param hex The hex string to convert into a Colour
138
-     *
139
-     * @return A Colour object corresponding to the hex input
140
-     */
124
+    @Override
141
     public Colour getColourFromHex(final String hex) {
125
     public Colour getColourFromHex(final String hex) {
142
         if (colourCache.containsKey(hex)) {
126
         if (colourCache.containsKey(hex)) {
143
             return colourCache.get(hex);
127
             return colourCache.get(hex);
163
         return colour;
147
         return colour;
164
     }
148
     }
165
 
149
 
166
-    /**
167
-     * Returns a Colour object that represents the colour associated with the specified IRC colour
168
-     * code. If the code is not found, a warning is logged with the client's Logger class, and white
169
-     * is returned.
170
-     *
171
-     * @param number The IRC colour code to look up
172
-     *
173
-     * @return The corresponding Colour object
174
-     */
150
+    @Override
175
     public Colour getColourFromIrcCode(final int number) {
151
     public Colour getColourFromIrcCode(final int number) {
176
         if (number >= 0 && number <= 15) {
152
         if (number >= 0 && number <= 15) {
177
             return ircColours[number];
153
             return ircColours[number];

+ 1
- 1
src/main/java/com/dmdirc/ui/messages/UnreadStatusManagerImpl.java Vedi File

57
     public UnreadStatusManagerImpl(final WindowModel container) {
57
     public UnreadStatusManagerImpl(final WindowModel container) {
58
         this.container = container;
58
         this.container = container;
59
         this.eventBus = container.getEventBus();
59
         this.eventBus = container.getEventBus();
60
-        this.colourManager = new ColourManager(container.getConfigManager());
60
+        this.colourManager = new ColourManagerImpl(container.getConfigManager());
61
     }
61
     }
62
 
62
 
63
     @Handler
63
     @Handler

+ 1
- 1
src/test/java/com/dmdirc/ui/messages/ColourManagerTest.java Vedi File

57
 
57
 
58
     @Before
58
     @Before
59
     public void setup() {
59
     public void setup() {
60
-        manager = new ColourManager(configManager);
60
+        manager = new ColourManagerImpl(configManager);
61
         verify(configManager).addChangeListener(anyString(), configListener.capture());
61
         verify(configManager).addChangeListener(anyString(), configListener.capture());
62
     }
62
     }
63
 
63
 

+ 1
- 1
src/test/java/com/dmdirc/ui/messages/IntelligentLinkingTest.java Vedi File

55
         when(connection.getGroupChatManager()).thenReturn(groupChatManager);
55
         when(connection.getGroupChatManager()).thenReturn(groupChatManager);
56
         when(groupChatManager.getChannelPrefixes()).thenReturn("#&+");
56
         when(groupChatManager.getChannelPrefixes()).thenReturn("#&+");
57
 
57
 
58
-        styliser = new Styliser(connection, manager, new ColourManager(manager));
58
+        styliser = new Styliser(connection, manager, new ColourManagerImpl(manager));
59
     }
59
     }
60
 
60
 
61
     @Test
61
     @Test

+ 1
- 1
src/test/java/com/dmdirc/ui/messages/StyliserStylesTest.java Vedi File

69
 
69
 
70
         final AggregateConfigProvider manager = mock(AggregateConfigProvider.class);
70
         final AggregateConfigProvider manager = mock(AggregateConfigProvider.class);
71
 
71
 
72
-        final Styliser styliser = new Styliser(null, manager, new ColourManager(manager));
72
+        final Styliser styliser = new Styliser(null, manager, new ColourManagerImpl(manager));
73
         styliser.addStyledString(null, input);  // TODO...
73
         styliser.addStyledString(null, input);  // TODO...
74
         final AttributedCharacterIterator aci = null; // TODO...
74
         final AttributedCharacterIterator aci = null; // TODO...
75
 
75
 

+ 1
- 1
src/test/java/com/dmdirc/ui/messages/StyliserTest.java Vedi File

70
         final String input2 = "abcdefghi";
70
         final String input2 = "abcdefghi";
71
 
71
 
72
         final AggregateConfigProvider manager = mock(AggregateConfigProvider.class);
72
         final AggregateConfigProvider manager = mock(AggregateConfigProvider.class);
73
-        final Styliser styliser = new Styliser(null, manager, new ColourManager(manager));
73
+        final Styliser styliser = new Styliser(null, manager, new ColourManagerImpl(manager));
74
 
74
 
75
         for (int i = 0; i < input2.length(); i++) {
75
         for (int i = 0; i < input2.length(); i++) {
76
             // TODO...
76
             // TODO...

Loading…
Annulla
Salva