/Users/lyon/j4p/src/sound/filterDesign/PlotCanvasBean.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: PlotCanvasBean.java
7
8 import java.awt.*;
9 import java.awt.event.*;
10 import java.beans.PropertyChangeSupport;
11 import java.io.Serializable;
12 import java.util.Vector;
13
14 public class PlotCanvasBean extends Canvas
15 implements ItemListener,
16 BodeListener,
17 MouseListener,
18 MouseMotionListener,
19 ActionListener,
20 Serializable {
21
22 public PlotCanvasBean() {
23 magColor = Color.red;
24 phaseColor = Color.blue;
25 constant = Math.log(10D);
26 myMouseListeners = new Vector();
27 pcs = new PropertyChangeSupport(this);
28 point = new Point();
29 poles = new Vector();
30 zeros = new Vector();
31 inputFrame = new ParamFrame(this);
32 autoMag = true;
33 magScale = 1;
34 phaseScale = 1;
35 degree = false;
36 grid = true;
37 grid2 = true;
38 pop = new PopupMenu();
39 m6 = new CheckboxMenuItem("Grid", true);
40 pop.add(m6);
41 m8 = new CheckboxMenuItem("Grid vertical (log)", true);
42 pop.add(m8);
43 pop.add("-");
44 m1 = new CheckboxMenuItem("Autoscale mag", true);
45 pop.add(m1);
46 m2 = new Menu("Plot organisation");
47 m2_1 = new CheckboxMenuItem("Both, seperate", true);
48 m2.add(m2_1);
49 m2_2 = new CheckboxMenuItem("Both, together", false);
50 m2.add(m2_2);
51 m2_3 = new CheckboxMenuItem("Only magnitude", false);
52 m2.add(m2_3);
53 m2_4 = new CheckboxMenuItem("Only phase", false);
54 m2.add(m2_4);
55 pop.add(m2);
56 m3 = new Menu("Phase scale");
57 m3_1 = new CheckboxMenuItem("Autoscale", true);
58 m3.add(m3_1);
59 m3_2 = new CheckboxMenuItem("Between -pi and pi", false);
60 m3.add(m3_2);
61 m3_3 = new CheckboxMenuItem("User scale", false);
62 m3.add(m3_3);
63 pop.add(m3);
64 m4 = new Menu("Magnitude");
65 m4_1 = new CheckboxMenuItem("dB", true);
66 m4.add(m4_1);
67 m4_2 = new CheckboxMenuItem("Log Magnitude", false);
68 m4.add(m4_2);
69 m4_3 = new CheckboxMenuItem("Magnitude", false);
70 m4.add(m4_3);
71 pop.add(m4);
72 m5 = new Menu("Phase");
73 m5_1 = new CheckboxMenuItem("Radians", true);
74 m5.add(m5_1);
75 m5_2 = new CheckboxMenuItem("Degrees", false);
76 m5.add(m5_2);
77 pop.add(m5);
78 pop.add("-");
79 m7 = new MenuItem("Set Parameters");
80 pop.add(m7);
81 add(pop);
82 addMouseListener(this);
83 addMouseMotionListener(this);
84 m1.addItemListener(this);
85 m2_1.addItemListener(this);
86 m2_2.addItemListener(this);
87 m2_3.addItemListener(this);
88 m2_4.addItemListener(this);
89 m3_1.addItemListener(this);
90 m3_2.addItemListener(this);
91 m3_3.addItemListener(this);
92 m4_1.addItemListener(this);
93 m4_2.addItemListener(this);
94 m4_3.addItemListener(this);
95 m5_1.addItemListener(this);
96 m5_2.addItemListener(this);
97 m6.addItemListener(this);
98 m7.addActionListener(this);
99 m8.addItemListener(this);
100 setBackground(Color.white);
101 setForeground(Color.black);
102 setCursor(new Cursor(1));
103 resultMag = new Vector();
104 resultPhase = new Vector();
105 precision = 10;
106 state = 1;
107 xMin = yMinMag = yMinPhase = 0.10000000000000001D;
108 xMax = yMaxMag = yMaxPhase = 10D;
109 K = 1.0D;
110 logK = 0.0D;
111 angleK = 0.0D;
112 scale = log(xMax) - log(xMin);
113 scale2 = log(yMaxMag) - log(yMinMag);
114 dW = dH = 40;
115 numberDecade();
116 }
117
118 public synchronized void paint(Graphics g) {
119 update(g);
120 }
121
122 public synchronized void update(Graphics g) {
123 Dimension dimension = getSize();
124 if (offGraphics == null ||
125 dimension.width != offDimension.width ||
126 dimension.height != offDimension.height) {
127 offDimension = dimension;
128 offImage = createImage(dimension.width, dimension.height);
129 offGraphics = offImage.getGraphics();
130 }
131 width = getSize().width;
132 height = getSize().height;
133 offGraphics.setColor(getBackground());
134 offGraphics.fillRect(0,
135 0,
136 offDimension.width,
137 offDimension.height);
138 calculate(resultMag, resultPhase);
139 if (magScale == 2)
140 numberDecade();
141 offGraphics.setColor(getForeground());
142 offGraphics.drawRect(0, 0, width - 1, height - 1);
143 if (grid)
144 gridOn(offGraphics);
145 if (magScale == 2 && grid2)
146 gridOn2(offGraphics);
147 paintMe(offGraphics);
148 g.drawImage(offImage, 0, 0, this);
149 }
150
151 public void calculate(Vector vector, Vector vector1) {
152 vector.removeAllElements();
153 vector1.removeAllElements();
154 double d5 = xMin;
155 double d4;
156 double d = d4 = 1.0D;
157 double d2 = 0.0D;
158 for (int j = 0; j < zeros.size(); j++) {
159 Zero zero = new Zero((Zero) zeros.elementAt(j));
160 d *= zero.absWrtOmega(xMin);
161 d2 += zero.angleWrtOmega(xMin);
162 if (zero.getImag() != 0.0D) {
163 zero.setImag(-zero.getImag());
164 d *= zero.absWrtOmega(xMin);
165 d2 += zero.angleWrtOmega(xMin);
166 }
167 }
168
169 for (int k = 0; k < poles.size(); k++) {
170 Pole pole = new Pole((Pole) poles.elementAt(k));
171 d /= pole.absWrtOmega(xMin);
172 d2 -= pole.angleWrtOmega(xMin);
173 if (pole.getImag() != 0.0D) {
174 pole.setImag(-pole.getImag());
175 d /= pole.absWrtOmega(xMin);
176 d2 -= pole.angleWrtOmega(xMin);
177 }
178 }
179
180 switch (magScale) {
181 case 1: // '\001'
182 d4 = 20D * logK + 10D * log(d);
183 break;
184
185 case 2: // '\002'
186 case 3: // '\003'
187 d4 = Math.abs(K) * Math.sqrt(d);
188 break;
189 }
190 if (autoMag)
191 yMinMag = yMaxMag = d4;
192 if (phaseScale == 1) {
193 yMinPhase = yMaxPhase = d2;
194 } else {
195 if (d2 < -3.1415926535897931D)
196 for (;
197 d2 > 3.1415926535897931D &&
198 d2 < -3.1415926535897931D;
199 d2 += 6.2831853071795862D) ;
200 if (d2 > 3.1415926535897931D)
201 for (;
202 d2 > 3.1415926535897931D &&
203 d2 < -3.1415926535897931D;
204 d2 -= 6.2831853071795862D) ;
205 }
206 vector.addElement(new Double(d4));
207 vector1.addElement(new Double(d2));
208 for (int i = precision;
209 i <= width - (state != 2 ? dW : 2 * dW);
210 i += precision) {
211 double d6 = xMin *
212 Math.pow(10D,
213 (scale * (double) i) /
214 (double) (width - (state != 2 ? dW : 2 * dW)));
215 double d1 = 1.0D;
216 double d3 = 0.0D;
217 for (int l = 0; l < zeros.size(); l++) {
218 Zero zero1 = new Zero((Zero) zeros.elementAt(l));
219 d1 *= zero1.absWrtOmega(d6);
220 d3 += zero1.angleWrtOmega(d6);
221 if (zero1.getImag() != 0.0D) {
222 zero1.setImag(-zero1.getImag());
223 d1 *= zero1.absWrtOmega(d6);
224 d3 += zero1.angleWrtOmega(d6);
225 }
226 }
227
228 for (int i1 = 0; i1 < poles.size(); i1++) {
229 Pole pole1 = new Pole((Pole) poles.elementAt(i1));
230 d1 /= pole1.absWrtOmega(d6);
231 d3 -= pole1.angleWrtOmega(d6);
232 if (pole1.getImag() != 0.0D) {
233 pole1.setImag(-pole1.getImag());
234 d1 /= pole1.absWrtOmega(d6);
235 d3 -= pole1.angleWrtOmega(d6);
236 }
237 }
238
239 switch (magScale) {
240 case 1: // '\001'
241 d4 = 20D * logK + 10D * log(d1);
242 break;
243
244 case 2: // '\002'
245 case 3: // '\003'
246 d4 = Math.abs(K) * Math.sqrt(d1);
247 break;
248 }
249 if (autoMag) {
250 if (yMinMag > d4)
251 yMinMag = d4;
252 if (yMaxMag < d4)
253 yMaxMag = d4;
254 }
255 if (phaseScale == 1) {
256 if (yMinPhase > d3)
257 yMinPhase = d3;
258 if (yMaxPhase < d3)
259 yMaxPhase = d3;
260 }
261 vector.addElement(new Double(d4));
262 if (phaseScale > 1) {
263 for (;
264 d3 < -3.1415926535897931D;
265 d3 += 6.2831853071795862D) ;
266 for (;
267 d3 > 3.1415926535897931D;
268 d3 -= 6.2831853071795862D) ;
269 }
270 vector1.addElement(new Double(d3));
271 }
272
273 if (yMaxMag - yMinMag < 9.9999999999999994E-12D) {
274 yMinMag = yMinMag - 1.0D;
275 yMaxMag = yMaxMag + 1.0D;
276 }
277 if (phaseScale == 1 &&
278 yMaxPhase - yMinPhase < 9.9999999999999994E-12D) {
279 yMinPhase = yMinPhase - 1.5707963267948966D;
280 yMaxPhase = yMaxPhase + 1.5707963267948966D;
281 }
282 if (phaseScale == 2) {
283 yMinPhase = -3.1415926535897931D;
284 yMaxPhase = 3.1415926535897931D;
285 }
286 if (magScale == 2 && yMinMag < 0.0D)
287 yMinMag = yMaxMag / 10D;
288 }
289
290 public void paintMe(Graphics g) {
291 int i = dW;
292 switch (state) {
293 case 1: // '\001'
294 drawAxes(g);
295 int j;
296 if (magScale == 2)
297 j =
298 (1 + height / 2) -
299 dH -
300 (int) Math.rint(
301 (log(
302 ((Double) resultMag.elementAt(
303 0)).doubleValue() /
304 yMinMag) *
305 (double) (height / 2 - dH)) /
306 (double) decade2);
307 else
308 j = (height / 2 -
309 (int) Math.rint(
310 ((((Double) resultMag.elementAt(0)).doubleValue() -
311 yMinMag) *
312 (double) (height / 2 - dH)) /
313 (yMaxMag - yMinMag)) -
314 dH) +
315 1;
316 int i1 = (height -
317 (int) Math.rint(
318 ((((Double) resultPhase.elementAt(0)).doubleValue() -
319 yMinPhase) *
320 (double) (height / 2 - dH)) /
321 (yMaxPhase - yMinPhase)) -
322 dH) +
323 1;
324 for (int j4 = 1; j4 < resultMag.size(); j4++) {
325 int l1 = i + precision;
326 int l2;
327 if (magScale == 2)
328 l2 =
329 (1 + height / 2) -
330 dH -
331 (int) Math.rint(
332 (log(
333 ((Double) resultMag.elementAt(
334 j4)).doubleValue() /
335 yMinMag) *
336 (double) (height / 2 - dH)) /
337 (double) decade2);
338 else
339 l2 = (height / 2 -
340 (int) Math.rint(
341 ((((Double) resultMag.elementAt(
342 j4)).doubleValue() -
343 yMinMag) *
344 (double) (height / 2 - dH)) /
345 (yMaxMag - yMinMag)) -
346 dH) +
347 1;
348 int k3 = (height -
349 (int) Math.rint(
350 ((((Double) resultPhase.elementAt(j4)).doubleValue() -
351 yMinPhase) *
352 (double) (height / 2 - dH)) /
353 (yMaxPhase - yMinPhase)) -
354 dH) +
355 1;
356 if (l2 > (height / 2 - dH) + 2)
357 l2 = height / 2 - dH;
358 g.setColor(magColor);
359 g.drawLine(i, j, l1, l2);
360 if (k3 > (height - dH) + 2)
361 k3 = height - dH;
362 if (k3 < height / 2 - 2)
363 k3 = height / 2 - 2;
364 g.setColor(phaseColor);
365 g.drawLine(i, i1, l1, k3);
366 i = l1;
367 j = l2;
368 i1 = k3;
369 }
370
371 return;
372
373 case 2: // '\002'
374 drawAxes(g);
375 int k;
376 if (magScale == 2)
377 k =
378 (1 + height) -
379 dH -
380 (int) Math.rint(
381 (log(
382 ((Double) resultMag.elementAt(
383 0)).doubleValue() /
384 yMinMag) *
385 (double) (height - dH)) /
386 (double) decade2);
387 else
388 k = (height -
389 (int) Math.rint(
390 ((((Double) resultMag.elementAt(0)).doubleValue() -
391 yMinMag) *
392 (double) (height - dH)) /
393 (yMaxMag - yMinMag)) -
394 dH) +
395 1;
396 int j1 = (height -
397 (int) Math.rint(
398 ((((Double) resultPhase.elementAt(0)).doubleValue() -
399 yMinPhase) *
400 (double) (height - dH)) /
401 (yMaxPhase - yMinPhase)) -
402 dH) +
403 1;
404 for (int k4 = 1; k4 < resultMag.size(); k4++) {
405 int i2 = i + precision;
406 int i3;
407 if (magScale == 2)
408 i3 =
409 (1 + height) -
410 dH -
411 (int) Math.rint(
412 (log(
413 ((Double) resultMag.elementAt(
414 k4)).doubleValue() /
415 yMinMag) *
416 (double) (height - dH)) /
417 (double) decade2);
418 else
419 i3 = (height -
420 (int) Math.rint(
421 ((((Double) resultMag.elementAt(
422 k4)).doubleValue() -
423 yMinMag) *
424 (double) (height - dH)) /
425 (yMaxMag - yMinMag)) -
426 dH) +
427 1;
428 int l3 = (height -
429 (int) Math.rint(
430 ((((Double) resultPhase.elementAt(k4)).doubleValue() -
431 yMinPhase) *
432 (double) (height - dH)) /
433 (yMaxPhase - yMinPhase)) -
434 dH) +
435 1;
436 if (i3 > (height - dH) + 2)
437 i3 = (height - dH) + 2;
438 g.setColor(magColor);
439 g.drawLine(i, k, i2, i3);
440 if (l3 > (height - dH) + 2)
441 l3 = height - dH;
442 g.setColor(phaseColor);
443 g.drawLine(i, j1, i2, l3);
444 i = i2;
445 k = i3;
446 j1 = l3;
447 }
448
449 return;
450
451 case 3: // '\003'
452 drawAxes(g);
453 int l;
454 if (magScale == 2)
455 l =
456 (1 + height) -
457 dH -
458 (int) Math.rint(
459 (log(
460 ((Double) resultMag.elementAt(
461 0)).doubleValue() /
462 yMinMag) *
463 (double) (height - dH)) /
464 (double) decade2);
465 else
466 l = (height -
467 (int) Math.rint(
468 ((((Double) resultMag.elementAt(0)).doubleValue() -
469 yMinMag) *
470 (double) (height - dH)) /
471 (yMaxMag - yMinMag)) -
472 dH) +
473 1;
474 for (int l4 = 1; l4 < resultMag.size(); l4++) {
475 int j2 = i + precision;
476 int j3;
477 if (magScale == 2)
478 j3 =
479 (1 + height) -
480 dH -
481 (int) Math.rint(
482 (log(
483 ((Double) resultMag.elementAt(
484 l4)).doubleValue() /
485 yMinMag) *
486 (double) (height - dH)) /
487 (double) decade2);
488 else
489 j3 = (height -
490 (int) Math.rint(
491 ((((Double) resultMag.elementAt(
492 l4)).doubleValue() -
493 yMinMag) *
494 (double) (height - dH)) /
495 (yMaxMag - yMinMag)) -
496 dH) +
497 1;
498 if (j3 > (height - dH) + 2)
499 j3 = height - dH;
500 g.setColor(magColor);
501 g.drawLine(i, l, j2, j3);
502 i = j2;
503 l = j3;
504 }
505
506 return;
507
508 case 4: // '\004'
509 drawAxes(g);
510 int k1 = (height -
511 (int) Math.rint(
512 ((((Double) resultPhase.elementAt(0)).doubleValue() -
513 yMinPhase) *
514 (double) (height - dH)) /
515 (yMaxPhase - yMinPhase)) -
516 dH) +
517 1;
518 for (int i5 = 1; i5 < resultPhase.size(); i5++) {
519 int k2 = i + precision;
520 int i4 = (height -
521 (int) Math.rint(
522 ((((Double) resultPhase.elementAt(i5)).doubleValue() -
523 yMinPhase) *
524 (double) (height - dH)) /
525 (yMaxPhase - yMinPhase)) -
526 dH) +
527 1;
528 if (i4 > (height - dH) + 2)
529 i4 = height - dH;
530 g.setColor(phaseColor);
531 g.drawLine(i, k1, k2, i4);
532 i = k2;
533 k1 = i4;
534 }
535
536 return;
537 }
538 }
539
540 public void actionPerformed(ActionEvent actionevent) {
541 Object obj = actionevent.getSource();
542 if (obj == m7)
543 inputFrame.wake();
544 }
545
546 public void itemStateChanged(ItemEvent itemevent) {
547 Object obj = itemevent.getSource();
548 if (obj == m6) {
549 gridon(m6.getState());
550 return;
551 }
552 if (obj == m7) {
553 gridon2(m8.getState());
554 return;
555 }
556 if (obj == m1) {
557 setAutoMag(m1.getState());
558 return;
559 }
560 if (obj == m2_1) {
561 m2_1.setState(true);
562 m2_2.setState(false);
563 m2_3.setState(false);
564 m2_4.setState(false);
565 setState(1);
566 return;
567 }
568 if (obj == m2_2) {
569 m2_2.setState(true);
570 m2_1.setState(false);
571 m2_3.setState(false);
572 m2_4.setState(false);
573 setState(2);
574 return;
575 }
576 if (obj == m2_3) {
577 m2_3.setState(true);
578 m2_2.setState(false);
579 m2_1.setState(false);
580 m2_4.setState(false);
581 setState(3);
582 return;
583 }
584 if (obj == m2_4) {
585 m2_4.setState(true);
586 m2_2.setState(false);
587 m2_3.setState(false);
588 m2_1.setState(false);
589 setState(4);
590 return;
591 }
592 if (obj == m3_1) {
593 m3_1.setState(true);
594 m3_2.setState(false);
595 m3_3.setState(false);
596 setAutoPhase(1);
597 return;
598 }
599 if (obj == m3_2) {
600 m3_2.setState(true);
601 m3_1.setState(false);
602 m3_3.setState(false);
603 setAutoPhase(2);
604 return;
605 }
606 if (obj == m3_3) {
607 m3_3.setState(true);
608 m3_2.setState(false);
609 m3_1.setState(false);
610 setAutoPhase(3);
611 return;
612 }
613 if (obj == m4_1) {
614 m4_1.setState(true);
615 m4_2.setState(false);
616 m4_3.setState(false);
617 setMagScale(1);
618 return;
619 }
620 if (obj == m4_2) {
621 m4_2.setState(true);
622 m4_1.setState(false);
623 m4_3.setState(false);
624 setMagScale(2);
625 return;
626 }
627 if (obj == m4_3) {
628 m4_3.setState(true);
629 m4_1.setState(false);
630 m4_2.setState(false);
631 setMagScale(3);
632 return;
633 }
634 if (obj == m5_1) {
635 m5_1.setState(true);
636 m5_2.setState(false);
637 setPhaseScale(false);
638 return;
639 }
640 if (obj == m5_2) {
641 m5_2.setState(true);
642 m5_1.setState(false);
643 setPhaseScale(true);
644 }
645 }
646
647 public void changeOccured(BodeEvent bodeevent) {
648 if (bodeevent.getSource() != this) {
649 switch (bodeevent.getType()) {
650 default:
651 break;
652
653 case 0: // '\0'
654 poles.addElement(new Pole((Pole) bodeevent.getRoot()));
655 break;
656
657 case 1: // '\001'
658 zeros.addElement(new Zero((Zero) bodeevent.getRoot()));
659 break;
660
661 case 2: // '\002'
662 ((Pole) poles.elementAt(bodeevent.getPosition())).setPos(
663 bodeevent.getRoot().getReal(),
664 bodeevent.getRoot().getImag());
665 break;
666
667 case 3: // '\003'
668 ((Zero) zeros.elementAt(bodeevent.getPosition())).setPos(
669 bodeevent.getRoot().getReal(),
670 bodeevent.getRoot().getImag());
671 break;
672
673 case 4: // '\004'
674 poles.removeElementAt(bodeevent.getPosition());
675 break;
676
677 case 5: // '\005'
678 zeros.removeElementAt(bodeevent.getPosition());
679 break;
680
681 case 6: // '\006'
682 zeros.removeAllElements();
683 poles.removeAllElements();
684 break;
685
686 case 7: // '\007'
687 Vector vector = bodeevent.getPoles();
688 synchronized (this) {
689 if (vector != null) {
690 poles.removeAllElements();
691 for (int i = 0; i < vector.size(); i++)
692 poles.addElement(
693 new Pole(
694 (Pole) vector.elementAt(i)));
695
696 }
697 }
698 break;
699
700 case 8: // '\b'
701 Vector vector1 = bodeevent.getZeros();
702 synchronized (this) {
703 if (vector1 != null) {
704 zeros.removeAllElements();
705 for (int j = 0; j < vector1.size(); j++)
706 zeros.addElement(
707 new Zero(
708 (Zero) vector1.elementAt(
709 j)));
710
711 }
712 }
713 break;
714
715 case 9: // '\t'
716 Vector vector2 = bodeevent.getPoles();
717 Vector vector3 = bodeevent.getZeros();
718 synchronized (this) {
719 if (vector2 != null) {
720 poles.removeAllElements();
721 for (int k = 0; k < vector2.size(); k++)
722 poles.addElement(
723 new Pole(
724 (Pole) vector2.elementAt(
725 k)));
726
727 }
728 if (vector3 != null) {
729 zeros.removeAllElements();
730 for (int l = 0; l < vector3.size(); l++)
731 zeros.addElement(
732 new Zero(
733 (Zero) vector3.elementAt(
734 l)));
735
736 }
737 }
738 break;
739 }
740 repaint();
741 }
742 }
743
744 public void mouseEntered(MouseEvent mouseevent) {
745 }
746
747 public void mouseClicked(MouseEvent mouseevent) {
748 }
749
750 public void mouseReleased(MouseEvent mouseevent) {
751 }
752
753 public void mouseExited(MouseEvent mouseevent) {
754 fireMyMouseEvent(new MyMouseEvent(this, "Bode Plot", 0.0D, 0.0D));
755 }
756
757 public void mousePressed(MouseEvent mouseevent) {
758 if ((mouseevent.getModifiers() & 4) == 4 ||
759 mouseevent.isShiftDown())
760 popup(mouseevent.getX(), mouseevent.getY());
761 }
762
763 public void mouseMoved(MouseEvent mouseevent) {
764 int i = mouseevent.getX();
765 int j = mouseevent.getY();
766 double d = 0.0D;
767 double d5 = 0.0D;
768 String s = "Bode Plot";
769 switch (state) {
770 case 1: // '\001'
771 double d1;
772 if (i > dW - 1) {
773 d1 =
774 xMin *
775 Math.pow(10D,
776 (scale * (double) (i - dW)) /
777 (double) (width - dW - 1));
778 if (j < (height / 2 - dH) + 2) {
779 switch (magScale) {
780 case 1: // '\001'
781 case 3: // '\003'
782 d5 = (((double) ((height / 2 - dH) + 1) -
783 (double) j) *
784 (yMaxMag - yMinMag)) /
785 (double) ((height / 2 - dH) + 1) +
786 yMinMag;
787 break;
788
789 case 2: // '\002'
790 d5 =
791 yMinMag *
792 Math.pow(10D,
793 (double) (decade2 *
794 ((-j + height / 2) - dH)) /
795 (double) (height / 2 - dH));
796 break;
797 }
798 s = "Magnitude";
799 } else if (j < (height - dH) + 2 &&
800 j > height / 2 - 1) {
801 d5 = (((double) (height / 2 - dH) -
802 ((double) j - (double) (height / 2) - 1.0D)) *
803 (yMaxPhase - yMinPhase)) /
804 (double) (height / 2 - dH) +
805 yMinPhase;
806 s = "Phase";
807 } else {
808 d1 = 0.0D;
809 d5 = 0.0D;
810 }
811 } else {
812 d1 = 0.0D;
813 d5 = 0.0D;
814 }
815 fireMyMouseEvent(new MyMouseEvent(this, s, d1, d5));
816 return;
817
818 case 2: // '\002'
819 double d2;
820 if (i > dW - 1 &&
821 i < (width - dW) + 1 &&
822 j < (height - dH) + 1) {
823 d2 =
824 xMin *
825 Math.pow(10D,
826 (scale * (double) (i - dW)) /
827 (double) (width - dW - 1));
828 switch (magScale) {
829 case 1: // '\001'
830 case 3: // '\003'
831 d5 = (((double) (height - dH) - (double) j) *
832 (yMaxMag - yMinMag)) /
833 (double) (height - dH) +
834 yMinMag;
835 break;
836
837 case 2: // '\002'
838 d5 =
839 yMinMag *
840 Math.pow(10D,
841 (double) (decade2 *
842 ((-j + height) - dH)) /
843 (double) (height - dH));
844 break;
845 }
846 } else {
847 d2 = 0.0D;
848 d5 = 0.0D;
849 }
850 fireMyMouseEvent(
851 new MyMouseEvent(this, "Magnitude", d2, d5));
852 return;
853
854 case 3: // '\003'
855 double d3;
856 if (i > dW - 1 && j < (height - dH) + 1) {
857 d3 =
858 xMin *
859 Math.pow(10D,
860 (scale * (double) (i - dW)) /
861 (double) (width - dW - 1));
862 switch (magScale) {
863 case 1: // '\001'
864 case 3: // '\003'
865 d5 = (((double) (height - dH) - (double) j) *
866 (yMaxMag - yMinMag)) /
867 (double) (height - dH) +
868 yMinMag;
869 break;
870
871 case 2: // '\002'
872 d5 =
873 yMinMag *
874 Math.pow(10D,
875 (double) (decade2 *
876 ((-j + height) - dH)) /
877 (double) (height - dH));
878 break;
879 }
880 } else {
881 d3 = 0.0D;
882 d5 = 0.0D;
883 }
884 fireMyMouseEvent(
885 new MyMouseEvent(this, "Magnitude", d3, d5));
886 return;
887
888 case 4: // '\004'
889 double d4;
890 double d6;
891 if (i > dW - 1 && j < (height - dH) + 1) {
892 d4 =
893 xMin *
894 Math.pow(10D,
895 (scale * (double) (i - dW)) /
896 (double) (width - dW - 1));
897 d6 = (((double) (height - dH) - (double) j) *
898 (yMaxPhase - yMinPhase)) /
899 (double) (height - dH) +
900 yMinPhase;
901 } else {
902 d4 = 0.0D;
903 d6 = 0.0D;
904 }
905 fireMyMouseEvent(new MyMouseEvent(this, "Phase", d4, d6));
906 return;
907 }
908 }
909
910 public void mouseDragged(MouseEvent mouseevent) {
911 }
912
913 public double log(double d) {
914 return Math.log(d) / constant;
915 }
916
917 public void numberDecade() {
918 decade = (int) Math.rint(Math.ceil(log(xMax) - log(xMin)));
919 xMax = xMin * Math.pow(10D, decade);
920 scale = log(xMax) - log(xMin);
921 logK = log(K);
922 angleK = K <= 0.0D ? 3.1415926535897931D : 0.0D;
923 if (magScale == 2) {
924 double d = yMinMag;
925 if (d < 1.0D) {
926 while ((d *= 10D) < 1.0D) ;
927 yMinMag /= d;
928 } else if (d > 10D) {
929 while ((d /= 10D) > 10D) ;
930 yMinMag /= d;
931 } else {
932 yMinMag /= yMinMag;
933 }
934 if ((new Double(yMaxMag)).isInfinite()) {
935 decade2 = 1;
936 yMaxMag = 10D;
937 yMinMag = 1.0D;
938 scale2 = 1.0D;
939 return;
940 }
941 scale2 = log(yMaxMag) - log(yMinMag);
942 decade2 = (int) Math.rint(Math.ceil(scale2));
943 yMaxMag = yMinMag * Math.pow(10D, decade2);
944 }
945 }
946
947 public void setState(int i) {
948 state = i;
949 repaint();
950 }
951
952 public void setAutoMag(boolean flag) {
953 autoMag = flag;
954 repaint();
955 }
956
957 public void setAutoPhase(int i) {
958 phaseScale = i;
959 repaint();
960 }
961
962 public void setPhaseScale(boolean flag) {
963 degree = flag;
964 repaint();
965 }
966
967 public void setMagScale(int i) {
968 magScale = i;
969 repaint();
970 }
971
972 public void popup(int i, int j) {
973 pop.show(this, i, j);
974 }
975
976 public void gridon(boolean flag) {
977 grid = flag;
978 repaint();
979 }
980
981 public void gridon2(boolean flag) {
982 grid2 = flag;
983 repaint();
984 }
985
986 public void drawAxes(Graphics g) {
987 switch (state) {
988 case 1: // '\001'
989 int i = dW;
990 int i1 = width - 1;
991 int i2 = 1;
992 int i3 = (height / 2 - dH) + 1;
993 g.drawLine(i, i2, i, i3);
994 g.drawLine(i, i2, i - 3, i2 + 5);
995 g.drawLine(i, i2, i + 3, i2 + 5);
996 g.drawString(d2str(yMaxMag), 1, 10);
997 g.drawString(d2str(yMinMag), 1, i3 + 5);
998 g.drawLine(i, i3, i1, i3);
999 g.drawLine(i1, i3, i1 - 5, i3 + 3);
1000 g.drawLine(i1, i3, i1 - 5, i3 - 3);
1001 g.drawString(d2str(xMin), dW - 5, i3 + 15);
1002 g.drawString(d2str(xMax), i1 - 35, i3 + 15);
1003 labelDecade(g, i3);
1004 i2 = height / 2 + 1;
1005 i3 = (height - dH) + 1;
1006 g.drawLine(i, i2, i, i3);
1007 g.drawLine(i, i2, i - 3, i2 + 5);
1008 g.drawLine(i, i2, i + 3, i2 + 5);
1009 g.drawString(
1010 degree ?
1011 String.valueOf(
1012 (int) Math.rint(
1013 (180D * yMaxPhase) /
1014 3.1415926535897931D)) :
1015 d2str(yMaxPhase),
1016 1,
1017 i2 + 10);
1018 g.drawString(
1019 degree ?
1020 String.valueOf(
1021 (int) Math.rint(
1022 (180D * yMinPhase) /
1023 3.1415926535897931D)) :
1024 d2str(yMinPhase),
1025 1,
1026 i3 + 5);
1027 g.drawLine(i, i3, i1, i3);
1028 g.drawLine(i1, i3, i1 - 5, i3 + 3);
1029 g.drawLine(i1, i3, i1 - 5, i3 - 3);
1030 g.drawString(d2str(xMin), dW - 5, i3 + 15);
1031 g.drawString(d2str(xMax), i1 - 35, i3 + 15);
1032 labelDecade(g, i3);
1033 return;
1034
1035 case 2: // '\002'
1036 int j = dW;
1037 int j1 = width - dW;
1038 int j2 = 1;
1039 int j3 = height - dH;
1040 g.drawLine(j, j2, j, j3);
1041 g.drawLine(j, j2, j - 3, j2 + 5);
1042 g.drawLine(j, j2, j + 3, j2 + 5);
1043 g.drawString(d2str(yMaxMag), 1, 10);
1044 g.drawString(d2str(yMinMag), 1, j3 + 5);
1045 g.drawLine(j, j3, j1, j3);
1046 g.drawLine(j1, j3, j1 - 5, j3 + 3);
1047 g.drawLine(j1, j3, j1 - 5, j3 - 3);
1048 g.drawString(d2str(xMin), dW - 5, j3 + 15);
1049 g.drawString(d2str(xMax), j1 - 25, j3 + 15);
1050 g.drawLine(j1, j2, j1, j3);
1051 g.drawLine(j1, j2, j1 - 3, j2 + 5);
1052 g.drawLine(j1, j2, j1 + 3, j2 + 5);
1053 g.drawString(
1054 degree ?
1055 String.valueOf(
1056 (int) Math.rint(
1057 (180D * yMaxPhase) /
1058 3.1415926535897931D)) :
1059 d2str(yMaxPhase),
1060 j1 + 3,
1061 10);
1062 g.drawString(
1063 degree ?
1064 String.valueOf(
1065 (int) Math.rint(
1066 (180D * yMinPhase) /
1067 3.1415926535897931D)) :
1068 d2str(yMinPhase),
1069 j1 + 3,
1070 j3 + 5);
1071 labelDecade(g, j3);
1072 return;
1073
1074 case 3: // '\003'
1075 int k = dW;
1076 int k1 = width;
1077 int k2 = 1;
1078 int k3 = height - dH;
1079 g.drawLine(k, k2, k, k3);
1080 g.drawLine(k, k2, k - 3, k2 + 5);
1081 g.drawLine(k, k2, k + 3, k2 + 5);
1082 g.drawString(d2str(yMaxMag), 1, 10);
1083 g.drawString(d2str(yMinMag), 1, k3 + 5);
1084 g.drawLine(k, k3, k1, k3);
1085 g.drawLine(k1, k3, k1 - 5, k3 + 3);
1086 g.drawLine(k1, k3, k1 - 5, k3 - 3);
1087 g.drawString(d2str(xMin), dW - 5, k3 + 15);
1088 g.drawString(d2str(xMax), k1 - 35, k3 + 15);
1089 labelDecade(g, k3);
1090 return;
1091
1092 case 4: // '\004'
1093 int l = dW;
1094 int l1 = width;
1095 int l2 = 1;
1096 int l3 = height - dH;
1097 g.drawLine(l, l2, l, l3);
1098 g.drawLine(l, l2, l - 3, l2 + 5);
1099 g.drawLine(l, l2, l + 3, l2 + 5);
1100 g.drawString(
1101 degree ?
1102 String.valueOf(
1103 (int) Math.rint(
1104 (180D * yMaxPhase) /
1105 3.1415926535897931D)) :
1106 d2str(yMaxPhase),
1107 1,
1108 10);
1109 g.drawString(
1110 degree ?
1111 String.valueOf(
1112 (int) Math.rint(
1113 (180D * yMinPhase) /
1114 3.1415926535897931D)) :
1115 d2str(yMinPhase),
1116 1,
1117 l3 + 5);
1118 g.drawLine(l, l3, l1, l3);
1119 g.drawLine(l1, l3, l1 - 5, l3 + 3);
1120 g.drawLine(l1, l3, l1 - 5, l3 - 3);
1121 g.drawString(d2str(xMin), dW - 5, l3 + 15);
1122 g.drawString(d2str(xMax), l1 - 35, l3 + 15);
1123 labelDecade(g, l3);
1124 return;
1125 }
1126 }
1127
1128 public void labelDecade(Graphics g, int i) {
1129 int k = width - (state != 2 ? dW : 2 * dW);
1130 for (double d = xMin * 10D; d < xMax; d *= 10D) {
1131 int j = dW + (int) ((log(d / xMin) * (double) k) / scale);
1132 g.drawLine(j, i - 3, j, i + 3);
1133 g.drawString(d2str(d), j - 15, i + 15);
1134 }
1135
1136 }
1137
1138 public void gridOn(Graphics g) {
1139 Color color = new Color(g.getColor().getRGB());
1140 g.setColor(Color.lightGray);
1141 int i = (width - (state != 2 ? dW : 2 * dW)) / decade;
1142 if (state == 1) {
1143 for (int j = 0; j < 10; j++) {
1144 int l = (int) Math.rint((double) dW + log(j) * (double) i);
1145 for (int j1 = 0; j1 < decade; j1++) {
1146 g.drawLine(l + j1 * i,
1147 height - 40,
1148 l + j1 * i,
1149 height / 2);
1150 g.drawLine(l + j1 * i,
1151 height / 2 - 40,
1152 l + j1 * i,
1153 1);
1154 }
1155
1156 }
1157
1158 g.setColor(color);
1159 return;
1160 }
1161 for (int k = 0; k < 10; k++) {
1162 int i1 = (int) Math.rint((double) dW + log(k) * (double) i);
1163 for (int k1 = 0; k1 < decade; k1++)
1164 g.drawLine(i1 + k1 * i, height - 40, i1 + k1 * i, 1);
1165
1166 }
1167
1168 g.setColor(color);
1169 }
1170
1171 public void gridOn2(Graphics g) {
1172 Color color = new Color(g.getColor().getRGB());
1173 g.setColor(Color.lightGray);
1174 switch (state) {
1175 default:
1176 break;
1177
1178 case 1: // '\001'
1179 int i = (height / 2 - dH) / decade2;
1180 for (int l = 1; l < 10; l++) {
1181 int k1 = (int) Math.rint(log(l) * (double) i);
1182 for (int j2 = 0; j2 < decade2; j2++)
1183 g.drawLine(dW,
1184 height / 2 - dH - k1 - j2 * i,
1185 width,
1186 height / 2 - dH - k1 - j2 * i);
1187
1188 }
1189
1190 break;
1191
1192 case 2: // '\002'
1193 int j = (height - dH) / decade2;
1194 for (int i1 = 1; i1 < 10; i1++) {
1195 int l1 = (int) Math.rint(log(i1) * (double) j);
1196 for (int k2 = 0; k2 < decade2; k2++)
1197 g.drawLine(dW,
1198 height - dH - l1 - k2 * j,
1199 width - dW,
1200 height - dH - l1 - k2 * j);
1201
1202 }
1203
1204 break;
1205
1206 case 3: // '\003'
1207 int k = (height - dH) / decade2;
1208 for (int j1 = 1; j1 < 10; j1++) {
1209 int i2 = (int) Math.rint(log(j1) * (double) k);
1210 for (int l2 = 0; l2 < decade2; l2++)
1211 g.drawLine(dW,
1212 height - dH - i2 - l2 * k,
1213 width,
1214 height - dH - i2 - l2 * k);
1215
1216 }
1217
1218 break;
1219 }
1220 g.setColor(color);
1221 }
1222
1223 public String d2str(double d) {
1224 int i = 0;
1225 int j = 0;
1226 int k = 0;
1227 if ((new Double(d)).isInfinite())
1228 return "Inf";
1229 if (d != 0.0D) {
1230 byte byte0 = 1;
1231 if (d < 0.0D) {
1232 byte0 = -1;
1233 d = Math.abs(d);
1234 }
1235 while (d >= 10D) {
1236 d /= 10D;
1237 i++;
1238 }
1239 while (d < 1.0D) {
1240 d *= 10D;
1241 i--;
1242 }
1243 j = (int) d;
1244 if (j == 10) {
1245 j = 1;
1246 i++;
1247 }
1248 d *= 10D;
1249 k = (int) Math.rint(d - (double) (j * 10));
1250 if (k == 10) {
1251 j++;
1252 k = 0;
1253 }
1254 j *= byte0;
1255 }
1256 String s = j + "." + k + "E" + i;
1257 return s;
1258 }
1259
1260 public void newParams(Vector vector) {
1261 params = vector;
1262 xMin = ((Double) params.elementAt(0)).doubleValue();
1263 xMax = ((Double) params.elementAt(1)).doubleValue();
1264 yMinMag = ((Double) params.elementAt(2)).doubleValue();
1265 yMaxMag = ((Double) params.elementAt(3)).doubleValue();
1266 yMinPhase = ((Double) params.elementAt(4)).doubleValue();
1267 yMaxPhase = ((Double) params.elementAt(5)).doubleValue();
1268 if (degree) {
1269 yMinPhase = (yMinPhase * 3.1415926535897931D) / 180D;
1270 yMaxPhase = (yMaxPhase * 3.1415926535897931D) / 180D;
1271 }
1272 precision = ((Integer) params.elementAt(6)).intValue();
1273 K = ((Double) params.elementAt(7)).doubleValue();
1274 numberDecade();
1275 repaint();
1276 }
1277
1278 public Vector oldParams() {
1279 params = new Vector();
1280 params.addElement(new Double(xMin));
1281 params.addElement(new Double(xMax));
1282 params.addElement(new Double(yMinMag));
1283 params.addElement(new Double(yMaxMag));
1284 params.addElement(
1285 new Double(
1286 degree ?
1287 (yMinPhase * 180D) / 3.1415926535897931D :
1288 yMinPhase));
1289 params.addElement(
1290 new Double(
1291 degree ?
1292 (yMaxPhase * 180D) / 3.1415926535897931D :
1293 yMaxPhase));
1294 params.addElement(new Integer(precision));
1295 params.addElement(new Double(K));
1296 return params;
1297 }
1298
1299 public void setBackground(Color color) {
1300 Color color1 = getBackground();
1301 super.setBackground(color);
1302 pcs.firePropertyChange("background", color1, color);
1303 }
1304
1305 public void setForeground(Color color) {
1306 Color color1 = getForeground();
1307 super.setForeground(color);
1308 pcs.firePropertyChange("foreground", color1, color);
1309 }
1310
1311 public void setMagColor(Color color) {
1312 magColor = color;
1313 repaint();
1314 }
1315
1316 public Color getMagColor() {
1317 return magColor;
1318 }
1319
1320 public void setPhaseColor(Color color) {
1321 phaseColor = color;
1322 repaint();
1323 }
1324
1325 public Color getPhaseColor() {
1326 return phaseColor;
1327 }
1328
1329 public Dimension getMinimumSize() {
1330 return new Dimension(20, 20);
1331 }
1332
1333 public synchronized void addMyMouseListener(
1334 MyMouseListener mymouselistener) {
1335 myMouseListeners.addElement(mymouselistener);
1336 }
1337
1338 public synchronized void removeMyMouseListener(
1339 MyMouseListener mymouselistener) {
1340 myMouseListeners.removeElement(mymouselistener);
1341 }
1342
1343 public void fireMyMouseEvent(MyMouseEvent mymouseevent) {
1344 Vector vector = null;
1345 synchronized (this) {
1346 vector = (Vector) myMouseListeners.clone();
1347 }
1348 for (int i = 0; i < vector.size(); i++) {
1349 MyMouseListener mymouselistener = (MyMouseListener) vector.elementAt(
1350 i);
1351 mymouselistener.mouseOccured(mymouseevent);
1352 }
1353
1354 }
1355
1356 private Color magColor;
1357 private Color phaseColor;
1358 boolean isZero;
1359 boolean smallChange;
1360 boolean degree;
1361 boolean autoMag;
1362 boolean grid;
1363 boolean grid2;
1364 double xMin;
1365 double xMax;
1366 double yMinMag;
1367 double yMaxMag;
1368 double yMinPhase;
1369 double yMaxPhase;
1370 double constant;
1371 int width;
1372 int height;
1373 int precision;
1374 int dW;
1375 int dH;
1376 int decade;
1377 int decade2;
1378 double K;
1379 double angleK;
1380 double logK;
1381 double scale;
1382 double scale2;
1383 int state;
1384 int rootNumber;
1385 int phaseScale;
1386 int magScale;
1387 Vector poles;
1388 Vector zeros;
1389 Vector resultMag;
1390 Vector resultPhase;
1391 Vector params;
1392 Point point;
1393 PopupMenu pop;
1394 ParamFrame inputFrame;
1395 Menu m2;
1396 Menu m3;
1397 Menu m4;
1398 Menu m5;
1399 MenuItem m7;
1400 CheckboxMenuItem m1;
1401 CheckboxMenuItem m2_1;
1402 CheckboxMenuItem m2_2;
1403 CheckboxMenuItem m2_3;
1404 CheckboxMenuItem m2_4;
1405 CheckboxMenuItem m3_1;
1406 CheckboxMenuItem m3_2;
1407 CheckboxMenuItem m3_3;
1408 CheckboxMenuItem m4_1;
1409 CheckboxMenuItem m4_2;
1410 CheckboxMenuItem m4_3;
1411 CheckboxMenuItem m5_1;
1412 CheckboxMenuItem m5_2;
1413 CheckboxMenuItem m6;
1414 CheckboxMenuItem m8;
1415 Dimension offDimension;
1416 transient Image offImage;
1417 transient Graphics offGraphics;
1418 private Vector myMouseListeners;
1419 private PropertyChangeSupport pcs;
1420 }
1421