Java Code Examples for org.w3c.css.sac.LexicalUnit#getFloatValue()

The following examples show how to use org.w3c.css.sac.LexicalUnit#getFloatValue() . 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: 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 2
Source File: CSSValue.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public float getFloatValue( short unitType ) throws DOMException
{
	if ( value instanceof LexicalUnit )
	{
		LexicalUnit lu = (LexicalUnit) value;
		return lu.getFloatValue( );
	}
	return 0;
}
 
Example 3
Source File: CSSValueFactory.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static CSSNumericValue createLengthValue( LexicalUnit value ) {
  final short lexicalUnitType = value.getLexicalUnitType();
  if ( lexicalUnitType == LexicalUnit.SAC_INTEGER ) {
    if ( value.getFloatValue() != 0 ) {
      return null;
    }
    return CSSNumericValue.createValue( CSSNumericType.PT, 0 );
  }
  if ( lexicalUnitType == LexicalUnit.SAC_EM ) {
    return CSSNumericValue.createValue( CSSNumericType.EM, value.getFloatValue() );
  } else if ( lexicalUnitType == LexicalUnit.SAC_EX ) {
    return CSSNumericValue.createValue( CSSNumericType.EX,
      value.getFloatValue() );
  } else if ( lexicalUnitType == LexicalUnit.SAC_PIXEL ) {
    return CSSNumericValue.createValue( CSSNumericType.PX,
      value.getFloatValue() );
  } else if ( lexicalUnitType == LexicalUnit.SAC_INCH ) {
    return CSSNumericValue.createValue( CSSNumericType.INCH,
      value.getFloatValue() );
  } else if ( lexicalUnitType == LexicalUnit.SAC_CENTIMETER ) {
    return CSSNumericValue.createValue( CSSNumericType.CM,
      value.getFloatValue() );
  } else if ( lexicalUnitType == LexicalUnit.SAC_MILLIMETER ) {
    return CSSNumericValue.createValue( CSSNumericType.MM,
      value.getFloatValue() );
  } else if ( lexicalUnitType == LexicalUnit.SAC_PICA ) {
    return CSSNumericValue.createValue( CSSNumericType.PC,
      value.getFloatValue() );
  } else if ( lexicalUnitType == LexicalUnit.SAC_POINT ) {
    return CSSNumericValue.createValue( CSSNumericType.PT,
      value.getFloatValue() );
  }
  return null;
}
 
Example 4
Source File: AbstractLengthManager.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
 */
public Value createValue( LexicalUnit lu, CSSEngine engine )
		throws DOMException
{
	switch ( lu.getLexicalUnitType( ) )
	{
		case LexicalUnit.SAC_EM :
			return new FloatValue( CSSPrimitiveValue.CSS_EMS, lu
					.getFloatValue( ) );

		case LexicalUnit.SAC_EX :
			return new FloatValue( CSSPrimitiveValue.CSS_EXS, lu
					.getFloatValue( ) );

		case LexicalUnit.SAC_PIXEL :
			return new FloatValue( CSSPrimitiveValue.CSS_PX, lu
					.getFloatValue( ) );

		case LexicalUnit.SAC_CENTIMETER :
			return new FloatValue( CSSPrimitiveValue.CSS_CM, lu
					.getFloatValue( ) );

		case LexicalUnit.SAC_MILLIMETER :
			return new FloatValue( CSSPrimitiveValue.CSS_MM, lu
					.getFloatValue( ) );

		case LexicalUnit.SAC_INCH :
			return new FloatValue( CSSPrimitiveValue.CSS_IN, lu
					.getFloatValue( ) );

		case LexicalUnit.SAC_POINT :
			return new FloatValue( CSSPrimitiveValue.CSS_PT, lu
					.getFloatValue( ) );

		case LexicalUnit.SAC_PICA :
			return new FloatValue( CSSPrimitiveValue.CSS_PC, lu
					.getFloatValue( ) );

		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 createInvalidLexicalUnitDOMException( lu.getLexicalUnitType( ) );
}