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.ColorRegistry;
016: import org.eclipse.jface.util.IPropertyChangeListener;
017: import org.eclipse.jface.util.PropertyChangeEvent;
018: import org.eclipse.swt.graphics.Color;
019: import org.eclipse.swt.graphics.RGB;
020: import org.eclipse.swt.widgets.Display;
021: import org.eclipse.ui.PlatformUI;
022:
023: /**
024: * @since 3.0
025: */
026: public class CascadingColorRegistry extends ColorRegistry {
027:
028: private ColorRegistry 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 CascadingColorRegistry(ColorRegistry 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.ColorRegistry#get(java.lang.String)
050: */
051: public Color get(String symbolicName) {
052: if (super .hasValueFor(symbolicName)) {
053: return super .get(symbolicName);
054: }
055:
056: return parent.get(symbolicName);
057: }
058:
059: /* (non-Javadoc)
060: * @see org.eclipse.jface.resource.ColorRegistry#getKeySet()
061: */
062: public Set getKeySet() {
063: Set keyUnion = new HashSet(super .getKeySet());
064: keyUnion.addAll(parent.getKeySet());
065: return keyUnion;
066: }
067:
068: /* (non-Javadoc)
069: * @see org.eclipse.jface.resource.ColorRegistry#getRGB(java.lang.String)
070: */
071: public RGB getRGB(String symbolicName) {
072: if (super .hasValueFor(symbolicName)) {
073: return super .getRGB(symbolicName);
074: }
075:
076: return parent.getRGB(symbolicName);
077: }
078:
079: /* (non-Javadoc)
080: * @see org.eclipse.jface.resource.ColorRegistry#hasValueFor(java.lang.String)
081: */
082: public boolean hasValueFor(String colorKey) {
083: return super .hasValueFor(colorKey)
084: || parent.hasValueFor(colorKey);
085: }
086:
087: /**
088: * Returns whether this cascading registry has an override for the provided
089: * color key.
090: *
091: * @param colorKey the provided color key
092: * @return hether this cascading registry has an override
093: */
094: public boolean hasOverrideFor(String colorKey) {
095: return super .hasValueFor(colorKey);
096: }
097:
098: /**
099: * Disposes of all allocated resources.
100: */
101: public void dispose() {
102: parent.removeListener(listener);
103: PlatformUI.getWorkbench().getDisplay().asyncExec(
104: displayRunnable);
105: }
106: }
|