KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > svggen > SVGCustomComposite


1 /*
2
3    Copyright 2001,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.svggen;
19
20 import java.awt.Composite JavaDoc;
21
22 import org.apache.batik.ext.awt.g2d.GraphicContext;
23 import org.w3c.dom.Element JavaDoc;
24
25 /**
26  * Utility class that converts an custom Composite object into
27  * a set of SVG properties and definitions.
28  *
29  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
30  * @version $Id: SVGCustomComposite.java,v 1.9 2004/08/18 07:14:59 vhardy Exp $
31  * @see org.apache.batik.svggen.SVGComposite
32  */

33 public class SVGCustomComposite extends AbstractSVGConverter {
34     /**
35      * @param generatorContext for use by SVGCustomComposite to build Elements
36      */

37     public SVGCustomComposite(SVGGeneratorContext generatorContext) {
38         super(generatorContext);
39     }
40
41     /**
42      * Converts part or all of the input GraphicContext into
43      * a set of attribute/value pairs and related definitions
44      *
45      * @param gc GraphicContext to be converted
46      * @return descriptor of the attributes required to represent
47      * some or all of the GraphicContext state, along
48      * with the related definitions
49      * @see org.apache.batik.svggen.SVGDescriptor
50      */

51     public SVGDescriptor toSVG(GraphicContext gc) {
52         return toSVG(gc.getComposite());
53     }
54
55     /**
56      * @param composite the Composite object to convert to SVG
57      * @return an SVGCompositeDescriptor mapping the SVG
58      * composite equivalent to the input Composite.
59      */

60     public SVGCompositeDescriptor toSVG(Composite JavaDoc composite) {
61         if (composite == null)
62             throw new NullPointerException JavaDoc();
63         SVGCompositeDescriptor compositeDesc =
64             (SVGCompositeDescriptor)descMap.get(composite);
65
66         if (compositeDesc == null) {
67             // First time this composite is used. Request handler
68
// to do the convertion
69
SVGCompositeDescriptor desc =
70                 generatorContext.
71                 extensionHandler.handleComposite(composite,
72                                                  generatorContext);
73
74             if (desc != null) {
75                 Element JavaDoc def = desc.getDef();
76                 if(def != null)
77                     defSet.add(def);
78                 descMap.put(composite, desc);
79             }
80         }
81
82         return compositeDesc;
83     }
84 }
85
Popular Tags