56
|
1 |
/*
|
87
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
56
|
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 |
package com.nokia.microedition.m2g;
|
|
19 |
|
|
20 |
import org.w3c.dom.svg.*;
|
|
21 |
import org.w3c.dom.DOMException;
|
|
22 |
import java.io.IOException;
|
|
23 |
import com.nokia.mj.impl.utils.Logger;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* This interface represents an "SVGPath" datatype used to define the path geometry.
|
|
27 |
* Corresponds to SVG path specification or the "d" attribute.
|
|
28 |
*/
|
|
29 |
public class M2GSVGPath extends M2GObject implements SVGPath
|
|
30 |
{
|
|
31 |
//--------------------------------------------------
|
|
32 |
// STATIC CONTANTS
|
|
33 |
//--------------------------------------------------
|
87
|
34 |
|
56
|
35 |
private static final int CLOSE_PARAMETER_COUNT = 0;
|
|
36 |
private static final int MOVE_TO_PARAMETER_COUNT = 2;
|
|
37 |
private static final int LINE_TO_PARAMETER_COUNT = 2;
|
|
38 |
private static final int CURVE_TO_PARAMETER_COUNT = 6;
|
|
39 |
private static final int QUAD_TO_PARAMETER_COUNT = 4;
|
|
40 |
|
|
41 |
//--------------------------------------------------
|
|
42 |
// VARIABLES
|
|
43 |
//--------------------------------------------------
|
|
44 |
|
|
45 |
//--------------------------------------------------
|
|
46 |
// METHODS
|
|
47 |
//--------------------------------------------------
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Constructor
|
|
51 |
* @param aHandle - native path object handle
|
|
52 |
* @param aDoCleanup - true if the native object needed to be deleted
|
|
53 |
*/
|
|
54 |
protected M2GSVGPath(int aHandle)
|
|
55 |
{
|
|
56 |
super();
|
|
57 |
setHandle(aHandle);
|
|
58 |
doConstruct();
|
|
59 |
}
|
|
60 |
|
|
61 |
/**
|
|
62 |
* @see com.nokia.microedition.m2g.M2GObject#doCheckValidity()
|
|
63 |
*/
|
|
64 |
public boolean doCheckValidity()
|
|
65 |
{
|
|
66 |
// SVGPath is invalid if it begins with any segment other
|
|
67 |
// than MOVE_TO segment. Note that an empty SVGPath is still a valid value.
|
|
68 |
try
|
|
69 |
{
|
|
70 |
if (!super.doCheckValidity() ||
|
|
71 |
((getNumberOfSegments() != 0) && (getSegment(0) != MOVE_TO)))
|
|
72 |
{
|
|
73 |
return false;
|
|
74 |
}
|
|
75 |
}
|
|
76 |
catch (IOException e)
|
|
77 |
{
|
|
78 |
return false;
|
|
79 |
}
|
|
80 |
return true;
|
|
81 |
}
|
|
82 |
|
|
83 |
/**
|
|
84 |
* @see com.nokia.microedition.m2g.M2GObject#doCleanup()
|
|
85 |
*/
|
|
86 |
protected void doCleanup()
|
|
87 |
{
|
|
88 |
_destroyPath(getNativeSVGProxyHandle(),
|
87
|
89 |
getHandle());
|
56
|
90 |
resetHandles();
|
|
91 |
}
|
|
92 |
|
|
93 |
/**
|
|
94 |
* @see com.nokia.microedition.m2g.M2GObject#doConstruct()
|
|
95 |
*/
|
|
96 |
protected void doConstruct()
|
|
97 |
{
|
|
98 |
super.doConstruct();
|
|
99 |
register(this);
|
|
100 |
}
|
|
101 |
|
|
102 |
|
|
103 |
/**
|
|
104 |
* @see org.w3c.dom.svg.SVGPath#getNumberOfSegments()
|
|
105 |
*/
|
|
106 |
public int getNumberOfSegments()
|
|
107 |
{
|
|
108 |
return _getNumberOfSegments(getNativeSVGProxyHandle(),
|
87
|
109 |
getHandle());
|
56
|
110 |
}
|
|
111 |
|
|
112 |
/**
|
|
113 |
* @see org.w3c.dom.svg.SVGPath#getSegment()
|
|
114 |
*/
|
|
115 |
public short getSegment(int index) throws DOMException
|
|
116 |
{
|
|
117 |
if ((index < 0) ||
|
|
118 |
(index >= getNumberOfSegments()))
|
|
119 |
{
|
|
120 |
Logger.ELOG(Logger.EJavaUI, "getSegment() - exception:"
|
|
121 |
+ /*SF*/"The segment index is out of bounds."/*SF*/);
|
|
122 |
throw new DOMException(
|
|
123 |
DOMException.INDEX_SIZE_ERR,
|
|
124 |
/*SF*/"The segment index is out of bounds."/*SF*/);
|
|
125 |
}
|
|
126 |
return M2GSVGConstants.parsePathCommand(
|
|
127 |
_getSegmentType(getNativeSVGProxyHandle(),
|
|
128 |
getHandle(),
|
|
129 |
index)
|
|
130 |
);
|
|
131 |
}
|
|
132 |
|
|
133 |
/**
|
|
134 |
* Checks that parameter index is valid
|
|
135 |
* @param aCommand -
|
|
136 |
* @param aParameterIndex -
|
|
137 |
*/
|
|
138 |
protected void checkParameterIndex(int aCommand, int aParameterIndex) throws DOMException
|
|
139 |
{
|
|
140 |
if ((aCommand == CLOSE && aParameterIndex >= CLOSE_PARAMETER_COUNT) ||
|
|
141 |
(aCommand == MOVE_TO && aParameterIndex >= MOVE_TO_PARAMETER_COUNT)
|
|
142 |
|| (aCommand == LINE_TO && aParameterIndex >= LINE_TO_PARAMETER_COUNT)
|
|
143 |
|| (aCommand == CURVE_TO && aParameterIndex >= CURVE_TO_PARAMETER_COUNT)
|
|
144 |
|| (aCommand == QUAD_TO && aParameterIndex >= QUAD_TO_PARAMETER_COUNT))
|
|
145 |
{
|
|
146 |
throw new DOMException(
|
|
147 |
DOMException.INDEX_SIZE_ERR,
|
|
148 |
/*SF*/"The parameter index is out of bounds for this segment's type."/*SF*/);
|
|
149 |
}
|
|
150 |
}
|
|
151 |
|
|
152 |
/**
|
|
153 |
* @see org.w3c.dom.svg.SVGPath#close()
|
|
154 |
*/
|
|
155 |
public void close()
|
|
156 |
{
|
|
157 |
_addClose(getNativeSVGProxyHandle(), getHandle());
|
|
158 |
}
|
|
159 |
|
|
160 |
/**
|
|
161 |
* @see org.w3c.dom.svg.SVGPath#curveTo()
|
|
162 |
*/
|
|
163 |
public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
|
|
164 |
{
|
|
165 |
_addCurveTo(getNativeSVGProxyHandle(),
|
87
|
166 |
getHandle(), x1, y1, x2, y2, x3, y3);
|
56
|
167 |
}
|
|
168 |
|
|
169 |
/**
|
|
170 |
* @see org.w3c.dom.svg.SVGPath#getSegmentParam()
|
|
171 |
*/
|
|
172 |
public float getSegmentParam(int cmdIndex, int paramIndex)
|
|
173 |
{
|
|
174 |
if ((cmdIndex >= getNumberOfSegments()) ||
|
|
175 |
(cmdIndex < 0) ||
|
|
176 |
(paramIndex < 0))
|
|
177 |
{
|
|
178 |
Logger.ELOG(Logger.EJavaUI, "getSegmentParam() - end, exception:"
|
|
179 |
+ /*SF*/"The segment index is out of bounds."/*SF*/);
|
|
180 |
throw new DOMException(
|
|
181 |
DOMException.INDEX_SIZE_ERR,
|
|
182 |
/*SF*/"The segment index is out of bounds."/*SF*/);
|
|
183 |
}
|
|
184 |
short command = getSegment(cmdIndex);
|
|
185 |
// Checks the validity of the parameter index.
|
|
186 |
checkParameterIndex(command, paramIndex);
|
|
187 |
return _getSegmentParameter(getNativeSVGProxyHandle(),
|
|
188 |
getHandle(),
|
|
189 |
cmdIndex,
|
|
190 |
paramIndex
|
|
191 |
);
|
|
192 |
}
|
|
193 |
|
|
194 |
/**
|
|
195 |
* @see org.w3c.dom.svg.SVGPath#lineTo()
|
|
196 |
*/
|
|
197 |
public void lineTo(float x, float y)
|
|
198 |
{
|
|
199 |
_addLineTo(getNativeSVGProxyHandle(), getHandle(), x, y);
|
|
200 |
}
|
|
201 |
|
|
202 |
/**
|
|
203 |
* @see org.w3c.dom.svg.SVGPath#moveTo()
|
|
204 |
*/
|
|
205 |
public void moveTo(float x, float y)
|
|
206 |
{
|
87
|
207 |
_addMoveTo(getNativeSVGProxyHandle(), getHandle(), x, y);
|
56
|
208 |
}
|
|
209 |
|
|
210 |
/**
|
|
211 |
* @see org.w3c.dom.svg.SVGPath#quadTo()
|
|
212 |
*/
|
|
213 |
public void quadTo(float x1, float y1, float x2, float y2)
|
|
214 |
{
|
|
215 |
_addQuadTo(getNativeSVGProxyHandle(),
|
|
216 |
getHandle(),
|
|
217 |
x1,
|
|
218 |
y1,
|
|
219 |
x2,
|
87
|
220 |
y2);
|
56
|
221 |
}
|
|
222 |
|
|
223 |
//--------------------------------------------------
|
|
224 |
// NATIVE METHODS
|
|
225 |
//--------------------------------------------------
|
|
226 |
private static native void _addClose(
|
|
227 |
int aSVGProxyHandle, int aPathHandle);
|
|
228 |
|
|
229 |
private static native void _addCurveTo(
|
|
230 |
int aSVGProxyHandle, int aPathHandle,
|
|
231 |
float aX1, float aY1, float aX2, float aY2, float aX3, float aY3);
|
|
232 |
|
|
233 |
private static native void _addLineTo(
|
|
234 |
int aSVGProxyHandle, int aPathHandle, float aX, float aY);
|
|
235 |
|
|
236 |
private static native void _addMoveTo(
|
|
237 |
int aSVGProxyHandle, int aPathHandle, float aX, float aY);
|
|
238 |
|
|
239 |
private static native void _addQuadTo(
|
|
240 |
int aSVGProxyHandle, int aPathHandle,
|
|
241 |
float aX1, float aY1, float aX2, float aY2);
|
|
242 |
|
|
243 |
static native int _createPath(
|
|
244 |
int aSVGProxyHandle);
|
|
245 |
|
|
246 |
private static native void _destroyPath(
|
|
247 |
int aSVGProxyHandle, int aPathHandle);
|
|
248 |
|
|
249 |
private static native int _getNumberOfSegments(
|
|
250 |
int aSVGProxyHandle, int aPathHandle);
|
|
251 |
|
|
252 |
private static native float _getSegmentParameter(
|
|
253 |
int aSVGProxyHandle, int aPathHandle, int aCmdIndex, int aParamIndex);
|
|
254 |
|
|
255 |
private static native short _getSegmentType(
|
|
256 |
int aSVGProxyHandle, int aPathHandle, int aIndex);
|
|
257 |
}
|
|
258 |
|