/Users/lyon/j4p/src/j2d/ImageProcessButton.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 gui.run.RunButton; 
9     
10   import java.awt.*; 
11    
12    
13   public class ImageProcessButton 
14           extends RunButton 
15           implements 
16           ImageProcessListener, 
17           ImageBeanInterface { 
18    
19       private Image originalImage; 
20       private Image processedImage; 
21    
22       public Image getProcessedImage() { 
23           return processedImage; 
24       } 
25    
26       public static ImageProcessButton[] getButtons(Image[] ia) { 
27           ImageProcessButton ipb[] = new ImageProcessButton[ia.length]; 
28           for (int i = 0; i < ia.length; i++) 
29               ipb[i] = new ImageProcessButton(ia[i]); 
30           return ipb; 
31       } 
32    
33       // ImagePanel constructor 
34       public ImageProcessButton(Image _img) { 
35           super("ok"); 
36           originalImage = _img; 
37           processedImage = _img; 
38    
39           setSize(_img.getWidth(null), _img.getHeight(null)); 
40    
41    
42       } // end ImagePanel constructor 
43    
44    
45       public void update(ImageProcessorInterface ip) { 
46           if (ip == null) { 
47               setImage(originalImage); 
48               return; 
49           } 
50           System.out.println("ip=" + ip); 
51           processedImage = ip.process(originalImage); 
52           repaint(); 
53       } 
54    
55       public void run() { 
56           new ImageTabbedFrame(this); 
57       } 
58    
59       public void revert() { 
60           processedImage = originalImage; 
61       } 
62    
63    
64       // draw ImagePanel 
65       public void paint(Graphics g) { 
66           Dimension d = getSize(); 
67           Image img = processedImage; 
68           int w = d.width; 
69           int h = d.height; 
70           if (img == null) return; 
71           g.drawImage(img, 0, 0, w, h, this); 
72       } 
73    
74       // get preferred ImagePanel size 
75    
76       public Dimension getMinimumSize() { 
77           return new Dimension(originalImage.getWidth(this) / 10, 
78                   originalImage.getHeight(this) / 10); 
79       } 
80    
81       public Dimension getMaximumSize2() { 
82           return new Dimension(originalImage.getWidth(this), 
83                   originalImage.getHeight(this)); 
84       } 
85    
86       public Dimension getPreferredSize() { 
87           return new Dimension(originalImage.getWidth(this), 
88                   originalImage.getHeight(this)); 
89       } 
90    
91    
92       public Image getImage() { 
93           return originalImage; 
94       } 
95    
96       public void setImage(Image image) { 
97           originalImage = image; 
98           processedImage = image; 
99           repaint(); 
100      } 
101  } 
102   
103   
104