c82cdb4f1b40f06c4fde2865fa21aed8b8521fad
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / externaltools / internal / model / ColorManager.java
1 package net.sourceforge.phpdt.externaltools.internal.model;
2
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp.  All rights reserved.
5 This file is made available under the terms of the Common Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/cpl-v10.html
8 **********************************************************************/
9
10 import java.util.HashMap;
11 import java.util.Iterator;
12 import java.util.Map;
13
14 import org.eclipse.swt.graphics.Color;
15 import org.eclipse.swt.graphics.RGB;
16 import org.eclipse.swt.widgets.Display;
17
18 /**
19  * Generic color manager.
20  */
21 public class ColorManager {     
22         
23         private static ColorManager fgColorManager;
24         
25         private ColorManager() {
26         }
27         
28         public static ColorManager getDefault() {
29                 if (fgColorManager == null) {
30                         fgColorManager= new ColorManager();
31                 }
32                 return fgColorManager;
33         }
34         
35         protected Map fColorTable= new HashMap(10);
36         
37         public Color getColor(RGB rgb) {
38                 Color color= (Color) fColorTable.get(rgb);
39                 if (color == null) {
40                         color= new Color(Display.getCurrent(), rgb);
41                         fColorTable.put(rgb, color);
42                 }
43                 return color;
44         }
45         
46         public void dispose() {
47                 Iterator e= fColorTable.values().iterator();
48                 while (e.hasNext())
49                         ((Color) e.next()).dispose();
50         }
51 }
52
53