KickJava   Java API By Example, From Geeks To Geeks.

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


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.AlphaComposite JavaDoc;
21 import java.awt.Composite JavaDoc;
22 import java.util.LinkedList JavaDoc;
23 import java.util.List JavaDoc;
24
25 import org.apache.batik.ext.awt.g2d.GraphicContext;
26
27 /**
28  * Utility class that converts a Composite object into
29  * a set of SVG properties and definitions.
30  * <p>Here is how Composites are mapped to SVG:</p>
31  * <ul>
32  * <li>AlphaComposite.SRC_OVER with extra alpha is mapped
33  * to the opacity attribute</li>
34  * <li>AlphaComposite's other rules are translated into
35  * predefined filter effects.</li>
36  * <li>Custom Composite implementations are handled by the
37  * extension mechanism.</li>
38  * </ul>
39  *
40  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
41  * @version $Id: SVGComposite.java,v 1.9 2005/03/27 08:58:35 cam Exp $
42  * @see org.apache.batik.svggen.SVGAlphaComposite
43  */

44 public class SVGComposite implements SVGConverter {
45     /**
46      * All AlphaComposite convertion is handed to svgAlphaComposite
47      */

48     private SVGAlphaComposite svgAlphaComposite;
49
50     /**
51      * All custom Composite convertion is handed to svgCustomComposite
52      */

53     private SVGCustomComposite svgCustomComposite;
54
55     /**
56      * Used to create DOM elements
57      */

58     private SVGGeneratorContext generatorContext;
59
60     /**
61      * @param generatorContext The generator context used for handling
62      * custom and alpha composites
63      */

64     public SVGComposite(SVGGeneratorContext generatorContext) {
65         this.svgAlphaComposite = new SVGAlphaComposite(generatorContext);
66         this.svgCustomComposite = new SVGCustomComposite(generatorContext);
67         this.generatorContext = generatorContext;
68     }
69
70     /**
71      * @return Set of filter Elements defining the composites this
72      * Converter has processed since it was created.
73      */

74     public List JavaDoc getDefinitionSet() {
75         List JavaDoc compositeDefs = new LinkedList JavaDoc(svgAlphaComposite.getDefinitionSet());
76         compositeDefs.addAll(svgCustomComposite.getDefinitionSet());
77         return compositeDefs;
78     }
79
80     public SVGAlphaComposite getAlphaCompositeConverter() {
81         return svgAlphaComposite;
82     }
83
84     public SVGCustomComposite getCustomCompositeConverter() {
85         return svgCustomComposite;
86     }
87
88     /**
89      * Converts part or all of the input GraphicContext into
90      * a set of attribute/value pairs and related definitions
91      *
92      * @param gc GraphicContext to be converted
93      * @return descriptor of the attributes required to represent
94      * some or all of the GraphicContext state, along
95      * with the related definitions
96      * @see org.apache.batik.svggen.SVGDescriptor
97      */

98     public SVGDescriptor toSVG(GraphicContext gc) {
99         return toSVG(gc.getComposite());
100     }
101
102     /**
103      * @param composite Composite to be converted to SVG
104      * @return an SVGCompositeDescriptor mapping the SVG composite
105      * equivalent of the input Composite
106      */

107     public SVGCompositeDescriptor toSVG(Composite JavaDoc composite) {
108         if (composite instanceof AlphaComposite JavaDoc)
109             return svgAlphaComposite.toSVG((AlphaComposite JavaDoc)composite);
110         else
111             return svgCustomComposite.toSVG(composite);
112     }
113 }
114
Popular Tags