You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by manuel berney <ma...@urbanet.ch> on 2003/09/22 22:46:44 UTC

osx bug?? rotate animation jumps

i already post this but in the wrong place sorry..

Here is my problem i try to do an svg  watch  and animate it's elements
my wach works fine on windows xp but not in OSX !!!!


for example the code below works fine
in windows XP jdk 1.4.2 and jdk 1.4.1 but in osx  the animation jumps  
like if the rotate cx cy had changed.


i'm new to batik and not a very experienced java developer so if you  
had time to tell me what's wrong with this
do i do something wrong or is it an osx jdk bug ??


here is three class and one svg file. The main class is rotateTest.

i use netbeans 3.5.1 on osx  10.2.6 and the new updated jdk 1.4.1

Thanks manu

---------------------------------------------------------

class rotateTest just  a frame with JSVGCanvas as shown in the batik  
example
-----------------------------------------------------
/*
  * rotateTest.java
  *
  * Created on 20 septembre 2003, 10:03
  */
import org.apache.batik.bridge.UpdateManager;
import org.apache.batik.swing.gvt.*;
import org.apache.batik.swing.svg.*;
import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.script.Window;
import org.apache.batik.bridge.ViewBox;
import org.apache.batik.bridge.*;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener;
import org.w3c.dom.events.EventTarget;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.URL;
import javax.swing.*;
/**
  *
  * @author  manu
  */

     public class rotateTest {
         JSVGCanvas canvas;
         JFrame frame = new JFrame();
         JPanel panel = new JPanel();
         Document document;
         Window window;
         motor motor;
         int refresh = 20;

         public rotateTest(){
             canvas = new JSVGCanvas();
             // Forces the canvas to always be dynamic even if the  
current
             // document does not contain scripting or animation.
             canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
             canvas.addSVGLoadEventDispatcherListener
             (new SVGLoadEventDispatcherAdapter() {
                 public void svgLoadEventDispatchStarted
                 (SVGLoadEventDispatcherEvent e) {
                     // At this time the document is available...
                     document = canvas.getSVGDocument();
                     // ...and the window object too.
                     window = canvas.getUpdateManager().
                     getScriptingEnvironment().createWindow();



                     registerListeners();


                 }
             });
                 canvas.setDoubleBufferedRendering(true);
             //canvas.setBackground(new Color(0,0,0));
                 canvas.setPreferredSize(new Dimension(250, 250));

                 panel.add(canvas);
                 frame.addWindowListener(new WindowAdapter() {
                 public void windowOpened(WindowEvent e) {

                 initDocument();

             }
            });
                 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                 frame.getContentPane().add(panel);

                 Dimension screenSize =  
Toolkit.getDefaultToolkit().getScreenSize();
                 Dimension labelSize = frame.getPreferredSize();
                 frame.setLocation(screenSize.width/2 -  
(labelSize.width/2),
                 screenSize.height/2 - (labelSize.height/2));
                 frame.pack();
                 frame.show();
         }

         public void registerListeners() {
             // Gets an element from the loaded document.
             Element level6Element = document.getElementById("level6");
             EventTarget level6ET = null;
             level6ET = (EventTarget)level6Element;

             // Adds a 'onload' listener
             level6ET.addEventListener("SVGLoad", new OnLoadAction(),  
false);
             //  Set the JSVGCanvas listeners.
             canvas.addSVGDocumentLoaderListener(new  
SVGDocumentLoaderAdapter() {

                 public void  
documentLoadingStarted(SVGDocumentLoaderEvent e) {
                     System.out.println("Document Loading...");

                 }

                 public void  
documentLoadingCompleted(SVGDocumentLoaderEvent e) {
                     System.out.println("Document Loaded.");
                 }
             });

             canvas.addGVTTreeBuilderListener(new  
GVTTreeBuilderAdapter() {

                 public void gvtBuildStarted(GVTTreeBuilderEvent e) {
                     System.out.println("Build Started...");
                 }

                 public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
                     System.out.println("Build Done.");
                 }
             });

             canvas.addGVTTreeRendererListener(new  
GVTTreeRendererAdapter() {

                 public void gvtRenderingPrepare(GVTTreeRendererEvent e)  
{
                     System.out.println("Rendering Started...");
                 }
                 public void gvtRenderingCompleted(GVTTreeRendererEvent  
e) {
                     System.out.println("Ready.");
                 }
             });
             canvas.addUpdateManagerListener(new UpdateManagerListener()  
{

                 public void managerResumed(UpdateManagerEvent e) {
                     System.out.println("managerResumed Started...");
                 }

                 public void managerStarted(UpdateManagerEvent e)  {
                     System.out.println("manager Started");
                 }
                 public void managerStopped(UpdateManagerEvent e) {
                     System.out.println("manager Stopped");
                 }
                 public void managerSuspended(UpdateManagerEvent e) {
                     System.out.println("manager Suspended");
                 }
                 public void updateStarted(UpdateManagerEvent e) {

                 }
                 public void updateCompleted(UpdateManagerEvent e) {
                 }
                 public void updateFailed(UpdateManagerEvent e) {
                     System.out.println("updateFailed");
                 }
             });


         }

         public void initDocument() {

             ClassLoader cl =  
Thread.currentThread().getContextClassLoader();
             URL baseDocumentURL = cl.getResource("level6.svg");
             System.out.println("SVGApplication:  
baseDocumentURL.toString() = " +
             baseDocumentURL.toString());
             canvas.setURI(baseDocumentURL.toString());
         }

         public motor newDefaultmotor() {
         // Class in charge of clock drawing
         gearTrain gt = new gearTrain(document);
         // Class in charge of simulating the stepping motor and
         // manage time related context.
         motor = new motor();
         motor.setGearTrain(gt);
         return motor;
     }

         public static void main(String[] args) {
         new rotateTest();


     }

         public class OnLoadAction implements EventListener {
             public void handleEvent(Event evt) {

             motor = newDefaultmotor();
             window.setInterval( motor, refresh);
         }
     }
}
----------------------------------------------

class gearTrain  transform level6.svg

-----------------------------------------------

/*
  * gearTrain.java
  *
  * Created on 20 septembre 2003, 10:19
  */
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
  *
  * @author  manu
  */
public class gearTrain {

     public static String LEVEL6_SVG_ID = "level6";
     public static String LEVEL6_CONTENT_SVG_ID = "level6Content";
     Document document = null;


     Element level6Element;
     /** Creates a new instance of gearTrain */
     public gearTrain(Document document) {

         this.document = document;


         level6Element = document.getElementById(LEVEL6_SVG_ID);
     }

     float level6X = 0f;
     public void setLevel6X(float level6X) {
         this.level6X = level6X;
     }

     float level6Y = 0f;
     public void setLevel6Y(float level6Y) {
         this.level6Y = level6Y;
     }

     float level6Cx = 158.978f;
     public void setLevel6Cx(float level6Cx) {
         this.level6Cx = level6Cx;
     }

     float level6Cy = 193.324f;
     public void setLevel6Cy(float level6Cy) {
         this.level6Cy = level6Cy;
     }
     /**
      *  Level 6 rotate angle
      */
     int level6RotateAngle = 0;
     public void setLevel6RotateAngle(int level6RotateAngle) {
         this.level6RotateAngle = level6RotateAngle;
     }
     public int getLevel6RotateAngle() {
         return level6RotateAngle;
     }

     public void refresh() {



         // Apply level 6 rotation
         level6Element.setAttribute(
             "transform",
             "translate("+ level6X + " "+ level6Y +") "+
             "rotate(" + getLevel6RotateAngle() +" "+ level6Cx +" "+  
level6Cy +")");

     }

}
-------------------------------------------

class motor implements runnable for the animation process

------------------------------------------

/*
  * motor.java
  *
  * Created on 20 septembre 2003, 10:28
  */

/**
  *
  * @author  manu
  */
public class motor implements Runnable {
     int i = 5;
     /** Creates a new instance of motor */
     public motor() {
     }
     gearTrain gearTrain = null;
     public void setGearTrain(gearTrain gearTrain) {
         this.gearTrain = gearTrain;
     }
     public void run() {


         gearTrain.setLevel6RotateAngle(i);
         gearTrain.refresh();
         i =i+5;
         }
     }

------------------------------------------

level6.svg

-----------------------------------------


<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: Adobe Illustrator 10, SVG Export Plug-In . SVG Version:  
3.0.0 Build 76)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"     
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
	<!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
	<!ENTITY ns_svg "http://www.w3.org/2000/svg">
	<!ENTITY ns_xlink "http://www.w3.org/1999/xlink">
]>
<svg  xmlns="&ns_svg;" xmlns:xlink="&ns_xlink;"  
xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
	 viewBox="0 0 351.901 386.867" overflow="visible"  
enable-background="new 0 0 351.901 386.867"
	 xml:space="preserve">

<g id="level6" transform="translate(0 0) rotate(0)">
			<g id="level6Content">
				<g id="fuseauContent">
					<g id="frouge">
						<path id="aiguille" fill="none" stroke="#BE0C30" stroke-width="3"  
style="stroke-antialiasing:true" d="M158.983,217.723l0.006-135.318"/>
						<path id="balance" fill="#BE0C30" stroke="#BE0C30"  
style="stroke-antialiasing:true"  
d="M161.218,222.934c0,3.905-1.007,7.075-2.25,7.075
							s-2.25-3.17-2.25-7.075s1.007-7.075,2.25- 
7.075S161.218,219.028,161.218,222.934z"/>
					</g>
				</g>
			</g>
		</g>
</svg>


___________________

end of level6.svg


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org