Dynamic, Static and Predefined Styles

J2ME Polish distinguishes between dynamic, static and predefined styles:

  • Predefined styles are used by the GUI for several items like screen-titles.
  • Static styles are defined in the source code of the application with the #style preprocessing directive.
  • Dynamic styles are used for items according to their position on the screen.

Static Styles

The easiest styles are the static ones. The programmer just needs to tell the designer the style names and what they are used for (that is for what kind of items or screens) and the designer defines them in the appropriate polish.css file. Static styles always start with a dot, e.g. ".myStyle". Static styles are faster than dynamic styles. It is therefore recommended to use static styles whenever possible.

Predefined Styles

Predefined styles are static styles which are used by the J2ME Polish GUI. In contrast to the normal "user-defined" static styles their names do not start with a dot, e.g. "title" instead of ".title". Following predefined styles are used:

Style  Description
title The style of screen-titles. For MIDP/2.0 devices the native implementation is used by default, unless the preprocessing variable "polish.usePolishTitle" is defined with "true":
<variable name="polish.usePolishTitle" value="true" unless="polish.Vendor == Nokia" />
focused The style of a currently focused item. This style is used in Lists, Forms and for Containers like the ChoiceGroup. You can also use custom styles for specific Screens or ChoiceGroups by using the "focused-style"-attribute.
menu This style is used for designing the menu bar in the full screen mode. The full screen mode can be triggered by the "fullScreenMode" attribute of the element in the build.xml (with fullScreenMode="menu"). In the menu style you can also define which style is used for the currently focused command with the "focused-style"-attribute, e.g. "focused-style: menuFocused;". In this case you need to define the static style ".menuFocused" as well.
menuItem The style used for the menu items (the commands) of a screen. When menuItem is not defined, the "menu" style is used instead.
label This style is used for the menu the label of any item. One can specify another label-style by defining the CSS-attribute "label-style" in the appropriate style, which refers to another style.
info The style which is used for displaying additional information in a screen. Currently this is only used for showing the current input mode when the direct input mode of a TextField or a TextBox is enabled.
default The style which is used by the J2ME Polish GUI when the desired predefined style is not defined. The default style is always defined, even when it is not explicitly defined in the polish.css file.

The names of predefined styles must not be used for static styles, so you must not use a static style with the name ".title" etc.

Dynamic Styles

Dynamic styles can be used to apply styles to items without using #style directives in the source code. With dynamic styles the designer can work completely independent of the programmer and try out new designs for GUI items which have not yet an associated static style. You can also check out the power and possibilities of the J2ME Polish API without changing the source code of an existing application at all. Obviously, dynamic styles need a bit more memory and processing time than static styles. It is recommended, therefore, to use static styles instead for finished applications. Dynamic styles do not start with a dot and use the selectors of the items they want to design: Texts use either "p", "a", "button" or "icon". Screens use the name of the screen, e.g. "form", "list" or "textbox".

p {
	font-color: black;
	font-size: medium;
	background: none;
}
form {
	margin: 5;
	background-color: gray;
	border: none;
	font-size: medium;
}

You can also design only items which are contained in other items or screens: The style "form p" designs all text-items (of the class StringItem) which are contained in a form:

form p {
	font-color: white;
	font-size: medium;
}

Static styles and dynamic styles can be used together, you can design all hyperlinks1 in the screen with the style ".startScreen" for example with the following style declaration:

.startScreen a {
	font-color: blue;
	font-size: medium;
	font-style: italic;
}

Items and screens have specific selectors for dynamic styles:

Item-Class  Selector  Explanation
StringItem p StringItem shows text. The "p" selector is used, when the item has the appearance mode PLAIN.
a The "a" selector is used, when the item has the appearance mode HYPERLINK.
button The "button" selector is used, when the item has the appearance mode BUTTON.
ImageItem img Shows an image.
Gauge gauge Shows a progress indicator.
Spacer spacer Is used for showing an empty space. The usage of the Spacer item is discouraged, since the spaces can be set for all items with the margin and padding attributes.
IconItem icon Shows an image together with text.
TextField textfield Allows textual input from the user.
DateField datefield Allows the input of dates or times from the user.
ChoiceGroup choicegroup Contains several choice items.
ChoiceItem listitem Shows a single choice. The selector "listitem" is used, when this item is contained in an implicit list.
radiobox The selector "radiobox" is used when the list or choice group has the type "exclusive".
checkbox The selector "checkbox" is used when the list or choice group has the type "multiple".
popup The selector "popup" is used when the choice group has the type "popup".

 

Screen-Class  Selector  Explanation
List list Shows several choice items.
Form form Contains different GUI items.
TextBox textbox Contains a single textfield.