1 11 package org.eclipse.ui.internal.themes; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.jface.resource.ColorRegistry; 17 import org.eclipse.jface.util.IPropertyChangeListener; 18 import org.eclipse.jface.util.PropertyChangeEvent; 19 import org.eclipse.swt.graphics.Color; 20 import org.eclipse.swt.graphics.RGB; 21 import org.eclipse.swt.widgets.Display; 22 import org.eclipse.ui.PlatformUI; 23 24 27 public class CascadingColorRegistry extends ColorRegistry { 28 29 private ColorRegistry parent; 30 31 private IPropertyChangeListener listener = new IPropertyChangeListener() { 32 public void propertyChange(PropertyChangeEvent event) { 33 fireMappingChanged(event.getProperty(), event.getOldValue(), event 34 .getNewValue()); 35 } 36 }; 37 38 43 public CascadingColorRegistry(ColorRegistry parent) { 44 super(Display.getCurrent(), false); 45 this.parent = parent; 46 parent.addListener(listener); 47 } 48 49 52 public Color get(String symbolicName) { 53 if (super.hasValueFor(symbolicName)) { 54 return super.get(symbolicName); 55 } 56 57 return parent.get(symbolicName); 58 } 59 60 63 public Set getKeySet() { 64 Set keyUnion = new HashSet (super.getKeySet()); 65 keyUnion.addAll(parent.getKeySet()); 66 return keyUnion; 67 } 68 69 72 public RGB getRGB(String symbolicName) { 73 if (super.hasValueFor(symbolicName)) { 74 return super.getRGB(symbolicName); 75 } 76 77 return parent.getRGB(symbolicName); 78 } 79 80 83 public boolean hasValueFor(String colorKey) { 84 return super.hasValueFor(colorKey) || parent.hasValueFor(colorKey); 85 } 86 87 94 public boolean hasOverrideFor(String colorKey) { 95 return super.hasValueFor(colorKey); 96 } 97 98 101 public void dispose() { 102 parent.removeListener(listener); 103 PlatformUI.getWorkbench().getDisplay().asyncExec(displayRunnable); 104 } 105 } 106 | Popular Tags |