/Users/lyon/j4p/src/j2d/edge/LoGPanel.java

1    package j2d.edge; 
2     
3    import gui.run.RunButton; 
4    import gui.run.RunSlider; 
5    import j2d.*; 
6    import j2d.animation.AnimationDialog; 
7     
8    import javax.swing.*; 
9    import java.awt.*; 
10    
11    
12   public class LoGPanel extends JPanel { 
13    
14    
15       private int kernelWidth = 19; 
16       private double sigma = 2.0; 
17    
18       ImageProcessListener ipl = null; 
19    
20       /**Construct the frame*/ 
21       public LoGPanel(ImageProcessListener _ipl) { 
22           ipl = _ipl; 
23           initGuiElements(); 
24    
25       } 
26    
27       /**Component initialization*/ 
28       private void initGuiElements() { 
29           setLayout(new FlowLayout()); 
30    
31           add(new RunButton("apply") { 
32               public void run() { 
33                   updateImage(); 
34               } 
35           }); 
36           add(new RunButton("Reset") { 
37               public void run() { 
38                   ipl.update(null); 
39               } 
40           }); 
41           add(new JLabel("kernel width")); 
42           add(new RunSlider(4, 19, 19) { 
43               public void run() { 
44                   kernelWidth = getValue(); 
45                   updateImage(); 
46               } 
47           }); 
48           add(new RunButton("comparison") { 
49               public void run() { 
50                   ImageProcessorFactory ipf = 
51                           new LoGProcessor( 
52                                   kernelWidth, 
53                                   sigma); 
54                   ComparisonUtils.showComparisonFrame( 
55                           getComparisonPanel(ipf)); 
56               } 
57           }); 
58           AnimationProcessor ap = new AnimationProcessor(); 
59           add(ap.getButton()); 
60       } 
61    
62       public JPanel getComparisonPanel(ImageProcessorFactory ipf) { 
63    
64           ImageBeanInterface origImagePanel = (ImageBeanInterface) ipl; 
65           Image sourceImage = origImagePanel.getImage(); 
66           return ComparisonUtils.getComparisonPanel(sourceImage, ipf); 
67    
68       } 
69    
70       public void updateImage() { 
71           try { 
72               ipl.update(new LoGProcessor( 
73                       kernelWidth, 
74                       sigma 
75               )); 
76           } catch (Exception e) { 
77               System.out.println("ER!:kernelWidth=" + kernelWidth); 
78           } 
79       } 
80    
81       class AnimationProcessor 
82               extends LoGProcessor { 
83           public RunButton getButton() { 
84               return 
85                       new RunButton("save Gifs") { 
86                           public void run() { 
87                               saveGifs(); 
88                           } 
89                       }; 
90           } 
91    
92           AnimationProcessor() { 
93               super(kernelWidth, 
94                       sigma); 
95           } 
96    
97           public ImageProcessorInterface getProcessor(int i) { 
98               return 
99                       new LoGProcessor( 
100                              kernelWidth, 
101                              i); 
102          } 
103   
104          public void saveGifs() { 
105              ImageBeanInterface origImagePanel = 
106                      (ImageBeanInterface) ipl; 
107              new AnimationDialog(origImagePanel.getImage(), 
108                      this); 
109          } 
110      } 
111   
112  } 
113