1 package org.jmage.filter;
2
3 import javax.media.jai.PlanarImage;
4 import java.util.Properties;
5
6 /***
7 * ConfigurableImageFilter accepts and maintains Properties
8 */
9 public abstract class ConfigurableImageFilter implements ImageFilter {
10 protected Properties filterProperties;
11 protected static String INITIALIZED = " initialized filter";
12 protected static String NOT_INITIALIZED = "unable to intialize filter, cause: ";
13
14 /***
15 * Initializes the ImageFilter with properties
16 *
17 * @param filterProperties
18 * @throws FilterException if the filter can't handle the properties.
19 */
20 public abstract void initialize(Properties filterProperties) throws FilterException;
21
22 /***
23 * Filter the image with additional properties
24 *
25 * @param image the image
26 * @param imageProperties additional imageProperties used only during this filter call
27 * @return the filtered image
28 * @throws FilterException
29 */
30 public PlanarImage filter(PlanarImage image, Properties imageProperties) throws FilterException {
31
32 Properties preconfigured = this.getFilterProperties();
33 Properties local = (Properties) preconfigured.clone();
34 local.putAll(imageProperties);
35
36
37 this.initialize(local);
38
39 image = this.filter(image);
40
41
42 this.initialize(preconfigured);
43
44 return image;
45 }
46
47 /***
48 * Gets the Filter's properties.
49 *
50 * @return the properties
51 */
52 public Properties getFilterProperties() {
53 return filterProperties;
54 }
55
56 public String toString() {
57 return "[" + this.getClass().getName() + "#" + this.hashCode() + "]";
58 }
59 }