comparison dwt/widgets/Item.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 2952d5604c0a
comparison
equal deleted inserted replaced
-1:000000000000 0:380af2bdd8e5
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 *******************************************************************************/
11 module dwt.widgets.Item;
12
13 import dwt.dwthelper.utils;
14
15
16 import dwt.DWT;
17 import dwt.DWTException;
18 import dwt.graphics.Image;
19
20 /**
21 * This class is the abstract superclass of all non-windowed
22 * user interface objects that occur within specific controls.
23 * For example, a tree will contain tree items.
24 * <dl>
25 * <dt><b>Styles:</b></dt>
26 * <dd>(none)</dd>
27 * <dt><b>Events:</b></dt>
28 * <dd>(none)</dd>
29 * </dl>
30 */
31
32 public abstract class Item extends Widget {
33 String text;
34 Image image;
35
36 /**
37 * Constructs a new instance of this class given its parent
38 * and a style value describing its behavior and appearance.
39 * The item is added to the end of the items maintained by its parent.
40 * <p>
41 * The style value is either one of the style constants defined in
42 * class <code>DWT</code> which is applicable to instances of this
43 * class, or must be built by <em>bitwise OR</em>'ing together
44 * (that is, using the <code>int</code> "|" operator) two or more
45 * of those <code>DWT</code> style constants. The class description
46 * lists the style constants that are applicable to the class.
47 * Style bits are also inherited from superclasses.
48 * </p>
49 *
50 * @param parent a widget which will be the parent of the new instance (cannot be null)
51 * @param style the style of item to construct
52 *
53 * @exception IllegalArgumentException <ul>
54 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
55 * </ul>
56 * @exception DWTException <ul>
57 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
58 * </ul>
59 *
60 * @see DWT
61 * @see Widget#getStyle
62 */
63 public Item (Widget parent, int style) {
64 super (parent, style);
65 text = "";
66 }
67
68 /**
69 * Constructs a new instance of this class given its parent
70 * and a style value describing its behavior and appearance,
71 * and the index at which to place it in the items maintained
72 * by its parent.
73 * <p>
74 * The style value is either one of the style constants defined in
75 * class <code>DWT</code> which is applicable to instances of this
76 * class, or must be built by <em>bitwise OR</em>'ing together
77 * (that is, using the <code>int</code> "|" operator) two or more
78 * of those <code>DWT</code> style constants. The class description
79 * lists the style constants that are applicable to the class.
80 * Style bits are also inherited from superclasses.
81 * </p>
82 *
83 * @param parent a widget which will be the parent of the new instance (cannot be null)
84 * @param style the style of item to construct
85 * @param index the zero-relative index at which to store the receiver in its parent
86 *
87 * @exception IllegalArgumentException <ul>
88 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
89 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
90 * </ul>
91 * @exception DWTException <ul>
92 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
93 * </ul>
94 *
95 * @see DWT
96 * @see Widget#getStyle
97 */
98 public Item (Widget parent, int style, int index) {
99 this (parent, style);
100 }
101
102 protected void checkSubclass () {
103 /* Do Nothing - Subclassing is allowed */
104 }
105
106 /**
107 * Returns the receiver's image if it has one, or null
108 * if it does not.
109 *
110 * @return the receiver's image
111 *
112 * @exception DWTException <ul>
113 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
114 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
115 * </ul>
116 */
117 public Image getImage () {
118 checkWidget ();
119 return image;
120 }
121
122 String getNameText () {
123 return getText ();
124 }
125
126 /**
127 * Returns the receiver's text, which will be an empty
128 * string if it has never been set.
129 *
130 * @return the receiver's text
131 *
132 * @exception DWTException <ul>
133 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
134 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
135 * </ul>
136 */
137 public String getText () {
138 checkWidget();
139 return text;
140 }
141
142 void releaseWidget () {
143 super.releaseWidget ();
144 text = null;
145 image = null;
146 }
147
148 /**
149 * Sets the receiver's image to the argument, which may be
150 * null indicating that no image should be displayed.
151 *
152 * @param image the image to display on the receiver (may be null)
153 *
154 * @exception IllegalArgumentException <ul>
155 * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
156 * </ul>
157 * @exception DWTException <ul>
158 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
159 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
160 * </ul>
161 */
162 public void setImage (Image image) {
163 checkWidget ();
164 if (image !is null && image.isDisposed()) error(DWT.ERROR_INVALID_ARGUMENT);
165 this.image = image;
166 }
167
168 /**
169 * Sets the receiver's text.
170 *
171 * @param string the new text
172 *
173 * @exception IllegalArgumentException <ul>
174 * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
175 * </ul>
176 * @exception DWTException <ul>
177 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
178 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
179 * </ul>
180 */
181 public void setText (String string) {
182 checkWidget ();
183 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
184 text = string;
185 }
186
187 }