KickJava   Java API By Example, From Geeks To Geeks.

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


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.Paint 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 Paint 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: SVGCustomPaint.java,v 1.8 2004/08/18 07:15:00 vhardy Exp $
31  * @see org.apache.batik.svggen.SVGPaint
32  */

33 public class SVGCustomPaint extends AbstractSVGConverter {
34     /**
35      * @param generatorContext the context.
36      */

37     public SVGCustomPaint(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.getPaint());
53     }
54
55     /**
56      * @param paint the Paint object to convert to SVG
57      * @return a description of the SVG paint and opacity corresponding
58      * to the Paint. The definiton of the paint is put in the
59      * linearGradientDefsMap
60      */

61     public SVGPaintDescriptor toSVG(Paint JavaDoc paint) {
62         SVGPaintDescriptor paintDesc = (SVGPaintDescriptor)descMap.get(paint);
63
64         if (paintDesc == null) {
65             // First time this paint is used. Request handler
66
// to do the convertion
67
paintDesc =
68                 generatorContext.extensionHandler.
69                 handlePaint(paint,
70                             generatorContext);
71
72             if (paintDesc != null) {
73                 Element JavaDoc def = paintDesc.getDef();
74                 if(def != null) defSet.add(def);
75                 descMap.put(paint, paintDesc);
76             }
77         }
78
79         return paintDesc;
80     }
81 }
82
Popular Tags