/** * Return an integer value from 0-255 for a component of an RGB color. * * @param color typed value from the CSS parser, which may be an INTEGER or a * PERCENTAGE * @return integer value from 0-255 * @throws IllegalArgumentException if the color is not an INTEGER or * PERCENTAGE value */ private static int getRgbComponentValue(LexicalUnit color) { switch (color.getLexicalUnitType()) { case LexicalUnit.SAC_INTEGER: return Math.min(color.getIntegerValue(), 255); case LexicalUnit.SAC_PERCENTAGE: return (int) Math.min(color.getFloatValue() * 255, 255); default: throw new CSSException(CSSException.SAC_SYNTAX_ERR, "RGB component value must be integer or percentage, was " + color, null); } }
return new NumberValue(value.getIntegerValue()); case LexicalUnit.SAC_REAL: return new NumberValue(value.getFloatValue()); case LexicalUnit.SAC_CENTIMETER: case LexicalUnit.SAC_DEGREE: case LexicalUnit.SAC_RADIAN: case LexicalUnit.SAC_SECOND: return new NumberValue(value.getFloatValue(), value.getDimensionUnitText()); case LexicalUnit.SAC_URI:
public float getFloatValue(final short unitType) throws DOMException { if (value_ instanceof LexicalUnit) { final LexicalUnit lu = (LexicalUnit) value_; return lu.getFloatValue(); } throw new DOMExceptionImpl( DOMException.INVALID_ACCESS_ERR, DOMExceptionImpl.FLOAT_ERROR); // We need to attempt a conversion // return 0; }
static Float readGradientPercent( LexicalUnit unit ) { Float result = null; short type = unit.getLexicalUnitType(); if( type == LexicalUnit.SAC_PERCENTAGE ) { result = Float.valueOf( normalizePercentValue( unit.getFloatValue() ) ); } else if( type == LexicalUnit.SAC_REAL ) { result = Float.valueOf( normalizePercentValue( unit.getFloatValue() * 100 ) ); } return result; }
private static Integer readSingleLengthUnit( LexicalUnit unit ) { Integer result = null; short type = unit.getLexicalUnitType(); if( type == LexicalUnit.SAC_INTEGER ) { if( unit.getIntegerValue() == 0 ) { result = Integer.valueOf( 0 ); } } else if( type == LexicalUnit.SAC_PIXEL ) { result = Integer.valueOf( ( int )unit.getFloatValue() ); } return result; }
public CSSValue createValue( StyleKey name, LexicalUnit value ) { if ( value.getLexicalUnitType() != LexicalUnit.SAC_PERCENTAGE ) { return null; } return CSSNumericValue.createValue ( CSSNumericType.PERCENTAGE, value.getFloatValue() ); } }
/** * Return a float representation of the receiver's value. * @param valueType a short representing the value type, see {@link CSSValue#getCssValueType()} */ public float getFloatValue(short valueType) throws DOMException { //If it's actually a SAC_INTEGER return the integer value, callers tend to expect and cast //There is no getIntegerFloat(short) //TODO Not sure the purpose of arg valyeType, its not referenced in this method if(value.getLexicalUnitType() == LexicalUnit.SAC_INTEGER) return value.getIntegerValue(); //TODO not sure what to do if it's not one of the lexical unit types that are specified in LexicalUnit#getFloatValue() //ie. SAC_DEGREE, SAC_GRADIAN, SAC_RADIAN, SAC_MILLISECOND, SAC_SECOND, SAC_HERTZ or SAC_KILOHERTZ return value.getFloatValue(); }
private static float getAmountValue(LexicalUnitImpl color) { LexicalUnit next = color.getNextLexicalUnit(); float amount = 10f; if (next != null && next.getNextLexicalUnit() != null) { next = next.getNextLexicalUnit(); amount = next.getFloatValue(); } return amount; }
protected CSSValue lookupValue( final LexicalUnit value ) { CSSValue constant = super.lookupValue( value ); if ( constant != null ) { return constant; } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) { return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() ); } return CSSValueFactory.createLengthValue( value ); }
public static CSSNumericValue createNumericValue( LexicalUnit value ) { final short lexicalUnitType = value.getLexicalUnitType(); if ( lexicalUnitType == LexicalUnit.SAC_INTEGER ) { return CSSNumericValue.createValue( CSSNumericType.NUMBER, value.getIntegerValue() ); } if ( lexicalUnitType == LexicalUnit.SAC_REAL ) { return CSSNumericValue.createValue( CSSNumericType.NUMBER, value.getFloatValue() ); } return null; }
protected CSSValue lookupValue( final LexicalUnit value ) { CSSValue constant = super.lookupValue( value ); if ( constant != null ) { return constant; } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) { return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() ); } return CSSValueFactory.createLengthValue( value ); } }
protected CSSValue lookupValue( final LexicalUnit value ) { CSSValue constant = super.lookupValue( value ); if ( constant != null ) { return constant; } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) { return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() ); } return CSSValueFactory.createLengthValue( value ); } }
protected CSSValue lookupValue( final LexicalUnit value ) { if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) { return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() ); } CSSValue constant = super.lookupValue( value ); if ( constant != null ) { return constant; } return CSSValueFactory.createLengthValue( value ); } }
protected CSSValue lookupValue( final LexicalUnit value ) { CSSValue constant = super.lookupValue( value ); if ( constant != null ) { return constant; } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) { return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() ); } return CSSValueFactory.createLengthValue( value ); } }
private CSSValue parseSingleSpacingValue( final LexicalUnit value ) { if ( value == null ) { return null; } if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) { if ( value.getStringValue().equalsIgnoreCase( "normal" ) ) { return SpacingLimitReadHandler.NORMAL; } return null; } if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) { return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() ); } return CSSValueFactory.createLengthValue( value ); }
protected CSSValue lookupValue( final LexicalUnit value ) { CSSValue constant = super.lookupValue( value ); if ( constant != null ) { return constant; } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) { return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() ); } return CSSValueFactory.createLengthValue( value ); } }
public CSSValue createValue( StyleKey name, LexicalUnit value ) { if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) { if ( value.getStringValue().equalsIgnoreCase( "auto" ) ) { return CSSAutoValue.getInstance(); } return null; } if ( value.getLexicalUnitType() == LexicalUnit.SAC_PERCENTAGE ) { return CSSNumericValue.createValue( CSSNumericType.PERCENTAGE, value.getFloatValue() ); } return CSSValueFactory.createLengthValue( value ); } }
/** * Creates a float value usable as a component of an RGBColor. */ protected float getColorValue(LexicalUnit lu) { expectNonNull(lu); switch (lu.getLexicalUnitType()) { case LexicalUnit.SAC_INTEGER: return lu.getIntegerValue(); case LexicalUnit.SAC_REAL: return lu.getFloatValue(); } throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); } }
/** * Creates a float value usable as a component of an RGBColor. */ protected float getColorValue(LexicalUnit lu) { expectNonNull(lu); switch (lu.getLexicalUnitType()) { case LexicalUnit.SAC_INTEGER: return lu.getIntegerValue(); case LexicalUnit.SAC_REAL: return lu.getFloatValue(); } throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); } }
/** * Creates a float value usable as a component of an RGBColor. */ protected float getColorValue(LexicalUnit lu) { expectNonNull(lu); switch (lu.getLexicalUnitType()) { case LexicalUnit.SAC_INTEGER: return lu.getIntegerValue(); case LexicalUnit.SAC_REAL: return lu.getFloatValue(); } throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); } }