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

1    package j2d.edge; 
2     
3    import gui.run.RunButton; 
4    import gui.run.RunCheckBox; 
5    import gui.run.RunSlider; 
6    import j2d.*; 
7    import j2d.animation.AnimationDialog; 
8     
9    import javax.swing.*; 
10   import java.awt.*; 
11    
12    
13   public class LoGSobelPanel extends JPanel { 
14    
15    
16       private int kernelWidth = 19; 
17       private double sigma = 2.0; 
18       private int thresh = 128; 
19       private boolean isThresh = true; 
20       private boolean isSobel = true; 
21    
22       ImageProcessListener ipl = null; 
23    
24       /**Construct the frame*/ 
25       public LoGSobelPanel(ImageProcessListener _ipl) { 
26           ipl = _ipl; 
27           initGuiElements(); 
28    
29       } 
30    
31       private JPanel getFlowPanel() { 
32           JPanel jp = new JPanel(); 
33           jp.setLayout(new FlowLayout()); 
34           return jp; 
35       } 
36    
37       /**Component initialization*/ 
38       private void initGuiElements() { 
39           setLayout(new GridLayout(0, 2)); 
40    
41           add(new JLabel("kernel width")); 
42           add(new RunSlider(4, 19, 19) { 
43               public void run() { 
44                   kernelWidth = getValue(); 
45               } 
46           }); 
47           add(new JLabel("thresh")); 
48           add(new RunSlider(4, 255, 128) { 
49               public void run() { 
50                   thresh = getValue(); 
51               } 
52           }); 
53    
54           add(getFlowComponents()); 
55    
56       } 
57    
58       private JPanel getFlowComponents() { 
59           JPanel jp = getFlowPanel(); 
60           jp.add(new RunCheckBox("thresh", true) { 
61               public void run() { 
62                   isThresh = isSelected(); 
63               } 
64           }); 
65           jp.add(new RunCheckBox("sobel", true) { 
66               public void run() { 
67                   isSobel = isSelected(); 
68               } 
69           }); 
70           jp.add(new RunButton("comparison") { 
71               public void run() { 
72                   ImageProcessorFactory ipf = 
73                           new AnimationProcessor( 
74                           ); 
75                   ComparisonUtils.showComparisonFrame( 
76                           getComparisonPanel(ipf)); 
77               } 
78           }); 
79           jp.add(new RunButton("save Gifs") { 
80               public void run() { 
81                   saveGifs(new LoGSobelProcessor( 
82                           kernelWidth, 
83                           sigma, thresh, 
84                           isThresh, isSobel)); 
85               } 
86           }); 
87    
88           jp.add(new RunButton("apply") { 
89               public void run() { 
90                   updateImage(); 
91               } 
92           }); 
93           jp.add(new RunButton("Reset") { 
94               public void run() { 
95                   ipl.update(null); 
96               } 
97           }); 
98           return jp; 
99       } 
100   
101      class AnimationProcessor 
102              extends LoGSobelProcessor { 
103          public RunButton getButton() { 
104              return 
105                      new RunButton("save Gifs") { 
106                          public void run() { 
107                              saveGifs(); 
108                          } 
109                      }; 
110          } 
111   
112          AnimationProcessor() { 
113              super(kernelWidth, 
114                      sigma, 
115                      thresh, 
116                      isThresh, 
117                      isSobel); 
118          } 
119   
120          public ImageProcessorInterface getProcessor(int i) { 
121              return 
122                      new LoGSobelProcessor( 
123                              kernelWidth, 
124                              i, 
125                              thresh, 
126                              isThresh, isSobel); 
127          } 
128   
129          public void saveGifs() { 
130              ImageBeanInterface origImagePanel = 
131                      (ImageBeanInterface) ipl; 
132              new AnimationDialog(origImagePanel.getImage(), 
133                      this); 
134          } 
135      } 
136   
137      public JPanel getComparisonPanel(ImageProcessorFactory ipf) { 
138   
139          ImageBeanInterface origImagePanel = (ImageBeanInterface) ipl; 
140          Image sourceImage = origImagePanel.getImage(); 
141          return ComparisonUtils.getComparisonPanel(sourceImage, ipf); 
142   
143      } 
144   
145      public void saveGifs(ImageProcessorFactory ipf) { 
146          ImageBeanInterface origImagePanel = 
147                  (ImageBeanInterface) ipl; 
148          new AnimationDialog(origImagePanel.getImage(), 
149                  ipf); 
150      } 
151   
152      public void updateImage() { 
153          try { 
154              ipl.update(new LoGSobelProcessor( 
155                      kernelWidth, 
156                      sigma, thresh, isThresh, isSobel 
157              )); 
158          } catch (Exception e) { 
159              System.out.println("ER!:kernelWidth=" + kernelWidth); 
160          } 
161      } 
162   
163   
164  } 
165