/Users/lyon/j4p/src/j2d/ImagePanel.java
|
1 // ImagePanel.java
2 // ImagePanel contains an image for display. The image is
3 // converted to a BufferedImage for filtering purposes.
4 package j2d;
5
6 // Java core packages
7
8 import javax.swing.*;
9 import java.awt.*;
10 import java.awt.image.ImageObserver;
11
12 public class ImagePanel
13 extends JPanel
14 implements ImageProcessListener,
15 ImageBeanInterface {
16
17 private Image originalImage;
18 private Image processedImage;
19
20 public Image getProcessedImage() {
21 return processedImage;
22 }
23
24
25 // ImagePanel constructor
26 public ImagePanel(Image _img) {
27 originalImage = _img;
28 processedImage = _img;
29
30 ImageUtils.waitForImage(this, getImage());
31
32 } // end ImagePanel constructor
33
34
35 public void update(ImageProcessorInterface ip) {
36 if (ip == null) {
37 setImage(originalImage);
38 return;
39 }
40 processedImage = ip.process(originalImage);
41 repaint();
42 }
43
44 public void revert() {
45 processedImage = originalImage;
46 }
47
48
49 // draw ImagePanel
50 public void paintComponent(Graphics g) {
51 super.paintComponent(g);
52 Dimension d = getSize();
53 ImageObserver io = this;
54 Image img = processedImage;
55 int w = d.width;
56 int h = d.height;
57 g.drawImage(img, 0, 0, w, h, io);
58 }
59
60 // get preferred ImagePanel size
61 public Dimension getPreferredSize() {
62 return new Dimension(originalImage.getWidth(this),
63 originalImage.getHeight(this));
64 }
65
66
67 public Image getImage() {
68 return originalImage;
69 }
70
71 public void setImage(Image image) {
72 originalImage = image;
73 processedImage = image;
74 repaint();
75 }
76 }
77
78
79