/**
   * Transforms the given {@link HSBType} into a light state.
   *
   * @param hsbType HSB type
   * @return light state representing the {@link HSBType}.
   */
  public static StateUpdate toColorLightState(HSBType hsbType) {
    int hue = (int) Math.round(hsbType.getHue().doubleValue() * HUE_FACTOR);
    int saturation = (int) Math.round(hsbType.getSaturation().doubleValue() * SATURATION_FACTOR);
    int brightness = (int) Math.round(hsbType.getBrightness().doubleValue() * BRIGHTNESS_FACTOR);

    StateUpdate stateUpdate = new StateUpdate().setHue(hue).setSat(saturation);
    if (brightness > 0) {
      stateUpdate.setBrightness(brightness);
    }
    return stateUpdate;
  }
Exemple #2
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) {
     return true;
   }
   if (obj == null) {
     return false;
   }
   if (!(obj instanceof HSBType)) {
     return false;
   }
   HSBType other = (HSBType) obj;
   if ((getHue() != null && other.getHue() == null)
       || (getHue() == null && other.getHue() != null)
       || (getSaturation() != null && other.getSaturation() == null)
       || (getSaturation() == null && other.getSaturation() != null)
       || (getBrightness() != null && other.getBrightness() == null)
       || (getBrightness() == null && other.getBrightness() != null)) {
     return false;
   }
   if (!getHue().equals(other.getHue())
       || !getSaturation().equals(other.getSaturation())
       || !getBrightness().equals(other.getBrightness())) {
     return false;
   }
   return true;
 }
  /** {@inheritDoc} */
  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;
      Color color = hsbState.toColor();
      hexValue = "#" + Integer.toHexString(color.getRGB()).substring(2);
    }
    String label = getLabel(cp);
    String purelabel = label;
    if (label.contains("<span>")) {
      purelabel = purelabel.substring(0, label.indexOf("<span>"));
    }

    snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(cp));
    snippet = StringUtils.replace(snippet, "%icon%", escapeURLPath(itemUIRegistry.getIcon(cp)));
    snippet = StringUtils.replace(snippet, "%item%", w.getItem());
    snippet = StringUtils.replace(snippet, "%label%", label);
    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;
  }