com.nokia.mid.ui
Class DirectUtils

java.lang.Object
  extended by com.nokia.mid.ui.DirectUtils

public class DirectUtils
extends java.lang.Object

This class contains utility methods for converting standard lcdui classes to Nokia UI classes and vice versa, and a method for creating images that are empty with pixels either transparent or colored, and creating mutable images from encoded image byte arrays. There is also a method for getting a Font with requested size.

Since:
1.0
See Also:
javax.microedition.lcdui.Graphics, DirectGraphics, javax.microedition.lcdui.Canvas, FullCanvas

Method Summary
static Image createImage(byte[] imageData, int imageOffset, int imageLength)
          Creates a mutable image that is decoded from the data stored in the specified byte array at the specified offset and length.
static Image createImage(int width, int height, int ARGBcolor)
           The method returns a newly created mutable Image with the specified dimension and all the pixels of the image defined by the specified ARGB color.
static DirectGraphics getDirectGraphics(Graphics g)
          Converts standard javax.microedition.lcdui.Graphics to DirectGraphics.
static Font getFont(int face, int style, int height)
           The method returns new instance of javax.microedition.lcdui.Font with custom font height.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDirectGraphics

public static DirectGraphics getDirectGraphics(Graphics g)
Converts standard javax.microedition.lcdui.Graphics to DirectGraphics. The returned object refers to the same graphics context. This means that calling draw operations or changing the state, for example, drawing color etc., via the original Graphics reference affect the DirectGraphics object, and vice versa.

Note that even though the graphics context that the DirectGraphics and Graphics refer to is the same, the object reference returned from this method may or may not be equal compared to the Graphics reference passed to this method. This means that purely casting Graphics object (g) passed in paint method of lcdui Canvas to DirectGraphics may not work ok. The safest way is to always do the conversion with this method.

Parameters:
g - Graphics object for which DirectGraphics should be returned
Returns:
the DirectGraphics object based on Graphics
Since:
1.0

createImage

public static Image createImage(byte[] imageData,
                                int imageOffset,
                                int imageLength)
Creates a mutable image that is decoded from the data stored in the specified byte array at the specified offset and length. The data must be in a self-identifying image file format supported by the implementation, e.g., PNG.

Note that the semantics of this method are exactly the same as javax.microedition.lcdui.Image#createImage(byte[],int,int) except that the returned image is mutable.

Parameters:
imageData - the array of image data in a supported image format
imageOffset - the offset of the start of the data in the array
imageLength - the length of the data in the array
Returns:
the created mutable image
Throws:
java.lang.ArrayIndexOutOfBoundsException - if imageOffset and imageLength specify an invalid range
java.lang.NullPointerException - if imageData is null
java.lang.IllegalArgumentException - if imageData is incorrectly formatted or otherwise cannot be decoded
Since:
1.0
See Also:
javax.microedition.lcdui.Image#createImage(byte[],int,int)

createImage

public static Image createImage(int width,
                                int height,
                                int ARGBcolor)

The method returns a newly created mutable Image with the specified dimension and all the pixels of the image defined by the specified ARGB color. The color can contain alpha channel transparency information.

Parameters:
width - the width of the new image, in pixels
height - the height of the new image, in pixels
ARGBcolor - the initial color for image
Returns:
the created image
Throws:
java.lang.IllegalArgumentException - if either width or height is zero or less
Since:
1.0

getFont

public static Font getFont(int face,
                           int style,
                           int height)

The method returns new instance of javax.microedition.lcdui.Font with custom font height. System provides a font that matches the requested attributes as closely as possible.

Font created in this way can be used only for Graphics instance (Canvas, CustomItem, Image). This font is not supported for high-level UI components (ChoiceGroup, StringItem and List). If font with custom height is set to some high-level component, it's replaced by default font.

Actual font height could be affected by system limitations, there may be a maximum height defined by the system.

Parameters:
face - one of FACE_SYSTEM, FACE_MONOSPACE, or FACE_PROPORTIONAL
style - STYLE_PLAIN, or a combination of STYLE_BOLD, STYLE_ITALIC, and STYLE_UNDERLINED
height - font height in pixels
Returns:
new instance of Font
Throws:
java.lang.IllegalArgumentException - if height is negative, if face or style are not legal values
Since:
1.2

forum.nokia.com/java

Copyright (c) 2002-2010 Nokia Corporation. All Rights Reserved.
Java is a trademark or registered trademark of Sun Microsystems, Inc.