KickJava   Java API By Example, From Geeks To Geeks.

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


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.Rectangle JavaDoc;
21 import java.awt.image.BufferedImageOp JavaDoc;
22 import java.awt.image.ConvolveOp JavaDoc;
23 import java.awt.image.LookupOp JavaDoc;
24 import java.awt.image.RescaleOp JavaDoc;
25 import java.util.LinkedList JavaDoc;
26 import java.util.List JavaDoc;
27
28 /**
29  * Utility class that converts a BufferedImageOp object into
30  * an SVG filter.
31  *
32  * @author <a HREF="mailto:vincent.hardy@eng.sun.com">Vincent Hardy</a>
33  * @version $Id: SVGBufferedImageOp.java,v 1.10 2004/08/18 07:14:59 vhardy Exp $
34  * @see org.apache.batik.svggen.SVGCustomBufferedImageOp
35  * @see org.apache.batik.svggen.SVGLookupOp
36  * @see org.apache.batik.svggen.SVGRescaleOp
37  * @see org.apache.batik.svggen.SVGConvolveOp
38  */

39 public class SVGBufferedImageOp extends AbstractSVGFilterConverter {
40     /**
41      * All LookupOp convertion is handed to svgLookupOp
42      */

43     private SVGLookupOp svgLookupOp;
44
45     /**
46      * All RescaleOp convertion is handed to svgRescaleOp
47      */

48     private SVGRescaleOp svgRescaleOp;
49
50     /**
51      * All ConvolveOp convertion is handed to svgConvolveOp
52      */

53     private SVGConvolveOp svgConvolveOp;
54
55     /**
56      * All custom BufferedImageOp convertion is handed to '
57      * svgCustomBufferedImageOp.
58      */

59     private SVGCustomBufferedImageOp svgCustomBufferedImageOp;
60
61     /**
62      * @param generatorContext used by the converter to create Element and other
63      * needed DOM objects and to handle unknown BufferedImageOp
64      * implementations.
65      */

66     public SVGBufferedImageOp(SVGGeneratorContext generatorContext) {
67         super(generatorContext);
68         this.svgLookupOp = new SVGLookupOp(generatorContext);
69         this.svgRescaleOp = new SVGRescaleOp(generatorContext);
70         this.svgConvolveOp = new SVGConvolveOp(generatorContext);
71         this.svgCustomBufferedImageOp =
72             new SVGCustomBufferedImageOp(generatorContext);
73     }
74
75     /**
76      * @return Set of filter Elements defining the BufferedImageOp this
77      * Converter has processed since it was created.
78      */

79     public List JavaDoc getDefinitionSet(){
80         List JavaDoc filterSet = new LinkedList JavaDoc(svgLookupOp.getDefinitionSet());
81         filterSet.addAll(svgRescaleOp.getDefinitionSet());
82         filterSet.addAll(svgConvolveOp.getDefinitionSet());
83         filterSet.addAll(svgCustomBufferedImageOp.getDefinitionSet());
84         return filterSet;
85     }
86
87     public SVGLookupOp getLookupOpConverter(){
88         return svgLookupOp;
89     }
90
91     public SVGRescaleOp getRescaleOpConverter(){
92         return svgRescaleOp;
93     }
94
95     public SVGConvolveOp getConvolveOpConverter(){
96         return svgConvolveOp;
97     }
98
99     public SVGCustomBufferedImageOp getCustomBufferedImageOpConverter(){
100         return svgCustomBufferedImageOp;
101     }
102
103     /**
104      * @param op BufferedImageOp to be converted to SVG
105      * @param filterRect Rectangle, in device space, that defines the area
106      * to which filtering applies. May be null, meaning that the
107      * area is undefined.
108      * @return an SVGFilterDescriptor representing the SVG filter
109      * equivalent of the input BufferedImageOp
110      */

111     public SVGFilterDescriptor toSVG(BufferedImageOp JavaDoc op,
112                                      Rectangle JavaDoc filterRect){
113         SVGFilterDescriptor filterDesc =
114             svgCustomBufferedImageOp.toSVG(op, filterRect);
115
116         if(filterDesc == null){
117             if(op instanceof LookupOp JavaDoc)
118                 filterDesc = svgLookupOp.toSVG((LookupOp JavaDoc)op, filterRect);
119             else if(op instanceof RescaleOp JavaDoc)
120                 filterDesc = svgRescaleOp.toSVG((RescaleOp JavaDoc)op, filterRect);
121             else if(op instanceof ConvolveOp JavaDoc)
122                 filterDesc = svgConvolveOp.toSVG((ConvolveOp JavaDoc)op, filterRect);
123         }
124
125         return filterDesc;
126     }
127 }
128
Popular Tags