1 package net.sourceforge.phpdt.internal.ui.text;
4 * (c) Copyright IBM Corp. 2000, 2001.
8 import java.util.HashMap;
9 import java.util.Iterator;
12 import org.eclipse.swt.graphics.Color;
13 import org.eclipse.swt.graphics.RGB;
14 import org.eclipse.swt.widgets.Display;
16 import net.sourceforge.phpdt.ui.text.IColorManager;
17 import net.sourceforge.phpdt.ui.text.IColorManagerExtension;
22 public class JavaColorManager implements IColorManager, IColorManagerExtension {
24 protected Map fKeyTable= new HashMap(10);
25 protected Map fDisplayTable= new HashMap(2);
28 public JavaColorManager() {
31 private void dispose(Display display) {
32 Map colorTable= (Map) fDisplayTable.get(display);
33 if (colorTable != null) {
34 Iterator e= colorTable.values().iterator();
36 ((Color) e.next()).dispose();
41 * @see IColorManager#getColor(RGB)
43 public Color getColor(RGB rgb) {
48 final Display display= Display.getCurrent();
49 Map colorTable= (Map) fDisplayTable.get(display);
50 if (colorTable == null) {
51 colorTable= new HashMap(10);
52 fDisplayTable.put(display, colorTable);
53 display.disposeExec(new Runnable() {
60 Color color= (Color) colorTable.get(rgb);
62 color= new Color(Display.getCurrent(), rgb);
63 colorTable.put(rgb, color);
70 * @see IColorManager#dispose
72 public void dispose() {
77 * @see IColorManager#getColor(String)
79 public Color getColor(String key) {
84 RGB rgb= (RGB) fKeyTable.get(key);
89 * @see IColorManagerExtension#bindColor(String, RGB)
91 public void bindColor(String key, RGB rgb) {
92 Object value= fKeyTable.get(key);
94 throw new UnsupportedOperationException();
96 fKeyTable.put(key, rgb);
100 * @see IColorManagerExtension#unbindColor(String)
102 public void unbindColor(String key) {
103 fKeyTable.remove(key);