Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Eclipse Rich Ajax Platform
Release 1.2

org.eclipse.swt.widgets
Class Widget


java.lang.Object
  extended by
org.eclipse.swt.widgets.Widget
All Implemented Interfaces:
Adaptable
Direct Known Subclasses:
Control, Item, Menu, ScrollBar

public abstract class Widget
extends Object
implements Adaptable

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.

Even though this class implements Adaptable this interface is not part of the RWT public API. It is only meant to be shared within the packages provided by RWT and should never be accessed from application code.

Since:
1.0
See Also:
checkSubclass()

Constructor Summary
Widget ( Widget parent, int style)
          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)
          Adds the listener to the collection of listeners who will be notified when the widget is disposed.
 void addListener (int eventType, Listener listener)
          Adds the listener to the collection of listeners who will be notified when an event of the given type occurs.
protected  void checkSubclass ()
           
protected  void checkWidget ()
          Throws an SWTException if the receiver can not be accessed by the caller.
 void dispose ()
          Disposes of the operating system resources associated with the receiver and all its descendents.
  Object getAdapter ( Class adapter)
          Implementation of the Adaptable interface.
  Object getData ()
          Returns the application defined widget data associated with the receiver, or null if it has not been set.
  Object getData ( String key)
          Returns the application defined property of the receiver with the specified name, or null if it has not been set.
  Display getDisplay ()
          Returns the Display that is associated with the receiver.
 int getStyle ()
          Returns the receiver's style information.
 boolean isDisposed ()
          Returns true if the widget has been disposed, and false otherwise.
 void notifyListeners (int eventType, Event event)
          Notifies all of the receiver's listeners for events of the given type that one such event has occurred by invoking their handleEvent() method.
 void removeDisposeListener ( DisposeListener listener)
          Removes the listener from the collection of listeners who will be notified when the widget is disposed.
 void removeListener (int eventType, Listener listener)
          Removes the listener from the collection of listeners who will be notified when an event of the given type occurs.
 void setData ( Object data)
          Sets the application defined widget data associated with the receiver to be the argument.
 void setData ( String key, Object value)
          Sets the application defined property of the receiver with the specified name to the given value.
  String toString ()
          Returns a string containing a concise, human-readable description of the receiver.
 
Methods inherited from class java.lang. Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Widget

public Widget(
Widget parent,
              int style)
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
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the parent is null
  • ERROR_INVALID_ARGUMENT - if the parent is disposed
SWTException -
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
  • ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
See Also:
SWT, checkSubclass(), getStyle()
Method Detail

getAdapter

public 
Object getAdapter(
Class adapter)
Implementation of the Adaptable interface.

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

Specified by:
getAdapter in interface Adaptable
Parameters:
adapter - the lookup class
Returns:
a object castable to the given class or null if there is no adapter associated with the given class.

getData

public 
Object getData()
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
Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - when the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread
See Also:
setData(Object)

setData

public void setData(
Object data)
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
Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - when the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread
See Also:
getData()

getData

public 
Object getData(
String key)
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
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the key is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
See Also:
setData(String, Object)

setData

public void setData(
String key,
                    
Object value)
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
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the key is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
See Also:
getData(String)

getDisplay

public 
Display getDisplay()
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
Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed

getStyle

public int getStyle()
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
Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver

addDisposeListener

public void addDisposeListener(
DisposeListener listener)
Adds the listener to the collection of listeners who will be notified 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
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
See Also:
DisposeListener, removeDisposeListener(org.eclipse.swt.events.DisposeListener)

removeDisposeListener

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

Parameters:
listener - the listener which should no longer be notified when the receiver is disposed
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
See Also:
DisposeListener, addDisposeListener(org.eclipse.swt.events.DisposeListener)

addListener

public void addListener(int eventType,
                        
Listener listener)
Adds the listener to the collection of listeners who will be notified 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. The event type is one of the event constants defined in class SWT.

Parameters:
eventType - the type of event to listen for
listener - the listener which should be notified when the event occurs
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
See Also:
Listener, SWT, removeListener(int, org.eclipse.swt.widgets.Listener), notifyListeners(int, org.eclipse.swt.widgets.Event)

removeListener

public void removeListener(int eventType,
                           
Listener listener)
Removes the listener from the collection of listeners who will be notified when an event of the given type occurs. The event type is one of the event constants defined in class SWT.

Parameters:
eventType - the type of event to listen for
listener - the listener which should no longer be notified when the event occurs
Throws:
IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
See Also:
Listener, SWT, addListener(int, org.eclipse.swt.widgets.Listener), notifyListeners(int, org.eclipse.swt.widgets.Event)

notifyListeners

public void notifyListeners(int eventType,
                            
Event event)
Notifies all of the receiver's listeners for events of the given type that one such event has occurred by invoking their handleEvent() method. The event type is one of the event constants defined in class SWT.

Parameters:
eventType - the type of event which has occurred
event - the event data
Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
Since:
1.2
See Also:
SWT, addListener(int, org.eclipse.swt.widgets.Listener), #getListeners(int), removeListener(int, Listener)

toString

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

Returns:
a string representation of the receiver

dispose

public void dispose()
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.

Throws:
SWTException -
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
See Also:
addDisposeListener(org.eclipse.swt.events.DisposeListener), removeDisposeListener(org.eclipse.swt.events.DisposeListener), checkWidget()

isDisposed

public boolean isDisposed()
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

checkSubclass

protected void checkSubclass()

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.

Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver

Eclipse Rich Ajax Platform
Release 1.2

Copyright (c) Innoopract Informationssysteme GmbH and others 2002, 2008. All rights reserved.


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire