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.Set;
013:
014: import org.eclipse.core.commands.common.EventManager;
015: import org.eclipse.jface.resource.ColorRegistry;
016: import org.eclipse.jface.resource.FontRegistry;
017: import org.eclipse.jface.util.IPropertyChangeListener;
018: import org.eclipse.jface.util.PropertyChangeEvent;
019: import org.eclipse.ui.themes.ITheme;
020:
021: /**
022: * @since 3.0
023: */
024: public class CascadingTheme extends EventManager implements ITheme {
025:
026: private CascadingFontRegistry fontRegistry;
027:
028: private CascadingColorRegistry colorRegistry;
029:
030: private ITheme currentTheme;
031:
032: private IPropertyChangeListener listener = new IPropertyChangeListener() {
033:
034: public void propertyChange(PropertyChangeEvent event) {
035: fire(event);
036: }
037: };
038:
039: /**
040: * @param colorRegistry
041: * @param fontRegistry
042: */
043: public CascadingTheme(ITheme currentTheme,
044: CascadingColorRegistry colorRegistry,
045: CascadingFontRegistry fontRegistry) {
046: this .currentTheme = currentTheme;
047: this .colorRegistry = colorRegistry;
048: this .fontRegistry = fontRegistry;
049:
050: fontRegistry.addListener(listener);
051: colorRegistry.addListener(listener);
052: }
053:
054: /**
055: * @param event
056: */
057: protected void fire(PropertyChangeEvent event) {
058: Object[] listeners = getListeners();
059: for (int i = 0; i < listeners.length; i++) {
060: ((IPropertyChangeListener) listeners[i])
061: .propertyChange(event);
062: }
063: }
064:
065: /* (non-Javadoc)
066: * @see org.eclipse.ui.themes.ITheme#addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
067: */
068: public void addPropertyChangeListener(
069: IPropertyChangeListener listener) {
070: addListenerObject(listener);
071: }
072:
073: /* (non-Javadoc)
074: * @see org.eclipse.ui.themes.ITheme#removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener)
075: */
076: public void removePropertyChangeListener(
077: IPropertyChangeListener listener) {
078: removeListenerObject(listener);
079: }
080:
081: /* (non-Javadoc)
082: * @see org.eclipse.ui.themes.ITheme#getId()
083: */
084: public String getId() {
085: return currentTheme.getId();
086: }
087:
088: /* (non-Javadoc)
089: * @see org.eclipse.ui.themes.ITheme#getLabel()
090: */
091: public String getLabel() {
092: return currentTheme.getLabel();
093: }
094:
095: /* (non-Javadoc)
096: * @see org.eclipse.ui.themes.ITheme#getColorRegistry()
097: */
098: public ColorRegistry getColorRegistry() {
099: return colorRegistry;
100: }
101:
102: /* (non-Javadoc)
103: * @see org.eclipse.ui.themes.ITheme#getFontRegistry()
104: */
105: public FontRegistry getFontRegistry() {
106: return fontRegistry;
107: }
108:
109: /* (non-Javadoc)
110: * @see org.eclipse.ui.themes.ITheme#dispose()
111: */
112: public void dispose() {
113: colorRegistry.removeListener(listener);
114: fontRegistry.removeListener(listener);
115: }
116:
117: /* (non-Javadoc)
118: * @see org.eclipse.ui.themes.ITheme#getString(java.lang.String)
119: */
120: public String getString(String key) {
121: return currentTheme.getString(key);
122: }
123:
124: /* (non-Javadoc)
125: * @see org.eclipse.ui.themes.ITheme#getInt(java.lang.String)
126: */
127: public int getInt(String key) {
128: return currentTheme.getInt(key);
129: }
130:
131: /* (non-Javadoc)
132: * @see org.eclipse.ui.themes.ITheme#getBoolean(java.lang.String)
133: */
134: public boolean getBoolean(String key) {
135: return currentTheme.getBoolean(key);
136: }
137:
138: /* (non-Javadoc)
139: * @see org.eclipse.ui.themes.ITheme#keySet()
140: */
141: public Set keySet() {
142: return currentTheme.keySet();
143: }
144:
145: }
|