001: /*******************************************************************************
002: * Copyright (c) 2004, 2007 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.Collection;
014: import java.util.Collections;
015: import java.util.HashMap;
016: import java.util.HashSet;
017: import java.util.Map;
018:
019: import org.eclipse.core.runtime.IConfigurationElement;
020:
021: /**
022: * Concrete implementation of a theme descriptor.
023: *
024: * @since 3.0
025: */
026: public class ThemeDescriptor implements IThemeDescriptor {
027:
028: /* Theme */
029: public static final String ATT_ID = "id";//$NON-NLS-1$
030:
031: private static final String ATT_NAME = "name";//$NON-NLS-1$
032:
033: private Collection colors = new HashSet();
034:
035: private String description;
036:
037: private Collection fonts = new HashSet();
038:
039: private String id;
040:
041: private String name;
042:
043: private Map dataMap = new HashMap();
044:
045: /**
046: * Create a new ThemeDescriptor
047: * @param id
048: */
049: public ThemeDescriptor(String id) {
050: this .id = id;
051: }
052:
053: /**
054: * Add a color override to this descriptor.
055: *
056: * @param definition the definition to add
057: */
058: void add(ColorDefinition definition) {
059: if (colors.contains(definition)) {
060: return;
061: }
062: colors.add(definition);
063: }
064:
065: /**
066: * Add a font override to this descriptor.
067: *
068: * @param definition the definition to add
069: */
070: void add(FontDefinition definition) {
071: if (fonts.contains(definition)) {
072: return;
073: }
074: fonts.add(definition);
075: }
076:
077: /**
078: * Add a data object to this descriptor.
079: *
080: * @param key the key
081: * @param data the data
082: */
083: void setData(String key, Object data) {
084: if (dataMap.containsKey(key)) {
085: return;
086: }
087:
088: dataMap.put(key, data);
089: }
090:
091: /* (non-Javadoc)
092: * @see org.eclipse.ui.internal.themes.IThemeDescriptor#getColorOverrides()
093: */
094: public ColorDefinition[] getColors() {
095: ColorDefinition[] defs = (ColorDefinition[]) colors
096: .toArray(new ColorDefinition[colors.size()]);
097: Arrays.sort(defs, IThemeRegistry.ID_COMPARATOR);
098: return defs;
099: }
100:
101: /* (non-Javadoc)
102: * @see org.eclipse.ui.internal.themes.IThemeElementDefinition#getDescription()
103: */
104: public String getDescription() {
105: return description;
106: }
107:
108: /* (non-Javadoc)
109: * @see org.eclipse.ui.internal.themes.IThemeDescriptor#getFontOverrides()
110: */
111: public FontDefinition[] getFonts() {
112: FontDefinition[] defs = (FontDefinition[]) fonts
113: .toArray(new FontDefinition[fonts.size()]);
114: Arrays.sort(defs, IThemeRegistry.ID_COMPARATOR);
115: return defs;
116: }
117:
118: /* (non-Javadoc)
119: * @see org.eclipse.ui.internal.registry.IThemeDescriptor#getID()
120: */
121: public String getId() {
122: return id;
123: }
124:
125: /* (non-Javadoc)
126: * @see org.eclipse.ui.internal.registry.IThemeDescriptor#getName()
127: */
128: public String getName() {
129: if (name == null)
130: return getId();
131: return name;
132: }
133:
134: /*
135: * load the name if it is not already set.
136: */
137: void extractName(IConfigurationElement configElement) {
138: if (name == null) {
139: name = configElement.getAttribute(ATT_NAME);
140: }
141: }
142:
143: /**
144: * Set the description.
145: *
146: * @param description the description
147: */
148: void setDescription(String description) {
149: if (this .description == null) {
150: this .description = description;
151: }
152: }
153:
154: /* (non-Javadoc)
155: * @see org.eclipse.ui.internal.themes.IThemeDescriptor#getData()
156: */
157: public Map getData() {
158: return Collections.unmodifiableMap(dataMap);
159: }
160: }
|