/Users/lyon/j4p/src/j2d/edge/SobelPanel.java
|
1 package j2d.edge;
2
3 import gui.run.RunButton;
4 import gui.run.RunCheckBox;
5 import gui.run.RunSlider;
6 import j2d.ComparisonUtils;
7 import j2d.ImageBeanInterface;
8 import j2d.ImageProcessListener;
9 import j2d.ImageProcessorFactory;
10
11 import javax.swing.*;
12 import java.awt.*;
13
14
15 public class SobelPanel extends JPanel {
16
17
18 private int a = 1;
19 private boolean isX = true;
20
21 ImageProcessListener ipl = null;
22
23 /**Construct the frame*/
24 public SobelPanel(ImageProcessListener _ipl) {
25 ipl = _ipl;
26 initGuiElements();
27
28 }
29
30 /**Component initialization*/
31 private void initGuiElements() {
32 setLayout(new FlowLayout());
33
34 add(new RunButton("apply") {
35 public void run() {
36 updateImage();
37 }
38 });
39 add(new RunButton("Reset") {
40 public void run() {
41 ipl.update(null);
42 }
43 });
44 add(new RunCheckBox() {
45 public void run() {
46 isX = !isX;
47 }
48 });
49 add(new RunSlider(1, 10, 1) {
50 public void run() {
51 a = this.getValue();
52 updateImage();
53 }
54 });
55
56 add(new RunButton("comparison") {
57 public void run() {
58 ImageProcessorFactory ipf =
59 new SobelProcessor(a, isX);
60 ComparisonUtils.showComparisonFrame(
61 getComparisonPanel(ipf));
62 }
63 });
64 }
65
66 public JPanel getComparisonPanel(ImageProcessorFactory ipf) {
67
68 ImageBeanInterface origImagePanel = (ImageBeanInterface) ipl;
69 Image sourceImage = origImagePanel.getImage();
70 return ComparisonUtils.getComparisonPanel(sourceImage, ipf);
71
72 }
73
74 public void updateImage() {
75 ipl.update(new SobelProcessor(a, isX));
76
77 }
78
79
80 }
81