Pārlūkot izejas kodu

Move Colour to utils.

Change-Id: Icb4de047bfada18231b66011838958974282a322
Depends-On: I73c10f367e5972031d1c9b0871c4cb9043008bec
Depends-On: Ibf9936e6cf89ebbe1243e1c32596bc726bebc5ce
Reviewed-on: http://gerrit.dmdirc.com/3860
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
pull/1/head
Greg Holmes 9 gadus atpakaļ
vecāks
revīzija
22e1a9aee1

+ 4
- 4
src/com/dmdirc/Channel.java Parādīt failu

@@ -38,16 +38,16 @@ import com.dmdirc.messages.MessageSinkManager;
38 38
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
39 39
 import com.dmdirc.parser.interfaces.ChannelInfo;
40 40
 import com.dmdirc.parser.interfaces.ClientInfo;
41
-import com.dmdirc.ui.Colour;
42 41
 import com.dmdirc.ui.core.components.WindowComponent;
43 42
 import com.dmdirc.ui.input.TabCompleterFactory;
44 43
 import com.dmdirc.ui.input.TabCompletionType;
45
-import com.dmdirc.ui.messages.ColourManager;
46 44
 import com.dmdirc.ui.messages.Styliser;
47 45
 import com.dmdirc.util.EventUtils;
48 46
 import com.dmdirc.util.URLBuilder;
49 47
 import com.dmdirc.util.collections.ListenerList;
50 48
 import com.dmdirc.util.collections.RollingList;
49
+import com.dmdirc.util.colours.Colour;
50
+import com.dmdirc.util.colours.ColourUtils;
51 51
 
52 52
 import com.google.common.base.Optional;
53 53
 
@@ -431,10 +431,10 @@ public class Channel extends MessageTarget implements GroupChat {
431 431
                 final String prefix;
432 432
 
433 433
                 if (map.containsKey(ChannelClientProperty.TEXT_BACKGROUND)) {
434
-                    prefix = ',' + ColourManager.getHex((Colour) map.get(
434
+                    prefix = ',' + ColourUtils.getHex((Colour) map.get(
435 435
                             ChannelClientProperty.TEXT_BACKGROUND));
436 436
                 } else {
437
-                    prefix = Styliser.CODE_HEXCOLOUR + ColourManager.getHex((Colour) map.get(
437
+                    prefix = Styliser.CODE_HEXCOLOUR + ColourUtils.getHex((Colour) map.get(
438 438
                             ChannelClientProperty.TEXT_FOREGROUND));
439 439
                 }
440 440
 

+ 1
- 1
src/com/dmdirc/FrameContainer.java Parādīt failu

@@ -37,7 +37,7 @@ import com.dmdirc.interfaces.config.AggregateConfigProvider;
37 37
 import com.dmdirc.interfaces.config.ConfigChangeListener;
38 38
 import com.dmdirc.messages.MessageSinkManager;
39 39
 import com.dmdirc.parser.common.CompositionState;
40
-import com.dmdirc.ui.Colour;
40
+import com.dmdirc.util.colours.Colour;
41 41
 import com.dmdirc.ui.IconManager;
42 42
 import com.dmdirc.ui.input.TabCompleter;
43 43
 import com.dmdirc.ui.messages.Formatter;

+ 1
- 1
src/com/dmdirc/actions/ColourActionComparison.java Parādīt failu

@@ -23,7 +23,7 @@
23 23
 package com.dmdirc.actions;
24 24
 
25 25
 import com.dmdirc.interfaces.actions.ActionComparison;
26
-import com.dmdirc.ui.Colour;
26
+import com.dmdirc.util.colours.Colour;
27 27
 import com.dmdirc.ui.messages.ColourManager;
28 28
 
29 29
 import javax.inject.Inject;

+ 1
- 1
src/com/dmdirc/actions/CoreActionComponent.java Parādīt failu

@@ -33,7 +33,7 @@ import com.dmdirc.logger.ErrorLevel;
33 33
 import com.dmdirc.logger.Logger;
34 34
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
35 35
 import com.dmdirc.parser.interfaces.ClientInfo;
36
-import com.dmdirc.ui.Colour;
36
+import com.dmdirc.util.colours.Colour;
37 37
 import com.dmdirc.ui.messages.Styliser;
38 38
 
39 39
 import java.awt.event.KeyEvent;

+ 1
- 1
src/com/dmdirc/commandparser/commands/channel/SetNickColour.java Parādīt failu

@@ -35,7 +35,7 @@ import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
35 35
 import com.dmdirc.commandparser.commands.context.CommandContext;
36 36
 import com.dmdirc.interfaces.CommandController;
37 37
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
38
-import com.dmdirc.ui.Colour;
38
+import com.dmdirc.util.colours.Colour;
39 39
 import com.dmdirc.ui.input.AdditionalTabTargets;
40 40
 import com.dmdirc.ui.input.TabCompletionType;
41 41
 import com.dmdirc.ui.messages.ColourManager;

+ 1
- 1
src/com/dmdirc/commandparser/commands/global/Notify.java Parādīt failu

@@ -31,7 +31,7 @@ import com.dmdirc.commandparser.commands.Command;
31 31
 import com.dmdirc.commandparser.commands.IntelligentCommand;
32 32
 import com.dmdirc.commandparser.commands.context.CommandContext;
33 33
 import com.dmdirc.interfaces.CommandController;
34
-import com.dmdirc.ui.Colour;
34
+import com.dmdirc.util.colours.Colour;
35 35
 import com.dmdirc.ui.input.AdditionalTabTargets;
36 36
 import com.dmdirc.ui.messages.ColourManager;
37 37
 

+ 1
- 1
src/com/dmdirc/events/DisplayProperty.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.events;
24 24
 
25
-import com.dmdirc.ui.Colour;
25
+import com.dmdirc.util.colours.Colour;
26 26
 
27 27
 /**
28 28
  * Describes a property that may be set on a {@link DisplayableEvent} to affect its display.

+ 1
- 1
src/com/dmdirc/events/NotificationSetEvent.java Parādīt failu

@@ -23,7 +23,7 @@
23 23
 package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
-import com.dmdirc.ui.Colour;
26
+import com.dmdirc.util.colours.Colour;
27 27
 
28 28
 /**
29 29
  * Fired when the notification colour has been changed.

+ 0
- 124
src/com/dmdirc/ui/Colour.java Parādīt failu

@@ -1,124 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 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;
24
-
25
-/**
26
- * A colour represented by an RGB triple. This implementation is immutable.
27
- */
28
-public class Colour {
29
-
30
-    /** The colour white. */
31
-    public static final Colour WHITE = new Colour(255, 255, 255);
32
-    /** The colour light gray. */
33
-    public static final Colour LIGHT_GRAY = new Colour(192, 192, 192);
34
-    /** The colour gray. */
35
-    public static final Colour GRAY = new Colour(128, 128, 128);
36
-    /** The colour dark gray. */
37
-    public static final Colour DARK_GRAY = new Colour(64, 64, 64);
38
-    /** The colour black. */
39
-    public static final Colour BLACK = new Colour(0, 0, 0);
40
-    /** The colour red. */
41
-    public static final Colour RED = new Colour(255, 0, 0);
42
-    /** The colour pink. */
43
-    public static final Colour PINK = new Colour(255, 175, 175);
44
-    /** The colour orange. */
45
-    public static final Colour ORANGE = new Colour(255, 200, 0);
46
-    /** The colour yellow. */
47
-    public static final Colour YELLOW = new Colour(255, 255, 0);
48
-    /** The colour green. */
49
-    public static final Colour GREEN = new Colour(0, 255, 0);
50
-    /** The colour magenta. */
51
-    public static final Colour MAGENTA = new Colour(255, 0, 255);
52
-    /** The colour cyan. */
53
-    public static final Colour CYAN = new Colour(0, 255, 255);
54
-    /** The colour blue. */
55
-    public static final Colour BLUE = new Colour(0, 0, 255);
56
-    /** The intensity of the red component of this colour (0-255). */
57
-    private final int red;
58
-    /** The intensity of the green component of this colour (0-255). */
59
-    private final int green;
60
-    /** The intensity of the blue component of this colour (0-255). */
61
-    private final int blue;
62
-
63
-    /**
64
-     * Creates a new Colour instance with the given RGB values.
65
-     *
66
-     * @param red   The intensity of the red component of the colour (0-255).
67
-     * @param green The intensity of the green component of the colour (0-255).
68
-     * @param blue  The intensity of the blue component of the colour (0-255).
69
-     */
70
-    public Colour(final int red, final int green, final int blue) {
71
-        this.red = red;
72
-        this.green = green;
73
-        this.blue = blue;
74
-    }
75
-
76
-    /**
77
-     * Gets the intensity of the blue component of this colour.
78
-     *
79
-     * @return The intensity on a scale of 0-255.
80
-     */
81
-    public int getBlue() {
82
-        return blue;
83
-    }
84
-
85
-    /**
86
-     * Gets the intensity of the green component of this colour.
87
-     *
88
-     * @return The intensity on a scale of 0-255.
89
-     */
90
-    public int getGreen() {
91
-        return green;
92
-    }
93
-
94
-    /**
95
-     * Gets the intensity of the red component of this colour.
96
-     *
97
-     * @return The intensity on a scale of 0-255.
98
-     */
99
-    public int getRed() {
100
-        return red;
101
-    }
102
-
103
-    @Override
104
-    public boolean equals(final Object obj) {
105
-        if (obj == null || getClass() != obj.getClass()) {
106
-            return false;
107
-        }
108
-
109
-        final Colour other = (Colour) obj;
110
-
111
-        return this.red == other.getRed() && this.green == other.getGreen()
112
-                && this.blue == other.getBlue();
113
-    }
114
-
115
-    @Override
116
-    public int hashCode() {
117
-        int hash = 7;
118
-        hash = 37 * hash + this.red;
119
-        hash = 37 * hash + this.green;
120
-        hash = 37 * hash + this.blue;
121
-        return hash;
122
-    }
123
-
124
-}

+ 1
- 28
src/com/dmdirc/ui/messages/ColourManager.java Parādīt failu

@@ -26,7 +26,7 @@ import com.dmdirc.interfaces.config.AggregateConfigProvider;
26 26
 import com.dmdirc.interfaces.config.ConfigChangeListener;
27 27
 import com.dmdirc.logger.ErrorLevel;
28 28
 import com.dmdirc.logger.Logger;
29
-import com.dmdirc.ui.Colour;
29
+import com.dmdirc.util.colours.Colour;
30 30
 import com.dmdirc.util.validators.ColourValidator;
31 31
 
32 32
 import java.util.HashMap;
@@ -182,31 +182,4 @@ public class ColourManager {
182 182
         }
183 183
     }
184 184
 
185
-    /**
186
-     * Retrieves the hex representation of the specified colour.
187
-     *
188
-     * @param colour The colour to be parsed
189
-     *
190
-     * @return A 6-digit hex string representing the colour
191
-     */
192
-    public static String getHex(final Colour colour) {
193
-        final int r = colour.getRed();
194
-        final int g = colour.getGreen();
195
-        final int b = colour.getBlue();
196
-
197
-        return toHex(r) + toHex(g) + toHex(b);
198
-    }
199
-
200
-    /**
201
-     * Converts the specified integer (in the range 0-255) into a hex string.
202
-     *
203
-     * @param value The integer to convert
204
-     *
205
-     * @return A 2 char hex string representing the specified integer
206
-     */
207
-    private static String toHex(final int value) {
208
-        final String hex = Integer.toHexString(value);
209
-        return (hex.length() < 2 ? "0" : "") + hex;
210
-    }
211
-
212 185
 }

+ 1
- 1
src/com/dmdirc/ui/messages/Styliser.java Parādīt failu

@@ -27,7 +27,7 @@ import com.dmdirc.interfaces.config.AggregateConfigProvider;
27 27
 import com.dmdirc.interfaces.config.ConfigChangeListener;
28 28
 import com.dmdirc.logger.ErrorLevel;
29 29
 import com.dmdirc.logger.Logger;
30
-import com.dmdirc.ui.Colour;
30
+import com.dmdirc.util.colours.Colour;
31 31
 
32 32
 import java.awt.Color;
33 33
 import java.util.Locale;

+ 4
- 10
test/com/dmdirc/ui/messages/ColourManagerTest.java Parādīt failu

@@ -26,7 +26,8 @@ import com.dmdirc.interfaces.config.AggregateConfigProvider;
26 26
 import com.dmdirc.interfaces.config.ConfigChangeListener;
27 27
 import com.dmdirc.logger.ErrorManager;
28 28
 import com.dmdirc.logger.Logger;
29
-import com.dmdirc.ui.Colour;
29
+import com.dmdirc.util.colours.Colour;
30
+import com.dmdirc.util.colours.ColourUtils;
30 31
 import com.dmdirc.util.validators.ColourValidator;
31 32
 
32 33
 import org.junit.Before;
@@ -130,19 +131,12 @@ public class ColourManagerTest {
130 131
         assertSame(result2, result3);
131 132
     }
132 133
 
133
-    @Test
134
-    public void testColourToHex() {
135
-        Colour c1 = manager.getColourFromHex("ab3400");
136
-
137
-        assertEquals("ab3400", ColourManager.getHex(c1).toLowerCase());
138
-    }
139
-
140 134
     @Test
141 135
     public void testCustomColours() {
142 136
         when(configManager.hasOptionString(eq("colour"), eq("4"), any(ColourValidator.class))).thenReturn(true);
143 137
         when(configManager.getOptionString("colour", "4")).thenReturn("00FF00");
144 138
         configListener.getValue().configChanged("colour", "4");
145
-        assertEquals("00ff00", ColourManager.getHex(manager.getColourFromIrcCode(4)).toLowerCase());
139
+        assertEquals("00ff00", ColourUtils.getHex(manager.getColourFromIrcCode(4)).toLowerCase());
146 140
     }
147 141
 
148 142
     @Test
@@ -153,6 +147,6 @@ public class ColourManagerTest {
153 147
 
154 148
         when(configManager.hasOptionString(eq("colour"), eq("4"), any(ColourValidator.class))).thenReturn(false);
155 149
         configListener.getValue().configChanged("colour", "4");
156
-        assertEquals("ff0000", ColourManager.getHex(manager.getColourFromIrcCode(4)).toLowerCase());
150
+        assertEquals("ff0000", ColourUtils.getHex(manager.getColourFromIrcCode(4)).toLowerCase());
157 151
     }
158 152
 }

Notiek ielāde…
Atcelt
Saglabāt