The value in a CSS declaration is usually a
literal. However, it is possible to write an expression in place of
a literal.
If the value begins with
@|
, then the remainder of the value is processed as an expression.
The syntax of the expressions, after the
@|
prefix, is close to the Java syntax. The expression type can be
arithmetic (type
int
,
long
,
float
, or
double
),
Boolean
, or
String
. Examples:
@|3+2*5 -> 13
@|true&&(true||!true) -> true
@|start+end -> "startend"
You can use the following regular
arithmetic operators, listed here in decreasing precedence:
Unary operators
+
,
-
,
!
Exponentiation operator
^
Multiplicative operators
*
,
/
,
%
Additive operators
+
,
-
Relational operators
==
,
!=
,
<
,
>
,
<=
,
>=
Conditional operators
&&
,
||
Conditional operator
?:
Note
The conditional operator is left-associative, unlike in Java
where it is right-associative. In CSS, the expression
a ? b : c ? d : e
is equivalent to
(a ? b : c) ? d : e
, whereas in Java it is equivalent to
a ? b : (c ? d : e)
.
In conditional expressions such as
A ? B : C
, put spaces around the colon because a colon can also be part
of a subexpression, for example, when B is
@abc
.
An expression can refer to model attributes.
The syntax is the usual one:
@|@speed/100+@drift
-> 1/100 of the value of
speed
plus the value of
drift
.
speed
and
drift
are attributes of the current object.
'@|"name is: " + @name'
-> "name is: Bob", if the value of the current object attribute
name
is
Bob
. Note the use of quotation marks to keep the space characters. You
could use the backslash (\) character instead, directly preceding
the space characters to retain them. The backslash works to quote
any character that directly follows it. The use of the backslash
character makes sure that the character thus quoted is not
interpreted by the expression parser.
For example, when you edit a style sheet
directly and you use double quotation marks for the entire
declaration value specification, you must use escaped double
quotation marks for inner strings of CSS expressions.
node {
name: "@|concat(\"Name is \", @name)" ;
}
Alternatively, you can use quotation marks:
node {
name: '@|concat("Name is ", @name)' ;
}
The standard functions
abs()
,
acos()
,
asin()
,
atan()
,
ceil()
,
cos()
,
exp()
,
floor()
,
log()
,
pi
,
rint()
,
round()
,
sin()
,
sqrt()
, and
tan()
are accepted, as in, for example:
@|3+sin(pi/2) -> 4
The following functions are also
available:
Function |
Description |
concat(arg1,...,argn) |
Returns the concatenation of
the arguments arg1,...,argn as
strings.
|
emptyString() |
Returns an empty string. |
messageFormat(format,arg0,arg1,... |
Returns a formatted string.
The formatting is done through the object MessageFormat corresponding to the
first argument. See class java.text.MessageFormat
for details.
|
decimalFormat(format, arg) |
Returns a formatted string.
The formatting is done through the object DecimalFormat corresponding to the
first argument. See class java.text.DecimalFormat
for details.
|
simpleDateFormat(format, arg[, locale]) |
Returns a formatted string.
The formatting is done through the object SimpleDateFormat corresponding to the
first argument. See class java.text.SimpleDateFormat
for details.
|
customFormat(formatBean,arg0,arg1,...) |
Returns a formatted string. formatBean must be a Java object of type
MessageFormat, NumberFormat, or DateFormat,
usually defined using the @#id
syntax.
|
locale() |
Returns the locale of the
object being styled or of the current context. |
localized(resourceBundleName,
resourceName[, locale]) |
Returns the localized value of
the designated resource, fetched from a ResourceBundle,
as a string.
|
id() |
Returns the ID of the object
being styled. |
type() |
Returns the CSS type of the
object being styled. |
cast(expr,type) |
Casts a value to a type. The
second argument can be a fully qualified class name (entered
as a string) or a class object. |
double(expr) |
Evaluates the argument as an
expression. The result is a number of type Double. |
float(expr) |
Evaluates the argument as an
expression. The result is a number of type Float. |
int(expr) |
Evaluates the argument as an
expression. The result is a number of type Integer. |
long(expr) |
Evaluates the argument as an
expression. The result is a number of type Long. |
min(arg0,arg1, ...) |
Returns the smallest number
among the arguments. All arguments must be numbers. Unless
otherwise specified, the arguments are interpreted as numbers
of type Double. |
max(arg0,arg1, ...) |
Returns the largest number
among the arguments. All arguments must be numbers. Unless
otherwise specified, the arguments are interpreted as numbers
of type Double. |
invoke(obj,methodname,signature,arg...) |
Invokes a method on the object
by introspection. The signature string specifies the argument
types of the method as a comma separated list of (fully
qualified) type names. The object and the arguments must be
cast accordingly. For example, the specification @|invoke(cast(@val,java.lang.String),substring,"int,int",int(3),int(6))
corresponds to the call ((String)@val).substring(3,6) .
|
invokeStatic(classname,methodname,signature,arg...) |
Invokes a static method on the
specified class by introspection. The signature string
specifies the argument types of the method as a comma
separated list of (fully qualified) type names. The arguments
must be cast accordingly. For example, the specification @|invokeStatic("java.lang.Math","atan2","double,double",double(0.6),double(0.4))
corresponds to the call java.lang.Math.atan2(0.6,0.4) .
|
new(classname,signature,arg...) |
Invokes a constructor on the
specified class by introspection. The signature string
specifies the argument types of the method as a comma
separated list of (fully qualified) type names. The arguments
must be cast accordingly. For example, the specification @|new("java.util.Date","long",long(1293840000000))
corresponds to the call java.util.Date(1293840000000L) .
|
random() |
Returns a random number
between 0 (inclusive) and 1 (exclusive). |
random(n) |
Returns a random number
between 0 (inclusive) and n (exclusive). |
point(x, y) |
Returns a point of type
IlvPoint. |
rect(x, y, w, h) |
Returns a rectangle of type
IlvRect. |
blinkingColor(onColor, offColor) |
Returns a blinking color with
the timing specified in the IlvBlinkingRenderer. |
blinkingColor(onColor, offColor, onTime,
offTime) |
Returns a blinking color with
the timing onTime and offTime specified in milliseconds. |
brighterColor(color) |
Returns a brighter color.
Corresponds to Color.brighter. |
darkerColor(color) |
Returns a darker color.
Corresponds to Color.darker. |
styleSheetURL() |
Returns the URL of the current
style sheet, if any. |
styleSheetURL(path) |
Returns a URL specified by a
path relative to the location of the style sheet. |
getGraphicFromId(id) |
Returns the graphic object
that corresponds to the SDM model object with the specified
ID. |
childrenCount() |
Returns the number of children
in the SDM model for the current node, for instance if the
current node is a subgraph. |
childrenCount(tag) |
Returns the number of children
with a given tag in the SDM model for the current node, for
instance if the current node is a subgraph. |
depends(expr, prop1, ...,propn) |
Returns the value of the
expression argument. The expression is declared to depend on
the mode properties prop1 to propn. When these properties
change, the expression is re-evaluated. |