KickJava   Java API By Example, From Geeks To Geeks.

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


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.ColorRegistry;
17 import org.eclipse.jface.util.IPropertyChangeListener;
18 import org.eclipse.jface.util.PropertyChangeEvent;
19 import org.eclipse.swt.graphics.Color;
20 import org.eclipse.swt.graphics.RGB;
21 import org.eclipse.swt.widgets.Display;
22 import org.eclipse.ui.PlatformUI;
23
24 /**
25  * @since 3.0
26  */

27 public class CascadingColorRegistry extends ColorRegistry {
28
29     private ColorRegistry 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 CascadingColorRegistry(ColorRegistry 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.ColorRegistry#get(java.lang.String)
51      */

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

63     public Set JavaDoc getKeySet() {
64         Set JavaDoc keyUnion = new HashSet JavaDoc(super.getKeySet());
65         keyUnion.addAll(parent.getKeySet());
66         return keyUnion;
67     }
68
69     /* (non-Javadoc)
70      * @see org.eclipse.jface.resource.ColorRegistry#getRGB(java.lang.String)
71      */

72     public RGB getRGB(String JavaDoc symbolicName) {
73         if (super.hasValueFor(symbolicName)) {
74             return super.getRGB(symbolicName);
75         }
76         
77         return parent.getRGB(symbolicName);
78     }
79
80     /* (non-Javadoc)
81      * @see org.eclipse.jface.resource.ColorRegistry#hasValueFor(java.lang.String)
82      */

83     public boolean hasValueFor(String JavaDoc colorKey) {
84         return super.hasValueFor(colorKey) || parent.hasValueFor(colorKey);
85     }
86
87     /**
88      * Returns whether this cascading registry has an override for the provided
89      * color key.
90      *
91      * @param colorKey the provided color key
92      * @return hether this cascading registry has an override
93      */

94     public boolean hasOverrideFor(String JavaDoc colorKey) {
95         return super.hasValueFor(colorKey);
96     }
97
98     /**
99      * Disposes of all allocated resources.
100      */

101     public void dispose() {
102         parent.removeListener(listener);
103         PlatformUI.getWorkbench().getDisplay().asyncExec(displayRunnable);
104     }
105 }
106
Popular Tags