|
GWT 2.7.0 | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.gwt.user.client.ui.UIObject com.google.gwt.user.client.ui.Widget
public class Widget
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 | |
---|---|
(package private) int |
eventsToSink
A bit-map of the events that should be sunk when the widget is attached to the DOM. |
Fields inherited from class com.google.gwt.user.client.ui.UIObject |
---|
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR |
Constructor Summary | |
---|---|
Widget()
|
Method Summary | ||
---|---|---|
HandlerRegistration |
addAttachHandler(AttachEvent.Handler handler)
Adds an AttachEvent handler. |
|
|
addBitlessDomHandler(H handler,
DomEvent.Type<H> type)
For browsers which do not leak, adds a native event handler to the widget. |
|
|
addDomHandler(H handler,
DomEvent.Type<H> type)
Adds a native event handler to the widget and sinks the corresponding native event. |
|
|
addHandler(H handler,
GwtEvent.Type<H> type)
Adds this handler to the widget. |
|
Widget |
asWidget()
Returns the Widget aspect of the receiver. |
|
static Widget |
asWidgetOrNull(IsWidget w)
This convenience method makes a null-safe call to IsWidget.asWidget() . |
|
protected HandlerManager |
createHandlerManager()
Creates the HandlerManager used by this Widget. |
|
protected void |
delegateEvent(Widget target,
GwtEvent<?> event)
Fires an event on a child widget. |
|
protected void |
doAttachChildren()
If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and call onAttach() for each of its
child widgets. |
|
protected void |
doDetachChildren()
If a widget contains one or more child widgets that are not in the logical widget hierarchy (the child is physically connected only on the DOM level), it must override this method and call onDetach() for each of its
child widgets. |
|
(package private) HandlerManager |
ensureHandlers()
Ensures the existence of the handler manager. |
|
void |
fireEvent(GwtEvent<?> event)
Fires the given event to the handlers listening to the event's type. |
|
protected int |
getHandlerCount(GwtEvent.Type<?> type)
Gets the number of handlers listening to the event type. |
|
(package private) HandlerManager |
getHandlerManager()
|
|
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). |
|
protected boolean |
isOrWasAttached()
Has this widget ever been attached? |
|
protected void |
onAttach()
This method is called when a widget is attached to the browser's document. |
|
void |
onBrowserEvent(Event event)
Fired whenever a browser event is received. |
|
protected void |
onDetach()
This method is called when a widget is detached from the browser's document. |
|
protected void |
onLoad()
This method is called immediately after a widget becomes attached to the browser's document. |
|
protected void |
onUnload()
This method is called immediately before a widget will be detached from the browser's document. |
|
void |
removeFromParent()
Removes this widget from its parent widget, if one exists. |
|
(package private) void |
replaceElement(Element elem)
Replaces this object's browser element. |
|
void |
setLayoutData(java.lang.Object layoutData)
Sets the panel-defined layout data associated with this widget. |
|
(package private) void |
setParent(Widget parent)
Sets this widget's parent. |
|
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. |
|
void |
unsinkEvents(int eventBitsToRemove)
Removes a set of events from this object's event list. |
Methods inherited from class com.google.gwt.user.client.ui.UIObject |
---|
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
int eventsToSink
Package protected to allow Composite to see it.
Constructor Detail |
---|
public Widget()
Method Detail |
---|
public static Widget asWidgetOrNull(IsWidget w)
IsWidget.asWidget()
.
null
if w is nullpublic HandlerRegistration addAttachHandler(AttachEvent.Handler handler)
HasAttachHandlers
AttachEvent
handler.
addAttachHandler
in interface HasAttachHandlers
handler
- the handler
public final <H extends EventHandler> HandlerRegistration addBitlessDomHandler(H handler, DomEvent.Type<H> type)
addDomHandler(EventHandler, com.google.gwt.event.dom.client.DomEvent.Type)
implementation, there is no need to attach the widget to the DOM in order
to cause the event handlers to be attached.
H
- the type of handler to addtype
- the event keyhandler
- the handler
HandlerRegistration
used to remove the handlerpublic final <H extends EventHandler> HandlerRegistration addDomHandler(H handler, DomEvent.Type<H> type)
H
- the type of handler to addtype
- the event keyhandler
- the handler
HandlerRegistration
used to remove the handlerpublic final <H extends EventHandler> HandlerRegistration addHandler(H handler, GwtEvent.Type<H> type)
H
- the type of handler to addtype
- the event typehandler
- the handler
HandlerRegistration
used to remove the handlerpublic Widget asWidget()
IsWidget
Widget
aspect of the receiver.
asWidget
in interface IsWidget
public void fireEvent(GwtEvent<?> event)
HasHandlers
Any exceptions thrown by handlers will be bundled into a
UmbrellaException
and then re-thrown after all handlers have
completed. An exception thrown by a handler will not prevent other handlers
from executing.
fireEvent
in interface HasHandlers
event
- the eventpublic java.lang.Object getLayoutData()
setLayoutData(java.lang.Object)
public Widget getParent()
public boolean isAttached()
isAttached
in interface HasAttachHandlers
true
if the widget is attachedpublic void onBrowserEvent(Event event)
EventListener
onBrowserEvent
in interface EventListener
event
- the event receivedpublic void removeFromParent()
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.
java.lang.IllegalStateException
- if this widget's parent does not support
removal (e.g. Composite
)public void setLayoutData(java.lang.Object layoutData)
layoutData
- the widget's layout datapublic void sinkEvents(int eventBitsToAdd)
isOrWasAttached()
:
@Override public void sinkEvents(int eventBitsToAdd) { if (isOrWasAttached()) { /* customized sink code goes here */ } else { super.sinkEvents(eventBitsToAdd); } }
sinkEvents
in class UIObject
eventBitsToAdd
- a bitfield representing the set of events to be added
to this element's event setEvent
public void unsinkEvents(int eventBitsToRemove)
UIObject
unsinkEvents
in class UIObject
eventBitsToRemove
- a bitfield representing the set of events to be
removed from this element's event setUIObject.sinkEvents(int)
,
Event
protected HandlerManager createHandlerManager()
HandlerManager
used by this Widget. You can override
this method to create a custom HandlerManager
.
HandlerManager
you want to useprotected void delegateEvent(Widget target, GwtEvent<?> event)
event
- the eventtarget
- fire the event on the given targetprotected void doAttachChildren()
onAttach()
for each of its
child widgets.
onAttach()
protected void doDetachChildren()
onDetach()
for each of its
child widgets.
onDetach()
protected int getHandlerCount(GwtEvent.Type<?> type)
type
- the event type
protected final boolean isOrWasAttached()
protected void onAttach()
This method is called when a widget is attached to the browser's document.
To receive notification after a Widget has been added to the document,
override the onLoad()
method or use addAttachHandler(com.google.gwt.event.logical.shared.AttachEvent.Handler)
.
It is strongly recommended that you override onLoad()
or
doAttachChildren()
instead of this method to avoid inconsistencies
between logical and physical attachment states.
Subclasses that override this method must call
super.onAttach()
to ensure that the Widget has been attached
to its underlying Element.
java.lang.IllegalStateException
- if this widget is already attachedonLoad()
,
doAttachChildren()
protected void onDetach()
This method is called when a widget is detached from the browser's
document. To receive notification before a Widget is removed from the
document, override the onUnload()
method or use addAttachHandler(com.google.gwt.event.logical.shared.AttachEvent.Handler)
.
It is strongly recommended that you override onUnload()
or
doDetachChildren()
instead of this method to avoid inconsistencies
between logical and physical attachment states.
Subclasses that override this method must call
super.onDetach()
to ensure that the Widget has been detached
from the underlying Element. Failure to do so will result in application
memory leaks due to circular references between DOM Elements and JavaScript
objects.
java.lang.IllegalStateException
- if this widget is already detachedonUnload()
,
doDetachChildren()
protected void onLoad()
protected void onUnload()
HandlerManager ensureHandlers()
HandlerManager getHandlerManager()
void replaceElement(Element elem)
UIObject
replaceElement
in class UIObject
elem
- the object's new elementvoid setParent(Widget parent)
Panel
and Composite
.
parent
- the widget's new parent
java.lang.IllegalStateException
- if parent
is non-null and the
widget already has a parent
|
GWT 2.7.0 | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |