/** {@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; }
private void setHSBValue(DmxService service, HSBType hsbValue) { hsbState = hsbValue; int valueLength = isRgbw() ? 4 : 3; int[] values = new int[valueLength]; values[0] = DmxUtil.getByteFromPercentType(hsbValue.getRed()); values[1] = DmxUtil.getByteFromPercentType(hsbValue.getGreen()); values[2] = DmxUtil.getByteFromPercentType(hsbValue.getBlue()); if (isRgbw()) { values[3] = DmxUtil.calculateWhite(values[0], values[1], values[3]); } int j = 0; for (int c : channels) { service.setChannelValue(c, values[j++]); if (j == values.length) { j = 0; } } }
private StateTransformable getState(Item item) { StateTransformable state = null; if (item.getState() instanceof HSBType) { HSBType hsb = (HSBType) item.getState(); state = new HSBData(hsb.getHue().longValue(), hsb.getHue().longValue(), hsb.getHue().longValue()); } else if (item.getState() instanceof DateTimeType) { DateTimeType dt = (DateTimeType) item.getState(); DateTimeDataType data = new DateTimeDataType(dt.toString()); state = new DateTimeData(data); } else if (item.getState() instanceof DecimalType) { } else if (item.getState() instanceof OnOffType) { } else if (item.getState() instanceof OpenClosedType) { } else if (item.getState() instanceof PercentType) { } else if (item.getState() instanceof UpDownType) { } return state; }
/** {@inheritDoc} */ @Override public void processCommand(DmxService service, Command command) { // process HSB command if (command instanceof HSBType) { HSBType hsbValue = (HSBType) command; setHSBValue(service, hsbValue); return; } // process increase/decrease if (command instanceof IncreaseDecreaseType && !isRedefinedByCustomCommand(command) && !service.hasChannelActions(channels[0])) { // rather than doing a linear fade on all channels, we fade only the // V part of HSV to maintain the color during the fade HSBType hsb = hsbState; int brightness = 0; IncreaseDecreaseType t = (IncreaseDecreaseType) command; if (IncreaseDecreaseType.INCREASE.equals(t)) { if (hsb == null) { hsb = new HSBType(Color.WHITE); } for (int ch : channels) { service.enableChannel(ch); } brightness = hsb.getBrightness().intValue(); brightness += BRIGHTNESS_STEP_SIZE; if (brightness > 100) { brightness = 100; } } else { if (hsb == null) { hsb = new HSBType(Color.BLACK); } brightness = hsb.getBrightness().intValue(); brightness -= BRIGHTNESS_STEP_SIZE; if (brightness <= 0) { brightness = 0; } } HSBType newHsb = new HSBType(hsb.getHue(), hsb.getSaturation(), new PercentType(brightness)); setHSBValue(service, newHsb); return; } // process percent command if (command instanceof PercentType && !isRedefinedByCustomCommand(command) && !service.hasChannelActions(channels[0])) { PercentType t = (PercentType) command; HSBType hsb = hsbState; if (hsb == null) { hsb = new HSBType(Color.WHITE); } HSBType newHsb = new HSBType(hsb.getHue(), hsb.getSaturation(), t); setHSBValue(service, newHsb); return; } // process on/off, increase/decrease, percent type super.processCommand(service, command); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated NOT */ @Override public void setSelectedColor(HSBType color, DeviceOptions opts) { logger.debug("setSelectedColor called"); // ColorMapping may be overridden by itemConfiguration char[] colorMapping = getColorMapping().toCharArray(); String leds = null; // handle options if (opts != null) { if (opts.containsKey(COLOR_MAPPING)) { logger.debug("custom color mapping {} ", opts.getOption(COLOR_MAPPING)); colorMapping = opts.getOption(COLOR_MAPPING).toCharArray(); } if (opts.containsKey(LEDS)) { leds = opts.getOption(LEDS).trim(); logger.debug("leds: {}", leds); } } if (leds == null || leds.length() == 0) { logger.error("\"leds\" option missing or empty, items configuration has to be fixed!"); return; } // get the rgb values from HSBType Color rgbColor = color.toColor(); short red = (short) rgbColor.getRed(); short green = (short) rgbColor.getGreen(); short blue = (short) rgbColor.getBlue(); logger.debug("rgb is: {}:{}:{}", red, green, blue); // construct the values for the setRGBValues call HashMap<Character, short[]> colorMap = new HashMap<Character, short[]>(3); short[] reds = {red, red, red, red, red, red, red, red, red, red, red, red, red, red, red, red}; short[] greens = { green, green, green, green, green, green, green, green, green, green, green, green, green, green, green, green }; short[] blues = { blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue, blue }; colorMap.put('r', reds); colorMap.put('g', greens); colorMap.put('b', blues); LedList ledList = Tools.parseLedString(leds); try { if (ledList.hasLedRanges()) { Map<Integer, Short> ledRanges = ledList.getLedRanges(); for (Integer led : ledRanges.keySet()) { tinkerforgeDevice.setRGBValues( led, ledRanges.get(led), colorMap.get(colorMapping[0]), colorMap.get(colorMapping[1]), colorMap.get(colorMapping[2])); } } if (ledList.hasLeds()) { for (Integer led : ledList.getLedNumbers()) { tinkerforgeDevice.setRGBValues( led, (short) 1, colorMap.get(colorMapping[0]), colorMap.get(colorMapping[1]), colorMap.get(colorMapping[2])); } } setColor(new HSBValue(color)); } catch (TimeoutException e) { TinkerforgeErrorHandler.handleError(this, TinkerforgeErrorHandler.TF_TIMEOUT_EXCEPTION, e); } catch (NotConnectedException e) { TinkerforgeErrorHandler.handleError( this, TinkerforgeErrorHandler.TF_NOT_CONNECTION_EXCEPTION, e); } }