KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > model > ColorManager


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

11 package org.eclipse.ant.internal.ui.model;
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.jface.text.source.ISharedTextColors;
19 import org.eclipse.swt.graphics.Color;
20 import org.eclipse.swt.graphics.RGB;
21 import org.eclipse.swt.widgets.Display;
22
23 /**
24  * Generic color manager.
25  */

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