org.cruxframework.crux.core.client.utils
Class StyleUtils

java.lang.Object
  extended by org.cruxframework.crux.core.client.utils.StyleUtils

public class StyleUtils
extends Object

Contains common operations for handling styles on HTML elements.

Author:
Gesse S. F. Dafe

Constructor Summary
StyleUtils()
           
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StyleUtils

public StyleUtils()
Method Detail

addStyleDependentName

public static void addStyleDependentName(com.google.gwt.dom.client.Element elem,
                                         String styleSuffix)
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 

Parameters:
styleSuffix - the suffix of the dependent style to be added.
See Also:
#setStylePrimaryName(String), #removeStyleDependentName(String), #addStyleName(String)

removeStyleDependentName

public static void removeStyleDependentName(com.google.gwt.dom.client.Element elem,
                                            String styleSuffix)
Removes a dependent style name by specifying the style name's suffix.

Parameters:
styleSuffix - the suffix of the dependent style to be removed
See Also:
#setStylePrimaryName(Element, String), #addStyleDependentName(String), #addStyleName(String)

removeStyleName

public static void removeStyleName(com.google.gwt.dom.client.Element elem,
                                   String style)
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.

Parameters:
elem -
style - the secondary style name to be removed
See Also:
#addStyleName(String)

addStyleName

public static void addStyleName(com.google.gwt.dom.client.Element elem,
                                String style)
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; }

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.

Parameters:
elem -
style - the secondary style name to be added
See Also:
UIObject, #removeStyleName(String)

addStyleProperty

public static void addStyleProperty(com.google.gwt.dom.client.Element element,
                                    String camelizedName,
                                    String value)


Copyright © 2014. All rights reserved.