KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > widgets > Item


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 package org.eclipse.swt.widgets;
12
13
14 import org.eclipse.swt.*;
15 import org.eclipse.swt.graphics.*;
16
17 /**
18  * This class is the abstract superclass of all non-windowed
19  * user interface objects that occur within specific controls.
20  * For example, a tree will contain tree items.
21  * <dl>
22  * <dt><b>Styles:</b></dt>
23  * <dd>(none)</dd>
24  * <dt><b>Events:</b></dt>
25  * <dd>(none)</dd>
26  * </dl>
27  */

28
29 public abstract class Item extends Widget {
30     String JavaDoc text;
31     Image image;
32
33 /**
34  * Constructs a new instance of this class given its parent
35  * and a style value describing its behavior and appearance.
36  * The item is added to the end of the items maintained by its parent.
37  * <p>
38  * The style value is either one of the style constants defined in
39  * class <code>SWT</code> which is applicable to instances of this
40  * class, or must be built by <em>bitwise OR</em>'ing together
41  * (that is, using the <code>int</code> "|" operator) two or more
42  * of those <code>SWT</code> style constants. The class description
43  * lists the style constants that are applicable to the class.
44  * Style bits are also inherited from superclasses.
45  * </p>
46  *
47  * @param parent a widget which will be the parent of the new instance (cannot be null)
48  * @param style the style of item to construct
49  *
50  * @exception IllegalArgumentException <ul>
51  * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
52  * </ul>
53  * @exception SWTException <ul>
54  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
55  * </ul>
56  *
57  * @see SWT
58  * @see Widget#getStyle
59  */

60 public Item (Widget parent, int style) {
61     super (parent, style);
62     text = "";
63 }
64
65 /**
66  * Constructs a new instance of this class given its parent
67  * and a style value describing its behavior and appearance,
68  * and the index at which to place it in the items maintained
69  * by its parent.
70  * <p>
71  * The style value is either one of the style constants defined in
72  * class <code>SWT</code> which is applicable to instances of this
73  * class, or must be built by <em>bitwise OR</em>'ing together
74  * (that is, using the <code>int</code> "|" operator) two or more
75  * of those <code>SWT</code> style constants. The class description
76  * lists the style constants that are applicable to the class.
77  * Style bits are also inherited from superclasses.
78  * </p>
79  *
80  * @param parent a widget which will be the parent of the new instance (cannot be null)
81  * @param style the style of item to construct
82  * @param index the zero-relative index at which to store the receiver in its parent
83  *
84  * @exception IllegalArgumentException <ul>
85  * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
86  * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
87  * </ul>
88  * @exception SWTException <ul>
89  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
90  * </ul>
91  *
92  * @see SWT
93  * @see Widget#getStyle
94  */

95 public Item (Widget parent, int style, int index) {
96     this (parent, style);
97 }
98
99 protected void checkSubclass () {
100     /* Do Nothing - Subclassing is allowed */
101 }
102
103 /**
104  * Returns the receiver's image if it has one, or null
105  * if it does not.
106  *
107  * @return the receiver's image
108  *
109  * @exception SWTException <ul>
110  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
111  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
112  * </ul>
113  */

114 public Image getImage () {
115     checkWidget ();
116     return image;
117 }
118
119 String JavaDoc getNameText () {
120     return getText ();
121 }
122
123 /**
124  * Returns the receiver's text, which will be an empty
125  * string if it has never been set.
126  *
127  * @return the receiver's text
128  *
129  * @exception SWTException <ul>
130  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
131  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
132  * </ul>
133  */

134 public String JavaDoc getText () {
135     checkWidget();
136     return text;
137 }
138
139 void releaseWidget () {
140     super.releaseWidget ();
141     text = null;
142     image = null;
143 }
144
145 /**
146  * Sets the receiver's image to the argument, which may be
147  * null indicating that no image should be displayed.
148  *
149  * @param image the image to display on the receiver (may be null)
150  *
151  * @exception IllegalArgumentException <ul>
152  * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
153  * </ul>
154  * @exception SWTException <ul>
155  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
156  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
157  * </ul>
158  */

159 public void setImage (Image image) {
160     checkWidget ();
161     if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
162     this.image = image;
163 }
164
165 /**
166  * Sets the receiver's text.
167  *
168  * @param string the new text
169  *
170  * @exception IllegalArgumentException <ul>
171  * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
172  * </ul>
173  * @exception SWTException <ul>
174  * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
175  * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
176  * </ul>
177  */

178 public void setText (String JavaDoc string) {
179     checkWidget ();
180     if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
181     text = string;
182 }
183
184 }
185
Popular Tags