logo       

RE: To dynamicaly update colour on SVG file: msg#00058

Subject: RE: To dynamicaly update colour on SVG file
Hi,

For a project I'm working on, I got around the lack of dynamic updates
in Batik-1.1 by manually creating my SVGDocument with a new colour every
time new colour was chosen. 

In my case the colours were prechosen by the user, and all I had to do
was to create a number of SVGs, render them into PNGs and then display
them.

This is basically all I did, (with some other gunk missing).

Dont know if this helps :)

//
//
//

public class NewIcon
{
   //
   DOMImplementation impl = SVGDOMImplementation.getDOMImplementation
();
   String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
   Document doc = impl.createDocument (svgNS, "svg", null);
      
   // Elements
   Element svgRoot = doc.getDocumentElement ();
   Element circle = doc.createElementNS (svgNS, "circle");
   Element line1  = doc.createElementNS (svgNS, "line");

   public NewIcon (String strColor)
   {
      // Set attributes 
      circle.setAttributeNS (null,"style", "stroke-width: 2.5; stroke: "
+ strColor);
      circle.setAttributeNS (null, "cx", Integer.toString (32));
      circle.setAttributeNS (null, "cy", Integer.toString (25));
      circle.setAttributeNS (null, "r",  Integer.toString (12));

      svgRoot.appendChild (circle);
   }

   public SVGDocument getDocument ()
   {
      return (SVGDocument)doc;
   }

   public ImageIcon SVGtoImage (SVGDocument svgDoc)
   {

      ImageIcon     iconTemp = null;

      PNGTranscoder t = new PNGTranscoder ();
      ByteArrayOutputStream byteOut = new ByteArrayOutputStream ();
      t.addTranscodingHint(PNGTranscoder.KEY_XML_PARSER_CLASSNAME,
                           "org.apache.crimson.parser.XMLReaderImpl");
      t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(64));
      t.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, new
Float(80));      

      // create the transcoder input
      try
      {

         TranscoderInput  input = new TranscoderInput(svgDoc);
         TranscoderOutput output = new TranscoderOutput(byteOut);

         t.transcode(input, output);
         // flush and close the stream then exit
         byteOut.flush ();
         byteOut.close ();

         // now byteOut contains the raw image data
         iconTemp = new ImageIcon (byteOut.toByteArray ());
         //iconTemp.setImage (imageTemp);
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }

      return iconTemp;
   }


}

On Tue, 2002-07-16 at 03:51, Arvind Sareen wrote:
> Hi Bala,
> 
> I do have access to SVGDocument object through the script but i do not have 
> any idea about dynamic property. Can u give me some more detail or code 
> which can help me out so that I can take input from the user and then set 
> the color of the line on the basis of the input received from the user.
> 
> Arvind
> 
> 
> >From: "K, Balamurugan (CORP, GEITC)" <Balamurugan.K@xxxxxxxxxxxx>
> >Reply-To: "Batik Users" <batik-users@xxxxxxxxxxxxxx>
> >To: Batik Users <batik-users@xxxxxxxxxxxxxx>
> >Subject: RE: To dynamicaly update colour on SVG file
> >Date: Fri, 12 Jul 2002 12:59:39 +0530
> >
> >Hi arvind,
> >         If you have access to the SVGDocument object you can set the new
> >color in the dom and re-render it. OR there is something as dynamic 
> >property
> >you can make use of it.
> >
> >Bala
> >
> >-----Original Message-----
> >From: Arvind Sareen [mailto:arvind_sareen@xxxxxxxxxxx]
> >Sent: Friday, July 12, 2002 12:34 PM
> >To: batik-users@xxxxxxxxxxxxxx
> >Subject: To dynamicaly update colour on SVG file
> >
> >
> >
> >Hi
> >
> >I need to dynamically update the colour of the line displayed in the SVG
> >file(i.e. once an SVG file is displayed , I need to change the colour of 
> >the
> >
> >line depending upon the user input)
> >Can anybody provide a workaround or solution to the above problem.
> >
> >Arvind
> >
> >_________________________________________________________________
> >Join the world's largest e-mail service with MSN Hotmail.
> >http://www.hotmail.com
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: batik-users-unsubscribe@xxxxxxxxxxxxxx
> >For additional commands, e-mail: batik-users-help@xxxxxxxxxxxxxx
> >
> >
> >"THIS E-MAIL MESSAGE ALONG WITH ANY ATTACHMENTS IS INTENDED ONLY FOR THE
> >ADDRESSEE and may contain confidential and privileged information.
> >If the reader of this message is not the intended recipient,
> >you are notified that any dissemination, distribution or copy of this
> >communication is strictly Prohibited.
> >If you have received this message by error, please notify us
> >immediately, return the original mail to the sender and delete the
> >message from your system."
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: batik-users-unsubscribe@xxxxxxxxxxxxxx
> >For additional commands, e-mail: batik-users-help@xxxxxxxxxxxxxx
> 
> 
> 
> 
> _________________________________________________________________
> Chat with friends online, try MSN Messenger: http://messenger.msn.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xxxxxxxxxxxxxx
> For additional commands, e-mail: batik-users-help@xxxxxxxxxxxxxx
> 

Attachment: signature.asc
Description: This is a digitally signed message part

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe