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