com.google.gwt.user.client.ui
Class Widget

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
All Implemented Interfaces:
HasHandlers, EventListener
Direct Known Subclasses:
CellList, CellTable, Composite, FileUpload, FocusWidget, Frame, Hidden, Hyperlink, Image, Label, MenuBar, Panel, Tree

public class Widget
extends UIObject
implements EventListener, HasHandlers

The base class for the majority of user-interface objects. Widget adds support for receiving events from the browser and being added directly to panels.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
Widget()
           
 
Method Summary
 void fireEvent(GwtEvent<?> event)
          Fires the given event to all the appropriate handlers.
 java.lang.Object getLayoutData()
          Gets the panel-defined layout data associated with this widget.
 Widget getParent()
          Gets this widget's parent panel.
 boolean isAttached()
          Determines whether this widget is currently attached to the browser's document (i.e., there is an unbroken chain of widgets between this widget and the underlying browser document).
 void onBrowserEvent(Event event)
          Fired whenever a browser event is received.
 void removeFromParent()
          Removes this widget from its parent widget, if one exists.
 void setLayoutData(java.lang.Object layoutData)
          Sets the panel-defined layout data associated with this widget.
 void sinkEvents(int eventBitsToAdd)
          Overridden to defer the call to super.sinkEvents until the first time this widget is attached to the dom, as a performance enhancement.
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Widget

public Widget()
Method Detail

fireEvent

public void fireEvent(GwtEvent<?> event)
Description copied from interface: HasHandlers
Fires the given event to all the appropriate handlers.

Specified by:
fireEvent in interface HasHandlers
Parameters:
event - the event to be fired

getLayoutData

public java.lang.Object getLayoutData()
Gets the panel-defined layout data associated with this widget.

Returns:
the widget's layout data
See Also:
setLayoutData(java.lang.Object)

getParent

public Widget getParent()
Gets this widget's parent panel.

Returns:
the widget's parent panel

isAttached

public boolean isAttached()
Determines whether this widget is currently attached to the browser's document (i.e., there is an unbroken chain of widgets between this widget and the underlying browser document).

Returns:
true if the widget is attached

onBrowserEvent

public void onBrowserEvent(Event event)
Description copied from interface: EventListener
Fired whenever a browser event is received.

Specified by:
onBrowserEvent in interface EventListener
Parameters:
event - the event received

removeFromParent

public void removeFromParent()
Removes this widget from its parent widget, if one exists.

If it has no parent, this method does nothing. If it is a "root" widget (meaning it's been added to the detach list via RootPanel.detachOnWindowClose(Widget)), it will be removed from the detached immediately. This makes it possible for Composites and Panels to adopt root widgets.

Throws:
java.lang.IllegalStateException - if this widget's parent does not support removal (e.g. Composite)

setLayoutData

public void setLayoutData(java.lang.Object layoutData)
Sets the panel-defined layout data associated with this widget. Only the panel that currently contains a widget should ever set this value. It serves as a place to store layout bookkeeping data associated with a widget.

Parameters:
layoutData - the widget's layout data

sinkEvents

public void sinkEvents(int eventBitsToAdd)
Overridden to defer the call to super.sinkEvents until the first time this widget is attached to the dom, as a performance enhancement. Subclasses wishing to customize sinkEvents can preserve this deferred sink behavior by putting their implementation behind a check of isOrWasAttached():
 @Override
 public void sinkEvents(int eventBitsToAdd) {
   if (isOrWasAttached()) {
     /* customized sink code goes here */
   } else {
     super.sinkEvents(eventBitsToAdd);
  }
} 

Overrides:
sinkEvents in class UIObject
Parameters:
eventBitsToAdd - a bitfield representing the set of events to be added to this element's event set
See Also:
Event