/** * 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 an int representation of the receiver's value. * @param valueType a short representing the value type, see {@link CSSValue#getCssValueType()} */ public int getIntegerValue(short valueType) throws DOMException { return value.getIntegerValue(); }
return new NumberValue(value.getIntegerValue()); case LexicalUnit.SAC_REAL: return new NumberValue(value.getFloatValue());
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_INTEGER ) { return CSSNumericValue.createValue( CSSNumericType.NUMBER, value.getIntegerValue() ); } return null; }
public CSSValue createValue( StyleKey name, LexicalUnit value ) { if ( value.getLexicalUnitType() == LexicalUnit.SAC_INTEGER ) { return CSSNumericValue.createValue( CSSNumericType.NUMBER, value.getIntegerValue() ); } return null; }
public CSSValue createValue( StyleKey name, LexicalUnit value ) { if ( value.getLexicalUnitType() == LexicalUnit.SAC_INTEGER ) { return CSSNumericValue.createValue( CSSNumericType.NUMBER, value.getIntegerValue() ); } return null; } }
/** * 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(); }
protected CSSValue lookupValue( final LexicalUnit value ) { CSSValue constant = super.lookupValue( value ); if ( constant != null ) { return constant; } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_INTEGER ) { return CSSNumericValue.createValue( CSSNumericType.NUMBER, value.getIntegerValue() ); } return null; } }
protected CSSValue lookupValue( final LexicalUnit value ) { CSSValue constant = super.lookupValue( value ); if ( constant != null ) { return constant; } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_INTEGER ) { return CSSNumericValue.createValue( CSSNumericType.NUMBER, value.getIntegerValue() ); } return null; } }
public CSSValue createValue( StyleKey name, LexicalUnit value ) { if ( value.getLexicalUnitType() == LexicalUnit.SAC_IDENT ) { if ( value.getStringValue().equalsIgnoreCase( "auto" ) ) { return CSSAutoValue.getInstance(); } return null; } else if ( value.getLexicalUnitType() == LexicalUnit.SAC_INTEGER ) { return CSSNumericValue.createValue( CSSNumericType.NUMBER, value.getIntegerValue() ); } return null; } }
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; }
/** * 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()); } }
/** * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}. */ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { switch (lu.getLexicalUnitType()) { case LexicalUnit.SAC_INHERIT: return SVGValueConstants.INHERIT_VALUE; case LexicalUnit.SAC_INTEGER: return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getIntegerValue()); case LexicalUnit.SAC_REAL: return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getFloatValue()); } throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); }
/** * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}. */ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { switch (lu.getLexicalUnitType()) { case LexicalUnit.SAC_INHERIT: return SVGValueConstants.INHERIT_VALUE; case LexicalUnit.SAC_INTEGER: return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getIntegerValue()); case LexicalUnit.SAC_REAL: return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getFloatValue()); default: throw createInvalidLexicalUnitDOMException (lu.getLexicalUnitType()); } }
/** * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}. */ public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { switch (lu.getLexicalUnitType()) { case LexicalUnit.SAC_INHERIT: return SVGValueConstants.INHERIT_VALUE; case LexicalUnit.SAC_INTEGER: return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getIntegerValue()); case LexicalUnit.SAC_REAL: return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getFloatValue()); } throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType()); }
public Value createValue(LexicalUnit lu, CSSEngine engine) throws DOMException { switch (lu.getLexicalUnitType()) { case LexicalUnit.SAC_INHERIT: return CssValueConstants.INHERIT_VALUE; case LexicalUnit.SAC_INTEGER: return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getIntegerValue()); case LexicalUnit.SAC_REAL: return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu.getFloatValue()); default: throw createInvalidLexicalUnitDOMException (lu.getLexicalUnitType(), engine); } }
/** * 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()); }