KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 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.Collection JavaDoc;
15 import java.util.Collections JavaDoc;
16 import java.util.HashMap JavaDoc;
17 import java.util.HashSet JavaDoc;
18 import java.util.Map JavaDoc;
19
20 import org.eclipse.core.runtime.IConfigurationElement;
21
22 /**
23  * Concrete implementation of a theme descriptor.
24  *
25  * @since 3.0
26  */

27 public class ThemeDescriptor implements IThemeDescriptor {
28
29     /* Theme */
30     public static final String JavaDoc ATT_ID = "id";//$NON-NLS-1$
31

32     private static final String JavaDoc ATT_NAME = "name";//$NON-NLS-1$
33

34     private Collection JavaDoc colors = new HashSet JavaDoc();
35
36     private String JavaDoc description;
37
38     private Collection JavaDoc fonts = new HashSet JavaDoc();
39
40     private String JavaDoc id;
41
42     private String JavaDoc name;
43
44     private Map JavaDoc dataMap = new HashMap JavaDoc();
45
46     /**
47      * Create a new ThemeDescriptor
48      * @param id
49      */

50     public ThemeDescriptor(String JavaDoc id) {
51         this.id = id;
52     }
53
54     /**
55      * Add a color override to this descriptor.
56      *
57      * @param definition the definition to add
58      */

59     void add(ColorDefinition definition) {
60         if (colors.contains(definition)) {
61             return;
62         }
63         colors.add(definition);
64     }
65
66     /**
67      * Add a font override to this descriptor.
68      *
69      * @param definition the definition to add
70      */

71     void add(FontDefinition definition) {
72         if (fonts.contains(definition)) {
73             return;
74         }
75         fonts.add(definition);
76     }
77
78     /**
79      * Add a data object to this descriptor.
80      *
81      * @param key the key
82      * @param data the data
83      */

84     void setData(String JavaDoc key, Object JavaDoc data) {
85         if (dataMap.containsKey(key)) {
86             return;
87         }
88             
89         dataMap.put(key, data);
90     }
91
92     /* (non-Javadoc)
93      * @see org.eclipse.ui.internal.themes.IThemeDescriptor#getColorOverrides()
94      */

95     public ColorDefinition[] getColors() {
96         ColorDefinition[] defs = (ColorDefinition[]) colors
97                 .toArray(new ColorDefinition[colors.size()]);
98         Arrays.sort(defs, IThemeRegistry.ID_COMPARATOR);
99         return defs;
100     }
101
102     /* (non-Javadoc)
103      * @see org.eclipse.ui.internal.themes.IThemeElementDefinition#getDescription()
104      */

105     public String JavaDoc getDescription() {
106         return description;
107     }
108
109     /* (non-Javadoc)
110      * @see org.eclipse.ui.internal.themes.IThemeDescriptor#getFontOverrides()
111      */

112     public FontDefinition[] getFonts() {
113         FontDefinition[] defs = (FontDefinition[]) fonts
114                 .toArray(new FontDefinition[fonts.size()]);
115         Arrays.sort(defs, IThemeRegistry.ID_COMPARATOR);
116         return defs;
117     }
118
119     /* (non-Javadoc)
120      * @see org.eclipse.ui.internal.registry.IThemeDescriptor#getID()
121      */

122     public String JavaDoc getId() {
123         return id;
124     }
125
126     /* (non-Javadoc)
127      * @see org.eclipse.ui.internal.registry.IThemeDescriptor#getName()
128      */

129     public String JavaDoc getName() {
130         if (name == null)
131             return getId();
132         return name;
133     }
134
135     /*
136      * load the name if it is not already set.
137      */

138     void extractName(IConfigurationElement configElement) {
139         if (name == null) {
140             name = configElement.getAttribute(ATT_NAME);
141         }
142     }
143
144     /**
145      * Set the description.
146      *
147      * @param description the description
148      */

149     void setDescription(String JavaDoc description) {
150         if (this.description == null) {
151             this.description = description;
152         }
153     }
154
155     /* (non-Javadoc)
156      * @see org.eclipse.ui.internal.themes.IThemeDescriptor#getData()
157      */

158     public Map JavaDoc getData() {
159         return Collections.unmodifiableMap(dataMap);
160     }
161 }
162
Popular Tags