All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vaadin.ui.HasStyleNames Maven / Gradle / Ivy

There is a newer version: 8.27.3
Show newest version
/*
 * Copyright (C) 2000-2024 Vaadin Ltd
 *
 * This program is available under Vaadin Commercial License and Service Terms.
 *
 * See  for the full
 * license.
 */
package com.vaadin.ui;

import java.io.Serializable;

/**
 * Implemented by components which support style names.
 *
 * 

* Each style name will occur only once as specified and it is not prefixed with * the style name of the component. *

* * @since 8.7 */ public interface HasStyleNames extends Serializable { /** * Gets all user-defined CSS style names of a component. If the component * has multiple style names defined, the return string is a space-separated * list of style names. Built-in style names defined in Vaadin or GWT are * not returned. * *

* The style names are returned only in the basic form in which they were * added. *

* * @since 8.7 * @return the style name or a space-separated list of user-defined style * names of the component * @see #setStyleName(String) * @see #addStyleName(String) * @see #removeStyleName(String) */ String getStyleName(); /** * Sets one or more user-defined style names of the component, replacing any * previous user-defined styles. Multiple styles can be specified as a * space-separated list of style names. The style names must be valid CSS * class names. * *

* It is normally a good practice to use {@link #addStyleName(String) * addStyleName()} rather than this setter, as different software * abstraction layers can then add their own styles without accidentally * removing those defined in other layers. *

* * @since 8.7 * @param style * the new style or styles of the component as a space-separated * list * @see #getStyleName() * @see #addStyleName(String) * @see #removeStyleName(String) */ void setStyleName(String style); /** * Adds or removes a style name. Multiple styles can be specified as a * space-separated list of style names. * * If the {@code add} parameter is true, the style name is added to the * component. If the {@code add} parameter is false, the style name is * removed from the component. *

* Functionally this is equivalent to using {@link #addStyleName(String)} or * {@link #removeStyleName(String)} * * @since 8.7 * @param style * the style name to be added or removed * @param add * true to add the given style, false * to remove it * @see #addStyleName(String) * @see #removeStyleName(String) */ default void setStyleName(String style, boolean add) { if (add) { addStyleName(style); } else { removeStyleName(style); } } /** * Adds one or more style names to this component. Multiple styles can be * specified as a space-separated list of style names. The style name will * be rendered as a HTML class name, which can be used in a CSS definition. * * * @since 8.7 * @param style * the new style to be added to the component * @see #getStyleName() * @see #setStyleName(String) * @see #removeStyleName(String) */ void addStyleName(String style); /** * Adds one or more style names to this component by using one or multiple * parameters. * * @since 8.7 * @param styles * the style name or style names to be added to the component * @see #addStyleName(String) * @see #setStyleName(String) * @see #removeStyleName(String) */ default void addStyleNames(String... styles) { for (String style : styles) { addStyleName(style); } } /** * Removes one or more style names from component. Multiple styles can be * specified as a space-separated list of style names. * *

* The parameter must be a valid CSS style name. Only user-defined style * names added with {@link #addStyleName(String) addStyleName()} or * {@link #setStyleName(String) setStyleName()} can be removed; built-in * style names defined in Vaadin or GWT can not be removed. *

* * @since 8.7 * @param style * the style name or style names to be removed * @see #getStyleName() * @see #setStyleName(String) * @see #addStyleName(String) */ void removeStyleName(String style); /** * Removes one or more style names from component. Multiple styles can be * specified by using multiple parameters. * *

* The parameter must be a valid CSS style name. Only user-defined style * names added with {@link #addStyleName(String) addStyleName()} or * {@link #setStyleName(String) setStyleName()} can be removed; built-in * style names defined in Vaadin or GWT can not be removed. *

* * @since 8.7 * @param styles * the style name or style names to be removed * @see #removeStyleName(String) * @see #setStyleName(String) * @see #addStyleName(String) */ default void removeStyleNames(String... styles) { for (String style : styles) { removeStyleName(style); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy