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.FontRegistry; 17 import org.eclipse.jface.util.IPropertyChangeListener; 18 import org.eclipse.jface.util.PropertyChangeEvent; 19 import org.eclipse.swt.graphics.Font; 20 import org.eclipse.swt.graphics.FontData; 21 import org.eclipse.swt.widgets.Display; 22 import org.eclipse.ui.PlatformUI; 23 24 27 public class CascadingFontRegistry extends FontRegistry { 28 29 private FontRegistry 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 CascadingFontRegistry(FontRegistry parent) { 44 super(Display.getCurrent(), false); 45 this.parent = parent; 46 parent.addListener(listener); 47 } 48 49 52 public Font get(String symbolicName) { 53 if (super.hasValueFor(symbolicName)) { 54 return super.get(symbolicName); 55 } 56 return parent.get(symbolicName); 57 } 58 59 62 public Set getKeySet() { 63 Set keyUnion = new HashSet (super.getKeySet()); 64 keyUnion.addAll(parent.getKeySet()); 65 return keyUnion; 66 } 67 68 public FontData[] getFontData(String symbolicName) { 69 if (super.hasValueFor(symbolicName)) { 70 return super.getFontData(symbolicName); 71 } 72 return parent.getFontData(symbolicName); 73 } 74 75 78 public boolean hasValueFor(String colorKey) { 79 return super.hasValueFor(colorKey) || parent.hasValueFor(colorKey); 80 } 81 82 89 public boolean hasOverrideFor(String fontKey) { 90 return super.hasValueFor(fontKey); 91 } 92 93 96 public void dispose() { 97 parent.removeListener(listener); 98 PlatformUI.getWorkbench().getDisplay().asyncExec(displayRunnable); 99 } 100 } 101 | Popular Tags |