本文整理汇总了Java中org.w3c.css.sac.LexicalUnit.SAC_FUNCTION属性的典型用法代码示例。如果您正苦于以下问题:Java LexicalUnit.SAC_FUNCTION属性的具体用法?Java LexicalUnit.SAC_FUNCTION怎么用?Java LexicalUnit.SAC_FUNCTION使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.w3c.css.sac.LexicalUnit
的用法示例。
在下文中一共展示了LexicalUnit.SAC_FUNCTION属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createValue
/**
* Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
*/
public Value createValue(LexicalUnit lu, CSSEngine engine)
throws DOMException {
switch (lu.getLexicalUnitType()) {
case LexicalUnit.SAC_FUNCTION:
if (!lu.getFunctionName().equalsIgnoreCase("rect")) {
break;
}
case LexicalUnit.SAC_RECT_FUNCTION:
lu = lu.getParameters();
Value top = createRectComponent(lu);
lu = lu.getNextLexicalUnit();
if (lu == null ||
lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) {
throw createMalformedRectDOMException();
}
lu = lu.getNextLexicalUnit();
Value right = createRectComponent(lu);
lu = lu.getNextLexicalUnit();
if (lu == null ||
lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) {
throw createMalformedRectDOMException();
}
lu = lu.getNextLexicalUnit();
Value bottom = createRectComponent(lu);
lu = lu.getNextLexicalUnit();
if (lu == null ||
lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) {
throw createMalformedRectDOMException();
}
lu = lu.getNextLexicalUnit();
Value left = createRectComponent(lu);
return new RectValue(top, right, bottom, left);
}
throw createMalformedRectDOMException();
}
示例2: createValue
/**
* Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
*/
public Value createValue(LexicalUnit lu, CSSEngine engine)
throws DOMException {
if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
if (lu.getStringValue().equalsIgnoreCase
(CSSConstants.CSS_CURRENTCOLOR_VALUE)) {
return SVGValueConstants.CURRENTCOLOR_VALUE;
}
}
Value v = super.createValue(lu, engine);
lu = lu.getNextLexicalUnit();
if (lu == null) {
return v;
}
//If we have more content here, there is a color function after the sRGB color.
if (lu.getLexicalUnitType() != LexicalUnit.SAC_FUNCTION) {
throw createInvalidLexicalUnitDOMException
(lu.getLexicalUnitType());
}
ListValue result = new ListValue(' ');
result.append(v);
Value colorValue = parseColorFunction(lu, v);
if (colorValue != null) {
result.append(colorValue);
} else {
return v; //use sRGB fallback if an unsupported color function is encountered
}
return result;
}
示例3: buildString
@Override
public String buildString(BuildStringStrategy strategy) {
short type = getLexicalUnitType();
String text = simpleAsString();
if (text == null) {
switch (type) {
case LexicalUnit.SAC_URI:
text = "url(" + getStringValue() + ")";
break;
case LexicalUnit.SAC_RGBCOLOR:
int[] rgb = getRgb();
if (rgb != null) {
text = ColorUtil.rgbToColorString(rgb);
break;
}
// else fall through to the function branch
case LexicalUnit.SAC_COUNTER_FUNCTION:
case LexicalUnit.SAC_COUNTERS_FUNCTION:
case LexicalUnit.SAC_RECT_FUNCTION:
case LexicalUnit.SAC_FUNCTION:
if (ColorUtil.isColor(this)) {
text = ColorUtil.rgbToColorString(ColorUtil
.colorToRgb(this));
break;
} else if (ColorUtil.isRgba(this) || ColorUtil.isHsla(this)) {
float alpha = params.get(params.size() - 1)
.getContainedValue().getFloatValue();
rgb = ColorUtil.colorToRgb(this);
if (alpha == 0.0f && rgb[0] == 0 && rgb[1] == 0
&& rgb[2] == 0) {
text = "transparent";
break;
} else if (alpha == 1.0f) {
text = ColorUtil.rgbToColorString(ColorUtil
.colorToRgb(this));
break;
} else if (params.size() == 2 || ColorUtil.isHsla(this)) {
String alphaText = alpha == 0.0f ? "0"
: CSS_FLOAT_FORMAT.format(alpha);
text = "rgba(" + rgb[0] + ", " + rgb[1] + ", " + rgb[2]
+ ", " + alphaText + ")";
break;
}
}
text = fname + "(" + params.buildString(strategy) + ")";
break;
case LexicalUnit.SAC_IDENT:
text = getStringValue();
break;
case LexicalUnit.SAC_STRING_VALUE:
// @@SEEME. not exact
text = "\"" + getStringValue() + "\"";
break;
case LexicalUnit.SAC_ATTR:
text = "attr(" + getStringValue() + ")";
break;
case LexicalUnit.SAC_UNICODERANGE:
text = "@@TODO";
break;
case LexicalUnit.SAC_SUB_EXPRESSION:
text = strategy.build(getParameterList());
break;
default:
text = "@unknown";
break;
}
}
return text;
}
示例4: isRgba
/**
* Returns true if the lexical unit represents a valid RGBA value, false
* otherwise.
*
* @param unit
* lexical unit
* @return true if unit represents an RGBA value
*/
public static boolean isRgba(LexicalUnitImpl unit) {
return unit.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION
&& "rgba".equals(unit.getFunctionName())
&& (unit.getParameterList().size() == 2 || unit
.getParameterList().size() == 4);
}
示例5: isHsla
/**
* Returns true if the lexical unit represents a valid HSLA value, false
* otherwise.
*
* @param unit
* lexical unit
* @return true if unit represents an HSLA value
*/
public static boolean isHsla(LexicalUnitImpl unit) {
return unit.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION
&& "hsla".equals(unit.getFunctionName())
&& unit.getParameterList().size() == 4;
}
示例6: isHslColor
/**
* Returns true if the lexical unit represents a valid hsl() color function
* call, false otherwise.
*
* @param unit
* lexical unit
* @return true if unit represents as HSL color
*/
public static boolean isHslColor(LexicalUnitImpl unit) {
return unit.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION
&& "hsl".equals(unit.getFunctionName())
&& unit.getParameterList().size() == 3;
}