| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2004, 2006 IBM Corporation and others. |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | *******************************************************************************/ |
| 11 | package org.eclipse.ui.internal.themes; |
| 12 | |
| 13 | import java.util.Set; |
| 14 | |
| 15 | import org.eclipse.core.commands.common.EventManager; |
| 16 | import org.eclipse.jface.resource.ColorRegistry; |
| 17 | import org.eclipse.jface.resource.FontRegistry; |
| 18 | import org.eclipse.jface.util.IPropertyChangeListener; |
| 19 | import org.eclipse.jface.util.PropertyChangeEvent; |
| 20 | import org.eclipse.ui.themes.ITheme; |
| 21 | |
| 22 | /** |
| 23 | * @since 3.0 |
| 24 | */ |
| 25 | public class CascadingTheme extends EventManager implements ITheme { |
| 26 | |
| 27 | private CascadingFontRegistry fontRegistry; |
| 28 | |
| 29 | private CascadingColorRegistry colorRegistry; |
| 30 | |
| 31 | private ITheme currentTheme; |
| 32 | |
| 33 | private IPropertyChangeListener listener = new IPropertyChangeListener() { |
| 34 | |
| 35 | public void propertyChange(PropertyChangeEvent event) { |
| 36 | fire(event); |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | /** |
| 41 | * @param colorRegistry |
| 42 | * @param fontRegistry |
| 43 | */ |
| 44 | public CascadingTheme(ITheme currentTheme, |
| 45 | CascadingColorRegistry colorRegistry, |
| 46 | CascadingFontRegistry fontRegistry) { |
| 47 | this.currentTheme = currentTheme; |
| 48 | this.colorRegistry = colorRegistry; |
| 49 | this.fontRegistry = fontRegistry; |
| 50 | |
| 51 | fontRegistry.addListener(listener); |
| 52 | colorRegistry.addListener(listener); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @param event |
| 57 | */ |
| 58 | protected void fire(PropertyChangeEvent event) { |
| 59 | Object[] listeners = getListeners(); |
| 60 | for (int i = 0; i < listeners.length; i++) { |
| 61 | ((IPropertyChangeListener) listeners[i]).propertyChange(event); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /* (non-Javadoc) |
| 66 | * @see org.eclipse.ui.themes.ITheme#addPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) |
| 67 | */ |
| 68 | public void addPropertyChangeListener(IPropertyChangeListener listener) { |
| 69 | addListenerObject(listener); |
| 70 | } |
| 71 | |
| 72 | /* (non-Javadoc) |
| 73 | * @see org.eclipse.ui.themes.ITheme#removePropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) |
| 74 | */ |
| 75 | public void removePropertyChangeListener(IPropertyChangeListener listener) { |
| 76 | removeListenerObject(listener); |
| 77 | } |
| 78 | |
| 79 | /* (non-Javadoc) |
| 80 | * @see org.eclipse.ui.themes.ITheme#getId() |
| 81 | */ |
| 82 | public String getId() { |
| 83 | return currentTheme.getId(); |
| 84 | } |
| 85 | |
| 86 | /* (non-Javadoc) |
| 87 | * @see org.eclipse.ui.themes.ITheme#getLabel() |
| 88 | */ |
| 89 | public String getLabel() { |
| 90 | return currentTheme.getLabel(); |
| 91 | } |
| 92 | |
| 93 | /* (non-Javadoc) |
| 94 | * @see org.eclipse.ui.themes.ITheme#getColorRegistry() |
| 95 | */ |
| 96 | public ColorRegistry getColorRegistry() { |
| 97 | return colorRegistry; |
| 98 | } |
| 99 | |
| 100 | /* (non-Javadoc) |
| 101 | * @see org.eclipse.ui.themes.ITheme#getFontRegistry() |
| 102 | */ |
| 103 | public FontRegistry getFontRegistry() { |
| 104 | return fontRegistry; |
| 105 | } |
| 106 | |
| 107 | /* (non-Javadoc) |
| 108 | * @see org.eclipse.ui.themes.ITheme#dispose() |
| 109 | */ |
| 110 | public void dispose() { |
| 111 | colorRegistry.removeListener(listener); |
| 112 | fontRegistry.removeListener(listener); |
| 113 | } |
| 114 | |
| 115 | /* (non-Javadoc) |
| 116 | * @see org.eclipse.ui.themes.ITheme#getString(java.lang.String) |
| 117 | */ |
| 118 | public String getString(String key) { |
| 119 | return currentTheme.getString(key); |
| 120 | } |
| 121 | |
| 122 | /* (non-Javadoc) |
| 123 | * @see org.eclipse.ui.themes.ITheme#getInt(java.lang.String) |
| 124 | */ |
| 125 | public int getInt(String key) { |
| 126 | return currentTheme.getInt(key); |
| 127 | } |
| 128 | |
| 129 | /* (non-Javadoc) |
| 130 | * @see org.eclipse.ui.themes.ITheme#getBoolean(java.lang.String) |
| 131 | */ |
| 132 | public boolean getBoolean(String key) { |
| 133 | return currentTheme.getBoolean(key); |
| 134 | } |
| 135 | |
| 136 | /* (non-Javadoc) |
| 137 | * @see org.eclipse.ui.themes.ITheme#keySet() |
| 138 | */ |
| 139 | public Set keySet() { |
| 140 | return currentTheme.keySet(); |
| 141 | } |
| 142 | |
| 143 | } |