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.Arrays;
013: import java.util.Comparator;
014: import java.util.Map;
015: import java.util.Set;
016:
017: /**
018: * Registry of color, font, gradient, category and theme descriptors.
019: *
020: * @since 3.0
021: */
022: public interface IThemeRegistry {
023:
024: /**
025: * A comparator that will sort IHierarchalThemeElementDefinition elements
026: * by defaultsTo depth.
027: *
028: * @since 3.0
029: */
030: public static class HierarchyComparator implements Comparator {
031:
032: private IHierarchalThemeElementDefinition[] definitions;
033:
034: /**
035: * Create a new comparator.
036: *
037: * @param definitions the elements to be sorted by depth, in ID order.
038: */
039: public HierarchyComparator(
040: IHierarchalThemeElementDefinition[] definitions) {
041: this .definitions = definitions;
042: }
043:
044: /* (non-Javadoc)
045: * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
046: */
047: public int compare(Object arg0, Object arg1) {
048: String def0 = arg0 == null ? null
049: : ((IHierarchalThemeElementDefinition) arg0)
050: .getDefaultsTo();
051: String def1 = arg1 == null ? null
052: : ((IHierarchalThemeElementDefinition) arg1)
053: .getDefaultsTo();
054:
055: if (def0 == null && def1 == null) {
056: return 0;
057: }
058:
059: if (def0 == null) {
060: return -1;
061: }
062:
063: if (def1 == null) {
064: return 1;
065: }
066:
067: return compare(getDefaultsTo(def0), getDefaultsTo(def1));
068: }
069:
070: /**
071: * @param id the identifier to search for.
072: * @return the <code>IHierarchalThemeElementDefinition</code> that
073: * matches the id.
074: */
075: private IHierarchalThemeElementDefinition getDefaultsTo(
076: String id) {
077: int idx = Arrays.binarySearch(definitions, id,
078: ID_COMPARATOR);
079: if (idx >= 0) {
080: return definitions[idx];
081: }
082: return null;
083: }
084: }
085:
086: /**
087: * A comparator that will sort <code>IThemeElementDefinition</code> elements
088: * by id depth. You may use this on both <code>String</code> and
089: * <code>IThemeElementDefinition</code> objects in order to perform
090: * searching.
091: *
092: * @since 3.0
093: */
094: public static final Comparator ID_COMPARATOR = new Comparator() {
095:
096: /* (non-Javadoc)
097: * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
098: */
099: public int compare(Object arg0, Object arg1) {
100: String str0 = getCompareString(arg0);
101: String str1 = getCompareString(arg1);
102: return str0.compareTo(str1);
103: }
104:
105: /**
106: * @param object
107: * @return <code>String</code> representation of the object.
108: */
109: private String getCompareString(Object object) {
110: if (object instanceof String) {
111: return (String) object;
112: } else if (object instanceof IThemeElementDefinition) {
113: return ((IThemeElementDefinition) object).getId();
114: }
115: return ""; //$NON-NLS-1$
116: }
117: };
118:
119: /**
120: * Returns the category matching the provided id.
121: *
122: * @param id the id to search for
123: * @return the element matching the provided id, or <code>null</code> if
124: * not found
125: */
126: public ThemeElementCategory findCategory(String id);
127:
128: /**
129: * Returns the color matching the provided id.
130: *
131: * @param id the id to search for
132: * @return the element matching the provided id, or <code>null</code> if
133: * not found
134: */
135: public ColorDefinition findColor(String id);
136:
137: /**
138: * Returns the font matching the provided id.
139: *
140: * @param id the id to search for
141: * @return the element matching the provided id, or <code>null</code> if
142: * not found
143: */
144: public FontDefinition findFont(String id);
145:
146: /**
147: * Returns the theme matching the provided id.
148: *
149: * @param id the id to search for
150: * @return the element matching the provided id, or <code>null</code> if
151: * not found
152: */
153: public IThemeDescriptor findTheme(String id);
154:
155: /**
156: * Returns a list of categories defined in the registry.
157: *
158: * @return the categories in this registry
159: */
160: public ThemeElementCategory[] getCategories();
161:
162: /**
163: * Returns a list of colors defined in the registry.
164: *
165: * @return the colors in this registry
166: */
167: public ColorDefinition[] getColors();
168:
169: /**
170: * Returns a list of colors defined for the given theme. This is the
171: * set of base colours overlayed with any theme specific overrides.
172: *
173: * @param themeId the theme id
174: * @return the colors in this theme
175: */
176: public ColorDefinition[] getColorsFor(String themeId);
177:
178: /**
179: * Returns a list of fonts defined for the given theme. This is the
180: * set of base fonts overlayed with any theme specific overrides.
181: *
182: * @param themeId the theme id
183: * @return the fonts in this theme
184: */
185: public FontDefinition[] getFontsFor(String themeId);
186:
187: /**
188: * Returns a list of fonts defined in the registry.
189: *
190: * @return the fonts in this registry
191: */
192: public FontDefinition[] getFonts();
193:
194: /**
195: * Returns a list of themes defined in the registry.
196: *
197: * @return the themes in this registry
198: */
199: public IThemeDescriptor[] getThemes();
200:
201: /**
202: * Return the data map.
203: *
204: * @return the data map
205: */
206: public Map getData();
207:
208: /**
209: * Return the set of category presentation bindings.
210: *
211: * @param category the category to test
212: * @return the set of bindings or <code>null</code> if this category has no bindings
213: */
214: public Set getPresentationsBindingsFor(ThemeElementCategory category);
215: }
|