8
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2004, 2006 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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.resource.ColorDescriptor;
|
|
14
|
|
15 import dwtx.jface.resource.DeviceResourceDescriptor;
|
|
16 import dwtx.jface.resource.RGBColorDescriptor;
|
|
17
|
|
18 import dwt.graphics.Color;
|
|
19 import dwt.graphics.Device;
|
|
20 import dwt.graphics.RGB;
|
|
21
|
|
22 import dwt.dwthelper.utils;
|
|
23
|
|
24 /**
|
|
25 * Lightweight descriptor for an DWT color. Each ColorDescriptor will create a particular DWT
|
|
26 * Color on demand. This object will be compared so hashCode(...) and equals(...) must
|
|
27 * return meaningful values.
|
|
28 *
|
|
29 * @since 3.1
|
|
30 */
|
|
31 public abstract class ColorDescriptor : DeviceResourceDescriptor {
|
|
32
|
|
33 /**
|
|
34 * Creates a ColorDescriptor from an existing Color, given the Device associated
|
|
35 * with the original Color. This is the usual way to convert a Color into
|
|
36 * a ColorDescriptor. Note that the returned ColorDescriptor depends on the
|
|
37 * original Color, and disposing the Color will invalidate the ColorDescriptor.
|
|
38 *
|
|
39 * @deprecated use {@link ColorDescriptor#createFrom(Color)}
|
|
40 *
|
|
41 * @since 3.1
|
|
42 *
|
|
43 * @param toCreate Color to convert into a ColorDescriptor.
|
|
44 * @param originalDevice this must be the same Device that was passed into the
|
|
45 * original Color's constructor.
|
|
46 * @return a newly created ColorDescriptor that describes the given Color.
|
|
47 */
|
|
48 public static ColorDescriptor createFrom(Color toCreate, Device originalDevice) {
|
|
49 return new RGBColorDescriptor(toCreate);
|
|
50 }
|
|
51
|
|
52 /**
|
|
53 * Creates a ColorDescriptor from an existing color.
|
|
54 *
|
|
55 * The returned ColorDescriptor depends on the original Color. Disposing
|
|
56 * the original colour while the color descriptor is still in use may cause
|
|
57 * DWT to throw a graphic disposed exception.
|
|
58 *
|
|
59 * @since 3.1
|
|
60 *
|
|
61 * @param toCreate Color to generate a ColorDescriptor from
|
|
62 * @return a newly created ColorDescriptor
|
|
63 */
|
|
64 public static ColorDescriptor createFrom(Color toCreate) {
|
|
65 return new RGBColorDescriptor(toCreate);
|
|
66 }
|
|
67
|
|
68 /**
|
|
69 * Returns a color descriptor for the given RGB values
|
|
70 * @since 3.1
|
|
71 *
|
|
72 * @param toCreate RGB values to create
|
|
73 * @return a new ColorDescriptor
|
|
74 */
|
|
75 public static ColorDescriptor createFrom(RGB toCreate) {
|
|
76 return new RGBColorDescriptor(toCreate);
|
|
77 }
|
|
78
|
|
79 /**
|
|
80 * Returns the Color described by this descriptor.
|
|
81 *
|
|
82 * @param device DWT device on which to allocate the Color
|
|
83 * @return a newly allocated DWT Color object (never null)
|
|
84 * @throws DeviceResourceException if unable to allocate the Color
|
|
85 */
|
|
86 public abstract Color createColor(Device device);
|
|
87
|
|
88 /**
|
|
89 * Undoes whatever was done by createColor.
|
|
90 *
|
|
91 * @since 3.1
|
|
92 *
|
|
93 * @param toDestroy a Color that was previously allocated by an equal ColorDescriptor
|
|
94 */
|
|
95 public abstract void destroyColor(Color toDestroy);
|
|
96
|
|
97 /* (non-Javadoc)
|
|
98 * @see dwtx.jface.resource.DeviceResourceDescriptor#createResource(dwt.graphics.Device)
|
|
99 */
|
|
100 public final Object createResource(Device device){
|
|
101 return createColor(device);
|
|
102 }
|
|
103
|
|
104 /* (non-Javadoc)
|
|
105 * @see dwtx.jface.resource.DeviceResourceDescriptor#destroyResource(java.lang.Object)
|
|
106 */
|
|
107 public final void destroyResource(Object previouslyCreatedObject) {
|
|
108 destroyColor(cast(Color)previouslyCreatedObject);
|
|
109 }
|
|
110 }
|