KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > themes > CascadingFontRegistry


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.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
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 /**
25  * @since 3.0
26  */

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     /**
39      * Create a new instance of this class.
40      *
41      * @param parent the parent registry
42      */

43     public CascadingFontRegistry(FontRegistry parent) {
44         super(Display.getCurrent(), false);
45         this.parent = parent;
46         parent.addListener(listener);
47     }
48
49     /* (non-Javadoc)
50      * @see org.eclipse.jface.resource.FontRegistry#get(java.lang.String)
51      */

52     public Font get(String JavaDoc symbolicName) {
53         if (super.hasValueFor(symbolicName)) {
54             return super.get(symbolicName);
55         }
56         return parent.get(symbolicName);
57     }
58
59     /* (non-Javadoc)
60      * @see org.eclipse.jface.resource.FontRegistry#getKeySet()
61      */

62     public Set JavaDoc getKeySet() {
63         Set JavaDoc keyUnion = new HashSet JavaDoc(super.getKeySet());
64         keyUnion.addAll(parent.getKeySet());
65         return keyUnion;
66     }
67
68     public FontData[] getFontData(String JavaDoc symbolicName) {
69         if (super.hasValueFor(symbolicName)) {
70             return super.getFontData(symbolicName);
71         }
72         return parent.getFontData(symbolicName);
73     }
74
75     /* (non-Javadoc)
76      * @see org.eclipse.jface.resource.ColorRegistry#hasValueFor(java.lang.String)
77      */

78     public boolean hasValueFor(String JavaDoc colorKey) {
79         return super.hasValueFor(colorKey) || parent.hasValueFor(colorKey);
80     }
81
82     /**
83      * Returns whether this cascading registry has an override for the provided
84      * color key.
85      *
86      * @param fontKey the provided color key
87      * @return hether this cascading registry has an override
88      */

89     public boolean hasOverrideFor(String JavaDoc fontKey) {
90         return super.hasValueFor(fontKey);
91     }
92
93     /**
94      * Disposes of all allocated resources.
95      */

96     public void dispose() {
97         parent.removeListener(listener);
98         PlatformUI.getWorkbench().getDisplay().asyncExec(displayRunnable);
99     }
100 }
101
Popular Tags