Developing with the SDK > Using CSS Syntax in the Style Sheet > Applying CSS To Java Objects > Divergences from CSS2

Java objects are not HTML documents. The CSS2 syntax remains, so that a CSS editor can still be used to create the style sheet. However, the differences lead to adaptations of the CSS mechanism so that its power can be fully exploited and to some specific behavior.

Cascading

Cascading is explicit: the API offers a means of cascading style sheets. However, the !important and inherit tags are not supported for the sake of simplicity.

Pseudo-classes and Pseudo-elements

The pseudo-class construct is fully implemented and used to represent renderer-specific states or GUI items. The list of predefined pseudo-classes and where they are used is as follows:

You can add custom pseudo-classes with the method IlvSDMEngine:setPseudoClasses.

The CSS2 predefined pseudo-elements and pseudo-classes (:link, :hover, and so forth) are not implemented because they have no meaning in Java.

Attribute Matching

The attribute pattern in CSS2 makes the following checks for strings: presence [att], equality [att=val], and inclusion [att~=val] . The |= operator is disabled.

For Java objects, there are the following numeric comparators >, >=, <>, <=, <, with the usual semantics.

There are also equal and not-equal comparators which make the distinction between string comparison and numerical comparison:

Syntax Enhancement

CSS for Java requires the use of quotation marks when a token contains special characters, such as dot (.), colon (:), at sign (@), number sign (also known as hash sign, #), space (  ), and so on.

Quotes can be used almost everywhere, in particular to delimit a declaration value, an element type, or a CSS class with reserved characters.

The closing ";" is optional.

Null Value

Sometimes it makes sense to specify a null value in a declaration. By convention, null is a zero-length string '' or "". For example:

node.not-handled {
  class : '' ;
}

When a null class name is specified, no object is created at all, and no error is reported as it would be for a malformed class name.

The notation '' is also used to denote a null array for properties expecting an array of values.

Empty String

The null syntax does not allow you to specify an empty string in the style sheet. Instead, you can create an empty string, as shown in Code Sample 3.13.

node {
  label : @#emptyString ;
}

Subobject#emptyString {
  class : 'java.lang.String';
}

Code Sample 3.13 Creating an Empty String

Better still, you can use the sharing mechanism to avoid the creation of several strings. The @= construct will create the empty string the first time only and will then reuse the same instance for all other occurrences of @#emptyString, see Code Sample 3.14.

node {
  label : @=emptyString ;
}

Subobject#emptyString {
  class : 'java.lang.String';
}

Code Sample 3.14 Sharing an Empty String