001: /*******************************************************************************
002: * Copyright (c) 2004, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.themes;
011:
012: import java.util.HashSet;
013: import java.util.Set;
014:
015: import org.eclipse.jface.resource.FontRegistry;
016: import org.eclipse.jface.util.IPropertyChangeListener;
017: import org.eclipse.jface.util.PropertyChangeEvent;
018: import org.eclipse.swt.graphics.Font;
019: import org.eclipse.swt.graphics.FontData;
020: import org.eclipse.swt.widgets.Display;
021: import org.eclipse.ui.PlatformUI;
022:
023: /**
024: * @since 3.0
025: */
026: public class CascadingFontRegistry extends FontRegistry {
027:
028: private FontRegistry parent;
029:
030: private IPropertyChangeListener listener = new IPropertyChangeListener() {
031: public void propertyChange(PropertyChangeEvent event) {
032: fireMappingChanged(event.getProperty(),
033: event.getOldValue(), event.getNewValue());
034: }
035: };
036:
037: /**
038: * Create a new instance of this class.
039: *
040: * @param parent the parent registry
041: */
042: public CascadingFontRegistry(FontRegistry parent) {
043: super (Display.getCurrent(), false);
044: this .parent = parent;
045: parent.addListener(listener);
046: }
047:
048: /* (non-Javadoc)
049: * @see org.eclipse.jface.resource.FontRegistry#get(java.lang.String)
050: */
051: public Font get(String symbolicName) {
052: if (super .hasValueFor(symbolicName)) {
053: return super .get(symbolicName);
054: }
055: return parent.get(symbolicName);
056: }
057:
058: /* (non-Javadoc)
059: * @see org.eclipse.jface.resource.FontRegistry#getKeySet()
060: */
061: public Set getKeySet() {
062: Set keyUnion = new HashSet(super .getKeySet());
063: keyUnion.addAll(parent.getKeySet());
064: return keyUnion;
065: }
066:
067: public FontData[] getFontData(String symbolicName) {
068: if (super .hasValueFor(symbolicName)) {
069: return super .getFontData(symbolicName);
070: }
071: return parent.getFontData(symbolicName);
072: }
073:
074: /* (non-Javadoc)
075: * @see org.eclipse.jface.resource.ColorRegistry#hasValueFor(java.lang.String)
076: */
077: public boolean hasValueFor(String colorKey) {
078: return super .hasValueFor(colorKey)
079: || parent.hasValueFor(colorKey);
080: }
081:
082: /**
083: * Returns whether this cascading registry has an override for the provided
084: * color key.
085: *
086: * @param fontKey the provided color key
087: * @return hether this cascading registry has an override
088: */
089: public boolean hasOverrideFor(String fontKey) {
090: return super .hasValueFor(fontKey);
091: }
092:
093: /**
094: * Disposes of all allocated resources.
095: */
096: public void dispose() {
097: parent.removeListener(listener);
098: PlatformUI.getWorkbench().getDisplay().asyncExec(
099: displayRunnable);
100: }
101: }
|