KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > bridge > SVGFeDiffuseLightingElementBridge


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.bridge;
19
20 import java.awt.geom.Rectangle2D JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import org.apache.batik.ext.awt.image.Light;
24 import org.apache.batik.ext.awt.image.renderable.DiffuseLightingRable8Bit;
25 import org.apache.batik.ext.awt.image.renderable.Filter;
26 import org.apache.batik.gvt.GraphicsNode;
27 import org.w3c.dom.Element JavaDoc;
28
29 /**
30  * Bridge class for the <feDiffuseLighting> element.
31  *
32  * @author <a HREF="mailto:tkormann@apache.org">Thierry Kormann</a>
33  * @version $Id: SVGFeDiffuseLightingElementBridge.java,v 1.16 2004/08/18 07:12:33 vhardy Exp $
34  */

35 public class SVGFeDiffuseLightingElementBridge
36     extends AbstractSVGLightingElementBridge {
37
38
39     /**
40      * Constructs a new bridge for the &lt;feDiffuseLighting> element.
41      */

42     public SVGFeDiffuseLightingElementBridge() {}
43
44     /**
45      * Returns 'feDiffuseLighting'.
46      */

47     public String JavaDoc getLocalName() {
48         return SVG_FE_DIFFUSE_LIGHTING_TAG;
49     }
50
51     /**
52      * Creates a <tt>Filter</tt> primitive according to the specified
53      * parameters.
54      *
55      * @param ctx the bridge context to use
56      * @param filterElement the element that defines a filter
57      * @param filteredElement the element that references the filter
58      * @param filteredNode the graphics node to filter
59      *
60      * @param inputFilter the <tt>Filter</tt> that represents the current
61      * filter input if the filter chain.
62      * @param filterRegion the filter area defined for the filter chain
63      * the new node will be part of.
64      * @param filterMap a map where the mediator can map a name to the
65      * <tt>Filter</tt> it creates. Other <tt>FilterBridge</tt>s
66      * can then access a filter node from the filterMap if they
67      * know its name.
68      */

69     public Filter createFilter(BridgeContext ctx,
70                                Element JavaDoc filterElement,
71                                Element JavaDoc filteredElement,
72                                GraphicsNode filteredNode,
73                                Filter inputFilter,
74                                Rectangle2D JavaDoc filterRegion,
75                                Map JavaDoc filterMap) {
76
77         // 'surfaceScale' attribute - default is 1
78
float surfaceScale
79             = convertNumber(filterElement, SVG_SURFACE_SCALE_ATTRIBUTE, 1);
80
81         // 'diffuseConstant' attribute - default is 1
82
float diffuseConstant
83             = convertNumber(filterElement, SVG_DIFFUSE_CONSTANT_ATTRIBUTE, 1);
84
85         // 'kernelUnitLength' attribute
86
// <!> FIXME: Why is it ignored ???
87

88         // extract the light definition from the filterElement's children list
89
Light light = extractLight(filterElement, ctx);
90
91         // 'kernelUnitLength' attribute
92
double [] kernelUnitLength = convertKernelUnitLength(filterElement);
93
94         // 'in' attribute
95
Filter in = getIn(filterElement,
96                           filteredElement,
97                           filteredNode,
98                           inputFilter,
99                           filterMap,
100                           ctx);
101         if (in == null) {
102             return null; // disable the filter
103
}
104
105         // Default region is the size of in (if in is SourceGraphic or
106
// SourceAlpha it will already include a pad/crop to the
107
// proper filter region size).
108
Rectangle2D JavaDoc defaultRegion = in.getBounds2D();
109         Rectangle2D JavaDoc primitiveRegion
110             = SVGUtilities.convertFilterPrimitiveRegion(filterElement,
111                                                         filteredElement,
112                                                         filteredNode,
113                                                         defaultRegion,
114                                                         filterRegion,
115                                                         ctx);
116         Filter filter = new DiffuseLightingRable8Bit(in,
117                                                      primitiveRegion,
118                                                      light,
119                                                      diffuseConstant,
120                                                      surfaceScale,
121                                                      kernelUnitLength);
122
123         // handle the 'color-interpolation-filters' property
124
handleColorInterpolationFilters(filter, filterElement);
125
126         // update the filter Map
127
updateFilterMap(filterElement, filter, filterMap);
128
129         return filter;
130     }
131 }
132
Popular Tags