Java Code Examples for com.google.gwt.dom.client.Style#HasCssName

The following examples show how to use com.google.gwt.dom.client.Style#HasCssName . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnumHelper.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
/**
 * Returns first enum constant found in at space-separated list of style names.
 *
 * @param styleName    Space-separated list of styles
 * @param enumClass    Type of enum
 * @param defaultValue Default value of no match was found
 * @return First enum constant found or default value
 */
@SuppressWarnings("unchecked")
public static <E extends Enum<? extends Style.HasCssName>> E fromStyleName(final String styleName,
                                                                           final Class<E> enumClass,
                                                                           final E defaultValue,
                                                                           final boolean ignoreSpaces) {
    if (styleName == null || enumClass == null) {
        return defaultValue;
    }

    for (final Enum<? extends Style.HasCssName> constant : enumClass.getEnumConstants()) {
        final Style.HasCssName anEnum = (Style.HasCssName) constant;
        final String cssClass = anEnum.getCssName();

        if(cssClass != null) {
            boolean contains;
            if (ignoreSpaces) {
                contains = styleName.equals(cssClass);
            } else {
                contains = StyleHelper.containsStyle(styleName, cssClass);
            }
            if (contains) {
                return (E) anEnum;
            }
        }
    }
    return defaultValue;
}
 
Example 2
Source File: StyleHelper.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method for first removing all enum style constants and then adding the single one.
 *
 * @see #removeEnumStyleNames(UIObject, Class)
 * @see #addEnumStyleName(UIObject, Style.HasCssName)
 */
public static <E extends Style.HasCssName, F extends Enum<? extends Style.HasCssName>> void addUniqueEnumStyleName(final UIObject uiObject,
                                                                                                                   final Class<F> enumClass,
                                                                                                                   final E style) {
    removeEnumStyleNames(uiObject, enumClass);
    addEnumStyleName(uiObject, style);
}
 
Example 3
Source File: StyleHelper.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
/**
 * Removes all CSS style names specified by an enum that implements {@link Style.HasCssName} from an UIObject.
 *
 * @param uiObject  Object to remove CSS class names from
 * @param enumClass Enum representing CSS class names
 * @param <E>       Enum type implementing {@link Style.HasCssName}
 */
public static <E extends Enum<? extends Style.HasCssName>> void removeEnumStyleNames(final UIObject uiObject,
                                                                                     final Class<E> enumClass) {

    for (final Enum<? extends Style.HasCssName> constant : enumClass.getEnumConstants()) {
        final String cssClass = ((Style.HasCssName) constant).getCssName();

        if (cssClass != null && !cssClass.isEmpty()) {
            uiObject.removeStyleName(cssClass);
        }
    }
}
 
Example 4
Source File: StyleHelper.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
/**
 * Adds enum value style name to UIObject unless style is {@code null}.
 *
 * @param uiObject Object to add style to
 * @param style    Style name
 */
public static <E extends Style.HasCssName> void addEnumStyleName(final UIObject uiObject,
                                                                 final E style) {

    if (style != null && style.getCssName() != null && !style.getCssName().isEmpty()) {
        uiObject.addStyleName(style.getCssName());
    }
}
 
Example 5
Source File: StyleHelper.java    From gwt-material with Apache License 2.0 5 votes vote down vote up
/**
 * Removes enum value style name from UIObject unless style is {@code null}.
 *
 * @param uiObject Object to remove style from
 * @param style    Style name
 */
public static <E extends Style.HasCssName> void removeEnumStyleName(final UIObject uiObject,
                                                                    final E style) {

    if (style != null && style.getCssName() != null && !style.getCssName().isEmpty()) {
        uiObject.removeStyleName(style.getCssName());
    }
}
 
Example 6
Source File: StyleHelper.java    From gwt-material with Apache License 2.0 4 votes vote down vote up
public static <F extends Enum<? extends Style.HasCssName>> F fromStyleName(final Class<F> enumClass,
                                                                           final Style.HasCssName styleName) {
    return EnumHelper.fromStyleName(styleName.getCssName(), enumClass, null);
}
 
Example 7
Source File: EnumHelper.java    From gwt-material with Apache License 2.0 2 votes vote down vote up
/**
 * Returns first enum constant found in at space-separated list of style names.
 *
 * @param styleName    Space-separated list of styles
 * @param enumClass    Type of enum
 * @param defaultValue Default value of no match was found
 * @return First enum constant found or default value
 */
public static <E extends Enum<? extends Style.HasCssName>> E fromStyleName(final String styleName,
                                                                           final Class<E> enumClass,
                                                                           final E defaultValue) {
    return EnumHelper.fromStyleName(styleName, enumClass, defaultValue, false);
}
 
Example 8
Source File: ColorHelper.java    From gwt-material with Apache License 2.0 2 votes vote down vote up
/**
 * Returns first enum constant found..
 *
 * @param styleName    Space-separated list of styles
 * @param enumClass    Type of enum
 * @param defaultValue Default value of no match was found
 * @return First enum constant found or default value
 */
public static <E extends Enum<? extends Style.HasCssName>> E fromStyleName(final String styleName,
                                                                           final Class<E> enumClass,
                                                                           final E defaultValue) {
    return EnumHelper.fromStyleName(styleName, enumClass, defaultValue, true);
}