|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
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 |
|
46 iSg = new M2GScalableGraphics(); |
|
47 |
|
48 } |
|
49 |
|
50 /** |
|
51 * Binds the given Graphics as the rendering target of this ScalableGraphics context. The |
|
52 * type of the Graphics object depends on the Java profile that this specification is |
|
53 * implemented on, as follows: |
|
54 * <ul> |
|
55 * <li> javax.microedition.lcdui.Graphics on profiles supporting LCDUI;</li> |
|
56 * <li> java.awt.Graphics on profiles supporting AWT;</li> |
|
57 * <li> either of the above on profiles supporting both AWT and LCDUI.</li> |
|
58 * </ul> |
|
59 * @param target the object (Graphics) to receive the rendered image. |
|
60 * @throws NullPointerException if <code>target</code> is null. |
|
61 * @throws IllegalArgumentException if <code>target</code> is invalid. |
|
62 * @throws IllegalStateException if <code>target</code> is already bound. |
|
63 */ |
|
64 public void bindTarget(java.lang.Object target) |
|
65 { |
|
66 |
|
67 iSg.bindTarget(target); |
|
68 |
|
69 } |
|
70 |
|
71 /** |
|
72 * Retrieve a new instance of ScalableGraphics that can be associated to |
|
73 * an application. |
|
74 * <p> |
|
75 * @return the newly created <code>ScalableGraphics</code> instance. |
|
76 */ |
|
77 public static ScalableGraphics createInstance() |
|
78 { |
|
79 return new ScalableGraphics(); |
|
80 } |
|
81 |
|
82 /** |
|
83 * Flushes the rendered ScalableImage to the currently bound target and then releases |
|
84 * the target. This ensures that the ScalableImage is actually made visible on the target |
|
85 * that was set in bindTarget. Otherwise, the image may or may not become visible. |
|
86 * @throws IllegalStateException if <code>target</code> is not bound. |
|
87 */ |
|
88 public void releaseTarget() |
|
89 { |
|
90 |
|
91 iSg.releaseTarget(); |
|
92 |
|
93 } |
|
94 |
|
95 /** |
|
96 * Renders the specified ScalableImage using the supplied anchor point. The anchor point given |
|
97 * is relative to the upper left corner of the rendering surface. It is important to note that |
|
98 * the content is made visible or flushed to the display only after a call is made to |
|
99 * <code>releaseTarget</code>. |
|
100 * @param x the X coordinate of the anchor point, in pixels. |
|
101 * @param y the Y coordinate of the anchor point, in pixels. |
|
102 * @param image the ScalableImage to be rendered. |
|
103 * @throws NullPointerException if <code>image</code> is null. |
|
104 * @throws IllegalStateException if <code>target</code> is not bound. |
|
105 * @see #releaseTarget |
|
106 */ |
|
107 public void render(int x, int y, ScalableImage image) |
|
108 { |
|
109 |
|
110 iSg.render(x,y, image); |
|
111 |
|
112 } |
|
113 |
|
114 /** |
|
115 * Set the quality of rendering in the ScalableGraphics context. It can take one of the values, |
|
116 * RENDERING_QUALITY_LOW or RENDERING_QUALITY_HIGH. Default=RENDERING_QUALITY_HIGH. The |
|
117 * implementation of these quality levels is implementation dependent and should be mapped |
|
118 * to definitions in SVG spec (shape, text, image and color rendering). |
|
119 * @param mode this value indicates the quality of rendering required. |
|
120 * @throws IllegalArgumentException if the <code>mode</code> is invalid. |
|
121 */ |
|
122 |
|
123 public void setRenderingQuality(int mode) |
|
124 { |
|
125 iSg.setRenderingQuality(mode); |
|
126 } |
|
127 |
|
128 /** |
|
129 * Set the transparency in the ScalableGraphics context with the supplied alpha value. |
|
130 * Alpha value must be a floating point number in the range [0.0, 1.0]. The source pixels |
|
131 * are always combined with destination pixels using the <i>Source Over Destination</i> |
|
132 * rule [Porter-Duff]. In this context, the Source Over Destination rule has the following |
|
133 * properties: a fully opaque pixel in the source must replace the destination pixel, a |
|
134 * fully transparent pixel in the source must leave the destination pixel unchanged, and |
|
135 * a semitransparent pixel in the source must be alpha blended with the destination pixel using |
|
136 * the supplied value. The default alpha value is 1.0 (fully opaque), when not specified. |
|
137 * |
|
138 * @param alpha the constant alpha value to be used for rendering. |
|
139 * |
|
140 * @throws IllegalArgumentException if <code>alpha</code> is out of range. |
|
141 */ |
|
142 public void setTransparency(float alpha) |
|
143 { |
|
144 iSg.setTransparency(alpha); |
|
145 } |
|
146 } |