Search in sources :

Example 1 with Colorpicker

use of org.eclipse.smarthome.model.sitemap.Colorpicker in project smarthome by eclipse.

the class ColorpickerRenderer method renderWidget.

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
    Colorpicker cp = (Colorpicker) w;
    String snippetName = "colorpicker";
    String snippet = getSnippet(snippetName);
    // set the default send-update frequency to 200ms
    String frequency = cp.getFrequency() == 0 ? "200" : Integer.toString(cp.getFrequency());
    // get RGB hex value
    State state = itemUIRegistry.getState(cp);
    String hexValue = "#ffffff";
    if (state instanceof HSBType) {
        HSBType hsbState = (HSBType) state;
        hexValue = "#" + Integer.toHexString(hsbState.getRGB()).substring(2);
    }
    String purelabel = itemUIRegistry.getLabel(w);
    purelabel = purelabel.replaceAll("\\\"", "\\\\'");
    // Should be called before preprocessSnippet
    snippet = StringUtils.replace(snippet, "%state%", hexValue);
    snippet = StringUtils.replace(snippet, "%icon_state%", escapeURL(hexValue));
    snippet = preprocessSnippet(snippet, w);
    snippet = StringUtils.replace(snippet, "%purelabel%", purelabel);
    snippet = StringUtils.replace(snippet, "%frequency%", frequency);
    snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME);
    String style = "";
    String color = itemUIRegistry.getLabelColor(w);
    if (color != null) {
        style = "color:" + color;
    }
    snippet = StringUtils.replace(snippet, "%labelstyle%", style);
    style = "";
    color = itemUIRegistry.getValueColor(w);
    if (color != null) {
        style = "color:" + color;
    }
    snippet = StringUtils.replace(snippet, "%valuestyle%", style);
    sb.append(snippet);
    return null;
}
Also used : State(org.eclipse.smarthome.core.types.State) HSBType(org.eclipse.smarthome.core.library.types.HSBType) Colorpicker(org.eclipse.smarthome.model.sitemap.Colorpicker)

Example 2 with Colorpicker

use of org.eclipse.smarthome.model.sitemap.Colorpicker in project smarthome by eclipse.

the class ColorpickerRenderer method renderWidget.

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
    Colorpicker cp = (Colorpicker) w;
    String snippetName = "colorpicker";
    String snippet = getSnippet(snippetName);
    // set the default send-update frequency to 200ms
    String frequency = cp.getFrequency() == 0 ? "200" : Integer.toString(cp.getFrequency());
    // get RGB hex value
    State state = itemUIRegistry.getState(cp);
    String hexValue = "#ffffff";
    if (state instanceof HSBType) {
        HSBType hsbState = (HSBType) state;
        hexValue = "#" + Integer.toHexString(hsbState.getRGB()).substring(2);
    }
    String label = getLabel(cp);
    String purelabel = itemUIRegistry.getLabel(w);
    purelabel = purelabel.replaceAll("\\\"", "\\\\'");
    snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(cp));
    snippet = StringUtils.replace(snippet, "%category%", getCategory(cp));
    snippet = StringUtils.replace(snippet, "%item%", w.getItem());
    snippet = StringUtils.replace(snippet, "%label%", label);
    snippet = StringUtils.replace(snippet, "%format%", getFormat());
    snippet = StringUtils.replace(snippet, "%purelabel%", purelabel);
    snippet = StringUtils.replace(snippet, "%state%", hexValue);
    snippet = StringUtils.replace(snippet, "%frequency%", frequency);
    snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME);
    String style = "";
    String color = itemUIRegistry.getLabelColor(w);
    if (color != null) {
        style = "color:" + color;
    }
    snippet = StringUtils.replace(snippet, "%labelstyle%", style);
    style = "";
    color = itemUIRegistry.getValueColor(w);
    if (color != null) {
        style = "color:" + color;
    }
    snippet = StringUtils.replace(snippet, "%valuestyle%", style);
    sb.append(snippet);
    return null;
}
Also used : State(org.eclipse.smarthome.core.types.State) HSBType(org.eclipse.smarthome.core.library.types.HSBType) Colorpicker(org.eclipse.smarthome.model.sitemap.Colorpicker)

Aggregations

HSBType (org.eclipse.smarthome.core.library.types.HSBType)2 State (org.eclipse.smarthome.core.types.State)2 Colorpicker (org.eclipse.smarthome.model.sitemap.Colorpicker)2