×

Discussion Board

Results 1 to 1 of 1
  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    23

    Question Howto: Change gradient of Polygon element programmatically

    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
    Last edited by ieising; 2009-05-25 at 16:42. Reason: Updating the layout of source code snippets.

Similar Threads

  1. [announce] Google Directions via PyS60
    By neil.young in forum Symbian
    Replies: 29
    Last Post: 2008-02-15, 10:55
  2. Change SIP and WLAN settings programmatically?
    By russellfeeed in forum Mobile Java Networking & Messaging & Security
    Replies: 6
    Last Post: 2007-05-04, 09:37
  3. How to change a label programmatically in a CAknForm?
    By Ishibo San in forum Symbian User Interface
    Replies: 1
    Last Post: 2007-03-29, 14:13
  4. Replies: 0
    Last Post: 2004-12-07, 10:56
  5. Can we change the phone profile programmatically
    By symbiannet in forum Symbian
    Replies: 1
    Last Post: 2004-03-04, 06:27

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×