org.w3c.dom.css.RGBColor Java Examples

The following examples show how to use org.w3c.dom.css.RGBColor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CSSEngineHelper.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private Color getColor(CSSValue value, Color defaultValue) {
	if( value instanceof RGBColor ) {
		RGBColor rgbValue = (RGBColor) value;
		RGB rgb = new RGB(
				Integer.parseInt(rgbValue.getRed().getCssText()), 
				Integer.parseInt(rgbValue.getGreen().getCssText()),
				Integer.parseInt(rgbValue.getBlue().getCssText()));
		return new Color(control.getDisplay(), rgb);
	} else if( value != null ) {
		try {
			Color c = (Color) cssEngine.convert(value, Color.class, control.getDisplay());
			// Create a copy because we are disposing this colors!!!
			return new Color(control.getDisplay(),c.getRed(),c.getGreen(),c.getBlue());
		} catch (Exception e) {
		}
	}
	
	
	return defaultValue;
}
 
Example #2
Source File: CSSDocumentHandler.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
private RGB createRGB(LexicalUnit value) {
	RGBColor rgbColor = new RGBColorImpl(value);
	int green = ((int) rgbColor.getGreen().getFloatValue(CSSPrimitiveValue.CSS_NUMBER));
	int red = ((int) rgbColor.getRed().getFloatValue(CSSPrimitiveValue.CSS_NUMBER));
	int blue = ((int) rgbColor.getBlue().getFloatValue(CSSPrimitiveValue.CSS_NUMBER));
	return new RGB(red, green, blue);
}
 
Example #3
Source File: AbstractColorManager.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Implements {@link
 * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}.
 */
public Value computeValue( CSSStylableElement elt, CSSEngine engine,
		int idx, Value value )
{
	if ( value.getCssValueType( ) == CSSValue.CSS_PRIMITIVE_VALUE )
	{
		CSSPrimitiveValue pvalue = (CSSPrimitiveValue) value;
		int primitiveType = pvalue.getPrimitiveType( );
		if ( primitiveType == CSSPrimitiveValue.CSS_IDENT )
		{
			String ident = pvalue.getStringValue( );
			// Search for a direct computed value.
			Value v = (Value) computedValues.get( ident );
			if ( v != null )
			{
				return v;
			}
			// Must be a system color...
			if ( values.get( ident ) == null )
			{
				throw new InternalError( );
			}
			return (Value) engine.getCSSContext( ).getSystemColor( ident );
		}
		if ( primitiveType == CSSPrimitiveValue.CSS_RGBCOLOR )
		{
			RGBColor color = value.getRGBColorValue( );
			CSSPrimitiveValue red = color.getRed( );
			CSSPrimitiveValue green = color.getGreen( );
			CSSPrimitiveValue blue = color.getBlue( );

			return createRGBColor( createColorComponent( red ),
					createColorComponent( green ),
					createColorComponent( blue ) );
		}
	}
	return super.computeValue( elt, engine, idx, value );
}
 
Example #4
Source File: SVGUtils.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static Color toSWTColor(Element element, String attributeName) {
	Document document = element.getOwnerDocument();
	ViewCSS viewCSS = (ViewCSS) document.getDocumentElement();
	CSSStyleDeclaration computedStyle = viewCSS.getComputedStyle(element, null);
	SVGPaint svgPaint = (SVGPaint) computedStyle.getPropertyCSSValue(attributeName);
	if (svgPaint.getPaintType() == SVGPaint.SVG_PAINTTYPE_RGBCOLOR) {
		RGBColor rgb = svgPaint.getRGBColor();
		float red = rgb.getRed().getFloatValue(CSSValue.CSS_PRIMITIVE_VALUE);
		float green = rgb.getGreen().getFloatValue(CSSValue.CSS_PRIMITIVE_VALUE);
		float blue = rgb.getBlue().getFloatValue(CSSValue.CSS_PRIMITIVE_VALUE);
		return new Color(Display.getCurrent(), (int) red, (int) green, (int) blue);
	}
	return null;
}
 
Example #5
Source File: RGBColorImpl.java    From tm4e with Eclipse Public License 1.0 4 votes vote down vote up
public RGBColor getRGBColorValue() throws DOMException {
	return this;
}
 
Example #6
Source File: CSSValueImpl.java    From tm4e with Eclipse Public License 1.0 4 votes vote down vote up
public RGBColor getRGBColorValue() throws DOMException {
	throw new DOMException(DOMException.INVALID_ACCESS_ERR, "RGBCOLOR_ERROR");
}
 
Example #7
Source File: RGBColorValue.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public RGBColor getRGBColorValue( ) throws DOMException
{
	return this;
}
 
Example #8
Source File: Value.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public RGBColor getRGBColorValue( ) throws DOMException
{
	throw createDOMException( );
}
 
Example #9
Source File: CSSValue.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public RGBColor getRGBColorValue( ) throws DOMException
{
	return null;
}