/Users/lyon/j4p/src/j2d/filters/GaussianPanel.java

1    package j2d.filters; 
2     
3    import gui.run.RunButton; 
4    import gui.run.RunSlider; 
5    import j2d.ImageProcessListener; 
6     
7    import javax.swing.*; 
8    import java.awt.*; 
9     
10    
11   public class GaussianPanel extends JPanel { 
12    
13    
14       private int widGaussianKernel = 15; 
15       private double sigma = 2.0; 
16    
17       ImageProcessListener ipl = null; 
18    
19       /**Construct the frame*/ 
20       public GaussianPanel(ImageProcessListener _ipl) { 
21           ipl = _ipl; 
22           initGuiElements(); 
23    
24       } 
25    
26       /**Component initialization*/ 
27       private void initGuiElements() { 
28           setLayout(new FlowLayout()); 
29    
30           add(new RunButton("apply") { 
31               public void run() { 
32                   updateImage(); 
33               } 
34           }); 
35           add(new RunButton("Reset") { 
36               public void run() { 
37                   ipl.update(null); 
38               } 
39           }); 
40           add(new JLabel("kernel width")); 
41           add(new RunSlider(3, 40, 15) { 
42               public void run() { 
43                   widGaussianKernel = getValue(); 
44                   updateImage(); 
45               } 
46           }); 
47       } 
48    
49       public void updateImage() { 
50           ipl.update(new GaussianSmoothingProcessor( 
51                   widGaussianKernel, 
52                   sigma 
53           )); 
54       } 
55    
56    
57   } 
58