/Users/lyon/j4p/src/ip/hak/Preview.java

1    package ip.hak; 
2     
3     
4    import java.awt.*; 
5     
6     
7    public class Preview extends ip.gui.frames.ClosableFrame { 
8     
9        Double4 d4[]; 
10    
11       int w = 220; 
12    
13       int h = 240; 
14    
15       double max,min; 
16    
17       double s = 0.0; 
18    
19    
20       public Preview(Double4 db4[]) { 
21    
22           super("Preview"); 
23    
24           d4 = db4; 
25    
26           setSize(w, h); 
27    
28           init(); 
29    
30           setVisible(true); 
31    
32           //setResizable(false); 
33    
34       } 
35    
36    
37       private void getMaxMin() { 
38    
39           max = min = d4[0].x; 
40    
41           for (int i = 1; i < d4.length; i++) { 
42    
43               if (max < d4[i].x + d4[i].r) 
44    
45                   max = d4[i].x + d4[i].r; 
46    
47               if (min > d4[i].x - d4[i].r) 
48    
49                   min = d4[i].x - d4[i].r; 
50    
51           } 
52    
53           for (int i = 0; i < d4.length; i++) { 
54    
55               if (max < d4[i].y + d4[i].r) 
56    
57                   max = d4[i].y + d4[i].r; 
58    
59               if (min > d4[i].y - d4[i].r) 
60    
61                   min = d4[i].y - d4[i].r; 
62    
63           } 
64    
65       } 
66    
67    
68       private void init() { 
69    
70           getMaxMin(); 
71    
72           //for (int i=0;i<d4.length;i++) 
73    
74           //{ 
75    
76           //System.out.println("X:"+d4[i].x+" Y:"+d4[i].y+" R:"+d4[i].r); 
77    
78           //} 
79    
80           s = (w - 20) / (max - min); 
81    
82           //System.out.println(s); 
83    
84    
85    
86           repaint(); 
87    
88       } 
89    
90    
91       public void paint(Graphics g) { 
92    
93           if (d4 == null || s == 0.0) 
94    
95               return; 
96    
97           for (int i = 0; i < d4.length; i++) { 
98    
99               int xp = (int) ((d4[i].x - min) * s); 
100   
101              int yp = h - 10 - (int) ((d4[i].y - min) * s); 
102   
103              int c = (int) (d4[i].r * s * 2); 
104   
105              int hc = c / 2; 
106   
107              g.drawOval(xp - hc, yp - hc, c, c); 
108   
109          } 
110   
111      } 
112   
113  }