/*
 * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package uk.org.ownage.dmdirc.ui.messages;

import java.awt.Color;
import uk.org.ownage.dmdirc.logger.ErrorLevel;
import uk.org.ownage.dmdirc.logger.Logger;

/**
 * The colour manager manages the colour scheme for the IRC client. It allows
 * other components to use IRC colour codes instead of absolute colours.
 * @author chris
 */
public class ColourManager {
    
    /** Creates a new instance of ColourManager */
    public ColourManager() {
    }
    
    /**
     * Retrieves a colour specified by either an IRC colour code (as an int),
     * or a hex string
     * @param spec The colour specification
     * @returns A colour corresponding to the spec, or WHITE on error
     */
    public static Color getColour(Object spec) {
        if (spec instanceof Integer) {
            return getColour(((Integer)spec).intValue());
        } else if (spec instanceof String) {
            return getColour((String)spec);
        } else {
            Logger.error(ErrorLevel.WARNING, "(ColourManager.getColour) Unknown object type: "+spec);
            return Color.WHITE;
        }
    }
    
    public static Color getColour(String hex) {
        return Color.decode("#"+hex);
    }
    
    /**
     * Returns a Color object that represents the colour associated with the
     * specified IRC colour code. If the code is not found, a warning is logged
     * with the client's Logger class, and black is returned.
     * @param number The IRC colour code to look up
     * @return The corresponding Color object
     */
    public static Color getColour(int number) {
        switch (number) {
            case 0:
                return Color.WHITE;
            case 1:
                return Color.BLACK;
            case 2:
                return new Color(0, 0, 127);
            case 3:
                return new Color(0, 141, 0);
            case 4:
                return Color.RED;
            case 5:
                return new Color(127, 0, 0);
            case 6:
                return new Color(160, 15, 160);
            case 7:
                return new Color(252, 127, 0);
            case 8:
                return Color.YELLOW;
            case 9:
                return new Color(0, 252, 0);
            case 10:
                return new Color(0, 128, 128);
            case 11:
                return new Color(0, 255, 255);
            case 12:
                return Color.BLUE;
            case 13:
                return new Color(255, 0, 255);
            case 14:
                return Color.GRAY;
            case 15:
                return Color.LIGHT_GRAY;
            default:
                Logger.error(ErrorLevel.WARNING, "Invalid colour: "+number);
                return Color.WHITE;
        }
    }
    
}

@@ -1572,21 +1572,22 @@
 */%0A    p
-ublic
+rivate
  ColourM
@@ -1873,16 +1873,22 @@
 tColour(
+final 
 Object s
@@ -2248,24 +2248,309 @@
 %0A    %7D%0A    %0A
+    /**%0A     * Returns a Color object that corresponds to the specified 6-digit hex%0A     * string. If the string is invalid, logs a warning and returns white.%0A     * @param hex The hex string to convert into a Color%0A     * @return A Color object corresponding to the hex input%0A     */%0A
     public s
@@ -2571,16 +2571,22 @@
 tColour(
+final 
 String h
@@ -2587,24 +2587,42 @@
 ring hex) %7B%0A
+        try %7B%0A    
         retu
@@ -2647,16 +2647,153 @@
 %22+hex);%0A
+        %7D catch (NumberFormatException ex) %7B%0A            Logger.error(ErrorLevel.WARNING, ex);%0A            return Color.WHITE;%0A        %7D%0A
     %7D%0A  
@@ -3007,13 +3007,13 @@
 and 
-black
+white
  is 
@@ -3120,32 +3120,32 @@
  object%0A     */%0A
-
     public stati
@@ -3162,16 +3162,22 @@
 tColour(
+final 
 int numb

Fix issue 140