comparison dwtx/jface/resource/RGBColorDescriptor.d @ 8:a3ff22a98bef

Dialog
author Frank Benoit <benoit@tionex.de>
date Sat, 29 Mar 2008 01:25:27 +0100
parents
children ea8ff534f622
comparison
equal deleted inserted replaced
7:8a302fdb4140 8:a3ff22a98bef
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.RGBColorDescriptor;
14
15 import dwtx.jface.resource.ColorDescriptor;
16
17 import dwt.graphics.Color;
18 import dwt.graphics.Device;
19 import dwt.graphics.RGB;
20
21 import dwt.dwthelper.utils;
22
23 /**
24 * Describes a color by its RGB values.
25 *
26 * @since 3.1
27 */
28 class RGBColorDescriptor : ColorDescriptor {
29
30 private RGB color;
31
32 /**
33 * Color being copied, or null if none
34 */
35 private Color originalColor = null;
36
37 /**
38 * Creates a new RGBColorDescriptor given some RGB values
39 *
40 * @param color RGB values (not null)
41 */
42 public this(RGB color) {
43 this.color = color;
44 }
45
46 /**
47 * Creates a new RGBColorDescriptor that describes an existing color.
48 *
49 * @since 3.1
50 *
51 * @param originalColor a color to describe
52 */
53 public this(Color originalColor) {
54 this(originalColor.getRGB());
55 this.originalColor = originalColor;
56 }
57
58 /* (non-Javadoc)
59 * @see java.lang.Object#equals(java.lang.Object)
60 */
61 public override int opEquals(Object obj) {
62 if ( auto other = cast(RGBColorDescriptor)obj ) {
63 return other.color.opEquals(color) && other.originalColor is originalColor;
64 }
65
66 return false;
67 }
68
69 /* (non-Javadoc)
70 * @see java.lang.Object#hashCode()
71 */
72 public override hash_t toHash() {
73 return color.toHash();
74 }
75
76 /* (non-Javadoc)
77 * @see dwtx.jface.resources.ColorDescriptor#createColor()
78 */
79 public Color createColor(Device device) {
80 // If this descriptor is wrapping an existing color, then we can return the original color
81 // if this is the same device.
82 if (originalColor !is null) {
83 // If we're allocating on the same device as the original color, return the original.
84 if (originalColor.getDevice() is device) {
85 return originalColor;
86 }
87 }
88
89 return new Color(device, color);
90 }
91
92 /* (non-Javadoc)
93 * @see dwtx.jface.resource.ColorDescriptor#destroyColor(dwt.graphics.Color)
94 */
95 public void destroyColor(Color toDestroy) {
96 if (toDestroy is originalColor) {
97 return;
98 }
99
100 toDestroy.dispose();
101 }
102 }