Class UIObject

public class UIObject
extends Object

// Superclass of MenuItem, TreeItem, Widget
The base class for all user-interface objects. It simply wraps a DOM element, and cannot receive events. Most interesting user-interface classes derive from Widget.

Methods

addStyleName(String)Adds a style name to the widget.
getAbsoluteLeft()Gets the object's absolute left position in pixels, as measured from the browser window's client area.
getAbsoluteTop()Gets the object's absolute top position in pixels, as measured from the browser window's client area.
getElement()Gets a handle to the object's underlying DOM element.
getOffsetHeight()Gets the object's offset height in pixels.
getOffsetWidth()Gets the object's offset width in pixels.
getStyleName()Gets the style name associated with the object.
getTitle()Gets the title associated with this object.
isVisible(Element)
isVisible()Determines whether or not this object is visible.
removeStyleName(String)Removes a style name from the widget.
setElement(Element)Sets this object's browser element.
setHeight(String)Sets the object's height.
setPixelSize(int, int)Sets the object's size, in pixels, not including decorations such as border, margin, and padding.
setSize(String, String)Sets the object's size.
setStyleName(Element, String, boolean)This convenience method implements allows one to easily add or remove the style name for any element.
setStyleName(String)Sets the object's style name, removing all other styles.
setTitle(String)Sets the title associated with this object.
setVisible(Element, boolean)
setVisible(boolean)Sets whether this object is visible.
setWidth(String)Sets the object's width.
sinkEvents(int)Adds a set of events to be sunk by this object.
toString()This method is overridden so that any object can be viewed in the debugger as an HTML snippet.
unsinkEvents(int)Removes a set of events from this object's event list.

Method Detail

addStyleName

public void addStyleName(String style)
Adds a style name to the widget.

Parameters

style
the style name to be added

See Also

removeStyleName(String)

getAbsoluteLeft

public int getAbsoluteLeft()
Gets the object's absolute left position in pixels, as measured from the browser window's client area.

Return Value

the object's absolute left position

getAbsoluteTop

public int getAbsoluteTop()
Gets the object's absolute top position in pixels, as measured from the browser window's client area.

Return Value

the object's absolute top position

getElement

public Element getElement()
Gets a handle to the object's underlying DOM element.

Return Value

the object's browser element

getOffsetHeight

public int getOffsetHeight()
Gets the object's offset height in pixels. This is the total height of the object, including decorations such as border, margin, and padding.

Return Value

the object's offset height

getOffsetWidth

public int getOffsetWidth()
Gets the object's offset width in pixels. This is the total width of the object, including decorations such as border, margin, and padding.

Return Value

the object's offset width

getStyleName

public String getStyleName()
Gets the style name associated with the object.

Return Value

the object's style name

See Also

setStyleName(String)

getTitle

public String getTitle()
Gets the title associated with this object. The title is the 'tool-tip' displayed to users when they hover over the object.

Return Value

the object's title

isVisible

public static boolean isVisible(Element elem)

Parameters

elem

isVisible

public boolean isVisible()
Determines whether or not this object is visible.

Return Value

true if the object is visible

removeStyleName

public void removeStyleName(String style)
Removes a style name from the widget.

Parameters

style
the style name to be added

See Also

addStyleName(String)

setElement

protected void setElement(Element elem)
Sets this object's browser element. UIObject subclasses must call this method before attempting to call any other methods.

Parameters

elem
the object's new element

setHeight

public void setHeight(String height)
Sets the object's height. This height does not include decorations such as border, margin, and padding.

Parameters

height
the object's new height, in CSS units (e.g. "10px", "1em")

setPixelSize

public void setPixelSize(int width, int height)
Sets the object's size, in pixels, not including decorations such as border, margin, and padding.

Parameters

width
the object's new width, in pixels
height
the object's new height, in pixels

setSize

public void setSize(String width, String height)
Sets the object's size. This size does not include decorations such as border, margin, and padding.

Parameters

width
the object's new width, in CSS units (e.g. "10px", "1em")
height
the object's new height, in CSS units (e.g. "10px", "1em")

setStyleName

protected static void setStyleName(Element elem, String style, boolean add)
This convenience method implements allows one to easily add or remove the style name for any element. This can be useful when you need to add and remove styles from a sub-element within a UIObject.

Parameters

elem
the element whose style is to be modified
style
the style name to be added or removed
add
true to add the given style, false to remove it

setStyleName

public void setStyleName(String style)
Sets the object's style name, removing all other styles.

The style name is the name referred to in CSS style rules (in HTML, this is referred to as the element's "class"). By convention, style rules are of the form [project]-[widget] (e.g. the Button widget's style name is .gwt-Button).

For example, if a widget's style name is myProject-MyWidget, then the style rule that applies to it will be .myProject-MyWidget. Note the "dot" prefix -- this is necessary because calling this method sets the underlying element's className property.

An object may have any number of style names, which may be manipulated using addStyleName(String) and removeStyleName(String). The attributes of all styles associated with the object will be applied to it.

Parameters

style
the style name to be added

See Also

addStyleName(String), removeStyleName(String)

setTitle

public void setTitle(String title)
Sets the title associated with this object. The title is the 'tool-tip' displayed to users when they hover over the object.

Parameters

title
the object's new title

setVisible

public static void setVisible(Element elem, boolean visible)

Parameters

elem
visible

setVisible

public void setVisible(boolean visible)
Sets whether this object is visible.

Parameters

visible
true to show the object, false to hide it

setWidth

public void setWidth(String width)
Sets the object's width. This width does not include decorations such as border, margin, and padding.

Parameters

width
the object's new width, in CSS units (e.g. "10px", "1em")

sinkEvents

public void sinkEvents(int eventBitsToAdd)
Adds a set of events to be sunk by this object. Note that only widgets may actually receive events, but can receive events from all objects contained within them.

Parameters

eventBitsToAdd
a bitfield representing the set of events to be added to this element's event set

See Also

Event

toString

public String toString()
This method is overridden so that any object can be viewed in the debugger as an HTML snippet.

Return Value

a string representation of the object

unsinkEvents

public void unsinkEvents(int eventBitsToRemove)
Removes a set of events from this object's event list.

Parameters

eventBitsToRemove
a bitfield representing the set of events to be removed from this element's event set

See Also

sinkEvents, Event