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 red, int green, int blue, int alpha) 

Source Link

Document

Creates a color that has the specified red, green, blue, and alpha values within the range [0 - 255].

Usage

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

License:Apache License

@Override
protected Color unserializeColor(String string) throws ConversionException {
    Matcher m = RGBA_PATTERN.matcher(string);
    if (!m.matches()) {
        throw new ConversionException("Could not convert '" + string + "' to a css rgba color");
    }// w  w  w.  j a va2  s  . co  m
    int red = parseColor(m.group(1));
    int greed = parseColor(m.group(2));
    int blue = parseColor(m.group(3));
    int alpha = parseAlpha(m.group(4));
    return new Color(red, greed, blue, alpha);
}

From source file:org.eclipse.hawkbit.ui.colorpicker.ColorPickerHelper.java

License:Open Source License

/**
 * Covert RGB code to {@link Color}.//from   ww  w  .  j a v  a  2  s .  co  m
 *
 * @param value
 *            RGB vale
 * @return Color
 */
public static Color rgbToColorConverter(final String value) {

    if (StringUtils.isEmpty(value) || (!StringUtils.isEmpty(value) && !value.startsWith("rgb"))) {
        throw new IllegalArgumentException(
                "String to convert is empty or of invalid format - value: '" + value + "'");
    }

    // RGB color format rgb/rgba(255,255,255,0.1)
    final String[] colors = value.substring(value.indexOf('(') + 1, value.length() - 1).split(",");
    final int red = Integer.parseInt(colors[0]);
    final int green = Integer.parseInt(colors[1]);
    final int blue = Integer.parseInt(colors[2]);
    if (colors.length > 3) {
        final int alpha = (int) (Double.parseDouble(colors[3]) * 255D);
        return new Color(red, green, blue, alpha);
    }
    return new Color(red, green, blue);
}