01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: * @author Igor V. Stolyarov
19: * @version $Revision$
20: */package java.awt.image;
21:
22: import java.util.Hashtable;
23:
24: public class FilteredImageSource implements ImageProducer {
25:
26: private final ImageProducer source;
27: private final ImageFilter filter;
28:
29: private final Hashtable<ImageConsumer, ImageConsumer> consTable = new Hashtable<ImageConsumer, ImageConsumer>();
30:
31: public FilteredImageSource(ImageProducer orig, ImageFilter imgf) {
32: source = orig;
33: filter = imgf;
34: }
35:
36: public synchronized boolean isConsumer(ImageConsumer ic) {
37: if (ic != null) {
38: return consTable.containsKey(ic);
39: }
40: return false;
41: }
42:
43: public void startProduction(ImageConsumer ic) {
44: addConsumer(ic);
45: ImageConsumer fic = consTable.get(ic);
46: source.startProduction(fic);
47: }
48:
49: public void requestTopDownLeftRightResend(ImageConsumer ic) {
50: if (ic != null && isConsumer(ic)) {
51: ImageFilter fic = (ImageFilter) consTable.get(ic);
52: fic.resendTopDownLeftRight(source);
53: }
54: }
55:
56: public synchronized void removeConsumer(ImageConsumer ic) {
57: if (ic != null && isConsumer(ic)) {
58: ImageConsumer fic = consTable.get(ic);
59: source.removeConsumer(fic);
60: consTable.remove(ic);
61: }
62: }
63:
64: public synchronized void addConsumer(ImageConsumer ic) {
65: if (ic != null && !isConsumer(ic)) {
66: ImageConsumer fic = filter.getFilterInstance(ic);
67: source.addConsumer(fic);
68: consTable.put(ic, fic);
69: }
70: }
71: }
|