comparison org.eclipse.jface/src/org/eclipse/jface/viewers/ViewerLabel.d @ 12:bc29606a740c

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