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