Mercurial > projects > dwt-addons
comparison dwtx/jface/viewers/ViewerLabel.d @ 10:b6c35faf97c8
Viewers
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 31 Mar 2008 00:47:19 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:6c14e54dfc11 | 10:b6c35faf97c8 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2004, 2007 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 * Tom Schindl <tom.shindl@bestsolution.at> - tooltip support | |
11 * Port to the D programming language: | |
12 * Frank Benoit <benoit@tionex.de> | |
13 *******************************************************************************/ | |
14 module dwtx.jface.viewers.ViewerLabel; | |
15 | |
16 import dwt.graphics.Color; | |
17 import dwt.graphics.Font; | |
18 import dwt.graphics.Image; | |
19 import dwt.graphics.Point; | |
20 | |
21 import dwt.dwthelper.utils; | |
22 | |
23 /** | |
24 * The ViewerLabel is the class that is passed to a viewer to handle updates of | |
25 * labels. It keeps track of both original and updates text. | |
26 * | |
27 * @see IViewerLabelProvider | |
28 * @since 3.0 | |
29 */ | |
30 public class ViewerLabel { | |
31 | |
32 // New values for the receiver. Null if nothing has been set. | |
33 private String newText = null; | |
34 | |
35 private Image newImage = null; | |
36 | |
37 private bool imageUpdated = false; | |
38 | |
39 private bool textUpdated = false; | |
40 | |
41 private Color background = null; | |
42 | |
43 private Color foreground = null; | |
44 | |
45 private Font font = null; | |
46 | |
47 // The initial values for the receiver. | |
48 private String startText; | |
49 | |
50 private Image startImage; | |
51 | |
52 private bool hasPendingDecorations_; | |
53 | |
54 private String tooltipText; | |
55 | |
56 private Color tooltipForegroundColor; | |
57 | |
58 private Color tooltipBackgroundColor; | |
59 | |
60 private Point tooltipShift; | |
61 | |
62 /** | |
63 * Create a new instance of the receiver with the supplied initial text and | |
64 * image. | |
65 * | |
66 * @param initialText | |
67 * @param initialImage | |
68 */ | |
69 public this(String initialText, Image initialImage) { | |
70 startText = initialText; | |
71 startImage = initialImage; | |
72 } | |
73 | |
74 /** | |
75 * Get the image for the receiver. If the new image has been set return it, | |
76 * otherwise return the starting image. | |
77 * | |
78 * @return Returns the image. | |
79 */ | |
80 public final Image getImage() { | |
81 if (imageUpdated) { | |
82 return newImage; | |
83 } | |
84 return startImage; | |
85 } | |
86 | |
87 /** | |
88 * Set the image for the receiver. | |
89 * | |
90 * @param image | |
91 * The image to set. | |
92 */ | |
93 public final void setImage(Image image) { | |
94 imageUpdated = true; | |
95 newImage = image; | |
96 } | |
97 | |
98 /** | |
99 * Get the text for the receiver. If the new text has been set return it, | |
100 * otherwise return the starting text. | |
101 * | |
102 * @return String or <code>null</code> if there was no initial text and | |
103 * nothing was updated. | |
104 */ | |
105 public final String getText() { | |
106 if (textUpdated) { | |
107 return newText; | |
108 } | |
109 return startText; | |
110 } | |
111 | |
112 /** | |
113 * Set the text for the receiver. | |
114 * | |
115 * @param text | |
116 * String The label to set. This value should not be | |
117 * <code>null</code>. | |
118 * @see #hasNewText() | |
119 */ | |
120 public final void setText(String text) { | |
121 newText = text; | |
122 textUpdated = true; | |
123 } | |
124 | |
125 /** | |
126 * Return whether or not the image has been set. | |
127 * | |
128 * @return bool. <code>true</code> if the image has been set to | |
129 * something new. | |
130 * | |
131 * @since 3.1 | |
132 */ | |
133 public bool hasNewImage() { | |
134 | |
135 // If we started with null any change is an update | |
136 if (startImage is null) { | |
137 return newImage !is null; | |
138 } | |
139 | |
140 if (imageUpdated) { | |
141 return !(startImage.opEquals(newImage)); | |
142 } | |
143 return false; | |
144 } | |
145 | |
146 /** | |
147 * Return whether or not the text has been set. | |
148 * | |
149 * @return bool. <code>true</code> if the text has been set to | |
150 * something new. | |
151 */ | |
152 public bool hasNewText() { | |
153 | |
154 // If we started with null any change is an update | |
155 if (startText is null) { | |
156 return newText !is null; | |
157 } | |
158 | |
159 if (textUpdated) { | |
160 return !(startText.equals(newText)); | |
161 } | |
162 | |
163 return false; | |
164 } | |
165 | |
166 /** | |
167 * Return whether or not the background color has been set. | |
168 * | |
169 * @return bool. <code>true</code> if the value has been set. | |
170 */ | |
171 public bool hasNewBackground() { | |
172 return background !is null; | |
173 } | |
174 | |
175 /** | |
176 * Return whether or not the foreground color has been set. | |
177 * | |
178 * @return bool. <code>true</code> if the value has been set. | |
179 * | |
180 * @since 3.1 | |
181 */ | |
182 public bool hasNewForeground() { | |
183 return foreground !is null; | |
184 } | |
185 | |
186 /** | |
187 * Return whether or not the font has been set. | |
188 * | |
189 * @return bool. <code>true</code> if the value has been set. | |
190 * | |
191 * @since 3.1 | |
192 */ | |
193 public bool hasNewFont() { | |
194 return font !is null; | |
195 } | |
196 | |
197 /** | |
198 * Get the background Color. | |
199 * | |
200 * @return Color or <code>null</code> if no new value was set. | |
201 * | |
202 * @since 3.1 | |
203 */ | |
204 public Color getBackground() { | |
205 return background; | |
206 } | |
207 | |
208 /** | |
209 * Set the background Color. | |
210 * | |
211 * @param background | |
212 * Color. This value should not be <code>null</code>. | |
213 * | |
214 * @since 3.1 | |
215 */ | |
216 public void setBackground(Color background) { | |
217 this.background = background; | |
218 } | |
219 | |
220 /** | |
221 * Get the font. | |
222 * | |
223 * @return Font or <code>null</code> if no new value was set. | |
224 * | |
225 * @since 3.1 | |
226 */ | |
227 public Font getFont() { | |
228 return font; | |
229 } | |
230 | |
231 /** | |
232 * Set the font. | |
233 * | |
234 * @param font | |
235 * Font This value should not be <code>null</code>. | |
236 * | |
237 * @since 3.1 | |
238 */ | |
239 public void setFont(Font font) { | |
240 this.font = font; | |
241 } | |
242 | |
243 /** | |
244 * Get the foreground Color. | |
245 * | |
246 * @return Color or <code>null</code> if no new value was set. | |
247 * | |
248 * @since 3.1 | |
249 */ | |
250 public Color getForeground() { | |
251 return foreground; | |
252 } | |
253 | |
254 /** | |
255 * Set the foreground Color. | |
256 * | |
257 * @param foreground | |
258 * Color This value should not be <code>null</code>. | |
259 * | |
260 * @since 3.1 | |
261 */ | |
262 public void setForeground(Color foreground) { | |
263 this.foreground = foreground; | |
264 } | |
265 | |
266 /** | |
267 * Set whether or not there are any decorations pending. | |
268 * | |
269 * @param hasPendingDecorations | |
270 */ | |
271 void setHasPendingDecorations(bool hasPendingDecorations_) { | |
272 this.hasPendingDecorations_ = hasPendingDecorations_; | |
273 } | |
274 | |
275 /** | |
276 * @return <code>bool</code>. <code>true</code> if there are any | |
277 * decorations pending. | |
278 */ | |
279 bool hasPendingDecorations() { | |
280 return hasPendingDecorations_; | |
281 } | |
282 | |
283 /** | |
284 * Returns the tooltipText. | |
285 * | |
286 * @return {@link String} or <code>null</code> if the tool tip text was | |
287 * never set. | |
288 * | |
289 * @since 3.3 | |
290 */ | |
291 public String getTooltipText() { | |
292 return tooltipText; | |
293 } | |
294 | |
295 /** | |
296 * Set the tool tip text. | |
297 * | |
298 * @param tooltipText | |
299 * The tooltipText {@link String} to set. This value should not | |
300 * be <code>null</code>. | |
301 * | |
302 * @since 3.3 | |
303 */ | |
304 public void setTooltipText(String tooltipText) { | |
305 this.tooltipText = tooltipText; | |
306 } | |
307 | |
308 /** | |
309 * Return whether or not the tool tip text has been set. | |
310 * | |
311 * @return <code>bool</code>. <code>true</code> if the tool tip text | |
312 * has been set. | |
313 * | |
314 * @since 3.3 | |
315 */ | |
316 public bool hasNewTooltipText() { | |
317 return this.tooltipText !is null; | |
318 } | |
319 | |
320 /** | |
321 * Return the tool tip background color. | |
322 * | |
323 * @return {@link Color} or <code>null</code> if the tool tip background | |
324 * color has not been set. | |
325 * | |
326 * @since 3.3 | |
327 */ | |
328 public Color getTooltipBackgroundColor() { | |
329 return tooltipBackgroundColor; | |
330 } | |
331 | |
332 /** | |
333 * Set the background {@link Color} for tool tip. | |
334 * | |
335 * @param tooltipBackgroundColor | |
336 * The {@link Color} to set. This value should not be | |
337 * <code>null</code>. | |
338 * | |
339 * @since 3.3 | |
340 */ | |
341 public void setTooltipBackgroundColor(Color tooltipBackgroundColor) { | |
342 this.tooltipBackgroundColor = tooltipBackgroundColor; | |
343 } | |
344 | |
345 /** | |
346 * Return whether or not the tool tip background color has been set. | |
347 * | |
348 * @return <code>bool</code>. <code>true</code> if the tool tip text | |
349 * has been set. | |
350 * | |
351 * @since 3.3 | |
352 */ | |
353 public bool hasNewTooltipBackgroundColor() { | |
354 return tooltipBackgroundColor !is null; | |
355 } | |
356 | |
357 /** | |
358 * Return the foreground {@link Color}. | |
359 * | |
360 * @return Returns {@link Color} or <code>null</code> if the tool tip | |
361 * foreground color has not been set. | |
362 * | |
363 * @since 3.3 | |
364 */ | |
365 public Color getTooltipForegroundColor() { | |
366 return tooltipForegroundColor; | |
367 } | |
368 | |
369 /** | |
370 * Set the foreground {@link Color} for tool tip. | |
371 * | |
372 * @param tooltipForegroundColor | |
373 * The tooltipForegroundColor to set. | |
374 * | |
375 * @since 3.3 | |
376 */ | |
377 public void setTooltipForegroundColor(Color tooltipForegroundColor) { | |
378 this.tooltipForegroundColor = tooltipForegroundColor; | |
379 } | |
380 | |
381 /** | |
382 * | |
383 * Return whether or not the tool tip foreground color has been set. | |
384 * | |
385 * @return <code>bool</code>. <code>true</code> if the tool tip foreground | |
386 * has been set. | |
387 * | |
388 * @since 3.3 | |
389 */ | |
390 public bool hasNewTooltipForegroundColor() { | |
391 return tooltipForegroundColor !is null; | |
392 } | |
393 | |
394 /** | |
395 * @return Returns the tooltipShift. | |
396 * @since 3.3 | |
397 */ | |
398 public Point getTooltipShift() { | |
399 return tooltipShift; | |
400 } | |
401 | |
402 /** | |
403 * @param tooltipShift | |
404 * The tooltipShift to set. | |
405 * @since 3.3 | |
406 */ | |
407 public void setTooltipShift(Point tooltipShift) { | |
408 this.tooltipShift = tooltipShift; | |
409 } | |
410 | |
411 /** | |
412 * @return Return whether or not the tool tip shift has been set. | |
413 * @since 3.3 | |
414 */ | |
415 public bool hasTooltipShift() { | |
416 return this.tooltipShift !is null; | |
417 } | |
418 } |