org.w3c.dom.css.CSSPrimitiveValue Java Examples

The following examples show how to use org.w3c.dom.css.CSSPrimitiveValue. 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: PropertyUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public static Color getColor( CSSValue value )
{
	if ( value != null && value instanceof RGBColorValue )
	{
		RGBColorValue color = (RGBColorValue) value;
		try
		{
			return new Color( color.getRed( ).getFloatValue(
					CSSPrimitiveValue.CSS_NUMBER ) / 255.0f, color
					.getGreen( ).getFloatValue(
							CSSPrimitiveValue.CSS_NUMBER ) / 255.0f, color
					.getBlue( )
					.getFloatValue( CSSPrimitiveValue.CSS_NUMBER ) / 255.0f );
		}
		catch ( RuntimeException ex )
		{
			logger.log( Level.WARNING, "invalid color: {0}", value ); //$NON-NLS-1$
		}
	}
	else if ( value instanceof StringValue )
		return getColor( value.toString( ) );
	return null;
}
 
Example #2
Source File: CDateTimePropertyHandler.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void applyCSSPropertyFont(final Control widget, final CSSValue value, final boolean picker) throws Exception {
	if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
		final CSSValueList valueList = (CSSValueList) value;
		final int length = valueList.getLength();
		for (int i = 0; i < length; i++) {
			final CSSValue value2 = valueList.item(i);
			if (value2.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
				final String cssProp = CSS2FontHelper.getCSSFontPropertyName((CSSPrimitiveValue) value2);
				if (cssProp.equals("font-family")) {
					applyCSSPropertyFamily(widget, value2, picker);
				} else if (cssProp.equals("font-size")) {
					applyCSSPropertySize(widget, value2, picker);
				} else if (cssProp.equals("font-weight") && ("bold".equals(value2.getCssText()) || "bolder".equals(value2.getCssText()))) {
					applyCSSPropertyWeight(widget, value2, picker);
				} else if (cssProp.equals("font-style") && ("italic".equals(value2.getCssText()) || "oblique".equals(value2.getCssText()))) {
					applyCSSPropertyStyle(widget, value2, picker);
				}
			}
		}
	}
}
 
Example #3
Source File: GridPropertyHandler.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void applyCSSPropertyFont(final Object element, final Grid grid, final CSSValue value, String target) throws Exception {
	if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
		final CSSValueList valueList = (CSSValueList) value;
		final int length = valueList.getLength();
		for (int i = 0; i < length; i++) {
			final CSSValue value2 = valueList.item(i);
			if (value2.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
				final String cssProp = CSS2FontHelper.getCSSFontPropertyName((CSSPrimitiveValue) value2);
				if (cssProp.equals("font-family")) {
					applyCSSPropertyFamily(element, grid, value2, target);
				} else if (cssProp.equals("font-size")) {
					applyCSSPropertySize(element, grid, value2, target);
				} else if (cssProp.equals("font-weight") && ("bold".equals(value2.getCssText()) || "bolder".equals(value2.getCssText()))) {
					applyCSSPropertyWeight(element, grid, value2, target);
				} else if (cssProp.equals("font-style") && ("italic".equals(value2.getCssText()) || "oblique".equals(value2.getCssText()))) {
					applyCSSPropertyStyle(element, grid, value2, target);
				}
			}
		}
	}
}
 
Example #4
Source File: ChartReportStyleProcessor.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private ColorDefinition getColor( CSSValue value )
{
	if ( value != null && value instanceof RGBColorValue )
	{
		RGBColorValue color = (RGBColorValue) value;
		try
		{
			return goFactory.createColorDefinition( Math.round( color.getRed( )
					.getFloatValue( CSSPrimitiveValue.CSS_NUMBER ) ),
					Math.round( color.getGreen( )
							.getFloatValue( CSSPrimitiveValue.CSS_NUMBER ) ),
					Math.round( color.getBlue( )
							.getFloatValue( CSSPrimitiveValue.CSS_NUMBER ) ) );
		}
		catch ( RuntimeException ex )
		{
			logger.log( Level.WARNING.intValue( ),
					"invalid color: {0}" + value.toString( ) ); //$NON-NLS-1$
		}
	}
	return null;
}
 
Example #5
Source File: IRTypeConverter.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public static FloatValue toFloatValue( Object value )
{
	if( value == null )
	{
		return null;
	}
	
	if( value instanceof Number )
	{
		return new FloatValue( CSSPrimitiveValue.CSS_NUMBER, ( ( Number ) value ).floatValue( ) );
	}
	else if( value instanceof DimensionType )
	{
		return toFloatValue( ( DimensionType ) value );
	}
	else
	{
		return toFloatValue( value.toString( ) );			
	}
}
 
Example #6
Source File: IRTypeConverter.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public static FloatValue toFloatValue( DimensionType value )
{
	if ( value.getValueType( ) == DimensionType.TYPE_DIMENSION )
	{
		Object obj = UnitMapping.get( value.getUnits( ) );
		short unit;
		if( obj != null )
		{
			unit = ( ( Short ) obj ).shortValue( );
		}
		else
		{
			unit = CSSPrimitiveValue.CSS_NUMBER;
		}
		
		return new FloatValue( unit, ( float ) value.getMeasure( ) );
	}
	return null;
}
 
Example #7
Source File: BackgroundPositionXManager.java    From birt with Eclipse Public License 1.0 6 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) {
		if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
			Value percentage = (Value) percentValues.get(value
					.getStringValue());
			if (percentage != null) {
				return percentage;
			}
			throw createInvalidIdentifierDOMException(value
					.getStringValue());
		}
	}
	return super.computeValue(elt, engine, idx, value);
}
 
Example #8
Source File: BackgroundPositionYManager.java    From birt with Eclipse Public License 1.0 6 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) {
		if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
			Value percentage = (Value) percentValues.get(value
					.getStringValue());
			if (percentage != null) {
				return percentage;
			}
			throw createInvalidIdentifierDOMException(value
					.getStringValue());
		}
	}
	return super.computeValue(elt, engine, idx, value);
}
 
Example #9
Source File: FloatValue.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Converts the current value into centimeters.
 */
protected static float toCentimeters( int type, float value )
{
	switch ( type )
	{
		case CSSPrimitiveValue.CSS_CM :
			return value;
		case CSSPrimitiveValue.CSS_MM :
			return ( value / 10 );
		case CSSPrimitiveValue.CSS_IN :
			return ( value * 2.54f );
		case CSSPrimitiveValue.CSS_PT :
			return ( value * 2.54f / 72 );
		case CSSPrimitiveValue.CSS_PC :
			return ( value * 2.54f / 6 );
		default :
			throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
	}
}
 
Example #10
Source File: FloatValue.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Converts the current value into inches.
 */
protected static float toInches( int type, float value )
{
	switch ( type )
	{
		case CSSPrimitiveValue.CSS_CM :
			return ( value / 2.54f );
		case CSSPrimitiveValue.CSS_MM :
			return ( value / 25.4f );
		case CSSPrimitiveValue.CSS_IN :
			return value;
		case CSSPrimitiveValue.CSS_PT :
			return ( value / 72 );
		case CSSPrimitiveValue.CSS_PC :
			return ( value / 6 );
		default :
			throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
	}
}
 
Example #11
Source File: FloatValue.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Converts the current value into millimeters.
 */
protected static float toMillimeters( int unit, float value )
{
	switch ( unit )
	{
		case CSSPrimitiveValue.CSS_CM :
			return ( value * 10 );
		case CSSPrimitiveValue.CSS_MM :
			return value;
		case CSSPrimitiveValue.CSS_IN :
			return ( value * 25.4f );
		case CSSPrimitiveValue.CSS_PT :
			return ( value * 25.4f / 72 );
		case CSSPrimitiveValue.CSS_PC :
			return ( value * 25.4f / 6 );
		default :
			throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
	}
}
 
Example #12
Source File: FloatValue.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Converts the current value into points.
 */
protected static float toPoints( int unit, float value )
{
	switch ( unit )
	{
		case CSSPrimitiveValue.CSS_CM :
			return ( value * 72 / 2.54f );
		case CSSPrimitiveValue.CSS_MM :
			return ( value * 72 / 25.4f );
		case CSSPrimitiveValue.CSS_IN :
			return ( value * 72 );
		case CSSPrimitiveValue.CSS_PT :
			return value;
		case CSSPrimitiveValue.CSS_PC :
			return ( value * 12 );
		default :
			throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
	}
}
 
Example #13
Source File: FontWeightManager.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the CSS value associated with the given font-weight.
 */
protected CSSPrimitiveValue createFontWeight(float f) {
	switch ((int) f) {
	case 100:
		return CSSValueConstants.NUMBER_100;
	case 200:
		return CSSValueConstants.NUMBER_200;
	case 300:
		return CSSValueConstants.NUMBER_300;
	case 400:
		return CSSValueConstants.NUMBER_400;
	case 500:
		return CSSValueConstants.NUMBER_500;
	case 600:
		return CSSValueConstants.NUMBER_600;
	case 700:
		return CSSValueConstants.NUMBER_700;
	case 800:
		return CSSValueConstants.NUMBER_800;
	default: // 900
		return CSSValueConstants.NUMBER_900;
	}
}
 
Example #14
Source File: FloatValue.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Converts the current value into picas.
 */
protected static float toPicas( int unit, float value )
{
	switch ( unit )
	{
		case CSSPrimitiveValue.CSS_CM :
			return ( value * 6 / 2.54f );
		case CSSPrimitiveValue.CSS_MM :
			return ( value * 6 / 25.4f );
		case CSSPrimitiveValue.CSS_IN :
			return ( value * 6 );
		case CSSPrimitiveValue.CSS_PT :
			return ( value / 12 );
		case CSSPrimitiveValue.CSS_PC :
			return value;
		default :
			throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
	}
}
 
Example #15
Source File: AbstractColorManager.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a color component from a lexical unit.
 */
protected Value createColorComponent( LexicalUnit lu ) throws DOMException
{
	switch ( lu.getLexicalUnitType( ) )
	{
		case LexicalUnit.SAC_INTEGER :
			return new FloatValue( CSSPrimitiveValue.CSS_NUMBER, lu
					.getIntegerValue( ) );

		case LexicalUnit.SAC_REAL :
			return new FloatValue( CSSPrimitiveValue.CSS_NUMBER, lu
					.getFloatValue( ) );

		case LexicalUnit.SAC_PERCENTAGE :
			return new FloatValue( CSSPrimitiveValue.CSS_PERCENTAGE, lu
					.getFloatValue( ) );
	}
	throw createInvalidRGBComponentUnitDOMException( lu
			.getLexicalUnitType( ) );
}
 
Example #16
Source File: TableComboPropertyHandler.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void applyCSSPropertyFont(final Object element, final Control widget, final CSSValue value) throws Exception {
	if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
		final CSSValueList valueList = (CSSValueList) value;
		final int length = valueList.getLength();
		for (int i = 0; i < length; i++) {
			final CSSValue value2 = valueList.item(i);
			if (value2.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
				final String cssProp = CSS2FontHelper.getCSSFontPropertyName((CSSPrimitiveValue) value2);
				if (cssProp.equals("font-family")) {
					applyCSSPropertyFamily(element, widget, value2);
				} else if (cssProp.equals("font-size")) {
					applyCSSPropertySize(element, widget, value2);
				} else if (cssProp.equals("font-weight") && ("bold".equals(value2.getCssText()) || "bolder".equals(value2.getCssText()))) {
					applyCSSPropertyWeight(element, widget, value2);
				} else if (cssProp.equals("font-style") && ("italic".equals(value2.getCssText()) || "oblique".equals(value2.getCssText()))) {
					applyCSSPropertyStyle(element, widget, value2);
				}
			}
		}
	}
}
 
Example #17
Source File: PropertyUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static float getPercentageValue( CSSValue value )
{
	if ( value != null && ( value instanceof FloatValue ) )
	{
		FloatValue fv = (FloatValue) value;
		float v = fv.getFloatValue( );
		if ( CSSPrimitiveValue.CSS_PERCENTAGE == fv.getPrimitiveType( ) )
		{
			return v / 100.0f;
		}
	}
	return 0.0f;
}
 
Example #18
Source File: PDFAbstractLM.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected int getDimensionValue( CSSValue value, int referenceLength )
{
	if ( value != null && ( value instanceof FloatValue ) )
	{
		FloatValue fv = (FloatValue) value;
		float v = fv.getFloatValue( );
		switch ( fv.getPrimitiveType( ) )
		{
			case CSSPrimitiveValue.CSS_CM :
				return (int) ( v * 72000 / 2.54 );

			case CSSPrimitiveValue.CSS_IN :
				return (int) ( v * 72000 );

			case CSSPrimitiveValue.CSS_MM :
				return (int) ( v * 7200 / 2.54 );

			case CSSPrimitiveValue.CSS_PT :
				return (int) ( v * 1000 );
			case CSSPrimitiveValue.CSS_NUMBER :
				return (int) v;
			case CSSPrimitiveValue.CSS_PERCENTAGE :

				return (int) ( referenceLength * v/100.0 );
		}
	}
	return 0;
}
 
Example #19
Source File: PropertyUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static int getDimensionValueConsiderDpi( CSSValue value,
		IContent content )
{
	if ( value != null && ( value instanceof FloatValue ) )
	{
		FloatValue fv = (FloatValue) value;
		float v = fv.getFloatValue( );
		switch ( fv.getPrimitiveType( ) )
		{
			case CSSPrimitiveValue.CSS_CM :
				return (int) ( v * 72000 / 2.54 );

			case CSSPrimitiveValue.CSS_IN :
				return (int) ( v * 72000 );

			case CSSPrimitiveValue.CSS_MM :
				return (int) ( v * 7200 / 2.54 );

			case CSSPrimitiveValue.CSS_PC :
				return (int) ( v * 12 * 1000 );

			case CSSPrimitiveValue.CSS_PX :
				ReportDesignHandle designHandle = content
						.getReportContent( ).getDesign( ).getReportDesign( );
				int dpi = designHandle.getImageDPI( );
				if ( dpi == 0 )
				{
					dpi = 96;
				}
				return (int) ( v / dpi * 72000f );

			case CSSPrimitiveValue.CSS_PT :
				return (int) ( v * 1000 );

			case CSSPrimitiveValue.CSS_NUMBER :
				return (int) v;
		}
	}
	return 0;
}
 
Example #20
Source File: Layout.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected int getDimensionValue( CSSValue value, int referenceLength )
{
	if ( value != null && ( value instanceof FloatValue ) )
	{
		FloatValue fv = (FloatValue) value;
		float v = fv.getFloatValue( );
		switch ( fv.getPrimitiveType( ) )
		{
			case CSSPrimitiveValue.CSS_CM :
				return (int) ( v * 72000 / 2.54 );

			case CSSPrimitiveValue.CSS_IN :
				return (int) ( v * 72000 );

			case CSSPrimitiveValue.CSS_MM :
				return (int) ( v * 7200 / 2.54 );

			case CSSPrimitiveValue.CSS_PT :
				return (int) ( v * 1000 );
			case CSSPrimitiveValue.CSS_NUMBER :
				return (int) v;
			case CSSPrimitiveValue.CSS_PERCENTAGE :

				return (int) ( referenceLength * v / 100.0 );
		}
	}
	return 0;
}
 
Example #21
Source File: PropertyUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private static int getDimensionValue( CSSValue value, int dpi,
		int referenceLength )
{
	if ( value != null && ( value instanceof FloatValue ) )
	{
		FloatValue fv = (FloatValue) value;
		float v = fv.getFloatValue( );
		switch ( fv.getPrimitiveType( ) )
		{
			case CSSPrimitiveValue.CSS_CM :
				return (int) ( v * 72000 / 2.54 );

			case CSSPrimitiveValue.CSS_IN :
				return (int) ( v * 72000 );

			case CSSPrimitiveValue.CSS_MM :
				return (int) ( v * 7200 / 2.54 );

			case CSSPrimitiveValue.CSS_PC :
				return (int) ( v * 12 * 1000 );

			case CSSPrimitiveValue.CSS_PX :
				return (int) ( v / dpi * 72000f );

			case CSSPrimitiveValue.CSS_PT :
				return (int) ( v * 1000 );

			case CSSPrimitiveValue.CSS_NUMBER :
				return (int) v;

			case CSSPrimitiveValue.CSS_PERCENTAGE :
				return (int) ( referenceLength * v / 100.0 );
		}
	}
	return 0;
}
 
Example #22
Source File: FloatValue.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Converts the current value into kHertz.
 */
protected static float tokHertz( int unit, float value )
{
	switch ( unit )
	{
		case CSSPrimitiveValue.CSS_HZ :
			return ( value * 1000 );
		case CSSPrimitiveValue.CSS_KHZ :
			return value;
		default :
			throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
	}
}
 
Example #23
Source File: FloatValue.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Converts the current value into Hertz.
 */
protected static float toHertz( int unit, float value )
{
	switch ( unit )
	{
		case CSSPrimitiveValue.CSS_HZ :
			return value;
		case CSSPrimitiveValue.CSS_KHZ :
			return ( value / 1000 );
		default :
			throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
	}
}
 
Example #24
Source File: FloatValue.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Converts the current value into seconds.
 */
protected static float toSeconds( int unit, float value )
{
	switch ( unit )
	{
		case CSSPrimitiveValue.CSS_MS :
			return ( value / 1000 );
		case CSSPrimitiveValue.CSS_S :
			return value;
		default :
			throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
	}
}
 
Example #25
Source File: FloatValue.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Converts the current value into milliseconds.
 */
protected static float toMilliseconds( int unit, float value )
{
	switch ( unit )
	{
		case CSSPrimitiveValue.CSS_MS :
			return value;
		case CSSPrimitiveValue.CSS_S :
			return ( value * 1000 );
		default :
			throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
	}
}
 
Example #26
Source File: FloatValue.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Converts the current value into radians.
 */
protected static float toRadians( int unit, float value )
{
	switch ( unit )
	{
		case CSSPrimitiveValue.CSS_DEG :
			return ( value * 5 / 9 );
		case CSSPrimitiveValue.CSS_RAD :
			return value;
		case CSSPrimitiveValue.CSS_GRAD :
			return (float) ( value * 100 / Math.PI );
		default :
			throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
	}
}
 
Example #27
Source File: FloatValue.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Converts the current value into degrees.
 */
protected static float toDegrees( int unit, float value )
{
	switch ( unit )
	{
		case CSSPrimitiveValue.CSS_DEG :
			return value;
		case CSSPrimitiveValue.CSS_RAD :
			return (float) ( value * 180 / Math.PI );
		case CSSPrimitiveValue.CSS_GRAD :
			return ( value * 9 / 5 );
		default :
			throw new DOMException( DOMException.INVALID_ACCESS_ERR, "" );
	}
}
 
Example #28
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 #29
Source File: FloatValue.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the CSS text associated with the given type/value pair.
 */
public static String getCssText( short unit, float value )
{
	if ( unit < 0 || unit >= UNITS.length )
	{
		throw new DOMException( DOMException.SYNTAX_ERR, "" );
	}
	String s = FORMATTER.format( value );
	return s + UNITS[unit - CSSPrimitiveValue.CSS_NUMBER];
}
 
Example #30
Source File: RGBColorValue.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new RGBColorValue.
 */
public RGBColorValue( CSSPrimitiveValue r, CSSPrimitiveValue g,
		CSSPrimitiveValue b )
{
	red = r;
	green = g;
	blue = b;
}