KickJava   Java API By Example, From Geeks To Geeks.

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


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.Arrays JavaDoc;
14 import java.util.Comparator JavaDoc;
15 import java.util.Map JavaDoc;
16 import java.util.Set JavaDoc;
17
18 /**
19  * Registry of color, font, gradient, category and theme descriptors.
20  *
21  * @since 3.0
22  */

23 public interface IThemeRegistry {
24
25     /**
26      * A comparator that will sort IHierarchalThemeElementDefinition elements
27      * by defaultsTo depth.
28      *
29      * @since 3.0
30      */

31     public static class HierarchyComparator implements Comparator JavaDoc {
32
33         private IHierarchalThemeElementDefinition[] definitions;
34
35         /**
36          * Create a new comparator.
37          *
38          * @param definitions the elements to be sorted by depth, in ID order.
39          */

40         public HierarchyComparator(
41                 IHierarchalThemeElementDefinition[] definitions) {
42             this.definitions = definitions;
43         }
44
45         /* (non-Javadoc)
46          * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
47          */

48         public int compare(Object JavaDoc arg0, Object JavaDoc arg1) {
49             String JavaDoc def0 = arg0 == null ? null
50                     : ((IHierarchalThemeElementDefinition) arg0)
51                             .getDefaultsTo();
52             String JavaDoc def1 = arg1 == null ? null
53                     : ((IHierarchalThemeElementDefinition) arg1)
54                             .getDefaultsTo();
55
56             if (def0 == null && def1 == null) {
57                 return 0;
58             }
59
60             if (def0 == null) {
61                 return -1;
62             }
63
64             if (def1 == null) {
65                 return 1;
66             }
67
68             return compare(getDefaultsTo(def0), getDefaultsTo(def1));
69         }
70
71         /**
72          * @param id the identifier to search for.
73          * @return the <code>IHierarchalThemeElementDefinition</code> that
74          * matches the id.
75          */

76         private IHierarchalThemeElementDefinition getDefaultsTo(String JavaDoc id) {
77             int idx = Arrays.binarySearch(definitions, id, ID_COMPARATOR);
78             if (idx >= 0) {
79                 return definitions[idx];
80             }
81             return null;
82         }
83     }
84
85     /**
86      * A comparator that will sort <code>IThemeElementDefinition</code> elements
87      * by id depth. You may use this on both <code>String</code> and
88      * <code>IThemeElementDefinition</code> objects in order to perform
89      * searching.
90      *
91      * @since 3.0
92      */

93     public static final Comparator JavaDoc ID_COMPARATOR = new Comparator JavaDoc() {
94
95         /* (non-Javadoc)
96          * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
97          */

98         public int compare(Object JavaDoc arg0, Object JavaDoc arg1) {
99             String JavaDoc str0 = getCompareString(arg0);
100             String JavaDoc str1 = getCompareString(arg1);
101             return str0.compareTo(str1);
102         }
103
104         /**
105          * @param object
106          * @return <code>String</code> representation of the object.
107          */

108         private String JavaDoc getCompareString(Object JavaDoc object) {
109             if (object instanceof String JavaDoc) {
110                 return (String JavaDoc) object;
111             } else if (object instanceof IThemeElementDefinition) {
112                 return ((IThemeElementDefinition) object).getId();
113             }
114             return ""; //$NON-NLS-1$
115
}
116     };
117
118     /**
119      * Returns the category matching the provided id.
120      *
121      * @param id the id to search for
122      * @return the element matching the provided id, or <code>null</code> if
123      * not found
124      */

125     public ThemeElementCategory findCategory(String JavaDoc id);
126
127     /**
128      * Returns the color matching the provided id.
129      *
130      * @param id the id to search for
131      * @return the element matching the provided id, or <code>null</code> if
132      * not found
133      */

134     public ColorDefinition findColor(String JavaDoc id);
135
136     /**
137      * Returns the font matching the provided id.
138      *
139      * @param id the id to search for
140      * @return the element matching the provided id, or <code>null</code> if
141      * not found
142      */

143     public FontDefinition findFont(String JavaDoc id);
144
145     /**
146      * Returns the theme matching the provided id.
147      *
148      * @param id the id to search for
149      * @return the element matching the provided id, or <code>null</code> if
150      * not found
151      */

152     public IThemeDescriptor findTheme(String JavaDoc id);
153
154     /**
155      * Returns a list of categories defined in the registry.
156      *
157      * @return the categories in this registry
158      */

159     public ThemeElementCategory[] getCategories();
160
161     /**
162      * Returns a list of colors defined in the registry.
163      *
164      * @return the colors in this registry
165      */

166     public ColorDefinition[] getColors();
167
168     /**
169      * Returns a list of colors defined for the given theme. This is the
170      * set of base colours overlayed with any theme specific overrides.
171      *
172      * @param themeId the theme id
173      * @return the colors in this theme
174      */

175     public ColorDefinition[] getColorsFor(String JavaDoc themeId);
176
177     /**
178      * Returns a list of fonts defined for the given theme. This is the
179      * set of base fonts overlayed with any theme specific overrides.
180      *
181      * @param themeId the theme id
182      * @return the fonts in this theme
183      */

184     public FontDefinition[] getFontsFor(String JavaDoc themeId);
185
186     /**
187      * Returns a list of fonts defined in the registry.
188      *
189      * @return the fonts in this registry
190      */

191     public FontDefinition[] getFonts();
192
193     /**
194      * Returns a list of themes defined in the registry.
195      *
196      * @return the themes in this registry
197      */

198     public IThemeDescriptor[] getThemes();
199
200     /**
201      * Return the data map.
202      *
203      * @return the data map
204      */

205     public Map JavaDoc getData();
206
207     /**
208      * Return the set of category presentation bindings.
209      *
210      * @param category the category to test
211      * @return the set of bindings or <code>null</code> if this category has no bindings
212      */

213     public Set JavaDoc getPresentationsBindingsFor(ThemeElementCategory category);
214 }
215
Popular Tags