KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > instruments > ImageFilterAdapter


1 package JSci.instruments;
2
3 import java.awt.*;
4 import javax.swing.*;
5 import javax.swing.border.*;
6
7 /** An object that filters frames. We only need to override
8 the <code>filter</code> method */

9
10 public abstract class ImageFilterAdapter implements ImageFilter {
11
12     private ImageSink sink;
13     public void setSink(ImageSink fs) {
14     if (sink!=fs) {
15         sink=fs;
16         sink.setSource(this);
17     }
18     }
19
20     private ImageSource source = null;
21     public void setSource(ImageSource fs) {
22     if (source!=fs) {
23         source=fs;
24         source.setSink(this);
25     }
26     }
27
28     public void receive(Image f) {
29     filter(f);
30     if (sink!=null) sink.receive(f);
31     }
32
33     public Component getControlComponent() {
34     JPanel t = new JPanel();
35     t.setLayout(new FlowLayout());
36     if (source.getControlComponent()!=null)
37         t.add(source.getControlComponent());
38     if (getFilterControlComponent()!=null) {
39         JPanel s = new JPanel();
40         s.setLayout(new BorderLayout());
41         s.add(getFilterControlComponent());
42         Border etched = BorderFactory.createEtchedBorder();
43         Border titled = BorderFactory.createTitledBorder(etched,getName());
44         s.setBorder(titled);
45         t.add(s);
46     }
47     return t;
48     }
49
50     public int getWidth() { return source.getWidth(); }
51     public int getHeight() { return source.getHeight(); }
52     public Dimension getSize() { return source.getSize(); }
53
54     /** defines the Component that controls this filter */
55     public Component getFilterControlComponent() { return null; }
56
57     /** defines the operations acutally needed for filtering */
58     public abstract void filter(Image f);
59
60     /** defines the name of the filter */
61     public String JavaDoc getName() { return "Filter"; }
62
63 }
64
65
Popular Tags