Mercurial > projects > dwt-win
annotate dwt/graphics/TextStyle.d @ 171:487072cb0473
fix some != to correct !is
author | Thomas Graber <d4rkdragon@gmail.com> |
---|---|
date | Sat, 23 Feb 2008 18:12:20 +0100 |
parents | 9a64a7781bab |
children | 0459ffa88f7d |
rev | line source |
---|---|
21 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 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 dwt.graphics.TextStyle; | |
14 | |
15 import dwt.DWT; | |
16 import dwt.graphics.Font; | |
17 import dwt.graphics.Color; | |
18 import dwt.graphics.GlyphMetrics; | |
19 | |
20 import tango.util.Convert; | |
21 /** | |
22 * <code>TextStyle</code> defines a set of styles that can be applied | |
23 * to a range of text. | |
24 * <p> | |
25 * The hashCode() method in this class uses the values of the public | |
26 * fields to compute the hash value. When storing instances of the | |
27 * class in hashed collections, do not modify these fields after the | |
28 * object has been inserted. | |
29 * </p> | |
30 * <p> | |
31 * Application code does <em>not</em> need to explicitly release the | |
32 * resources managed by each instance when those instances are no longer | |
33 * required, and thus no <code>dispose()</code> method is provided. | |
34 * </p> | |
35 * | |
36 * @see TextLayout | |
37 * @see Font | |
38 * @see Color | |
39 * | |
40 * @since 3.0 | |
41 */ | |
42 public class TextStyle { | |
43 | |
44 /** | |
45 * the font of the style | |
46 */ | |
47 public Font font; | |
48 | |
49 /** | |
50 * the foreground of the style | |
51 */ | |
52 public Color foreground; | |
53 | |
54 /** | |
55 * the background of the style | |
56 */ | |
57 public Color background; | |
58 | |
59 /** | |
60 * the underline flag of the style | |
61 * | |
62 * @since 3.1 | |
63 */ | |
64 public bool underline; | |
65 | |
66 /** | |
67 * the strikeout flag of the style | |
68 * | |
69 * @since 3.1 | |
70 */ | |
71 public bool strikeout; | |
72 | |
73 /** | |
74 * the GlyphMetrics of the style | |
75 * | |
76 * @since 3.2 | |
77 */ | |
78 public GlyphMetrics metrics; | |
79 | |
80 /** | |
81 * the baseline rise of the style. | |
82 * | |
83 * @since 3.2 | |
84 */ | |
85 public int rise; | |
86 | |
87 /** | |
88 * Create a new text style with the specified font, foreground | |
89 * and background. | |
90 * | |
91 * @param font the font of the style, <code>null</code> if none | |
92 * @param foreground the foreground color of the style, <code>null</code> if none | |
93 * @param background the background color of the style, <code>null</code> if none | |
94 */ | |
95 public this (Font font, Color foreground, Color background) { | |
96 if (font !is null && font.isDisposed()) DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
97 if (foreground !is null && foreground.isDisposed()) DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
98 if (background !is null && background.isDisposed()) DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
99 this.font = font; | |
100 this.foreground = foreground; | |
101 this.background = background; | |
102 } | |
103 | |
104 /** | |
105 * Compares the argument to the receiver, and returns true | |
106 * if they represent the <em>same</em> object using a class | |
107 * specific comparison. | |
108 * | |
109 * @param object the object to compare with this object | |
110 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
111 * | |
112 * @see #hashCode() | |
113 */ | |
114 public override int opEquals(Object object) { | |
115 if (object is this) return true; | |
116 if (object is null) return false; | |
117 if (!(cast(TextStyle)object)) return false; | |
118 TextStyle style = cast(TextStyle)object; | |
119 if (foreground !is null) { | |
120 if ( foreground != style.foreground ) return false; | |
121 } else if (style.foreground !is null) return false; | |
122 if (background !is null) { | |
123 if ( background != style.background ) return false; | |
124 } else if (style.background !is null) return false; | |
125 if (font !is null) { | |
126 if (font != style.font) return false; | |
127 } else if (style.font !is null) return false; | |
128 if (metrics !is null || style.metrics !is null) return false; | |
129 if (underline !is style.underline) return false; | |
130 if (strikeout !is style.strikeout) return false; | |
131 if (rise !is style.rise) return false; | |
132 return true; | |
133 } | |
134 | |
135 /** | |
136 * Returns an integer hash code for the receiver. Any two | |
137 * objects that return <code>true</code> when passed to | |
138 * <code>equals</code> must return the same value for this | |
139 * method. | |
140 * | |
141 * @return the receiver's hash | |
142 * | |
143 * @see #equals(Object) | |
144 */ | |
145 public override hash_t toHash() { | |
146 int hash = 0; | |
147 if (foreground !is null) hash ^= foreground.toHash(); | |
148 if (background !is null) hash ^= background.toHash(); | |
149 if (font !is null) hash ^= font.toHash(); | |
150 if (metrics !is null) hash ^= metrics.toHash(); | |
151 if (underline) hash ^= hash; | |
152 if (strikeout) hash ^= hash; | |
153 hash ^= rise; | |
154 return hash; | |
155 } | |
156 | |
157 /** | |
158 * Returns a string containing a concise, human-readable | |
159 * description of the receiver. | |
160 * | |
161 * @return a string representation of the <code>TextStyle</code> | |
162 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
21
diff
changeset
|
163 override public char[] toString () { |
21 | 164 char[] buffer = "TextStyle {"; |
165 int startLength = buffer.length; | |
171
487072cb0473
fix some != to correct !is
Thomas Graber <d4rkdragon@gmail.com>
parents:
48
diff
changeset
|
166 if (font !is null) { |
21 | 167 if (buffer.length > startLength) buffer ~= ", "; |
168 buffer ~= "font="; | |
169 buffer ~= font.toString; | |
170 } | |
171
487072cb0473
fix some != to correct !is
Thomas Graber <d4rkdragon@gmail.com>
parents:
48
diff
changeset
|
171 if (foreground !is null) { |
21 | 172 if (buffer.length > startLength) buffer ~= ", "; |
173 buffer ~= "foreground="; | |
174 buffer ~= foreground.toString; | |
175 } | |
171
487072cb0473
fix some != to correct !is
Thomas Graber <d4rkdragon@gmail.com>
parents:
48
diff
changeset
|
176 if (background !is null) { |
21 | 177 if (buffer.length > startLength) buffer ~= ", "; |
178 buffer ~= "background="; | |
179 buffer ~= background.toString; | |
180 } | |
181 if (underline) { | |
182 if (buffer.length > startLength) buffer ~= ", "; | |
183 buffer ~= "underlined"; | |
184 } | |
185 if (strikeout) { | |
186 if (buffer.length > startLength) buffer ~= ", "; | |
187 buffer ~= "striked out"; | |
188 } | |
189 if (rise != 0) { | |
190 if (buffer.length > startLength) buffer ~= ", "; | |
191 buffer ~= "rise="; | |
192 buffer ~= to!(char[])(rise); | |
193 } | |
171
487072cb0473
fix some != to correct !is
Thomas Graber <d4rkdragon@gmail.com>
parents:
48
diff
changeset
|
194 if (metrics !is null) { |
21 | 195 if (buffer.length > startLength) buffer ~= ", "; |
196 buffer ~= "metrics="; | |
197 buffer ~= metrics.toString; | |
198 } | |
199 buffer ~= "}"; | |
200 return buffer; | |
201 } | |
202 | |
203 } |