Hi,
I'm trying to change the gradient used to fill a polygon based on some value. For this to work I have defined a few gradients with different ID's. I link to this gradient using a url for the fill. See below:
<------------------------------------------ SNIP START ---------------------------------------->
<linearGradient id="gradient" gradientUnits="userSpaceOnUse" x1="8.583" y1="-8.583" x2="-8.583" y2="8.583">
<stop offset="0" style="stop-color:#060000"/>
<stop offset="0.7" style="stop-color:#043600"/>
<stop offset="1" style="stop-color:#008B00"/>
</linearGradient>
<linearGradient id="gradient2" gradientUnits="userSpaceOnUse" x1="8.583" y1="-8.583" x2="-8.583" y2="8.583">
<stop offset="0" style="stop-color:#060000"/>
<stop offset="0.6" style="stop-color:#043600"/>
<stop offset="1" style="stop-color:#00AB00"/>
</linearGradient>
<linearGradient id="gradient3" gradientUnits="userSpaceOnUse" x1="8.583" y1="-8.583" x2="-8.583" y2="8.583">
<stop offset="0" style="stop-color:#060000"/>
<stop offset="0.5" style="stop-color:#043600"/>
<stop offset="1" style="stop-color:#00CB00"/>
</linearGradient>
<linearGradient id="gradient5" gradientUnits="userSpaceOnUse" x1="8.583" y1="-8.583" x2="-8.583" y2="8.583">
<stop offset="0" style="stop-color:#060000"/>
<stop offset="0.3" style="stop-color:#043600"/>
<stop offset="1" style="stop-color:#00EB00"/>
</linearGradient>
<linearGradient id="gradient10" gradientUnits="userSpaceOnUse" x1="8.583" y1="-8.583" x2="-8.583" y2="8.583">
<stop offset="0" style="stop-color:#060000"/>
<stop offset="0.1" style="stop-color:#043600"/>
<stop offset="1" style="stop-color:#00FD00"/>
</linearGradient>
<polygon id="centerPiece" fill="url(#gradient2)" points="-6.283,10.882 -12.565,0.000 -6.283,-10.882 6.283,-10.882 12.565,0.000 6.283,10.882"/>
<------------------------------------------ SNIP END ---------------------------------------->
The following code I use to change the gradient:
<------------------------------------------ SNIP START ---------------------------------------->
public void setGradient(Document doc, int fillValue) {
SVGElement fill = (SVGElement) doc.getElementById("centerPiece");
try {
if (fill != null) {
switch (fillValue) {
case 0:
fill.setTrait("fill", "black");
break;
case 1:
fill.setTrait("fill", "url(#gradient)");
break;
case 2:
fill.setTrait("fill", "url(#gradient2)");
break;
case 3:
case 4:
fill.setTrait("fill", "url(#gradient3)");
break;
case 5:
case 6:
case 7:
case 8:
case 9:
fill.setTrait("fill", "url(#gradient5)");
break;
case 10:
fill.setTrait("fill", "url(#gradient10)");
break;
}
}
} catch (DOMException dOMException) {
System.err.println("[" + new Date().toString() + "] Screen : DOMException with error-code: " + dOMException.code);
System.err.println("[" + new Date().toString() + "] Screen : DOMException Message: " + dOMException.getMessage());
System.err.println("[" + new Date().toString() + "] Screen : DOMException Element: " + fill);
}
}
<------------------------------------------ SNIP END ---------------------------------------->
When I run this code in the JavaSDK 3.0 or the WTK 2.5.2 emulator, all works fine, when I run it on my N85 and my N95 I get the exception.
I haven't been able to find:
- What traits I can set and how.
- What Nokia phones support
- How to do it differently and possibly portable as well.
All help is obviously highly appreciated.
Iwan

Reply With Quote

