update CSS Decoration - Java org.w3c.dom.css

Java examples for org.w3c.dom.css:CSSStyleDeclaration

Description

update CSS Decoration

Demo Code


//package com.java2s;
import javax.swing.ButtonModel;
import org.w3c.dom.css.CSSStyleDeclaration;
import org.w3c.dom.css.CSSValue;
import org.w3c.dom.css.ElementCSSInlineStyle;

public class Main {
    public static void updateDecoration(ButtonModel model,
            ElementCSSInlineStyle elemStyle) {
        if (model.isSelected()) {
            selectDecoration(elemStyle);
        } else {//from   ww  w  .j  a  v  a2s.  co m
            unselectDecoration(elemStyle);
        }
    }

    public static void selectDecoration(ElementCSSInlineStyle elemStyle) {
        CSSStyleDeclaration style = elemStyle.getStyle();
        CSSValue cssValue = style.getPropertyCSSValue("color"); // Usar el CSSValue es la forma m?s lenta pero es para testear
        if (cssValue == null)
            style.setProperty("color", "red", "");
        else
            cssValue.setCssText("red");
    }

    public static void unselectDecoration(ElementCSSInlineStyle elemStyle) {
        CSSStyleDeclaration style = elemStyle.getStyle();
        style.removeProperty("color");
    }
}

Related Tutorials