1 11 package org.eclipse.ui.internal.themes; 12 13 import java.util.Arrays ; 14 import java.util.Collection ; 15 import java.util.Collections ; 16 import java.util.HashMap ; 17 import java.util.HashSet ; 18 import java.util.Map ; 19 20 import org.eclipse.core.runtime.IConfigurationElement; 21 22 27 public class ThemeDescriptor implements IThemeDescriptor { 28 29 30 public static final String ATT_ID = "id"; 32 private static final String ATT_NAME = "name"; 34 private Collection colors = new HashSet (); 35 36 private String description; 37 38 private Collection fonts = new HashSet (); 39 40 private String id; 41 42 private String name; 43 44 private Map dataMap = new HashMap (); 45 46 50 public ThemeDescriptor(String id) { 51 this.id = id; 52 } 53 54 59 void add(ColorDefinition definition) { 60 if (colors.contains(definition)) { 61 return; 62 } 63 colors.add(definition); 64 } 65 66 71 void add(FontDefinition definition) { 72 if (fonts.contains(definition)) { 73 return; 74 } 75 fonts.add(definition); 76 } 77 78 84 void setData(String key, Object data) { 85 if (dataMap.containsKey(key)) { 86 return; 87 } 88 89 dataMap.put(key, data); 90 } 91 92 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 105 public String getDescription() { 106 return description; 107 } 108 109 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 122 public String getId() { 123 return id; 124 } 125 126 129 public String getName() { 130 if (name == null) 131 return getId(); 132 return name; 133 } 134 135 138 void extractName(IConfigurationElement configElement) { 139 if (name == null) { 140 name = configElement.getAttribute(ATT_NAME); 141 } 142 } 143 144 149 void setDescription(String description) { 150 if (this.description == null) { 151 this.description = description; 152 } 153 } 154 155 158 public Map getData() { 159 return Collections.unmodifiableMap(dataMap); 160 } 161 } 162 | Popular Tags |