1 11 package org.eclipse.ui.internal.editors.text; 12 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.Map ; 16 17 import org.eclipse.swt.graphics.Color; 18 import org.eclipse.swt.graphics.RGB; 19 import org.eclipse.swt.widgets.Display; 20 21 import org.eclipse.jface.text.source.ISharedTextColors; 22 23 27 class SharedTextColors implements ISharedTextColors { 28 29 30 private Map fDisplayTable; 31 32 33 public SharedTextColors() { 34 super(); 35 } 36 37 40 public Color getColor(RGB rgb) { 41 if (rgb == null) 42 return null; 43 44 if (fDisplayTable == null) 45 fDisplayTable= new HashMap (2); 46 47 final Display display= Display.getCurrent(); 48 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 () { 54 public void run() { 55 dispose(display); 56 } 57 }); 58 } 59 60 Color color= (Color) colorTable.get(rgb); 61 if (color == null) { 62 color= new Color(display, rgb); 63 colorTable.put(rgb, color); 64 } 65 66 return color; 67 } 68 69 72 public void dispose() { 73 if (fDisplayTable == null) 74 return; 75 76 Iterator iter= fDisplayTable.values().iterator(); 77 while (iter.hasNext()) 78 dispose((Map )iter.next()); 79 fDisplayTable= null; 80 } 81 82 88 private void dispose(Display display) { 89 if (fDisplayTable != null) 90 dispose((Map )fDisplayTable.remove(display)); 91 } 92 93 99 private void dispose(Map colorTable) { 100 if (colorTable == null) 101 return; 102 103 Iterator iter= colorTable.values().iterator(); 104 while (iter.hasNext()) 105 ((Color) iter.next()).dispose(); 106 107 colorTable.clear(); 108 } 109 110 } 111 | Popular Tags |