Example usage for com.vaadin.shared.ui.colorpicker Color Color

List of usage examples for com.vaadin.shared.ui.colorpicker Color Color

Introduction

In this page you can find the example usage for com.vaadin.shared.ui.colorpicker Color Color.

Prototype

public Color(int rgb) 

Source Link

Document

Creates a color based on an RGB value.

Usage

From source file:eu.maxschuster.vaadin.colorpickerfield.AbstractColorPickerField.java

License:Apache License

@Override
public void readDesign(Element design, DesignContext designContext) {
    super.readDesign(design, designContext);
    Attributes attributes = design.attributes();

    // see com.vaadin.ui.AbstractColorPicker#readDesign()
    if (attributes.hasKey("color")) {
        // Ignore the # character
        String hexColor = DesignAttributeHandler.readAttribute("color", attributes, String.class).substring(1);
        setValue(new Color(Integer.parseInt(hexColor, 16)));
    }/*from   w w w  .ja  va  2  s  .c om*/

    if (attributes.hasKey("position")) {
        String[] position = attributes.get("position").split(",");
        setPosition(Integer.parseInt(position[0]), Integer.parseInt(position[1]));
    }

    if (attributes.hasKey("popup-style")) {
        setPopupStyle(
                AbstractColorPicker.PopupStyle.valueOf("POPUP_" + attributes.get("popup-style").toUpperCase()));
    }

}

From source file:eu.maxschuster.vaadin.colorpickerfield.converter.AbstractHexColorConverter.java

License:Apache License

@Override
protected Color unserializeColor(String string) throws ConversionException {
    Matcher m = HEX_PATTERN.matcher(string);
    if (!m.matches()) {
        throw new ConversionException("Could not convert '" + string + "' to a css hex color");
    }/*from   w  ww  . jav a  2  s  .  c  o m*/
    String hex = m.group(2);
    if (hex.length() == 3) {
        // Maybe a mathematically whay to do this?
        StringBuilder sb = new StringBuilder(6);
        for (char character : hex.toCharArray()) {
            sb.append(character).append(character);
        }
        hex = sb.toString();
    }
    return new Color(Integer.parseInt(hex, 16));
}

From source file:org.eclipse.hawkbit.ui.common.CoordinatesToColor.java

License:Open Source License

private static Color calculateHSVColor(final int x, final int y) {
    final float h = x / 220F;
    float s = 1F;
    float v = 1F;
    if (y < 110) {
        s = y / 110F;/*from   ww  w  .j  a v  a  2 s.  com*/
    } else if (y > 110) {
        v = 1F - (y - 110F) / 110F;
    }
    return new Color(Color.HSVtoRGB(h, s, v));
}