public class StyleUtils extends Object
| Constructor and Description |
|---|
StyleUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addStyleDependentName(com.google.gwt.dom.client.Element elem,
String styleSuffix)
Adds a dependent style name by specifying the style name's suffix.
|
static void |
addStyleName(com.google.gwt.dom.client.Element elem,
String style)
Adds a secondary or dependent style name to this object.
|
static void |
addStyleProperty(com.google.gwt.dom.client.Element element,
String camelizedName,
String value) |
static void |
removeStyleDependentName(com.google.gwt.dom.client.Element elem,
String styleSuffix)
Removes a dependent style name by specifying the style name's suffix.
|
static void |
removeStyleName(com.google.gwt.dom.client.Element elem,
String style)
Removes a style name.
|
public static void addStyleDependentName(com.google.gwt.dom.client.Element elem,
String styleSuffix)
getStylePrimaryName() + '-' + styleSuffix
styleSuffix - the suffix of the dependent style to be added.#setStylePrimaryName(String),
#removeStyleDependentName(String),
#addStyleName(String)public static void removeStyleDependentName(com.google.gwt.dom.client.Element elem,
String styleSuffix)
styleSuffix - the suffix of the dependent style to be removed#setStylePrimaryName(Element, String),
#addStyleDependentName(String),
#addStyleName(String)public static void removeStyleName(com.google.gwt.dom.client.Element elem,
String style)
elem - style - the secondary style name to be removed#addStyleName(String)public static void addStyleName(com.google.gwt.dom.client.Element elem,
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.
elem - style - the secondary style name to be addedUIObject,
#removeStyleName(String)Copyright © 2015. All rights reserved.