001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.swt.widgets;
011:
012: import org.eclipse.swt.*;
013: import org.eclipse.swt.graphics.*;
014:
015: /**
016: * This class is the abstract superclass of all non-windowed
017: * user interface objects that occur within specific controls.
018: * For example, a tree will contain tree items.
019: * <dl>
020: * <dt><b>Styles:</b></dt>
021: * <dd>(none)</dd>
022: * <dt><b>Events:</b></dt>
023: * <dd>(none)</dd>
024: * </dl>
025: */
026:
027: public abstract class Item extends Widget {
028: String text;
029: Image image;
030:
031: /**
032: * Constructs a new instance of this class given its parent
033: * and a style value describing its behavior and appearance.
034: * The item is added to the end of the items maintained by its parent.
035: * <p>
036: * The style value is either one of the style constants defined in
037: * class <code>SWT</code> which is applicable to instances of this
038: * class, or must be built by <em>bitwise OR</em>'ing together
039: * (that is, using the <code>int</code> "|" operator) two or more
040: * of those <code>SWT</code> style constants. The class description
041: * lists the style constants that are applicable to the class.
042: * Style bits are also inherited from superclasses.
043: * </p>
044: *
045: * @param parent a widget which will be the parent of the new instance (cannot be null)
046: * @param style the style of item to construct
047: *
048: * @exception IllegalArgumentException <ul>
049: * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
050: * </ul>
051: * @exception SWTException <ul>
052: * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
053: * </ul>
054: *
055: * @see SWT
056: * @see Widget#getStyle
057: */
058: public Item(Widget parent, int style) {
059: super (parent, style);
060: text = "";
061: }
062:
063: /**
064: * Constructs a new instance of this class given its parent
065: * and a style value describing its behavior and appearance,
066: * and the index at which to place it in the items maintained
067: * by its parent.
068: * <p>
069: * The style value is either one of the style constants defined in
070: * class <code>SWT</code> which is applicable to instances of this
071: * class, or must be built by <em>bitwise OR</em>'ing together
072: * (that is, using the <code>int</code> "|" operator) two or more
073: * of those <code>SWT</code> style constants. The class description
074: * lists the style constants that are applicable to the class.
075: * Style bits are also inherited from superclasses.
076: * </p>
077: *
078: * @param parent a widget which will be the parent of the new instance (cannot be null)
079: * @param style the style of item to construct
080: * @param index the zero-relative index at which to store the receiver in its parent
081: *
082: * @exception IllegalArgumentException <ul>
083: * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
084: * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li>
085: * </ul>
086: * @exception SWTException <ul>
087: * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
088: * </ul>
089: *
090: * @see SWT
091: * @see Widget#getStyle
092: */
093: public Item(Widget parent, int style, int index) {
094: this (parent, style);
095: }
096:
097: protected void checkSubclass() {
098: /* Do Nothing - Subclassing is allowed */
099: }
100:
101: /**
102: * Returns the receiver's image if it has one, or null
103: * if it does not.
104: *
105: * @return the receiver's image
106: *
107: * @exception SWTException <ul>
108: * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
109: * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
110: * </ul>
111: */
112: public Image getImage() {
113: checkWidget();
114: return image;
115: }
116:
117: String getNameText() {
118: return getText();
119: }
120:
121: /**
122: * Returns the receiver's text, which will be an empty
123: * string if it has never been set.
124: *
125: * @return the receiver's text
126: *
127: * @exception SWTException <ul>
128: * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
129: * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
130: * </ul>
131: */
132: public String getText() {
133: checkWidget();
134: return text;
135: }
136:
137: void releaseWidget() {
138: super .releaseWidget();
139: text = null;
140: image = null;
141: }
142:
143: /**
144: * Sets the receiver's image to the argument, which may be
145: * null indicating that no image should be displayed.
146: *
147: * @param image the image to display on the receiver (may be null)
148: *
149: * @exception IllegalArgumentException <ul>
150: * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
151: * </ul>
152: * @exception SWTException <ul>
153: * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
154: * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
155: * </ul>
156: */
157: public void setImage(Image image) {
158: checkWidget();
159: if (image != null && image.isDisposed())
160: error(SWT.ERROR_INVALID_ARGUMENT);
161: this .image = image;
162: }
163:
164: /**
165: * Sets the receiver's text.
166: *
167: * @param string the new text
168: *
169: * @exception IllegalArgumentException <ul>
170: * <li>ERROR_NULL_ARGUMENT - if the text is null</li>
171: * </ul>
172: * @exception SWTException <ul>
173: * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
174: * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
175: * </ul>
176: */
177: public void setText(String string) {
178: checkWidget();
179: if (string == null)
180: error(SWT.ERROR_NULL_ARGUMENT);
181: text = string;
182: }
183:
184: }
|