javauis/m2g_qt/javasrc/javax/microedition/m2g/ScalableGraphics.java
author hgs
Fri, 15 Oct 2010 12:29:39 +0300
changeset 80 d6dafc5d983f
child 87 1627c337e51e
permissions -rw-r--r--
v2.2.19_1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
80
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
     1
/*
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
     2
* Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
     3
* All rights reserved.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
     8
*
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
     9
* Initial Contributors:
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    11
*
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    12
* Contributors:
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    13
*
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    14
* Description:
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    15
*
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    16
*/
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    17
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    18
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    19
package javax.microedition.m2g;
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    20
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    21
import com.nokia.microedition.m2g.M2GScalableGraphics;
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    22
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    23
/**
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    24
 * This is the fundamental class for 2D rendering. The ScalableGraphics context class
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    25
 * provides and handles all the rendering capability within this package. In other
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    26
 * words, the rendering can only be achieved through the render method provided
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    27
 * in this class. Note that the ScalableGraphics instance must be bound to the rendering
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    28
 * target prior to calling the render method. The implementation must clip to the
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    29
 * viewport boundaries.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    30
*/
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    31
public class ScalableGraphics
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    32
{
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    33
    // Defines a low rendering quality level.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    34
    public static final int RENDERING_QUALITY_LOW = 1;
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    35
    // Defines a high rendering quality level.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    36
    public static final int RENDERING_QUALITY_HIGH = 2;
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    37
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    38
    private M2GScalableGraphics iSg;
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    39
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    40
    /**
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    41
     *  Constructor
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    42
     */
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    43
    private ScalableGraphics()
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    44
    {
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    45
				
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    46
        iSg = new M2GScalableGraphics();
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    47
        
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    48
    }
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    49
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    50
    /**
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    51
     * Binds the given Graphics as the rendering target of this ScalableGraphics context. The
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    52
     * type of the Graphics object depends on the Java profile that this specification is
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    53
     * implemented on, as follows:
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    54
     * <ul>
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    55
     * <li> javax.microedition.lcdui.Graphics on profiles supporting LCDUI;</li>
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    56
     * <li> java.awt.Graphics on profiles supporting AWT;</li>
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    57
     * <li> either of the above on profiles supporting both AWT and LCDUI.</li>
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    58
     * </ul>
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    59
     * @param target the object (Graphics) to receive the rendered image.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    60
     * @throws NullPointerException if <code>target</code> is null.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    61
     * @throws IllegalArgumentException if <code>target</code> is invalid.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    62
     * @throws IllegalStateException if <code>target</code> is already bound.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    63
     */
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    64
    public void bindTarget(java.lang.Object target)
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    65
    {
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    66
    		
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    67
        iSg.bindTarget(target);
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    68
        
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    69
    }
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    70
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    71
    /**
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    72
     * Retrieve a new instance of ScalableGraphics that can be associated to
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    73
     * an application.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    74
     * <p>
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    75
     * @return the newly created <code>ScalableGraphics</code> instance.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    76
     */
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    77
    public static ScalableGraphics createInstance()
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    78
    {
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    79
        return new ScalableGraphics();
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    80
    }
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    81
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    82
    /**
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    83
     * Flushes the rendered ScalableImage to the currently bound target and then releases
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    84
     * the target. This ensures that the ScalableImage is actually made visible on the target
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    85
     * that was set in bindTarget. Otherwise, the image may or may not become visible.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    86
     * @throws IllegalStateException if <code>target</code> is not bound.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    87
     */
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    88
    public void releaseTarget()
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    89
    {
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    90
				
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    91
        iSg.releaseTarget();
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    92
     		
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    93
    }
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    94
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    95
    /**
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    96
     * Renders the specified ScalableImage using the supplied anchor point. The anchor point given
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    97
     * is relative to the upper left corner of the rendering surface. It is important to note that
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    98
     * the content is made visible or flushed to the display only after a call is made to
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
    99
     * <code>releaseTarget</code>.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   100
     * @param x the X coordinate of the anchor point, in pixels.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   101
     * @param y the Y coordinate of the anchor point, in pixels.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   102
     * @param image the ScalableImage to be rendered.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   103
     * @throws NullPointerException if <code>image</code> is null.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   104
     * @throws IllegalStateException if <code>target</code> is not bound.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   105
     * @see #releaseTarget
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   106
     */
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   107
    public void render(int x, int y, ScalableImage image)
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   108
    {
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   109
    		
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   110
        iSg.render(x,y, image);
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   111
        
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   112
    }
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   113
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   114
    /**
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   115
     * Set the quality of rendering in the ScalableGraphics context. It can take one of the values,
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   116
     * RENDERING_QUALITY_LOW or RENDERING_QUALITY_HIGH. Default=RENDERING_QUALITY_HIGH. The
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   117
     * implementation of these quality levels is implementation dependent and should be mapped
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   118
     * to definitions in SVG spec (shape, text, image and color rendering).
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   119
     * @param mode this value indicates the quality of rendering required.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   120
     * @throws IllegalArgumentException if the <code>mode</code> is invalid.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   121
     */
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   122
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   123
    public void setRenderingQuality(int mode)
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   124
    {
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   125
        iSg.setRenderingQuality(mode);
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   126
    }
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   127
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   128
    /**
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   129
     * Set the transparency in the ScalableGraphics context with the supplied alpha value.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   130
     * Alpha value must be a floating point number in the range [0.0, 1.0]. The source pixels
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   131
     * are always combined with destination pixels using the <i>Source Over Destination</i>
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   132
     * rule [Porter-Duff]. In this context, the Source Over Destination rule has the following
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   133
     * properties: a fully opaque pixel in the source must replace the destination pixel, a
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   134
     * fully transparent pixel in the source must leave the destination pixel unchanged, and
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   135
     * a semitransparent pixel in the source must be alpha blended with the destination pixel using
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   136
     * the supplied value. The default alpha value is 1.0 (fully opaque), when not specified.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   137
     *
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   138
     * @param alpha the constant alpha value to be used for rendering.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   139
     *
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   140
     * @throws IllegalArgumentException if <code>alpha</code> is out of range.
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   141
     */
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   142
    public void setTransparency(float alpha)
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   143
    {
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   144
        iSg.setTransparency(alpha);
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   145
    }
d6dafc5d983f v2.2.19_1
hgs
parents:
diff changeset
   146
}