|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.gwt.user.client.ui.UIObject
public abstract class UIObject
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)
and removeStyleName(String)
.
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.
Constructor Summary | |
---|---|
UIObject()
|
Method Summary | |
---|---|
void |
addStyleDependentName(java.lang.String styleSuffix)
Adds a dependent style name by specifying the style name's suffix. |
void |
addStyleName(java.lang.String style)
Adds a secondary or dependent style name to this object. |
int |
getAbsoluteLeft()
Gets the object's absolute left position in pixels, as measured from the browser window's client area. |
int |
getAbsoluteTop()
Gets the object's absolute top position in pixels, as measured from the browser window's client area. |
Element |
getElement()
Gets a handle to the object's underlying DOM element. |
int |
getOffsetHeight()
Gets the object's offset height in pixels. |
int |
getOffsetWidth()
Gets the object's offset width in pixels. |
protected Element |
getStyleElement()
Template method that returns the element to which style names will be applied. |
java.lang.String |
getStyleName()
Gets all of the object's style names, as a space-separated list. |
protected static java.lang.String |
getStyleName(Element elem)
Gets all of the element's style names, as a space-separated list. |
java.lang.String |
getStylePrimaryName()
Gets the primary style name associated with the object. |
protected static java.lang.String |
getStylePrimaryName(Element elem)
Gets the element's primary style name. |
java.lang.String |
getTitle()
Gets the title associated with this object. |
boolean |
isVisible()
Determines whether or not this object is visible. |
static boolean |
isVisible(Element elem)
|
void |
removeStyleDependentName(java.lang.String styleSuffix)
Removes a dependent style name by specifying the style name's suffix. |
void |
removeStyleName(java.lang.String style)
Removes a style name. |
protected void |
setElement(Element elem)
Sets this object's browser element. |
void |
setHeight(java.lang.String height)
Sets the object's height. |
void |
setPixelSize(int width,
int height)
Sets the object's size, in pixels, not including decorations such as border, margin, and padding. |
void |
setSize(java.lang.String width,
java.lang.String height)
Sets the object's size. |
protected static void |
setStyleName(Element elem,
java.lang.String styleName)
Clears all of the element's style names and sets it to the given style. |
protected static void |
setStyleName(Element elem,
java.lang.String style,
boolean add)
This convenience method adds or removes a style name for a given element. |
void |
setStyleName(java.lang.String style)
Clears all of the object's style names and sets it to the given style. |
protected static void |
setStylePrimaryName(Element elem,
java.lang.String style)
Sets the element's primary style name and updates all dependent style names. |
void |
setStylePrimaryName(java.lang.String style)
Sets the object's primary style name and updates all dependent style names. |
void |
setTitle(java.lang.String title)
Sets the title associated with this object. |
void |
setVisible(boolean visible)
Sets whether this object is visible. |
static void |
setVisible(Element elem,
boolean visible)
|
void |
setWidth(java.lang.String width)
Sets the object's width. |
void |
sinkEvents(int eventBitsToAdd)
Adds a set of events to be sunk by this object. |
java.lang.String |
toString()
This method is overridden so that any object can be viewed in the debugger as an HTML snippet. |
void |
unsinkEvents(int eventBitsToRemove)
Removes a set of events from this object's event list. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public UIObject()
Method Detail |
---|
public static boolean isVisible(Element elem)
public static void setVisible(Element elem, boolean visible)
protected static java.lang.String getStyleName(Element elem)
elem
- the element whose style is to be retrieved
protected static java.lang.String getStylePrimaryName(Element elem)
elem
- the element whose primary style name is to be retrieved
protected static void setStyleName(Element elem, java.lang.String styleName)
elem
- the element whose style is to be modifiedstyleName
- the new style nameprotected static void setStyleName(Element elem, java.lang.String style, boolean add)
setStyleName(String)
for a description of how
primary and secondary style names are used.
elem
- the element whose style is to be modifiedstyle
- the secondary style name to be added or removedadd
- true
to add the given style, false
to remove itprotected static void setStylePrimaryName(Element elem, java.lang.String style)
elem
- the element whose style is to be resetstyle
- the new primary style namesetStyleName(Element, String, boolean)
public void addStyleDependentName(java.lang.String styleSuffix)
getStylePrimaryName() + '-' + styleSuffix
styleSuffix
- the suffix of the dependent style to be added.setStylePrimaryName(String)
,
removeStyleDependentName(String)
,
addStyleName(String)
public void addStyleName(java.lang.String style)
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; }
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 addedUIObject
,
removeStyleName(String)
public int getAbsoluteLeft()
public int getAbsoluteTop()
public Element getElement()
public int getOffsetHeight()
public int getOffsetWidth()
public java.lang.String getStyleName()
getStylePrimaryName()
.
getStylePrimaryName()
public java.lang.String getStylePrimaryName()
setStyleName(String)
,
addStyleName(String)
,
removeStyleName(String)
public java.lang.String getTitle()
public boolean isVisible()
true
if the object is visiblepublic void removeStyleDependentName(java.lang.String styleSuffix)
styleSuffix
- the suffix of the dependent style to be removedsetStylePrimaryName(Element, String)
,
addStyleDependentName(String)
,
addStyleName(String)
public void removeStyleName(java.lang.String style)
style
- the secondary style name to be removedaddStyleName(String)
public void setHeight(java.lang.String height)
height
- the object's new height, in CSS units (e.g. "10px", "1em")public void setPixelSize(int width, int height)
width
- the object's new width, in pixelsheight
- the object's new height, in pixelspublic void setSize(java.lang.String width, java.lang.String height)
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")public void setStyleName(java.lang.String style)
setStylePrimaryName(String)
unless you wish to
explicitly remove all existing styles.
style
- the new style namesetStylePrimaryName(String)
public void setStylePrimaryName(java.lang.String style)
style
- the new primary style nameaddStyleName(String)
,
removeStyleName(String)
public void setTitle(java.lang.String title)
title
- the object's new titlepublic void setVisible(boolean visible)
visible
- true
to show the object, false
to hide itpublic void setWidth(java.lang.String width)
width
- the object's new width, in CSS units (e.g. "10px", "1em")public void sinkEvents(int eventBitsToAdd)
widgets
may actually receive events, but can receive events
from all objects contained within them.
eventBitsToAdd
- a bitfield representing the set of events to be added
to this element's event setEvent
public java.lang.String toString()
toString
in class java.lang.Object
public void unsinkEvents(int eventBitsToRemove)
eventBitsToRemove
- a bitfield representing the set of events to be
removed from this element's event setsinkEvents(int)
,
Event
protected Element getStyleElement()
protected void setElement(Element elem)
elem
- the object's new element
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |