KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > swing > SetSVGDocumentTest


1 /*
2
3    Copyright 2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.swing;
19
20 import org.apache.batik.test.svg.JSVGRenderingAccuracyTest;
21 import org.apache.batik.util.SVGConstants;
22 import org.apache.batik.dom.GenericDOMImplementation;
23
24 import org.w3c.dom.Document JavaDoc;
25 import org.w3c.dom.DOMImplementation JavaDoc;
26 import org.w3c.dom.Element JavaDoc;
27
28 /**
29  * Test setDocument on JSVGComponent with non-Batik SVGOMDocument.
30  *
31  * This test constructs a generic Document with SVG content then it
32  * ensures that when this is passed to JSVGComponet.setDocument it is
33  * properly imported to an SVGOMDocument and rendered from there.
34  *
35  * @author <a HREF="mailto:deweese@apache.org">l449433</a>
36  * @version $Id: SetSVGDocumentTest.java,v 1.5 2005/03/27 08:58:37 cam Exp $
37  */

38 public class SetSVGDocumentTest extends JSVGRenderingAccuracyTest {
39     public SetSVGDocumentTest() {
40     }
41     protected String JavaDoc[] breakSVGFile(String JavaDoc svgFile){
42         if(svgFile == null) {
43             throw new IllegalArgumentException JavaDoc(svgFile);
44         }
45
46         String JavaDoc [] ret = new String JavaDoc[3];
47         ret[0] = "test-resources/org/apache/batik/test/svg/";
48         ret[1] = "SetSVGDocumentTest";
49         ret[2] = ".svg";
50         return ret;
51     }
52
53     /* JSVGCanvasHandler.Delegate Interface */
54     public boolean canvasInit(JSVGCanvas canvas) {
55         DOMImplementation impl =
56             GenericDOMImplementation.getDOMImplementation();
57         Document JavaDoc doc = impl.createDocument(SVGConstants.SVG_NAMESPACE_URI,
58                                            SVGConstants.SVG_SVG_TAG, null);
59         Element JavaDoc e = doc.createElementNS(SVGConstants.SVG_NAMESPACE_URI,
60                                         SVGConstants.SVG_RECT_TAG);
61         e.setAttribute("x", "10");
62         e.setAttribute("y", "10");
63         e.setAttribute("width", "100");
64         e.setAttribute("height", "50");
65         e.setAttribute("fill", "crimson");
66         doc.getDocumentElement().appendChild(e);
67
68         e = doc.createElementNS(SVGConstants.SVG_NAMESPACE_URI,
69                                 SVGConstants.SVG_CIRCLE_TAG);
70         e.setAttribute("cx", "55");
71         e.setAttribute("cy", "35");
72         e.setAttribute("r", "30");
73         e.setAttribute("fill", "gold");
74         doc.getDocumentElement().appendChild(e);
75         
76         canvas.setDocument(doc);
77         return false; // We didn't trigger a load event.
78
}
79
80     public boolean canvasUpdated(JSVGCanvas canvas) {
81         return true;
82     }
83 }
84
Popular Tags