Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/nokia/mid/ui/DirectUtils.java


1   /*
2    *  Nokia API for MicroEmulator
3    *  Copyright (C) 2003 Markus Heberling <markus@heberling.net>
4    *
5    *  This library is free software; you can redistribute it and/or
6    *  modify it under the terms of the GNU Lesser General Public
7    *  License as published by the Free Software Foundation; either
8    *  version 2.1 of the License, or (at your option) any later version.
9    *
10   *  This library is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   *  Lesser General Public License for more details.
14   *
15   *  You should have received a copy of the GNU Lesser General Public
16   *  License along with this library; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package com.nokia.mid.ui;
21  
22  import javax.microedition.lcdui.Graphics;
23  import javax.microedition.lcdui.Image;
24  
25  /** This class is a placeholder for utility methods. It contains 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. */
26  public class DirectUtils
27  {
28  
29    /** 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.
30     *
31     * 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.
32     * @param g Graphics object for which DirectGraphics should be returned
33     * @return the DirectGraphics object based on Graphics
34     */    
35    public static DirectGraphics getDirectGraphics(Graphics g)
36    {
37      return new DirectGraphicsImp(g);
38    }
39  
40    /** 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.
41     *
42     * Note that the semantics of this method are exactly the same as Image.createImage(byte[],int,int) except that the returned image is mutable.
43     * @param imageData the array of image data in a supported image format
44     * @param imageOffset the offset of the start of the data in the array
45     * @param imageLength the length of the data in the array
46     * @return the created mutable image
47     */    
48    public static Image createImage(byte imageData[], int imageOffset, int imageLength)
49    {
50      Image source = Image.createImage(imageData, imageOffset, imageLength);
51      Image target = Image.createImage(source.getWidth(), source.getHeight());
52      target.getGraphics().drawImage(source,0,0,0);
53      return target;
54    }
55  
56    /** The method will return 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.
57     * @param width the width of the new image, in pixels
58     * @param height the height of the new image, in pixels
59     * @param argb the initial color for image<br>Note: This is argb color, but alpha channel is currently
60     * not supported by this emulation.
61     * @return the created image
62     */    
63    public static Image createImage(int width, int height, int argb)
64    {
65      Image img = Image.createImage(width, height);
66      Graphics g = img.getGraphics();
67      g.setColor(argb);
68      g.fillRect(0,0, width,height);
69      g.setColor(0);
70      return img;
71    }
72  
73  }