java.lang.Object | |
↳ | com.google.gwt.user.client.ui.UIObject |
Known Direct Subclasses |
Known Indirect Subclasses
AbsolutePanel,
AbstractCellTree,
AbstractHasData<T>,
AbstractPager,
Anchor,
Audio,
Button,
ButtonBase,
CalendarView,
Canvas,
CaptionPanel,
CellBrowser,
CellList<T>,
CellPanel,
CellTable<T>,
and
92 others.
|
The superclass for all user-interface objects. It simply wraps a DOM element,
and cannot receive events. Most interesting user-interface classes derive
from Widget
.
All UIObject
objects can be styled using CSS. Style names that
are specified programmatically in Java source are implicitly associated with
CSS style rules. In terms of HTML and CSS, a GWT style name is the element's
CSS "class". By convention, GWT style names are of the form
[project]-[widget]
.
For example, the Button
widget has the style name
gwt-Button
, meaning that within the Button
constructor, the following call occurs:
setStyleName("gwt-Button");A corresponding CSS style rule can then be written as follows:
// Example of how you might choose to style a Button widget .gwt-Button { background-color: yellow; color: black; font-size: 24pt; }Note the dot prefix in the CSS style rule. This syntax is called a CSS class selector.
Every UIObject
has a primary style name that identifies
the key CSS style rule that should always be applied to it. Use
setStylePrimaryName(String)
to specify an object's primary style
name. In most cases, the primary style name is set in a widget's constructor
and never changes again during execution. In the case that no primary style
name is specified, it defaults to the first style name that is added.
More complex styling behavior can be achieved by manipulating an object's
secondary style names. Secondary style names can be added and removed
using addStyleName(String)
, removeStyleName(String)
, or
setStyleName(String, boolean)
. The purpose of secondary style names
is to associate a variety of CSS style rules over time as an object
progresses through different visual states.
There is an important special formulation of secondary style names called
dependent style names. A dependent style name is a secondary style
name prefixed with the primary style name of the widget itself. See
addStyleName(String)
for details.
Setter methods that follow JavaBean property conventions are exposed as
attributes in UiBinder
templates. For example, because UiObject implements setWidth(String)
you can set the width of any widget like so:
<g:Label width='15em'>Hello there</g:Label>Generally speaking, values are parsed as if they were Java literals, so methods like
setVisible(boolean)
are also available:
<g:Label width='15em' visible='false'>Hello there</g:Label>Enum properties work this way too. Imagine a Bagel widget with a handy Type enum and a setType(Type) method:
enum Type { poppy, sesame, raisin, jalapeno } <my:Bagel type='poppy' />There is also special case handling for two common method signatures,
(int, int)
and (double, Unit
)
<g:Label pixelSize='100, 100'>Hello there</g:Label>Finally, a few UiObject methods get special handling. The debug id (see
ensureDebugId(Element, String)
) of any UiObject can be set via the
debugId
attribute, and addtional style names and dependent style
names can be set with the addStyleNames
and
addStyleDependentNames
attributes.<g:Label debugId='helloLabel' addStyleNames='pretty rounded big'>Hello there</g:Label>Style names can be space or comma separated.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
UIObject.DebugIdImpl | The implementation of the set debug id method, which does nothing by default. | ||||||||||
UIObject.DebugIdImplEnabled | The implementation of the setDebugId method, which sets the id of the
Element s in this UIObject . |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | DEBUG_ID_PREFIX |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a dependent style name by specifying the style name's suffix.
| |||||||||||
Adds a secondary or dependent style name to this object.
| |||||||||||
Ensure that elem has an ID property set, which allows it to integrate with third-party libraries and test tools. | |||||||||||
Gets the object's absolute left position in pixels, as measured from the
browser window's client area.
| |||||||||||
Gets the object's absolute top position in pixels, as measured from the
browser window's client area.
| |||||||||||
Gets a handle to the object's underlying DOM element.
| |||||||||||
Gets the object's offset height in pixels.
| |||||||||||
Gets the object's offset width in pixels.
| |||||||||||
Gets all of the object's style names, as a space-separated list.
| |||||||||||
Gets the primary style name associated with the object.
| |||||||||||
Gets the title associated with this object.
| |||||||||||
Determines whether or not this object is visible.
| |||||||||||
Removes a dependent style name by specifying the style name's suffix.
| |||||||||||
Removes a style name.
| |||||||||||
Sets the object's height.
| |||||||||||
Sets the object's size, in pixels, not including decorations such as
border, margin, and padding.
| |||||||||||
Sets the object's size.
| |||||||||||
Adds or removes a dependent style name by specifying the style name's
suffix.
| |||||||||||
Clears all of the object's style names and sets it to the given style.
| |||||||||||
Adds or removes a style name.
| |||||||||||
Sets the object's primary style name and updates all dependent style names.
| |||||||||||
Sets the title associated with this object.
| |||||||||||
Sets whether this object is visible.
| |||||||||||
Sets the object's width.
| |||||||||||
Adds a set of events to be sunk by this object.
| |||||||||||
This method is overridden so that any object can be viewed in the debugger
as an HTML snippet.
| |||||||||||
Removes a set of events from this object's event list.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Set the debug id of a specific element.
| |||||||||||
Template method that returns the element to which style names will be
applied.
| |||||||||||
Gets all of the element's style names, as a space-separated list.
| |||||||||||
Gets the element's primary style name.
| |||||||||||
Called when the user sets the id using the
ensureDebugId(String)
method. | |||||||||||
Sets this object's browser element.
| |||||||||||
Sets this object's browser element.
| |||||||||||
Clears all of the element's style names and sets it to the given style.
| |||||||||||
This convenience method adds or removes a style name for a given element.
| |||||||||||
Sets the element's primary style name and updates all dependent style
names.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Adds a dependent style name by specifying the style name's suffix. The actual form of the style name that is added is:
getStylePrimaryName() + '-' + styleSuffix
styleSuffix | the suffix of the dependent style to be added. |
---|
Adds a secondary or dependent style name to this object. A secondary style
name is an additional style name that is, in HTML/CSS terms, included as a
space-separated token in the value of the CSS class
attribute
for this object's root element.
The most important use for this method is to add a special kind of
secondary style name called a dependent style name. To add a
dependent style name, use addStyleDependentName(String)
, which
will prefix the 'style' argument with the result of
getStylePrimaryName()
(followed by a '-'). For example, suppose
the primary style name is gwt-TextBox
. If the following method
is called as obj.setReadOnly(true)
:
public void setReadOnly(boolean readOnly) { isReadOnlyMode = readOnly; // Create a dependent style name. String readOnlyStyle = "readonly"; if (readOnly) { addStyleDependentName(readOnlyStyle); } else { removeStyleDependentName(readOnlyStyle); } }
then both of the CSS style rules below will be applied:
// This rule is based on the primary style name and is always active. .gwt-TextBox { font-size: 12pt; } // This rule is based on a dependent style name that is only active // when the widget has called addStyleName(getStylePrimaryName() + // "-readonly"). .gwt-TextBox-readonly { background-color: lightgrey; border: none; }
The code can also be simplified with
setStyleDependentName(String, boolean)
:
public void setReadOnly(boolean readOnly) { isReadOnlyMode = readOnly; setStyleDependentName("readonly", readOnly); }
Dependent style names are powerful because they are automatically updated whenever the primary style name changes. Continuing with the example above, if the primary style name changed due to the following call:
setStylePrimaryName("my-TextThingy");
then the object would be re-associated with following style rules, removing those that were shown above.
.my-TextThingy { font-size: 20pt; } .my-TextThingy-readonly { background-color: red; border: 2px solid yellow; }
Secondary style names that are not dependent style names are not automatically updated when the primary style name changes.
style | the secondary style name to be added |
---|
Ensure that the main Element
for this UIObject
has an ID
property set, which allows it to integrate with third-party libraries and
test tools. Complex Widget
s will also set the IDs of their
important sub-elements.
If the main element already has an ID, this method WILL override it.
The ID that you specify will be prefixed by the static string
DEBUG_ID_PREFIX
.
This method will be compiled out and will have no effect unless you inherit
the DebugID module in your gwt.xml file by adding the following line:
<inherits name="com.google.gwt.user.Debug"/>
id | the ID to set on the main element |
---|
Ensure that elem has an ID property set, which allows it to integrate with
third-party libraries and test tools. If elem already has an ID, this
method WILL override it. The ID that you specify will be prefixed by the
static string DEBUG_ID_PREFIX
.
This method will be compiled out and will have no effect unless you inherit the DebugID module in your gwt.xml file by adding the following line:
<inherits name="com.google.gwt.user.Debug"/>
elem | the target Element |
---|---|
id | the ID to set on the element |
Gets the object's absolute left position in pixels, as measured from the browser window's client area.
Gets the object's absolute top position in pixels, as measured from the browser window's client area.
Gets a handle to the object's underlying DOM element.
This method should not be overridden. It is non-final solely to support
legacy code that depends upon overriding it. If it is overridden, the
subclass implementation must not return a different element than was
previously set using
setElement(com.google.gwt.user.client.Element)
.
Gets the object's offset height in pixels. This is the total height of the object, including decorations such as border, margin, and padding.
Gets the object's offset width in pixels. This is the total width of the object, including decorations such as border, margin, and padding.
Gets all of the object's style names, as a space-separated list. If you
wish to retrieve only the primary style name, call
getStylePrimaryName()
.
Gets the primary style name associated with the object.
Gets the title associated with this object. The title is the 'tool-tip' displayed to users when they hover over the object.
Determines whether or not this object is visible.
true
if the object is visible
Removes a dependent style name by specifying the style name's suffix.
styleSuffix | the suffix of the dependent style to be removed |
---|
Removes a style name. This method is typically used to remove secondary style names, but it can be used to remove primary stylenames as well. That use is not recommended.
style | the secondary style name to be removed |
---|
Sets the object's height. This height does not include decorations such as border, margin, and padding.
height | the object's new height, in CSS units (e.g. "10px", "1em") |
---|
Sets the object's size, in pixels, not including decorations such as border, margin, and padding.
width | the object's new width, in pixels |
---|---|
height | the object's new height, in pixels |
Sets the object's size. This size does not include decorations such as border, margin, and padding.
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") |
Adds or removes a dependent style name by specifying the style name's suffix. The actual form of the style name that is added is:
getStylePrimaryName() + '-' + styleSuffix
styleSuffix | the suffix of the dependent style to be added or removed |
---|---|
add | true to add the given style, false to
remove it |
Clears all of the object's style names and sets it to the given style. You
should normally use setStylePrimaryName(String)
unless you wish to
explicitly remove all existing styles.
style | the new style name |
---|
Adds or removes a style name. This method is typically used to remove secondary style names, but it can be used to remove primary stylenames as well. That use is not recommended.
style | the style name to be added or removed |
---|---|
add | true to add the given style, false to
remove it |
Sets the object's primary style name and updates all dependent style names.
style | the new primary style name |
---|
Sets the title associated with this object. The title is the 'tool-tip' displayed to users when they hover over the object.
title | the object's new title |
---|
Sets whether this object is visible.
visible | true to show the object, false to
hide it
|
---|
Sets the object's width. This width does not include decorations such as border, margin, and padding.
width | the object's new width, in CSS units (e.g. "10px", "1em") |
---|
This method is overridden so that any object can be viewed in the debugger as an HTML snippet.
Removes a set of events from this object's event list.
eventBitsToRemove | a bitfield representing the set of events to be removed from this element's event set |
---|
Set the debug id of a specific element. The id will be appended to the end of the base debug id, with a dash separator. The base debug id is the ID of the main element in this UIObject.
elem | the element |
---|---|
baseID | the base ID used by the main element |
id | the id to append to the base debug id |
Template method that returns the element to which style names will be applied. By default it returns the root element, but this method may be overridden to apply styles to a child element.
Gets all of the element's style names, as a space-separated list.
elem | the element whose style is to be retrieved |
---|
Gets the element's primary style name.
elem | the element whose primary style name is to be retrieved |
---|
Called when the user sets the id using the ensureDebugId(String)
method. Subclasses of UIObject
can override this method to add IDs
to their sub elements. If a subclass does override this method, it should
list the IDs (relative to the base ID), that will be applied to each sub
Element
with a short description. For example:
<inherits name="com.google.gwt.user.Debug"/>
baseID | the base ID used by the main element |
---|
Sets this object's browser element. UIObject subclasses must call this method before attempting to call any other methods, and it may only be called once.
elem | the object's element |
---|
Sets this object's browser element. UIObject subclasses must call this
method before attempting to call any other methods, and it may only be
called once.
This method exists for backwards compatibility with pre-1.5 code. As of GWT
1.5, setElement(Element)
is the preferred method.
elem | the object's element |
---|
Clears all of the element's style names and sets it to the given style.
elem | the element whose style is to be modified |
---|---|
styleName | the new style name |
This convenience method adds or removes a style name for a given element.
This method is typically used to add and remove secondary style names, but
it can be used to remove primary stylenames as well, but that is not
recommended. See setStyleName(String)
for a description of how
primary and secondary style names are used.
elem | the element whose style is to be modified |
---|---|
style | the secondary style name to be added or removed |
add | true to add the given style, false to
remove it
|
Sets the element's primary style name and updates all dependent style names.
elem | the element whose style is to be reset |
---|---|
style | the new primary style name |