sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.util/src/com/nokia/carbide/cpp/pi/util/AWTColorPalette.java
changeset 2 b9ab3b238396
child 12 ae255c9aa552
equal deleted inserted replaced
1:1050670c6980 2:b9ab3b238396
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the License "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: 
       
    15  *
       
    16  */
       
    17 
       
    18 package com.nokia.carbide.cpp.pi.util;
       
    19 
       
    20 import org.eclipse.swt.graphics.RGB;
       
    21 
       
    22 /**
       
    23  * Class for managing all Color resource for PI
       
    24  * 
       
    25  */
       
    26 
       
    27 public class AWTColorPalette {
       
    28 
       
    29 	private static CacheMap<RGB, java.awt.Color> palette = new CacheMap<RGB, java.awt.Color>();
       
    30 	
       
    31 	private static AWTColorPalette colorPalette = null;
       
    32 
       
    33 	private AWTColorPalette() {
       
    34 		// private so we can't new ColorPalette
       
    35 		// user getInstance() to access this class
       
    36 	}
       
    37 	
       
    38 	public static AWTColorPalette getInstance() {
       
    39 		if (colorPalette == null)
       
    40 	    {
       
    41 	    	colorPalette = new AWTColorPalette();
       
    42 	    }
       
    43 	    return colorPalette;		
       
    44 	}
       
    45 
       
    46 	public static void add(RGB rgb) {
       
    47 		synchronized(palette) {
       
    48 			palette.put(new RGB(rgb.red, rgb.green, rgb.blue), new java.awt.Color(rgb.red, rgb.green, rgb.blue));
       
    49 		}
       
    50 	}
       
    51 
       
    52 	public static java.awt.Color getColor(RGB rgb) {
       
    53 		synchronized(palette) {
       
    54 			if (palette.get(rgb) == null) {
       
    55 				add(rgb);
       
    56 			}
       
    57 			return (java.awt.Color) palette.get(rgb);
       
    58 		}
       
    59 	}
       
    60 
       
    61 	public static int size() {
       
    62 		return palette.size();
       
    63 	}
       
    64 
       
    65 	public static void dispose() {
       
    66 		// CacheMap.dispose() is going to free up resource
       
    67 		palette.dispose();
       
    68 	}
       
    69 	
       
    70 	protected void finalize() {
       
    71 		palette.dispose();
       
    72 	}
       
    73 }