de.enough.polish.ui
Class StyleSheet

java.lang.Object
  extended by de.enough.polish.ui.StyleSheet

public final class StyleSheet
extends Object

Manages all defined styles of a specific project.

This class is actually pre-processed to get the styles specific for the project and the device.

Author:
Robert Virkus, robert@enough.de
 history
        05-Jan-2004 - rob creation
 

Field Summary
static AnimationThread animationThread
          Access to the AnimationThread responsible for animating all user interface components
static Command CANCEL_CMD
          default CANCEL command
static Screen currentScreen
          Access to the currently shown J2ME Polish screen, if any
static Style defaultStyle
          default style
static Display display
          Access to the application's Display
static Style focusedStyle
          default style for focused/hovered items
protected static Hashtable imagesByName
           
static Style labelStyle
          default style for labels
static Style menuStyle
          default style for the commands menu
static MIDlet midlet
          Access to the currently running MIDlet
static Command OK_CMD
          default OK command
 
Method Summary
static void addMediaQuery(String condition, Style[] styles)
          Adds a media query to this set of styles if the condition is fulfilled.
static Style[] getDynamicStyles()
           
static Image getImage(String url, Object parent, boolean cache)
          Retrieves the image with the given name.
static Style getStyle(Item item)
          Retrieves the style for the given item.
static Style getStyle(Screen screen)
          Retrieves a dynamic style for the given screen.
static Style getStyle(String name)
          Gets the style with the specified name.
static Hashtable getStyles()
          Retrieves all registered styles in a Hashtable.
static void notifyImageConsumers(String name, Image image)
          Notifies the GUI items which requested images about the successful loading of thoses images.
static void releaseResources()
          Releases all (memory intensive) resources such as images or RGB arrays of this style sheet.
static void replaceStyleAttributes(Style oldAttributesStyle, Style newAttributesStyle, String styleNameMatch)
          Replaces any old attributes in all matching styles with the given new attributes.
static void showNotify()
          placeholder for showNotify method which is added when using media queries
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

imagesByName

protected static Hashtable imagesByName

defaultStyle

public static Style defaultStyle
default style


focusedStyle

public static Style focusedStyle
default style for focused/hovered items


labelStyle

public static Style labelStyle
default style for labels


menuStyle

public static Style menuStyle
default style for the commands menu


currentScreen

public static Screen currentScreen
Access to the currently shown J2ME Polish screen, if any


display

public static Display display
Access to the application's Display


midlet

public static MIDlet midlet
Access to the currently running MIDlet


animationThread

public static AnimationThread animationThread
Access to the AnimationThread responsible for animating all user interface components


OK_CMD

public static Command OK_CMD
default OK command


CANCEL_CMD

public static Command CANCEL_CMD
default CANCEL command

Method Detail

getImage

public static Image getImage(String url,
                             Object parent,
                             boolean cache)
                      throws IOException
Retrieves the image with the given name. When the image has been cached before, it will be returned immediately. When it has not been cached before, it either will be loaded directly or in a background thread. This behaviour is set in the polish.xml file.

Parameters:
url - the URL of the Image, e.g. "/background.png"
parent - the object which needs the image, when the image should be loaded in the background, the parent need to implement the ImageConsumer interface when it wants to be notified when the picture has been loaded.
cache - true when the image should be cached for later retrieval. This costs RAM obviously, so you should decide carefully if large images should be cached.
Returns:
the image when it either was cached or is loaded directly. When the should be loaded in the background, it will be later set via the ImageConsumer.setImage()-method.
Throws:
IOException - when the image could not be loaded directly
See Also:
ImageConsumer.setImage(String, Image)

notifyImageConsumers

public static void notifyImageConsumers(String name,
                                        Image image)
Notifies the GUI items which requested images about the successful loading of thoses images.

Parameters:
name - the URL of the image
image - the image

getStyle

public static Style getStyle(String name)
Gets the style with the specified name.

Parameters:
name - the name of the style
Returns:
the specified style or null when no style with the given name has been defined.

getStyles

public static Hashtable getStyles()
Retrieves all registered styles in a Hashtable.

Returns:
all registered styles in a Hashtable.

getStyle

public static Style getStyle(Item item)
Retrieves the style for the given item. This function is only available when the <buildSetting>-attribute [useDynamicStyles] is enabled. This function allows to set styles without actually using the preprocessing- directive //#style. Beware that this dynamic style retrieval is not as performant as the direct-style-setting with the //#style preprocessing directive.

Parameters:
item - the item for which the style should be retrieved
Returns:
the appropriate style. When no specific style is found, the default style is returned.

getStyle

public static Style getStyle(Screen screen)
Retrieves a dynamic style for the given screen.

Parameters:
screen - the screen for which a style should be retrieved
Returns:
the style for the given screen.

showNotify

public static void showNotify()
placeholder for showNotify method which is added when using media queries


addMediaQuery

public static void addMediaQuery(String condition,
                                 Style[] styles)
Adds a media query to this set of styles if the condition is fulfilled. This method is only accessible when the preprocessing symbol polish.css.mediaquery is true.

Parameters:
condition - the condition, compare http://www.w3.org/TR/css3-mediaqueries/
styles - the styles that should be modified by this condition

replaceStyleAttributes

public static void replaceStyleAttributes(Style oldAttributesStyle,
                                          Style newAttributesStyle,
                                          String styleNameMatch)
Replaces any old attributes in all matching styles with the given new attributes. This can be useful for example for implementing a day and night theme of your app.

Parameters:
oldAttributesStyle - the old attributes that should be replaced
newAttributesStyle - the new attributes that should be used
styleNameMatch - a string like "feature" (matching all styles with names that contain "feature"), "feature*" (names start with "feature") or "*feature" (names end with "feature"). Use null to match _all_ styles.

releaseResources

public static void releaseResources()
Releases all (memory intensive) resources such as images or RGB arrays of this style sheet.


getDynamicStyles

public static Style[] getDynamicStyles()