KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > ColorManager


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui;
12
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.Map JavaDoc;
17
18 import org.eclipse.swt.graphics.Color;
19 import org.eclipse.swt.graphics.RGB;
20 import org.eclipse.swt.widgets.Display;
21
22 /**
23  * Generic color manager.
24  */

25 public class ColorManager {
26     
27     private static ColorManager fgColorManager;
28     
29     private ColorManager() {
30     }
31     
32     public static ColorManager getDefault() {
33         if (fgColorManager == null) {
34             fgColorManager= new ColorManager();
35         }
36         return fgColorManager;
37     }
38     
39     protected Map JavaDoc fColorTable= new HashMap JavaDoc(10);
40     
41     public Color getColor(RGB rgb) {
42         Color color= (Color) fColorTable.get(rgb);
43         if (color == null) {
44             color= new Color(Display.getCurrent(), rgb);
45             fColorTable.put(rgb, color);
46         }
47         return color;
48     }
49     
50     public void dispose() {
51         Iterator JavaDoc e= fColorTable.values().iterator();
52         while (e.hasNext())
53             ((Color) e.next()).dispose();
54     }
55 }
56
57
58
Popular Tags