comparison dwtx/jface/resource/ColorRegistry.d @ 70:46a6e0e6ccd4

Merge with d-fied sources of 3.4M7
author Frank Benoit <benoit@tionex.de>
date Thu, 22 May 2008 01:36:46 +0200
parents ea8ff534f622
children 4878bef4a38e
comparison
equal deleted inserted replaced
69:07b9d96fd764 70:46a6e0e6ccd4
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2003, 2006 IBM Corporation and others. 2 * Copyright (c) 2003, 2007 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
52 * @since 3.0 52 * @since 3.0
53 */ 53 */
54 public class ColorRegistry : ResourceRegistry { 54 public class ColorRegistry : ResourceRegistry {
55 55
56 /** 56 /**
57 * Default color value. This is cyan (very unappetizing).
58 * @since 3.4
59 */
60 private static final ColorDescriptor DEFAULT_COLOR = new RGBColorDescriptor(new RGB(0, 255, 255));
61
62 /**
57 * This registries <code>Display</code>. All colors will be allocated using 63 * This registries <code>Display</code>. All colors will be allocated using
58 * it. 64 * it.
59 */ 65 */
60 protected Display display; 66 protected Display display;
61 67
197 203
198 /** 204 /**
199 * Returns the color data associated with the given symbolic color name. 205 * Returns the color data associated with the given symbolic color name.
200 * 206 *
201 * @param symbolicName symbolic color name. 207 * @param symbolicName symbolic color name.
202 * @return the <code>RGB</code> data. 208 * @return the <code>RGB</code> data, or <code>null</code> if the symbolic name
209 * is not valid.
203 */ 210 */
204 public RGB getRGB(String symbolicName) { 211 public RGB getRGB(String symbolicName) {
205 Assert.isNotNull(symbolicName); 212 Assert.isNotNull(symbolicName);
206 return stringToRGB.get(symbolicName); 213 return stringToRGB.get(symbolicName);
207 } 214 }
208 215
209 /** 216 /**
210 * Returns the color descriptor associated with the given symbolic color name. 217 * Returns the color descriptor associated with the given symbolic color
218 * name. As of 3.4 if this color is not defined then an unspecified color
219 * is returned. Users that wish to ensure a reasonable default value should
220 * use {@link #getColorDescriptor(String, ColorDescriptor)} instead.
221 *
211 * @since 3.1 222 * @since 3.1
212 * 223 *
213 * @param symbolicName 224 * @param symbolicName
214 * @return the color descriptor associated with the given symbolic color name. 225 * @return the color descriptor associated with the given symbolic color
226 * name or an unspecified sentinel.
215 */ 227 */
216 public ColorDescriptor getColorDescriptor(String symbolicName) { 228 public ColorDescriptor getColorDescriptor(String symbolicName) {
217 return ColorDescriptor.createFrom(getRGB(symbolicName)); 229 return getColorDescriptor(symbolicName, DEFAULT_COLOR);
218 } 230 }
219 231
220 /* (non-Javadoc) 232 /**
233 * Returns the color descriptor associated with the given symbolic color
234 * name. If this name does not exist within the registry the supplied
235 * default value will be used.
236 *
237 * @param symbolicName
238 * @param defaultValue
239 * @return the color descriptor associated with the given symbolic color
240 * name or the default
241 * @since 3.4
242 */
243 public ColorDescriptor getColorDescriptor(String symbolicName,
244 ColorDescriptor defaultValue) {
245 RGB rgb = getRGB(symbolicName);
246 if (rgb is null)
247 return defaultValue;
248 return ColorDescriptor.createFrom(rgb);
249 }
250
251 /*
252 * (non-Javadoc)
253 *
221 * @see dwtx.jface.resource.ResourceRegistry#clearCaches() 254 * @see dwtx.jface.resource.ResourceRegistry#clearCaches()
222 */ 255 */
223 protected override void clearCaches() { 256 protected override void clearCaches() {
224 foreach( k, v; stringToColor ){ 257 foreach( k, v; stringToColor ){
225 v.dispose(); 258 v.dispose();