Mercurial > projects > dwt-mac
comparison dwt/widgets/TreeItem.d @ 0:380af2bdd8e5
Upload of whole dwt tree
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sat, 09 Aug 2008 17:00:02 +0200 |
parents | |
children | 649b8e223d5a |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:380af2bdd8e5 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 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 *******************************************************************************/ | |
11 module dwt.widgets.TreeItem; | |
12 | |
13 import dwt.dwthelper.utils; | |
14 | |
15 | |
16 import dwt.DWT; | |
17 import dwt.DWTException; | |
18 import dwt.graphics.Color; | |
19 import dwt.graphics.Font; | |
20 import dwt.graphics.GC; | |
21 import dwt.graphics.Image; | |
22 import dwt.graphics.Rectangle; | |
23 import dwt.internal.cocoa.NSAttributedString; | |
24 import dwt.internal.cocoa.NSColor; | |
25 import dwt.internal.cocoa.NSMutableDictionary; | |
26 import dwt.internal.cocoa.NSOutlineView; | |
27 import dwt.internal.cocoa.NSRect; | |
28 import dwt.internal.cocoa.NSString; | |
29 import dwt.internal.cocoa.OS; | |
30 import dwt.internal.cocoa.SWTTreeItem; | |
31 | |
32 /** | |
33 * Instances of this class represent a selectable user interface object | |
34 * that represents a hierarchy of tree items in a tree widget. | |
35 * | |
36 * <dl> | |
37 * <dt><b>Styles:</b></dt> | |
38 * <dd>(none)</dd> | |
39 * <dt><b>Events:</b></dt> | |
40 * <dd>(none)</dd> | |
41 * </dl> | |
42 * <p> | |
43 * IMPORTANT: This class is <em>not</em> intended to be subclassed. | |
44 * </p> | |
45 */ | |
46 public class TreeItem extends Item { | |
47 Tree parent; | |
48 TreeItem parentItem; | |
49 TreeItem[] items; | |
50 int itemCount; | |
51 String [] strings; | |
52 Image [] images; | |
53 bool checked, grayed, cached, expanded; | |
54 Color foreground, background; | |
55 Color[] cellForeground, cellBackground; | |
56 Font font; | |
57 Font[] cellFont; | |
58 int width = -1; | |
59 // | |
60 SWTTreeItem handle; | |
61 | |
62 /** | |
63 * Constructs a new instance of this class given its parent | |
64 * (which must be a <code>Tree</code> or a <code>TreeItem</code>) | |
65 * and a style value describing its behavior and appearance. | |
66 * The item is added to the end of the items maintained by its parent. | |
67 * <p> | |
68 * The style value is either one of the style constants defined in | |
69 * class <code>DWT</code> which is applicable to instances of this | |
70 * class, or must be built by <em>bitwise OR</em>'ing together | |
71 * (that is, using the <code>int</code> "|" operator) two or more | |
72 * of those <code>DWT</code> style constants. The class description | |
73 * lists the style constants that are applicable to the class. | |
74 * Style bits are also inherited from superclasses. | |
75 * </p> | |
76 * | |
77 * @param parent a tree control which will be the parent of the new instance (cannot be null) | |
78 * @param style the style of control to construct | |
79 * | |
80 * @exception IllegalArgumentException <ul> | |
81 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
82 * </ul> | |
83 * @exception DWTException <ul> | |
84 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
85 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
86 * </ul> | |
87 * | |
88 * @see DWT | |
89 * @see Widget#checkSubclass | |
90 * @see Widget#getStyle | |
91 */ | |
92 public TreeItem (Tree parent, int style) { | |
93 this (checkNull (parent), null, style, -1, true); | |
94 } | |
95 | |
96 /** | |
97 * Constructs a new instance of this class given its parent | |
98 * (which must be a <code>Tree</code> or a <code>TreeItem</code>), | |
99 * a style value describing its behavior and appearance, and the index | |
100 * at which to place it in the items maintained by its parent. | |
101 * <p> | |
102 * The style value is either one of the style constants defined in | |
103 * class <code>DWT</code> which is applicable to instances of this | |
104 * class, or must be built by <em>bitwise OR</em>'ing together | |
105 * (that is, using the <code>int</code> "|" operator) two or more | |
106 * of those <code>DWT</code> style constants. The class description | |
107 * lists the style constants that are applicable to the class. | |
108 * Style bits are also inherited from superclasses. | |
109 * </p> | |
110 * | |
111 * @param parent a tree control which will be the parent of the new instance (cannot be null) | |
112 * @param style the style of control to construct | |
113 * @param index the zero-relative index to store the receiver in its parent | |
114 * | |
115 * @exception IllegalArgumentException <ul> | |
116 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
117 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li> | |
118 * </ul> | |
119 * @exception DWTException <ul> | |
120 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
121 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
122 * </ul> | |
123 * | |
124 * @see DWT | |
125 * @see Widget#checkSubclass | |
126 * @see Widget#getStyle | |
127 */ | |
128 public TreeItem (Tree parent, int style, int index) { | |
129 this (checkNull (parent), null, style, checkIndex (index), true); | |
130 } | |
131 | |
132 /** | |
133 * Constructs a new instance of this class given its parent | |
134 * (which must be a <code>Tree</code> or a <code>TreeItem</code>) | |
135 * and a style value describing its behavior and appearance. | |
136 * The item is added to the end of the items maintained by its parent. | |
137 * <p> | |
138 * The style value is either one of the style constants defined in | |
139 * class <code>DWT</code> which is applicable to instances of this | |
140 * class, or must be built by <em>bitwise OR</em>'ing together | |
141 * (that is, using the <code>int</code> "|" operator) two or more | |
142 * of those <code>DWT</code> style constants. The class description | |
143 * lists the style constants that are applicable to the class. | |
144 * Style bits are also inherited from superclasses. | |
145 * </p> | |
146 * | |
147 * @param parentItem a tree control which will be the parent of the new instance (cannot be null) | |
148 * @param style the style of control to construct | |
149 * | |
150 * @exception IllegalArgumentException <ul> | |
151 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
152 * </ul> | |
153 * @exception DWTException <ul> | |
154 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
155 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
156 * </ul> | |
157 * | |
158 * @see DWT | |
159 * @see Widget#checkSubclass | |
160 * @see Widget#getStyle | |
161 */ | |
162 public TreeItem (TreeItem parentItem, int style) { | |
163 this (checkNull (parentItem).parent, parentItem, style, -1, true); | |
164 } | |
165 | |
166 /** | |
167 * Constructs a new instance of this class given its parent | |
168 * (which must be a <code>Tree</code> or a <code>TreeItem</code>), | |
169 * a style value describing its behavior and appearance, and the index | |
170 * at which to place it in the items maintained by its parent. | |
171 * <p> | |
172 * The style value is either one of the style constants defined in | |
173 * class <code>DWT</code> which is applicable to instances of this | |
174 * class, or must be built by <em>bitwise OR</em>'ing together | |
175 * (that is, using the <code>int</code> "|" operator) two or more | |
176 * of those <code>DWT</code> style constants. The class description | |
177 * lists the style constants that are applicable to the class. | |
178 * Style bits are also inherited from superclasses. | |
179 * </p> | |
180 * | |
181 * @param parentItem a tree control which will be the parent of the new instance (cannot be null) | |
182 * @param style the style of control to construct | |
183 * @param index the zero-relative index to store the receiver in its parent | |
184 * | |
185 * @exception IllegalArgumentException <ul> | |
186 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
187 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li> | |
188 * </ul> | |
189 * @exception DWTException <ul> | |
190 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
191 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
192 * </ul> | |
193 * | |
194 * @see DWT | |
195 * @see Widget#checkSubclass | |
196 * @see Widget#getStyle | |
197 */ | |
198 public TreeItem (TreeItem parentItem, int style, int index) { | |
199 this (checkNull (parentItem).parent, parentItem, style, checkIndex (index), true); | |
200 } | |
201 | |
202 TreeItem (Tree parent, TreeItem parentItem, int style, int index, bool create) { | |
203 super (parent, style); | |
204 this.parent = parent; | |
205 this.parentItem = parentItem; | |
206 if (create) parent.createItem (this, parentItem, index); | |
207 } | |
208 | |
209 static TreeItem checkNull (TreeItem item) { | |
210 if (item is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
211 return item; | |
212 } | |
213 | |
214 static Tree checkNull (Tree parent) { | |
215 if (parent is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); | |
216 return parent; | |
217 } | |
218 | |
219 static int checkIndex (int index) { | |
220 if (index < 0) DWT.error (DWT.ERROR_INVALID_RANGE); | |
221 return index; | |
222 } | |
223 | |
224 int calculateWidth (int index, GC gc) { | |
225 if (index is 0 && width !is -1) return width; | |
226 int width = 0; | |
227 Image image = getImage (index); | |
228 String text = getText (index); | |
229 gc.setFont (getFont (index)); | |
230 // if (image !is null) width += image.getBounds ().width + parent.getGap (); | |
231 if (text !is null && text.length () > 0) width += gc.stringExtent (text).x; | |
232 // if (parent.hooks (DWT.MeasureItem)) { | |
233 // Event event = new Event (); | |
234 // event.item = this; | |
235 // event.index = index; | |
236 // event.gc = gc; | |
237 // short [] height = new short [1]; | |
238 // OS.GetDataBrowserTableViewRowHeight (parent.handle, height); | |
239 // event.width = width; | |
240 // event.height = height [0]; | |
241 // parent.sendEvent (DWT.MeasureItem, event); | |
242 // if (parent.itemHeight < event.height) { | |
243 // parent.itemHeight = event.height; | |
244 // OS.SetDataBrowserTableViewRowHeight (parent.handle, (short) event.height); | |
245 // } | |
246 // width = event.width; | |
247 // } | |
248 if (index is 0) this.width = width; | |
249 return width; | |
250 } | |
251 | |
252 protected void checkSubclass () { | |
253 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS); | |
254 } | |
255 | |
256 void clear () { | |
257 cached = false; | |
258 text = ""; | |
259 image = null; | |
260 strings = null; | |
261 images = null; | |
262 checked = grayed = false; | |
263 foreground = background = null; | |
264 cellForeground = cellBackground = null; | |
265 font = null; | |
266 cellFont = null; | |
267 } | |
268 | |
269 /** | |
270 * Clears the item at the given zero-relative index in the receiver. | |
271 * The text, icon and other attributes of the item are set to the default | |
272 * value. If the tree was created with the <code>DWT.VIRTUAL</code> style, | |
273 * these attributes are requested again as needed. | |
274 * | |
275 * @param index the index of the item to clear | |
276 * @param all <code>true</code> if all child items of the indexed item should be | |
277 * cleared recursively, and <code>false</code> otherwise | |
278 * | |
279 * @exception IllegalArgumentException <ul> | |
280 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> | |
281 * </ul> | |
282 * @exception DWTException <ul> | |
283 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
284 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
285 * </ul> | |
286 * | |
287 * @see DWT#VIRTUAL | |
288 * @see DWT#SetData | |
289 * | |
290 * @since 3.2 | |
291 */ | |
292 public void clear (int index, bool all) { | |
293 checkWidget (); | |
294 int count = getItemCount (); | |
295 if (index < 0 || index >= count) DWT.error (DWT.ERROR_INVALID_RANGE); | |
296 parent.clear (this, index, all); | |
297 } | |
298 | |
299 | |
300 /** | |
301 * Clears all the items in the receiver. The text, icon and other | |
302 * attributes of the items are set to their default values. If the | |
303 * tree was created with the <code>DWT.VIRTUAL</code> style, these | |
304 * attributes are requested again as needed. | |
305 * | |
306 * @param all <code>true</code> if all child items should be cleared | |
307 * recursively, and <code>false</code> otherwise | |
308 * | |
309 * @exception DWTException <ul> | |
310 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
311 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
312 * </ul> | |
313 * | |
314 * @see DWT#VIRTUAL | |
315 * @see DWT#SetData | |
316 * | |
317 * @since 3.2 | |
318 */ | |
319 public void clearAll (bool all) { | |
320 checkWidget (); | |
321 parent.clearAll (this, all); | |
322 } | |
323 | |
324 NSAttributedString createString(int index) { | |
325 NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(4); | |
326 Color foreground = cellForeground !is null ? cellForeground [index] : null; | |
327 if (foreground is null) foreground = this.foreground; | |
328 if (foreground is null) foreground = parent.foreground; | |
329 if (foreground !is null) { | |
330 NSColor color = NSColor.colorWithDeviceRed(foreground.handle[0], foreground.handle[1], foreground.handle[2], 1); | |
331 dict.setObject(color, OS.NSForegroundColorAttributeName()); | |
332 } | |
333 Font font = cellFont !is null ? cellFont [index] : null; | |
334 if (font is null) font = this.font; | |
335 // if (font is null) font = parent.font; | |
336 if (font !is null) { | |
337 dict.setObject(font.handle, OS.NSFontAttributeName()); | |
338 } | |
339 Color background = cellBackground !is null ? cellBackground [index] : null; | |
340 if (background is null) background = this.background; | |
341 if (background !is null) { | |
342 NSColor color = NSColor.colorWithDeviceRed(background.handle[0], background.handle[1], background.handle[2], 1); | |
343 dict.setObject(color, OS.NSBackgroundColorAttributeName()); | |
344 } | |
345 String text = getText (index); | |
346 int length = text.length(); | |
347 char[] chars = new char[length]; | |
348 text.getChars(0, length, chars, 0); | |
349 NSString str = NSString.stringWithCharacters(chars, length); | |
350 NSAttributedString attribStr = ((NSAttributedString)new NSAttributedString().alloc()).initWithString_attributes_(str, dict); | |
351 attribStr.autorelease(); | |
352 return attribStr; | |
353 } | |
354 | |
355 void destroyWidget () { | |
356 parent.destroyItem (this); | |
357 releaseHandle (); | |
358 } | |
359 | |
360 /** | |
361 * Returns the receiver's background color. | |
362 * | |
363 * @return the background color | |
364 * | |
365 * @exception DWTException <ul> | |
366 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
367 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
368 * </ul> | |
369 * | |
370 * @since 2.0 | |
371 * | |
372 */ | |
373 public Color getBackground () { | |
374 checkWidget (); | |
375 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
376 return background !is null ? background : parent.getBackground (); | |
377 } | |
378 | |
379 /** | |
380 * Returns the background color at the given column index in the receiver. | |
381 * | |
382 * @param index the column index | |
383 * @return the background color | |
384 * | |
385 * @exception DWTException <ul> | |
386 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
387 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
388 * </ul> | |
389 * | |
390 * @since 3.1 | |
391 */ | |
392 public Color getBackground (int index) { | |
393 checkWidget (); | |
394 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
395 int count = Math.max (1, parent.columnCount); | |
396 if (0 > index || index > count -1) return getBackground (); | |
397 if (cellBackground is null || cellBackground [index] is null) return getBackground (); | |
398 return cellBackground [index]; | |
399 } | |
400 | |
401 /** | |
402 * Returns a rectangle describing the receiver's size and location | |
403 * relative to its parent. | |
404 * | |
405 * @return the receiver's bounding rectangle | |
406 * | |
407 * @exception DWTException <ul> | |
408 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
409 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
410 * </ul> | |
411 */ | |
412 public Rectangle getBounds () { | |
413 checkWidget (); | |
414 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
415 NSOutlineView outlineView = (NSOutlineView) parent.view; | |
416 int row = outlineView.rowForItem(handle); | |
417 NSRect rect = outlineView.rectOfRow (row); | |
418 rect = outlineView.convertRect_toView_ (rect, parent.scrollView); | |
419 Rectangle result = new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height); | |
420 return result; | |
421 } | |
422 | |
423 /** | |
424 * Returns a rectangle describing the receiver's size and location | |
425 * relative to its parent at a column in the tree. | |
426 * | |
427 * @param index the index that specifies the column | |
428 * @return the receiver's bounding column rectangle | |
429 * | |
430 * @exception DWTException <ul> | |
431 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
432 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
433 * </ul> | |
434 * | |
435 * @since 3.1 | |
436 */ | |
437 public Rectangle getBounds (int index) { | |
438 checkWidget (); | |
439 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
440 if (index !is 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0); | |
441 NSOutlineView outlineView = (NSOutlineView) parent.view; | |
442 int row = outlineView.rowForItem(handle); | |
443 if ((parent.style & DWT.CHECK) !is 0) index ++; | |
444 NSRect rect = outlineView.frameOfCellAtColumn(index, row); | |
445 rect = outlineView.convertRect_toView_ (rect, parent.scrollView); | |
446 return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); | |
447 } | |
448 | |
449 /** | |
450 * Returns <code>true</code> if the receiver is checked, | |
451 * and false otherwise. When the parent does not have | |
452 * the <code>CHECK style, return false. | |
453 * <p> | |
454 * | |
455 * @return the checked state | |
456 * | |
457 * @exception DWTException <ul> | |
458 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
459 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
460 * </ul> | |
461 */ | |
462 public bool getChecked () { | |
463 checkWidget (); | |
464 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
465 if ((parent.style & DWT.CHECK) is 0) return false; | |
466 return checked; | |
467 } | |
468 | |
469 /** | |
470 * Returns <code>true</code> if the receiver is expanded, | |
471 * and false otherwise. | |
472 * <p> | |
473 * | |
474 * @return the expanded state | |
475 * | |
476 * @exception DWTException <ul> | |
477 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
478 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
479 * </ul> | |
480 */ | |
481 public bool getExpanded () { | |
482 checkWidget (); | |
483 return expanded; | |
484 } | |
485 | |
486 /** | |
487 * Returns the font that the receiver will use to paint textual information for this item. | |
488 * | |
489 * @return the receiver's font | |
490 * | |
491 * @exception DWTException <ul> | |
492 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
493 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
494 * </ul> | |
495 * | |
496 * @since 3.0 | |
497 */ | |
498 public Font getFont () { | |
499 checkWidget (); | |
500 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
501 return font !is null ? font : parent.getFont (); | |
502 } | |
503 | |
504 /** | |
505 * Returns the font that the receiver will use to paint textual information | |
506 * for the specified cell in this item. | |
507 * | |
508 * @param index the column index | |
509 * @return the receiver's font | |
510 * | |
511 * @exception DWTException <ul> | |
512 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
513 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
514 * </ul> | |
515 * | |
516 * @since 3.1 | |
517 */ | |
518 public Font getFont (int index) { | |
519 checkWidget (); | |
520 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
521 int count = Math.max (1, parent.columnCount); | |
522 if (0 > index || index > count -1) return getFont (); | |
523 if (cellFont is null || cellFont [index] is null) return getFont (); | |
524 return cellFont [index]; | |
525 } | |
526 | |
527 /** | |
528 * Returns the foreground color that the receiver will use to draw. | |
529 * | |
530 * @return the receiver's foreground color | |
531 * | |
532 * @exception DWTException <ul> | |
533 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
534 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
535 * </ul> | |
536 * | |
537 * @since 2.0 | |
538 * | |
539 */ | |
540 public Color getForeground () { | |
541 checkWidget (); | |
542 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
543 return foreground !is null ? foreground : parent.getForeground (); | |
544 } | |
545 | |
546 /** | |
547 * | |
548 * Returns the foreground color at the given column index in the receiver. | |
549 * | |
550 * @param index the column index | |
551 * @return the foreground color | |
552 * | |
553 * @exception DWTException <ul> | |
554 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
555 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
556 * </ul> | |
557 * | |
558 * @since 3.1 | |
559 */ | |
560 public Color getForeground (int index) { | |
561 checkWidget (); | |
562 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
563 int count = Math.max (1, parent.columnCount); | |
564 if (0 > index || index > count -1) return getForeground (); | |
565 if (cellForeground is null || cellForeground [index] is null) return getForeground (); | |
566 return cellForeground [index]; | |
567 } | |
568 | |
569 /** | |
570 * Returns <code>true</code> if the receiver is grayed, | |
571 * and false otherwise. When the parent does not have | |
572 * the <code>CHECK style, return false. | |
573 * <p> | |
574 * | |
575 * @return the grayed state of the checkbox | |
576 * | |
577 * @exception DWTException <ul> | |
578 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
579 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
580 * </ul> | |
581 */ | |
582 public bool getGrayed () { | |
583 checkWidget (); | |
584 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
585 if ((parent.style & DWT.CHECK) is 0) return false; | |
586 return grayed; | |
587 } | |
588 | |
589 public Image getImage () { | |
590 checkWidget (); | |
591 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
592 return super.getImage (); | |
593 } | |
594 | |
595 /** | |
596 * Returns the image stored at the given column index in the receiver, | |
597 * or null if the image has not been set or if the column does not exist. | |
598 * | |
599 * @param index the column index | |
600 * @return the image stored at the given column index in the receiver | |
601 * | |
602 * @exception DWTException <ul> | |
603 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
604 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
605 * </ul> | |
606 * | |
607 * @since 3.1 | |
608 */ | |
609 public Image getImage (int index) { | |
610 checkWidget (); | |
611 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
612 if (index is 0) return getImage (); | |
613 if (images !is null) { | |
614 if (0 <= index && index < images.length) return images [index]; | |
615 } | |
616 return null; | |
617 } | |
618 | |
619 /** | |
620 * Returns a rectangle describing the size and location | |
621 * relative to its parent of an image at a column in the | |
622 * tree. | |
623 * | |
624 * @param index the index that specifies the column | |
625 * @return the receiver's bounding image rectangle | |
626 * | |
627 * @exception DWTException <ul> | |
628 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
629 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
630 * </ul> | |
631 * | |
632 * @since 3.1 | |
633 */ | |
634 public Rectangle getImageBounds (int index) { | |
635 checkWidget (); | |
636 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
637 // if (index !is 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0); | |
638 // Rect rect = new Rect(); | |
639 // int columnId = parent.columnCount is 0 ? parent.column_id : parent.columns [index].id; | |
640 // if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect) !is OS.noErr) { | |
641 // return new Rectangle (0, 0, 0, 0); | |
642 // } | |
643 // int x = rect.left, y = rect.top; | |
644 // int width = 0; | |
645 // if (index is 0 && image !is null) { | |
646 // Rectangle bounds = image.getBounds (); | |
647 // width += bounds.width; | |
648 // } | |
649 // if (index !is 0 && images !is null && images[index] !is null) { | |
650 // Rectangle bounds = images [index].getBounds (); | |
651 // width += bounds.width; | |
652 // } | |
653 // int height = rect.bottom - rect.top + 1; | |
654 // return new Rectangle (x, y, width, height); | |
655 return null; | |
656 } | |
657 | |
658 /** | |
659 * Returns the item at the given, zero-relative index in the | |
660 * receiver. Throws an exception if the index is out of range. | |
661 * | |
662 * @param index the index of the item to return | |
663 * @return the item at the given index | |
664 * | |
665 * @exception IllegalArgumentException <ul> | |
666 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> | |
667 * </ul> | |
668 * @exception DWTException <ul> | |
669 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
670 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
671 * </ul> | |
672 * | |
673 * @since 3.1 | |
674 */ | |
675 public TreeItem getItem (int index) { | |
676 checkWidget (); | |
677 if (index < 0) error (DWT.ERROR_INVALID_RANGE); | |
678 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
679 if (index >= itemCount) error (DWT.ERROR_INVALID_RANGE); | |
680 return parent._getItem (this, index); | |
681 } | |
682 | |
683 /** | |
684 * Returns the number of items contained in the receiver | |
685 * that are direct item children of the receiver. | |
686 * | |
687 * @return the number of items | |
688 * | |
689 * @exception DWTException <ul> | |
690 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
691 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
692 * </ul> | |
693 */ | |
694 public int getItemCount () { | |
695 checkWidget (); | |
696 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
697 return itemCount; | |
698 } | |
699 | |
700 /** | |
701 * Returns a (possibly empty) array of <code>TreeItem</code>s which | |
702 * are the direct item children of the receiver. | |
703 * <p> | |
704 * Note: This is not the actual structure used by the receiver | |
705 * to maintain its list of items, so modifying the array will | |
706 * not affect the receiver. | |
707 * </p> | |
708 * | |
709 * @return the receiver's items | |
710 * | |
711 * @exception DWTException <ul> | |
712 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
713 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
714 * </ul> | |
715 */ | |
716 public TreeItem [] getItems () { | |
717 checkWidget (); | |
718 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
719 TreeItem [] result = new TreeItem [itemCount]; | |
720 for (int i=0; i<itemCount; i++) { | |
721 result [i] = parent._getItem (this, i); | |
722 } | |
723 return result; | |
724 } | |
725 | |
726 String getNameText () { | |
727 if ((parent.style & DWT.VIRTUAL) !is 0) { | |
728 if (!cached) return "*virtual*"; //$NON-NLS-1$ | |
729 } | |
730 return super.getNameText (); | |
731 } | |
732 | |
733 /** | |
734 * Returns the receiver's parent, which must be a <code>Tree</code>. | |
735 * | |
736 * @return the receiver's parent | |
737 * | |
738 * @exception DWTException <ul> | |
739 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
740 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
741 * </ul> | |
742 */ | |
743 public Tree getParent () { | |
744 checkWidget (); | |
745 return parent; | |
746 } | |
747 | |
748 /** | |
749 * Returns the receiver's parent item, which must be a | |
750 * <code>TreeItem</code> or null when the receiver is a | |
751 * root. | |
752 * | |
753 * @return the receiver's parent item | |
754 * | |
755 * @exception DWTException <ul> | |
756 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
757 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
758 * </ul> | |
759 */ | |
760 public TreeItem getParentItem () { | |
761 checkWidget (); | |
762 return parentItem; | |
763 } | |
764 | |
765 public String getText () { | |
766 checkWidget (); | |
767 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
768 return super.getText (); | |
769 } | |
770 | |
771 /** | |
772 * Returns the text stored at the given column index in the receiver, | |
773 * or empty string if the text has not been set. | |
774 * | |
775 * @param index the column index | |
776 * @return the text stored at the given column index in the receiver | |
777 * | |
778 * @exception DWTException <ul> | |
779 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
780 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
781 * </ul> | |
782 * | |
783 * @since 3.1 | |
784 */ | |
785 public String getText (int index) { | |
786 checkWidget (); | |
787 if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
788 if (index is 0) return getText (); | |
789 if (strings !is null) { | |
790 if (0 <= index && index < strings.length) { | |
791 String string = strings [index]; | |
792 return string !is null ? string : ""; | |
793 } | |
794 } | |
795 return ""; | |
796 } | |
797 | |
798 /** | |
799 * Returns a rectangle describing the size and location | |
800 * relative to its parent of the text at a column in the | |
801 * tree. | |
802 * | |
803 * @param index the index that specifies the column | |
804 * @return the receiver's bounding text rectangle | |
805 * | |
806 * @exception DWTException <ul> | |
807 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
808 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
809 * </ul> | |
810 * | |
811 * @since 3.3 | |
812 */ | |
813 public Rectangle getTextBounds (int index) { | |
814 checkWidget (); | |
815 // if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); | |
816 // if (index !is 0 && !(0 <= index && index < parent.columnCount)) return new Rectangle (0, 0, 0, 0); | |
817 // Rect rect = new Rect(); | |
818 // int columnId = parent.columnCount is 0 ? parent.column_id : parent.columns [index].id; | |
819 // if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyEnclosingPart, rect) !is OS.noErr) { | |
820 // return new Rectangle (0, 0, 0, 0); | |
821 // } | |
822 // int[] disclosure = new int [1]; | |
823 // OS.GetDataBrowserListViewDisclosureColumn (parent.handle, disclosure, new bool [1]); | |
824 // int imageWidth = 0; | |
825 // int margin = index is 0 ? 0 : parent.getInsetWidth (columnId, false) / 2; | |
826 // Image image = getImage (index); | |
827 // if (image !is null) { | |
828 // Rectangle bounds = image.getBounds (); | |
829 // imageWidth = bounds.width + parent.getGap (); | |
830 // } | |
831 // int x, y, width, height; | |
832 // if (OS.VERSION >= 0x1040 && disclosure [0] !is columnId) { | |
833 // if (parent.getLinesVisible ()) { | |
834 // rect.left += Tree.GRID_WIDTH; | |
835 // rect.top += Tree.GRID_WIDTH; | |
836 // } | |
837 // x = rect.left + imageWidth + margin; | |
838 // y = rect.top; | |
839 // width = Math.max (0, rect.right - rect.left - imageWidth - margin * 2);; | |
840 // height = rect.bottom - rect.top; | |
841 // } else { | |
842 // Rect rect2 = new Rect(); | |
843 // if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect2) !is OS.noErr) { | |
844 // return new Rectangle (0, 0, 0, 0); | |
845 // } | |
846 // x = rect2.left + imageWidth + margin; | |
847 // y = rect2.top; | |
848 // width = Math.max (0, rect.right - rect2.left + 1 - imageWidth - margin * 2); | |
849 // height = rect2.bottom - rect2.top + 1; | |
850 // } | |
851 // return new Rectangle (x, y, width, height); | |
852 return null; | |
853 } | |
854 | |
855 /** | |
856 * Searches the receiver's list starting at the first item | |
857 * (index 0) until an item is found that is equal to the | |
858 * argument, and returns the index of that item. If no item | |
859 * is found, returns -1. | |
860 * | |
861 * @param item the search item | |
862 * @return the index of the item | |
863 * | |
864 * @exception IllegalArgumentException <ul> | |
865 * <li>ERROR_NULL_ARGUMENT - if the item is null</li> | |
866 * <li>ERROR_INVALID_ARGUMENT - if the item has been disposed</li> | |
867 * </ul> | |
868 * @exception DWTException <ul> | |
869 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
870 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
871 * </ul> | |
872 * | |
873 * @since 3.1 | |
874 */ | |
875 public int indexOf (TreeItem item) { | |
876 checkWidget (); | |
877 if (item is null) error (DWT.ERROR_NULL_ARGUMENT); | |
878 if (item.isDisposed ()) error (DWT.ERROR_INVALID_ARGUMENT); | |
879 if (item.parentItem !is this) return -1; | |
880 for (int i = 0; i < itemCount; i++) { | |
881 if (item is items[i]) return i; | |
882 } | |
883 return -1; | |
884 } | |
885 | |
886 void releaseChildren (bool destroy) { | |
887 for (int i=0; i<items.length; i++) { | |
888 TreeItem item = items [i]; | |
889 if (item !is null && !item.isDisposed ()) { | |
890 item.release (false); | |
891 } | |
892 } | |
893 items = null; | |
894 itemCount = 0; | |
895 super.releaseChildren (destroy); | |
896 } | |
897 | |
898 void releaseHandle () { | |
899 super.releaseHandle (); | |
900 if (handle !is null) handle.release(); | |
901 handle = null; | |
902 parentItem = null; | |
903 parent = null; | |
904 } | |
905 | |
906 void releaseWidget () { | |
907 super.releaseWidget (); | |
908 strings = null; | |
909 images = null; | |
910 background = foreground = null; | |
911 font = null; | |
912 cellBackground = cellForeground = null; | |
913 cellFont = null; | |
914 } | |
915 | |
916 /** | |
917 * Removes all of the items from the receiver. | |
918 * <p> | |
919 * @exception DWTException <ul> | |
920 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
921 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
922 * </ul> | |
923 * | |
924 * @since 3.1 | |
925 */ | |
926 public void removeAll () { | |
927 checkWidget (); | |
928 // for (int i=itemCount - 1; i >= 0; i--) { | |
929 // TreeItem item = parent._getItem (childIds [i], false); | |
930 // if (item !is null && !item.isDisposed ()) { | |
931 // item.dispose (); | |
932 // } | |
933 // } | |
934 } | |
935 | |
936 /** | |
937 * Sets the receiver's background color to the color specified | |
938 * by the argument, or to the default system color for the item | |
939 * if the argument is null. | |
940 * | |
941 * @param color the new color (or null) | |
942 * | |
943 * @exception IllegalArgumentException <ul> | |
944 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
945 * </ul> | |
946 * @exception DWTException <ul> | |
947 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
948 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
949 * </ul> | |
950 * | |
951 * @since 2.0 | |
952 * | |
953 */ | |
954 public void setBackground (Color color) { | |
955 checkWidget (); | |
956 if (color !is null && color.isDisposed ()) { | |
957 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
958 } | |
959 Color oldColor = background; | |
960 if (oldColor is color) return; | |
961 background = color; | |
962 if (oldColor !is null && oldColor.equals (color)) return; | |
963 cached = true; | |
964 ((NSOutlineView)parent.view).reloadItem_(handle); | |
965 } | |
966 | |
967 /** | |
968 * Sets the background color at the given column index in the receiver | |
969 * to the color specified by the argument, or to the default system color for the item | |
970 * if the argument is null. | |
971 * | |
972 * @param index the column index | |
973 * @param color the new color (or null) | |
974 * | |
975 * @exception IllegalArgumentException <ul> | |
976 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
977 * </ul> | |
978 * @exception DWTException <ul> | |
979 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
980 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
981 * </ul> | |
982 * | |
983 * @since 3.1 | |
984 * | |
985 */ | |
986 public void setBackground (int index, Color color) { | |
987 checkWidget (); | |
988 if (color !is null && color.isDisposed ()) { | |
989 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
990 } | |
991 int count = Math.max (1, parent.columnCount); | |
992 if (0 > index || index > count - 1) return; | |
993 if (cellBackground is null) { | |
994 if (color is null) return; | |
995 cellBackground = new Color [count]; | |
996 } | |
997 Color oldColor = cellBackground [index]; | |
998 if (oldColor is color) return; | |
999 cellBackground [index] = color; | |
1000 if (oldColor !is null && oldColor.equals (color)) return; | |
1001 cached = true; | |
1002 ((NSOutlineView)parent.view).reloadItem_(handle); | |
1003 } | |
1004 | |
1005 /** | |
1006 * Sets the checked state of the receiver. | |
1007 * <p> | |
1008 * | |
1009 * @param checked the new checked state | |
1010 * | |
1011 * @exception DWTException <ul> | |
1012 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1013 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1014 * </ul> | |
1015 */ | |
1016 public void setChecked (bool checked) { | |
1017 checkWidget (); | |
1018 if ((parent.style & DWT.CHECK) is 0) return; | |
1019 if (this.checked is checked) return; | |
1020 this.checked = checked; | |
1021 cached = true; | |
1022 ((NSOutlineView)parent.view).reloadItem_(handle); | |
1023 } | |
1024 | |
1025 /** | |
1026 * Sets the expanded state of the receiver. | |
1027 * <p> | |
1028 * | |
1029 * @param expanded the new expanded state | |
1030 * | |
1031 * @exception DWTException <ul> | |
1032 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1033 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1034 * </ul> | |
1035 */ | |
1036 public void setExpanded (bool expanded) { | |
1037 checkWidget (); | |
1038 if (expanded is getExpanded ()) return; | |
1039 parent.ignoreExpand = true; | |
1040 if (expanded) { | |
1041 ((NSOutlineView)parent.view).expandItem_(handle); | |
1042 } else { | |
1043 ((NSOutlineView)parent.view).collapseItem_(handle); | |
1044 } | |
1045 parent.ignoreExpand = false; | |
1046 cached = true; | |
1047 // if (expanded) { | |
1048 // parent.setScrollWidth (false, childIds, false); | |
1049 // } else { | |
1050 // parent.setScrollWidth (true); | |
1051 // parent.fixScrollBar (); | |
1052 // } | |
1053 } | |
1054 | |
1055 /** | |
1056 * Sets the font that the receiver will use to paint textual information | |
1057 * for this item to the font specified by the argument, or to the default font | |
1058 * for that kind of control if the argument is null. | |
1059 * | |
1060 * @param font the new font (or null) | |
1061 * | |
1062 * @exception IllegalArgumentException <ul> | |
1063 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
1064 * </ul> | |
1065 * @exception DWTException <ul> | |
1066 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1067 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1068 * </ul> | |
1069 * | |
1070 * @since 3.0 | |
1071 */ | |
1072 public void setFont (Font font) { | |
1073 checkWidget (); | |
1074 if (font !is null && font.isDisposed ()) { | |
1075 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
1076 } | |
1077 Font oldFont = this.font; | |
1078 if (oldFont is font) return; | |
1079 this.font = font; | |
1080 if (oldFont !is null && oldFont.equals (font)) return; | |
1081 cached = true; | |
1082 ((NSOutlineView)parent.view).reloadItem_(handle); | |
1083 } | |
1084 | |
1085 /** | |
1086 * Sets the font that the receiver will use to paint textual information | |
1087 * for the specified cell in this item to the font specified by the | |
1088 * argument, or to the default font for that kind of control if the | |
1089 * argument is null. | |
1090 * | |
1091 * @param index the column index | |
1092 * @param font the new font (or null) | |
1093 * | |
1094 * @exception IllegalArgumentException <ul> | |
1095 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
1096 * </ul> | |
1097 * @exception DWTException <ul> | |
1098 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1099 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1100 * </ul> | |
1101 * | |
1102 * @since 3.1 | |
1103 */ | |
1104 public void setFont (int index, Font font) { | |
1105 checkWidget (); | |
1106 if (font !is null && font.isDisposed ()) { | |
1107 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
1108 } | |
1109 int count = Math.max (1, parent.columnCount); | |
1110 if (0 > index || index > count - 1) return; | |
1111 if (cellFont is null) { | |
1112 if (font is null) return; | |
1113 cellFont = new Font [count]; | |
1114 } | |
1115 Font oldFont = this.font; | |
1116 if (oldFont is font) return; | |
1117 cellFont [index] = font; | |
1118 if (oldFont !is null && oldFont.equals (font)) return; | |
1119 cached = true; | |
1120 ((NSOutlineView)parent.view).reloadItem_(handle); | |
1121 } | |
1122 | |
1123 /** | |
1124 * Sets the receiver's foreground color to the color specified | |
1125 * by the argument, or to the default system color for the item | |
1126 * if the argument is null. | |
1127 * | |
1128 * @param color the new color (or null) | |
1129 * | |
1130 * @since 2.0 | |
1131 * | |
1132 * @exception IllegalArgumentException <ul> | |
1133 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
1134 * </ul> | |
1135 * @exception DWTException <ul> | |
1136 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1137 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1138 * </ul> | |
1139 * | |
1140 * @since 2.0 | |
1141 * | |
1142 */ | |
1143 public void setForeground (Color color) { | |
1144 checkWidget (); | |
1145 if (color !is null && color.isDisposed ()) { | |
1146 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
1147 } | |
1148 Color oldColor = foreground; | |
1149 if (oldColor is color) return; | |
1150 foreground = color; | |
1151 if (oldColor !is null && oldColor.equals (color)) return; | |
1152 cached = true; | |
1153 ((NSOutlineView)parent.view).reloadItem_(handle); | |
1154 } | |
1155 | |
1156 /** | |
1157 * Sets the foreground color at the given column index in the receiver | |
1158 * to the color specified by the argument, or to the default system color for the item | |
1159 * if the argument is null. | |
1160 * | |
1161 * @param index the column index | |
1162 * @param color the new color (or null) | |
1163 * | |
1164 * @exception IllegalArgumentException <ul> | |
1165 * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> | |
1166 * </ul> | |
1167 * @exception DWTException <ul> | |
1168 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1169 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1170 * </ul> | |
1171 * | |
1172 * @since 3.1 | |
1173 * | |
1174 */ | |
1175 public void setForeground (int index, Color color){ | |
1176 checkWidget (); | |
1177 if (color !is null && color.isDisposed ()) { | |
1178 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | |
1179 } | |
1180 int count = Math.max (1, parent.columnCount); | |
1181 if (0 > index || index > count - 1) return; | |
1182 if (cellForeground is null) { | |
1183 if (color is null) return; | |
1184 cellForeground = new Color [count]; | |
1185 } | |
1186 Color oldColor = cellForeground [index]; | |
1187 if (oldColor is color) return; | |
1188 cellForeground [index] = color; | |
1189 if (oldColor !is null && oldColor.equals (color)) return; | |
1190 cached = true; | |
1191 ((NSOutlineView)parent.view).reloadItem_(handle); | |
1192 } | |
1193 | |
1194 /** | |
1195 * Sets the grayed state of the checkbox for this item. This state change | |
1196 * only applies if the Tree was created with the DWT.CHECK style. | |
1197 * | |
1198 * @param grayed the new grayed state of the checkbox | |
1199 * | |
1200 * @exception DWTException <ul> | |
1201 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1202 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1203 * </ul> | |
1204 */ | |
1205 public void setGrayed (bool grayed) { | |
1206 checkWidget (); | |
1207 if ((parent.style & DWT.CHECK) is 0) return; | |
1208 if (this.grayed is grayed) return; | |
1209 this.grayed = grayed; | |
1210 cached = true; | |
1211 ((NSOutlineView)parent.view).reloadItem_(handle); | |
1212 } | |
1213 | |
1214 /** | |
1215 * Sets the image for multiple columns in the tree. | |
1216 * | |
1217 * @param images the array of new images | |
1218 * | |
1219 * @exception IllegalArgumentException <ul> | |
1220 * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li> | |
1221 * <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li> | |
1222 * </ul> | |
1223 * @exception DWTException <ul> | |
1224 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1225 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1226 * </ul> | |
1227 * | |
1228 * @since 3.1 | |
1229 */ | |
1230 public void setImage (Image [] images) { | |
1231 checkWidget (); | |
1232 if (images is null) error (DWT.ERROR_NULL_ARGUMENT); | |
1233 for (int i=0; i<images.length; i++) { | |
1234 setImage (i, images [i]); | |
1235 } | |
1236 } | |
1237 | |
1238 /** | |
1239 * Sets the receiver's image at a column. | |
1240 * | |
1241 * @param index the column index | |
1242 * @param image the new image | |
1243 * | |
1244 * @exception IllegalArgumentException <ul> | |
1245 * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> | |
1246 * </ul> | |
1247 * @exception DWTException <ul> | |
1248 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1249 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1250 * </ul> | |
1251 * | |
1252 * @since 3.1 | |
1253 */ | |
1254 public void setImage (int index, Image image) { | |
1255 checkWidget (); | |
1256 if (image !is null && image.isDisposed ()) { | |
1257 error(DWT.ERROR_INVALID_ARGUMENT); | |
1258 } | |
1259 // if (parent.imageBounds is null && image !is null) { | |
1260 // parent.setItemHeight (image); | |
1261 // } | |
1262 if (index is 0) { | |
1263 if (image !is null && image.type is DWT.ICON) { | |
1264 if (image.equals (this.image)) return; | |
1265 } | |
1266 width = -1; | |
1267 super.setImage (image); | |
1268 } | |
1269 int count = Math.max (1, parent.columnCount); | |
1270 if (0 <= index && index < count) { | |
1271 if (images is null) images = new Image [count]; | |
1272 if (image !is null && image.type is DWT.ICON) { | |
1273 if (image.equals (images [index])) return; | |
1274 } | |
1275 images [index] = image; | |
1276 } | |
1277 // cached = true; | |
1278 // if (index is 0) parent.setScrollWidth (this); | |
1279 ((NSOutlineView)parent.view).reloadItem_(handle); | |
1280 } | |
1281 | |
1282 public void setImage (Image image) { | |
1283 checkWidget (); | |
1284 setImage (0, image); | |
1285 } | |
1286 | |
1287 /** | |
1288 * Sets the number of child items contained in the receiver. | |
1289 * | |
1290 * @param count the number of items | |
1291 * | |
1292 * @exception DWTException <ul> | |
1293 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1294 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1295 * </ul> | |
1296 * | |
1297 * @since 3.2 | |
1298 */ | |
1299 public void setItemCount (int count) { | |
1300 checkWidget (); | |
1301 count = Math.max (0, count); | |
1302 parent.setItemCount (this, count); | |
1303 } | |
1304 | |
1305 /** | |
1306 * Sets the text for multiple columns in the tree. | |
1307 * | |
1308 * @param strings the array of new strings | |
1309 * | |
1310 * @exception IllegalArgumentException <ul> | |
1311 * <li>ERROR_NULL_ARGUMENT - if the text is null</li> | |
1312 * </ul> | |
1313 * @exception DWTException <ul> | |
1314 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1315 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1316 * </ul> | |
1317 * | |
1318 * @since 3.1 | |
1319 */ | |
1320 public void setText (String [] strings) { | |
1321 checkWidget (); | |
1322 if (strings is null) error (DWT.ERROR_NULL_ARGUMENT); | |
1323 for (int i=0; i<strings.length; i++) { | |
1324 String string = strings [i]; | |
1325 if (string !is null) setText (i, string); | |
1326 } | |
1327 } | |
1328 | |
1329 /** | |
1330 * Sets the receiver's text at a column | |
1331 * | |
1332 * @param index the column index | |
1333 * @param string the new text | |
1334 * | |
1335 * @exception IllegalArgumentException <ul> | |
1336 * <li>ERROR_NULL_ARGUMENT - if the text is null</li> | |
1337 * </ul> | |
1338 * @exception DWTException <ul> | |
1339 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
1340 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
1341 * </ul> | |
1342 * | |
1343 * @since 3.1 | |
1344 */ | |
1345 public void setText (int index, String string) { | |
1346 checkWidget (); | |
1347 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | |
1348 if (index is 0) { | |
1349 if (string.equals (text)) return; | |
1350 width = -1; | |
1351 super.setText (string); | |
1352 } | |
1353 int count = Math.max (1, parent.columnCount); | |
1354 if (0 <= index && index < count) { | |
1355 if (strings is null) strings = new String [count]; | |
1356 if (string.equals (strings [index])) return; | |
1357 strings [index] = string; | |
1358 } | |
1359 cached = true; | |
1360 if (index is 0) parent.setScrollWidth (this); | |
1361 ((NSOutlineView)parent.view).reloadItem_(handle); | |
1362 } | |
1363 | |
1364 public void setText (String string) { | |
1365 checkWidget (); | |
1366 setText (0, string); | |
1367 } | |
1368 | |
1369 } |