org.eclipse.swt.widgets
Class Widget

java.lang.Object
  |
  +--org.eclipse.swt.widgets.Widget
Direct Known Subclasses:
Caret, Control, DragSource, DropTarget, Item, Menu, ScrollBar, Tracker

public abstract class Widget
extends Object

Unsafe: This class is the abstract superclass of all user interface objects. Widgets are created, disposed and issue notification to listeners when events occur which affect them.

Styles:
(none)
Events:
Dispose

IMPORTANT: This class is intended to be subclassed only within the SWT implementation. However, it has not been marked final to allow those outside of the SWT development team to implement patched versions of the class in order to get around specific limitations in advance of when those limitations can be addressed by the team. Any class built using subclassing to access the internals of this class will likely fail to compile or run between releases and may be strongly platform specific. Subclassing should not be attempted without an intimate and detailed understanding of the workings of the hierarchy. No support is provided for user-written classes which are implemented as subclasses of this class.

See Also:
checkSubclass()

Field Summary
(package private) static int CANVAS
           
(package private) static int COMCTL32_MAJOR
           
(package private) static int COMCTL32_MINOR
           
(package private)  Object data
           
(package private) static int DEFAULT_HEIGHT
           
(package private) static int DEFAULT_WIDTH
           
(package private) static int DISABLED
           
(package private) static int DISPOSED
           
(package private)  EventTable eventTable
           
(package private) static int HIDDEN
           
(package private)  String[] keys
           
(package private) static int MAJOR
           
(package private) static int MINOR
           
(package private) static char Mnemonic
           
(package private)  int state
           
(package private)  int style
           
(package private)  Object[] values
           
 
Constructor Summary
(package private) Widget()
          Prevents uninitialized instances from being created outside the package.
  Widget(Widget parent, int style)
          Enabled: Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
 
Method Summary
 void addDisposeListener(DisposeListener listener)
          Enabled: Adds the listener to the collection of listeners who will be notifed when the widget is disposed.
 void addListener(int eventType, Listener listener)
          Enabled: Adds the listener to the collection of listeners who will be notifed when an event of the given type occurs.
(package private) static int checkBits(int style, int int0, int int1, int int2, int int3, int int4, int int5)
          Returns a style with exactly one style bit set out of the specified set of exclusive style bits.
(package private)  void checkOrientation(Widget parent)
           
(package private)  void checkParent(Widget parent)
          Throws an exception if the specified widget can not be used as a parent for the receiver.
protected  void checkSubclass()
          Checks that this class can be subclassed.
protected  void checkWidget()
          Throws an SWTException if the receiver can not be accessed by the caller.
(package private)  void destroyWidget()
          Destroys the widget in the operating system and releases the widget's handle.
 void dispose()
          Enabled: Disposes of the operating system resources associated with the receiver and all its descendents.
(package private)  void error(int code)
          Does whatever widget specific cleanup is required, and then uses the code in SWTError.error to handle the error.
(package private)  boolean filters(int eventType)
           
 Object getData()
          Suppressed: Returns the application defined widget data associated with the receiver, or null if it has not been set.
 Object getData(String key)
          Suppressed: Returns the application defined property of the receiver with the specified name, or null if it has not been set.
abstract  Display getDisplay()
          Suppressed: Returns the Display that is associated with the receiver.
(package private)  String getName()
          Returns the name of the widget.
(package private)  String getNameText()
           
 int getStyle()
          Enabled: Returns the receiver's style information.
(package private)  boolean hooks(int eventType)
           
 boolean isDisposed()
          Enabled: Returns true if the widget has been disposed, and false otherwise.
protected  boolean isListening(int eventType)
          Returns true if there are any listeners for the specified event type associated with the receiver, and false otherwise.
(package private)  boolean isValidSubclass()
           
(package private)  boolean isValidThread()
           
(package private)  char mbcsToWcs(int ch)
           
(package private)  char mbcsToWcs(int ch, int codePage)
           
 void notifyListeners(int eventType, Event event)
          Suppressed: Notifies all of the receiver's listeners for events of the given type that one such event has occurred by invoking their handleEvent() method.
(package private)  void postEvent(int eventType)
           
(package private)  void postEvent(int eventType, Event event)
           
(package private)  void releaseChild()
           
(package private)  void releaseHandle()
           
(package private)  void releaseResources()
           
(package private)  void releaseWidget()
           
 void removeDisposeListener(DisposeListener listener)
          Enabled: Removes the listener from the collection of listeners who will be notifed when the widget is disposed.
 void removeListener(int eventType, Listener listener)
          Enabled: Removes the listener from the collection of listeners who will be notifed when an event of the given type occurs.
protected  void removeListener(int eventType, org.eclipse.swt.internal.SWTEventListener listener)
          Removes the listener from the collection of listeners who will be notifed when an event of the given type occurs.
(package private)  void sendEvent(Event event)
           
(package private)  void sendEvent(int eventType)
           
(package private)  void sendEvent(int eventType, Event event)
           
(package private)  void sendEvent(int eventType, Event event, boolean send)
           
 void setData(Object data)
          Suppressed: Sets the application defined widget data associated with the receiver to be the argument.
 void setData(String key, Object value)
          Suppressed: Sets the application defined property of the receiver with the specified name to the given value.
(package private)  boolean setInputState(Event event, int type)
           
(package private)  boolean setKeyState(Event event, int type)
           
 String toString()
          Suppressed: Returns a string containing a concise, human-readable description of the receiver.
(package private)  int wcsToMbcs(char ch)
           
(package private)  int wcsToMbcs(char ch, int codePage)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

style

int style

state

int state

eventTable

EventTable eventTable

data

Object data

keys

String[] keys

values

Object[] values

DISABLED

static final int DISABLED

HIDDEN

static final int HIDDEN

DISPOSED

static final int DISPOSED

CANVAS

static final int CANVAS

DEFAULT_WIDTH

static final int DEFAULT_WIDTH

DEFAULT_HEIGHT

static final int DEFAULT_HEIGHT

Mnemonic

static final char Mnemonic

MAJOR

static final int MAJOR

MINOR

static final int MINOR

COMCTL32_MAJOR

static final int COMCTL32_MAJOR

COMCTL32_MINOR

static final int COMCTL32_MINOR
Constructor Detail

Widget

Widget()
Prevents uninitialized instances from being created outside the package.


Widget

public Widget(Widget parent,
              int style)
Enabled: Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

Parameters:
parent - a widget which will be the parent of the new instance (cannot be null)
style - the style of widget to construct
See Also:
SWT, checkSubclass(), getStyle()
Method Detail

addListener

public void addListener(int eventType,
                        Listener listener)
Enabled: Adds the listener to the collection of listeners who will be notifed when an event of the given type occurs. When the event does occur in the widget, the listener is notified by sending it the handleEvent() message.

Parameters:
eventType - the type of event to listen for
listener - the listener which should be notified when the event occurs
See Also:
Listener, removeListener(int, org.eclipse.swt.widgets.Listener)

addDisposeListener

public void addDisposeListener(DisposeListener listener)
Enabled: Adds the listener to the collection of listeners who will be notifed when the widget is disposed. When the widget is disposed, the listener is notified by sending it the widgetDisposed() message.

Parameters:
listener - the listener which should be notified when the receiver is disposed
See Also:
DisposeListener, removeDisposeListener(org.eclipse.swt.events.DisposeListener)

checkBits

static int checkBits(int style,
                     int int0,
                     int int1,
                     int int2,
                     int int3,
                     int int4,
                     int int5)
Returns a style with exactly one style bit set out of the specified set of exclusive style bits. All other possible bits are cleared when the first matching bit is found. Bits that are not part of the possible set are untouched.

Parameters:
style - the original style bits
int0 - the 0th possible style bit
int1 - the 1st possible style bit
int2 - the 2nd possible style bit
int3 - the 3rd possible style bit
int4 - the 4th possible style bit
int5 - the 5th possible style bit
Returns:
the new style bits

checkOrientation

void checkOrientation(Widget parent)

checkParent

void checkParent(Widget parent)
Throws an exception if the specified widget can not be used as a parent for the receiver.


checkSubclass

protected void checkSubclass()
Checks that this class can be subclassed.

The SWT class library is intended to be subclassed only at specific, controlled points (most notably, Composite and Canvas when implementing new widgets). This method enforces this rule unless it is overridden.

IMPORTANT: By providing an implementation of this method that allows a subclass of a class which does not normally allow subclassing to be created, the implementer agrees to be fully responsible for the fact that any such subclass will likely fail between SWT releases and will be strongly platform specific. No support is provided for user-written classes which are implemented in this fashion.

The ability to subclass outside of the allowed SWT classes is intended purely to enable those not on the SWT development team to implement patches in order to get around specific limitations in advance of when those limitations can be addressed by the team. Subclassing should not be attempted without an intimate and detailed understanding of the hierarchy.


checkWidget

protected void checkWidget()
Throws an SWTException if the receiver can not be accessed by the caller. This may include both checks on the state of the receiver and more generally on the entire execution context. This method should be called by widget implementors to enforce the standard SWT invariants.

Currently, it is an error to invoke any method (other than isDisposed()) on a widget that has had its dispose() method called. It is also an error to call widget methods from any thread that is different from the thread that created the widget.

In future releases of SWT, there may be more or fewer error checks and exceptions may be thrown for different reasons.


destroyWidget

void destroyWidget()
Destroys the widget in the operating system and releases the widget's handle. If the widget does not have a handle, this method may hide the widget, mark the widget as destroyed or do nothing, depending on the widget.

When a widget is destroyed in the operating system, its descendents are also destroyed by the operating system. This means that it is only necessary to call destroyWidget on the root of the widget tree.

This method is called after releaseWidget.

See Also:
dispose(), releaseChild(), releaseWidget(), releaseHandle()

dispose

public void dispose()
Enabled: Disposes of the operating system resources associated with the receiver and all its descendents. After this method has been invoked, the receiver and all descendents will answer true when sent the message isDisposed(). Any internal connections between the widgets in the tree will have been removed to facilitate garbage collection.

NOTE: This method is not called recursively on the descendents of the receiver. This means that, widget implementers can not detect when a widget is being disposed of by re-implementing this method, but should instead listen for the Dispose event.

See Also:
addDisposeListener(org.eclipse.swt.events.DisposeListener), removeDisposeListener(org.eclipse.swt.events.DisposeListener), checkWidget()

error

void error(int code)
Does whatever widget specific cleanup is required, and then uses the code in SWTError.error to handle the error.

Parameters:
code - the descriptive error code
See Also:
SWTError#error

filters

boolean filters(int eventType)

getData

public Object getData()
Suppressed: Returns the application defined widget data associated with the receiver, or null if it has not been set. The widget data is a single, unnamed field that is stored with every widget.

Applications may put arbitrary objects in this field. If the object stored in the widget data needs to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.

Returns:
the widget data
See Also:
setData(java.lang.Object)

getData

public Object getData(String key)
Suppressed: Returns the application defined property of the receiver with the specified name, or null if it has not been set.

Applications may have associated arbitrary objects with the receiver in this fashion. If the objects stored in the properties need to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.

Parameters:
key - the name of the property
Returns:
the value of the property or null if it has not been set
See Also:
setData(java.lang.Object)

getDisplay

public abstract Display getDisplay()
Suppressed: Returns the Display that is associated with the receiver.

A widget's display is either provided when it is created (for example, top level Shells) or is the same as its parent's display.

Returns:
the receiver's display

getName

String getName()
Returns the name of the widget. This is the name of the class without the package name.

Returns:
the name of the widget

getNameText

String getNameText()

getStyle

public int getStyle()
Enabled: Returns the receiver's style information.

Note that the value which is returned by this method may not match the value which was provided to the constructor when the receiver was created. This can occur when the underlying operating system does not support a particular combination of requested styles. For example, if the platform widget used to implement a particular SWT widget always has scroll bars, the result of calling this method would always have the SWT.H_SCROLL and SWT.V_SCROLL bits set.

Returns:
the style bits

hooks

boolean hooks(int eventType)

isDisposed

public boolean isDisposed()
Enabled: Returns true if the widget has been disposed, and false otherwise.

This method gets the dispose state for the widget. When a widget has been disposed, it is an error to invoke any other method using the widget.

Returns:
true when the widget is disposed and false otherwise

isListening

protected boolean isListening(int eventType)
Returns true if there are any listeners for the specified event type associated with the receiver, and false otherwise.

Parameters:
eventType - the type of event
Returns:
true if the event is hooked

isValidSubclass

boolean isValidSubclass()

isValidThread

boolean isValidThread()

mbcsToWcs

char mbcsToWcs(int ch)

mbcsToWcs

char mbcsToWcs(int ch,
               int codePage)

notifyListeners

public void notifyListeners(int eventType,
                            Event event)
Suppressed: Notifies all of the receiver's listeners for events of the given type that one such event has occurred by invoking their handleEvent() method.

Parameters:
eventType - the type of event which has occurred
event - the event data

postEvent

void postEvent(int eventType)

postEvent

void postEvent(int eventType,
               Event event)

releaseChild

void releaseChild()

releaseHandle

void releaseHandle()

releaseResources

void releaseResources()

releaseWidget

void releaseWidget()

removeListener

public void removeListener(int eventType,
                           Listener listener)
Enabled: Removes the listener from the collection of listeners who will be notifed when an event of the given type occurs.

Parameters:
eventType - the type of event to listen for
listener - the listener which should no longer be notified when the event occurs
See Also:
Listener, addListener(int, org.eclipse.swt.widgets.Listener)

removeListener

protected void removeListener(int eventType,
                              org.eclipse.swt.internal.SWTEventListener listener)
Removes the listener from the collection of listeners who will be notifed when an event of the given type occurs.

IMPORTANT: This method is not part of the SWT public API. It is marked public only so that it can be shared within the packages provided by SWT. It should never be referenced from application code.

Parameters:
eventType - the type of event to listen for
listener - the listener which should no longer be notified when the event occurs
See Also:
Listener, addListener(int, org.eclipse.swt.widgets.Listener)

removeDisposeListener

public void removeDisposeListener(DisposeListener listener)
Enabled: Removes the listener from the collection of listeners who will be notifed when the widget is disposed.

Parameters:
listener - the listener which should no longer be notified when the receiver is disposed
See Also:
DisposeListener, addDisposeListener(org.eclipse.swt.events.DisposeListener)

sendEvent

void sendEvent(Event event)

sendEvent

void sendEvent(int eventType)

sendEvent

void sendEvent(int eventType,
               Event event)

sendEvent

void sendEvent(int eventType,
               Event event,
               boolean send)

setData

public void setData(Object data)
Suppressed: Sets the application defined widget data associated with the receiver to be the argument. The widget data is a single, unnamed field that is stored with every widget.

Applications may put arbitrary objects in this field. If the object stored in the widget data needs to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.

Parameters:
data - the widget data

setData

public void setData(String key,
                    Object value)
Suppressed: Sets the application defined property of the receiver with the specified name to the given value.

Applications may associate arbitrary objects with the receiver in this fashion. If the objects stored in the properties need to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.

Parameters:
key - the name of the property
value - the new value for the property
See Also:
getData()

setInputState

boolean setInputState(Event event,
                      int type)

setKeyState

boolean setKeyState(Event event,
                    int type)

toString

public String toString()
Suppressed: Returns a string containing a concise, human-readable description of the receiver.

Overrides:
toString in class Object
Returns:
a string representation of the receiver

wcsToMbcs

int wcsToMbcs(char ch,
              int codePage)

wcsToMbcs

int wcsToMbcs(char ch)


comments?