/Users/lyon/j4p/src/sound/filterDesign/HsCanvas.java

1    package sound.filterDesign; 
2     
3    // Decompiled by Jad v1.5.8c. Copyright 2001 Pavel Kouznetsov. 
4    // Jad home page: http://www.geocities.com/kpdus/jad.html 
5    // Decompiler options: packimports(3)  
6    // Source File Name:   HsCanvas.java 
7     
8    import java.awt.*; 
9    import java.awt.event.MouseEvent; 
10   import java.awt.event.MouseListener; 
11   import java.awt.event.MouseMotionListener; 
12   import java.awt.image.MemoryImageSource; 
13   import java.io.Serializable; 
14   import java.util.Vector; 
15    
16   public class HsCanvas extends Canvas 
17           implements MouseListener, MouseMotionListener, Serializable { 
18    
19       public HsCanvas() { 
20           setCursor(new Cursor(1)); 
21           setFont(new Font("TimesNewRoman", 1, 16)); 
22           setBackground(Color.white); 
23           setForeground(Color.black); 
24           addMouseListener(this); 
25           addMouseMotionListener(this); 
26           xMouse = yMouse = 0; 
27       } 
28    
29       public void paint(Graphics g) { 
30           update(g); 
31       } 
32    
33       public void update(Graphics g) { 
34           g.drawImage(boxImage, 0, 0, this); 
35           g.setColor(getBackground()); 
36           g.fillRect(0, height, width + 20, 22); 
37           g.setColor(getForeground()); 
38           if (xMouse >= 0 && 
39                   yMouse >= 0 && 
40                   xMouse < width && 
41                   yMouse < height) 
42               g.drawString("H(s)= " + mag[xMouse + width * yMouse], 
43                       5, 
44                       height + 18); 
45       } 
46    
47       public void mouseDragged(MouseEvent mouseevent) { 
48       } 
49    
50       public void mouseMoved(MouseEvent mouseevent) { 
51           xMouse = mouseevent.getX(); 
52           yMouse = mouseevent.getY(); 
53           repaint(); 
54       } 
55    
56       public void mouseClicked(MouseEvent mouseevent) { 
57       } 
58    
59       public void mouseEntered(MouseEvent mouseevent) { 
60       } 
61    
62       public void mouseExited(MouseEvent mouseevent) { 
63       } 
64    
65       public void mousePressed(MouseEvent mouseevent) { 
66       } 
67    
68       public void mouseReleased(MouseEvent mouseevent) { 
69       } 
70    
71       public int findColor(double d) { 
72           int i; 
73           if (d < 1.0D) 
74               i = (int) (d * 200D) + 56; 
75           else if (d < 5D) { 
76               i = (int) (d * 40D) + 56; 
77               i <<= 8; 
78           } else if (d > 20D) { 
79               i = 0xffffff; 
80           } else { 
81               i = (int) (d * 10D) + 56; 
82               i <<= 16; 
83           } 
84           return i; 
85       } 
86    
87       public void calculate() { 
88           for (int i = 0; i < width; i++) { 
89               double d = ((double) ((i - width / 2) * 2) * xmax) / 
90                       (double) width; 
91               for (int j = 0; j < height; j++) { 
92                   double d1 = ((double) ((height / 2 - j) * 2) * ymax) / 
93                           (double) height; 
94                   double d2 = 1.0D; 
95                   for (int k = 0; k < zeros.size(); k++) { 
96                       double d3 = ((Zero) zeros.elementAt(k)).getReal(); 
97                       double d5 = ((Zero) zeros.elementAt(k)).getImag(); 
98                       d2 *= (d3 - d) * (d3 - d) + (d5 - d1) * (d5 - d1); 
99                       if (d5 != 0.0D) { 
100                          d5 = -d5; 
101                          d2 *= (d3 - d) * (d3 - d) + (d5 - d1) * (d5 - d1); 
102                      } 
103                  } 
104   
105                  for (int l = 0; l < poles.size(); l++) { 
106                      double d4 = ((Pole) poles.elementAt(l)).getReal(); 
107                      double d6 = ((Pole) poles.elementAt(l)).getImag(); 
108                      d2 /= (d4 - d) * (d4 - d) + (d6 - d1) * (d6 - d1); 
109                      if (d6 != 0.0D) { 
110                          d6 = -d6; 
111                          d2 /= (d4 - d) * (d4 - d) + (d6 - d1) * (d6 - d1); 
112                      } 
113                  } 
114   
115                  d2 = Math.sqrt(d2); 
116                  mag[i + j * width] = d2; 
117                  result[i + j * width] = 0xff000000 | findColor(d2); 
118              } 
119   
120          } 
121   
122      } 
123   
124      public void newInfo(Vector vector, 
125                          Vector vector1, 
126                          Dimension dimension, 
127                          double d, 
128                          double d1) { 
129          xmax = d; 
130          ymax = d1; 
131          width = dimension.width; 
132          height = dimension.height; 
133          if (height % 2 != 0) 
134              height--; 
135          setSize(width, height + 20); 
136          zeros = new Vector(); 
137          poles = new Vector(); 
138          synchronized (this) { 
139              if (vector1 != null && vector1.size() > 0) { 
140                  for (int i = 0; i < vector1.size(); i++) 
141                      poles.addElement(new Pole((Pole) vector1.elementAt(i))); 
142   
143              } 
144              if (vector != null && vector.size() > 0) { 
145                  for (int j = 0; j < vector.size(); j++) 
146                      zeros.addElement(new Zero((Zero) vector.elementAt(j))); 
147   
148              } 
149          } 
150          result = new int[width * height]; 
151          mag = new double[width * height]; 
152          calculate(); 
153          box = new MemoryImageSource(width, height, result, 0, width); 
154          boxImage = createImage(box); 
155          repaint(); 
156      } 
157   
158      Vector zeros; 
159      Vector poles; 
160      int result[]; 
161      int buffer[]; 
162      double mag[]; 
163      int width; 
164      int height; 
165      int xMouse; 
166      int yMouse; 
167      double xmax; 
168      double ymax; 
169      double K; 
170      Dimension offDimension; 
171      MemoryImageSource box; 
172      Image boxImage; 
173      Image offImage; 
174      Graphics offGraphics; 
175  } 
176