/Users/lyon/j4p/src/j2d/gui/ImageChildFrame.java

1    // Glenn Josefiak 
2    // Fairfield University 
3    // SW513 
4    // Spring 2003 
5     
6    package j2d.gui; 
7     
8    import j2d.ShortImageBean; 
9     
10   import javax.swing.*; 
11   import java.awt.*; 
12    
13   /** 
14    * MDI child frame for displaying an image 
15    */ 
16   public class ImageChildFrame extends JInternalFrame { 
17       private ImagePanel ipnDisplay; 
18       private Image imgBaseImage; 
19    
20       /** 
21        * Construct a new frame with the specified base image and 
22        * title. 
23        * 
24        * @param img   The base image.  This is the intially displayed 
25        *              image and the one on which signal processing is 
26        *              performed. 
27        * @param title Text for the frame's title bar 
28        */ 
29       public ImageChildFrame(Image img, String title) { 
30           Container c; 
31           JScrollPane jsp; 
32    
33           setTitle(title); 
34    
35           imgBaseImage = img; 
36    
37           ipnDisplay = new ImagePanel(); 
38           ipnDisplay.setImage(img); 
39    
40           c = getContentPane(); 
41           c.setLayout(new BorderLayout()); 
42           jsp = new JScrollPane(); 
43           jsp.setViewportView(ipnDisplay); 
44           c.add(jsp, BorderLayout.CENTER); 
45    
46           setMinimumSize(new Dimension(100, 100)); 
47           setClosable(true); 
48           setMaximizable(true); 
49           setResizable(true); 
50       } 
51    
52       /** 
53        * Set the displayed image, typically a processed version of the base 
54        * image generated outside of this class 
55        * 
56        * @param img The image to display 
57        */ 
58       public void setImage(Image img) { 
59           ipnDisplay.setImage(img); 
60       } 
61    
62       /** 
63        * Obtain a handle to the base image. 
64        */ 
65       public Image getBaseImage() { 
66           return imgBaseImage; 
67       } 
68    
69       /** 
70        * Obtain a handle to the displayed image. 
71        */ 
72       public Image getImage() { 
73           return ipnDisplay.getImage(); 
74       } 
75       public void negate() { 
76           ShortImageBean sib = new ShortImageBean(imgBaseImage); 
77           sib.negate(); 
78           ipnDisplay.setImage(sib.getImage()); 
79       } 
80       /** 
81        * Display the base image. 
82        */ 
83       public void revert() { 
84           ipnDisplay.setImage(imgBaseImage); 
85       } 
86   }