View Javadoc

1   /*
2    * Copyright (c) 2006 Stiftung Deutsches Elektronen-Synchroton,
3    * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY.
4    *
5    * THIS SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "../AS IS" BASIS.
6    * WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
7    * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR PARTICULAR PURPOSE AND
8    * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
9    * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10   * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
11   * THE USE OR OTHER DEALINGS IN THE SOFTWARE. SHOULD THE SOFTWARE PROVE DEFECTIVE
12   * IN ANY RESPECT, THE USER ASSUMES THE COST OF ANY NECESSARY SERVICING, REPAIR OR
13   * CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
14   * NO USE OF ANY SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
15   * DESY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
16   * OR MODIFICATIONS.
17   * THE FULL LICENSE SPECIFYING FOR THE SOFTWARE THE REDISTRIBUTION, MODIFICATION,
18   * USAGE AND OTHER RIGHTS AND OBLIGATIONS IS INCLUDED WITH THE DISTRIBUTION OF THIS
19   * PROJECT IN THE FILE LICENSE.HTML. IF THE LICENSE IS NOT INCLUDED YOU MAY FIND A COPY
20   * AT HTTP://WWW.DESY.DE/LEGAL/LICENSE.HTM
21   */
22  
23  package de.desy.acop.chart;
24  
25  import java.awt.BasicStroke;
26  import java.awt.Color;
27  import java.awt.Point;
28  import java.beans.Beans;
29  
30  public class AcopHisto
31  {
32    protected int hisIndex; // own histo index number
33    protected int npoints; // display points
34    protected int displayON, // on or off
35        number, // the display order
36        markerFlag, marker_ary_cpy, xextent, yextent;
37    protected int lockFlag, dismode;
38    protected int disBarHisto, disDots;
39    protected int xlabON, disFlag, xlabLength;
40    protected int wrapindex, wraphigh;
41    protected double originxmin, originxmax; // x range
42        // CPen pen;
43        // LOGBRUSH lb, lbEdge, lbMarker;
44    protected int penStyle, penWidth, halfWidth;
45    protected BasicStroke stroke;
46    protected java.awt.Color penColor;
47    protected int pixelWidth;
48    protected int[] ix, iy, imy; // converted int array, marker array
49    protected double[] x, y; // input display data
50    protected String[] str;
51    protected double[] markery;
52    // char *buf; // diaplay buffer (npoints*4*3] convert integer x and y arrays
53    protected int[] dispOn, dispxOn, dispyOn; // diaplay flag for each point(on:
54                                              // within the area)
55    protected char[] disable;
56    protected int[] dispindex; // diaplay index starting point
57    protected int[] dispnumber; // number poinst to diaplay
58    protected java.awt.Color[] m_tagColorArray; // keep tagged color
59    protected java.lang.String[] xlab; // xlabel array
60    protected double xext, yext;
61    protected boolean colorfilled;
62    protected int barlineColorFilled;
63    protected int xaryFlag;
64    // int aryinput,byref;
65    protected int format;
66    protected boolean saveInvert;
67    protected int DrawDataSize;
68    protected double saveYShift, saveYScale, saveXShift, saveXScale;
69    protected short tagHist, initTagBuffer; // flag for tagging display
70    protected java.awt.Color tagColor, vorColor; // tagging and histo background
71                                                  // color for this histogram!
72    protected boolean yScaleEnable, errWindowEnable;
73    protected java.awt.Color errorColor;
74    protected double err_xmin, err_xmax, err_ymin, err_ymax; // error window
75                                                              // display rectangle
76    protected int arrpoints, nextPos; // for appendscreen
77    protected int gaps;
78    protected int moving, fFT;
79    protected int edgeIndex, edgeMode;
80    // CPen edgePen;
81    protected BasicStroke edgeStroke;
82    protected int edgeStyle, edgeWidth;
83    protected java.awt.Color edgeColor;
84    protected double edgePercentX, edgePercentY;
85    protected double edgeExtentX, edgeExtentY;
86    protected int edgePixel;
87    // CPen markerPen;
88    protected BasicStroke mStroke;
89    protected int markerStyle, markerWidth;
90    protected java.awt.Color markerColor;
91    protected int markerMode;
92    protected double markerExtentX, markerExtentY;
93    protected double markerPercentX, markerPercentY;
94    protected int polycounter; // number of polypoints inside display window
95    protected boolean yReferenceEnable;
96    protected boolean bindSecondaryY;
97    private Acop acop;
98    private AcopFFT acopfft;
99    private int dotsScale[] = {200, 200, 150, 140, 130, 120, 110, 105};
100   public AcopHisto(Acop acop, int index)
101   {
102     this.acop = acop;
103     npoints = 0;
104     y = null;
105     hisIndex = index;
106     // {{INIT_CONTROLS
107     // }}
108   }
109   // {{DECLARE_CONTROLS
110   protected int disHisto(int start, int stop)
111   {
112     int i, j;
113     for (j = start; j < stop; j++)
114     {
115       i = j < npoints ? j : j - npoints;
116       if (disable[i] != 0) continue;
117       disFlag++;
118       disable[i] = 1; // disable
119     }
120     return 0;
121   }
122   protected static int getArrayLength(Object inputArray)
123   {
124     int length;
125     if (inputArray == null)
126       length = 0;
127     else if (inputArray instanceof double[])
128       length = ((double[]) inputArray).length;
129     else if (inputArray instanceof float[])
130       length = ((float[]) inputArray).length;
131     else if (inputArray instanceof int[])
132       length = ((int[]) inputArray).length;
133     else if (inputArray instanceof short[])
134       length = ((short[]) inputArray).length;
135     else if (inputArray instanceof byte[])
136       length = ((byte[]) inputArray).length;
137     else if (inputArray instanceof char[])
138       length = ((char[]) inputArray).length;
139     else if (inputArray instanceof Color[])
140       length = ((Color[]) inputArray).length;
141     else
142       length = 0;
143     return length;
144   }
145   protected static int copyArray(double[] doubleArray, Object inputArray, int start, int length,
146       int aryMaxNumber, int loadToDoubleArray)
147   {
148     int i, j, k;
149     if (inputArray instanceof double[])
150       for (k = start; k < length; k++)
151       {
152         i = k - start;
153         j = k < aryMaxNumber ? k : (k - aryMaxNumber);
154         if (loadToDoubleArray == 1)
155           doubleArray[j] = (double) ((double[]) inputArray)[i];
156         else
157           ((double[]) inputArray)[i] = (double) doubleArray[j];
158       }
159     else if (inputArray instanceof float[])
160       for (k = start; k < length; k++)
161       {
162         i = k - start;
163         j = k < aryMaxNumber ? k : (k - aryMaxNumber);
164         if (loadToDoubleArray == 1)
165           doubleArray[j] = (double) ((float[]) inputArray)[i];
166         else
167           ((float[]) inputArray)[i] = (float) doubleArray[j];
168       }
169     else if (inputArray instanceof int[])
170       for (k = start; k < length; k++)
171       {
172         i = k - start;
173         j = k < aryMaxNumber ? k : (k - aryMaxNumber);
174         if (loadToDoubleArray == 1)
175           doubleArray[j] = (double) ((int[]) inputArray)[i];
176         else
177           ((int[]) inputArray)[i] = (int) doubleArray[j];
178       }
179     else if (inputArray instanceof short[])
180       for (k = start; k < length; k++)
181       {
182         i = k - start;
183         j = k < aryMaxNumber ? k : (k - aryMaxNumber);
184         if (loadToDoubleArray == 1)
185           doubleArray[j] = (double) ((short[]) inputArray)[i];
186         else
187           ((short[]) inputArray)[i] = (short) doubleArray[j];
188       }
189     else if (inputArray instanceof byte[])
190       for (k = start; k < length; k++)
191       {
192         i = k - start;
193         j = k < aryMaxNumber ? k : (k - aryMaxNumber);
194         if (loadToDoubleArray == 1)
195           doubleArray[j] = (double) ((byte[]) inputArray)[i];
196         else
197           ((byte[]) inputArray)[i] = (byte) doubleArray[j];
198       }
199     else if (inputArray instanceof char[])
200       for (k = start; k < length; k++)
201       {
202         i = k - start;
203         j = k < aryMaxNumber ? k : (k - aryMaxNumber);
204         if (loadToDoubleArray == 1)
205           doubleArray[j] = (double) ((char[]) inputArray)[i];
206         else
207           ((char[]) inputArray)[i] = (char) doubleArray[j];
208       }
209     else
210       length = 0;
211     return length;
212   }
213   protected static int copyCharArray(char[] charArray, Object inputArray, int length)
214   {
215     int i;
216     if (inputArray instanceof double[])
217       for (i = 0; i < length; i++)
218         charArray[i] = (char) ((double[]) inputArray)[i];
219     else if (inputArray instanceof float[])
220       for (i = 0; i < length; i++)
221         charArray[i] = (char) ((float[]) inputArray)[i];
222     else if (inputArray instanceof int[])
223       for (i = 0; i < length; i++)
224         charArray[i] = (char) ((int[]) inputArray)[i];
225     else if (inputArray instanceof short[])
226       for (i = 0; i < length; i++)
227         charArray[i] = (char) ((short[]) inputArray)[i];
228     else if (inputArray instanceof byte[])
229       for (i = 0; i < length; i++)
230         charArray[i] = (char) ((byte[]) inputArray)[i];
231     else if (inputArray instanceof char[])
232       for (i = 0; i < length; i++)
233         charArray[i] = (char) ((char[]) inputArray)[i];
234     else
235       length = 0;
236     return length;
237   }
238   protected void keephisto()
239   {
240     boolean change;
241     change = (penWidth != acop.keepWidth || penStyle != acop.keepStyle) ? true : false;
242     penWidth = acop.keepWidth;
243     halfWidth = penWidth / 2;
244     penStyle = acop.keepStyle;
245     penColor = acop.keepColor;
246     if (change == false) return;
247     stroke = AcopConst.createStroke(penWidth, penStyle);
248   }
249   protected int getDrawnData(Object Yarray, Object Xarray, int Npoints, int StartIndex, int hDisplay)
250   {
251     int length, num, start, i, j, k;
252     num = Npoints; // number of points, at least 1 point
253     if (num < 0)
254       num = npoints;
255     else if (num == 0) return -7;
256     start = StartIndex; // start point: 0 to (npoints-1)
257     if (start < 0)
258       start = 0;
259     else if (start >= npoints) return -8;
260     if (num + start > npoints) num = npoints - start;
261     num += start;
262     if (Yarray == null && Xarray == null) return -2;
263     if (disFlag != 0)
264     {
265       for (i = start; i < num; i++)
266         if (disable[i] != 0) break;
267       if (i != num) num = i;
268       if (i == start) return -9; // no valid data
269     }
270     if (Yarray != null)
271     {
272       length = getArrayLength(Yarray);
273       if (length < num - start)
274         length += start;
275       else
276         length = num;
277       copyArray(y, Yarray, start, length, npoints, 0);
278     }
279     if (Xarray != null)
280     {
281       length = getArrayLength(Xarray);
282       if (length < num - start)
283         length += start;
284       else
285         length = num;
286       
287       if (Xarray instanceof String[])
288         for (k = start; k < num; k++)
289         {
290           i = k - start;
291           j = k < npoints ? k : (k - npoints);
292           if ( xlab != null  )
293             ((String[])Xarray)[i] = xlab[j];
294           else
295             ((String[])Xarray)[i] = String.valueOf(j);
296         }
297       else
298         copyArray(x, Xarray, start, num, npoints, 0);
299     }
300     return num - start; // return number of valid data
301   }
302   private double[] getPlotableArray(Object data)
303   {
304     if (data instanceof double[]) return (double[]) data;
305     if (data instanceof float[])
306     {
307       int siz = ((float[])data).length;
308       double[] x = new double[siz];
309       for (int i = 0; i < siz; i++) x[i] = ((float[]) data)[i];
310       return x;
311     }
312     if (data instanceof byte[])
313     {
314       int siz = ((byte[])data).length;
315       double[] x = new double[siz];
316       for (int i = 0; i < siz; i++) x[i] = ((byte[]) data)[i];
317       return x;
318     }
319     if (data instanceof short[])
320     {
321       int siz = ((short[])data).length;
322       double[] x = new double[siz];
323       for (int i = 0; i < siz; i++) x[i] = ((short[]) data)[i];
324       return x;
325     }
326     if (data instanceof int[])
327     {
328       int siz = ((int[])data).length;
329       double[] x = new double[siz];
330       for (int i = 0; i < siz; i++) x[i] = ((int[]) data)[i];
331       return x;
332     }
333     if (data instanceof long[])
334     {
335       int siz = ((long[])data).length;
336       double[] x = new double[siz];
337       for (int i = 0; i < siz; i++) x[i] = ((long[]) data)[i];
338       return x;
339     }    
340     return null;
341   }
342   protected int updateScreen(boolean AppendFlag, Object Yarray, int Npoints, int StartIndex, Object Xarray)
343   {
344     int format, i, num, start, j, ndata, fsize, k, newX;
345     /*
346      * SAFEARRAY FAR* sa; HRESULT hr; char *data; double *df;
347      */
348     double maximum, xpostmp;
349     int aryType, saveNext;
350     int refBegin, refEnd; // refresh screen left and right histoindexes
351     int enaUpdate, changeStart;
352     double lowTmp = 0, highTmp = 0;
353     int autoTimeScaling, DataSize;
354     boolean tmpboolean;
355     double[] yaxis;
356     double[] xaxis;
357     if (acop.getAcopTransport() != null)
358     {
359       yaxis = acop.getAcopTransport().getYAxis(Yarray);
360       xaxis = acop.getAcopTransport().getXAxis(Xarray);
361     }
362     else
363     {
364       yaxis = getPlotableArray(Yarray);
365       xaxis = getPlotableArray(Xarray);
366     }
367     changeStart = 0;
368     autoTimeScaling = 0;
369     newX = 0;
370     if (Npoints < 1)
371       Npoints = AppendFlag ? 1 : npoints;
372     else if (Npoints > npoints) return -7;
373     num = Npoints; // number of points, at least 1 point
374     start = StartIndex; // start point: 0 to (npoints-1)
375     if (start >= npoints) return -8;
376     if (start < 0)
377       start = AppendFlag ? nextPos : 0;
378     else if (start != nextPos) changeStart = 1;
379     saveNext = nextPos;
380     if (AppendFlag)
381     {
382       if (num + gaps > npoints) num = npoints - gaps;
383       if (moving == 0)
384       {
385         // case 1
386         if (start >= npoints || (start + num) > npoints)
387         { // make a gap
388           if (gaps != 0) disHisto(npoints - gaps, npoints);
389           // make copy, what about x??
390           for (j = 0, i = start - (npoints - gaps - num); i < start; i++, j++)
391           {
392             y[j] = y[i];
393             if (markerFlag != 0) markery[j] = markery[i];
394             if (acop.sca[0].xtime == 1) x[j] = x[i]; // time plot
395           }
396           // change start point
397           start = npoints - gaps - num;
398           refBegin = 0; // refresh whole screen
399           refEnd = npoints;
400         }
401         else
402         // case 2
403         {
404           // get data from start to start + num, refresh part screen start to
405           // start + num, only
406           refBegin = start; // refresh only this part
407           refEnd = start + num;
408         }
409         nextPos = start + num;
410       }
411       else
412       {
413         fsize = 0;
414         if (start >= npoints)
415         {
416           start = 0;
417           fsize = 1;
418         }
419         if (gaps != 0)
420         {
421           if (changeStart != 0 || num > gaps)
422             disHisto(start + num, start + num + gaps);
423           else
424             disHisto(start + gaps, start + num + gaps);
425         }
426         nextPos = start + num;
427         // if ((start + num) >= disp[hDisplay]->npoints) disp[hDisplay]->nextPos
428         // -= disp[hDisplay]->npoints;
429         refBegin = start; // refresh this part + gaps
430         refEnd = start + num + gaps;
431         if (edgeMode != 0 && fsize != 0) refBegin = npoints - 1;
432       }
433       num += start;
434     }
435     else
436     // case 0
437     {
438       if (num + start > npoints) num = npoints - start;
439       num += start;
440       refBegin = start;
441       refEnd = num;
442     }
443     DataSize = 0;
444     fsize = getArrayLength(yaxis);
445     if (fsize <= 0)
446     {
447       if (AppendFlag) nextPos = saveNext;
448       return fsize - 1;
449     }
450     if (fsize < num - start) num = start + fsize;
451     enaUpdate = (AppendFlag || (num - start) < npoints) ? 1 : 0;
452     // RedrawTextHist = 1;
453     // df = disp[hDisplay]->y ; // load new y array
454     // SetArrayFromVariant(df, data, start, num, format, aryType, DataSize,
455     // disp[hDisplay]->npoints, 1);
456     copyArray(y, yaxis, start, num, npoints, 1);
457     acop.averagingScaling(y, start, num, hisIndex);
458     for (k = start; k < num; k++)
459     {
460       j = k < npoints ? k : (k - npoints);
461       // if ( fabs(disp[hDisplay]->shift) > 1.0e-14 ) df[j] +=
462       // (disp[hDisplay]->number * disp[hDisplay]->shift);
463       if (Math.abs(saveYShift) > AcopConst.zero_check) y[j] += saveYShift;// shift
464                                                                           // first
465       y[j] *= saveYScale;
466       // enable refreshed or updated points
467       if (disFlag != 0 && enaUpdate != 0 && disable[j] != 0)
468       {
469         disFlag--;
470         disable[j] = 0; // enable for update
471         if (dismode == AcopConst.mode_polyline)
472         {
473           dispxOn[j] = 0;
474           dispyOn[j] = 0;
475         }
476       }
477     }
478     if (saveInvert) for (k = start; k < num; k++)
479     {
480       i = k < npoints ? k : (k - npoints);
481       if (Math.abs(y[i]) > AcopConst.zero_check) y[i] = 1 / y[i];
482     }
483     // fft => overwrite y array !!! it works only when input whole array!!!
484     if (fFT != 0)
485     {
486       double[] maxPerCut = new double[3];
487       maxPerCut[1] = 0.5;
488       maxPerCut[2] = 12;
489       acopfft.fFT(npoints, y, y, maxPerCut, fFT);
490     }
491     if (AppendFlag && edgeMode != 0)
492     {
493       j = num - 1;
494       edgeIndex = j < npoints ? j : (j - npoints);
495     }
496     // check Xarray
497     DataSize = 0;
498     fsize = getArrayLength(xaxis);
499     // if ( fsize == 0 && (aryType || format == disp[hDisplay]->format) )
500     if (fsize > 0)
501     {
502       if (fsize < num - start) num = start + fsize;
503       copyArray(x, xaxis, start, num, npoints, 1);
504       j = k;
505       for (k = start; k < num; k++)
506       {
507         j = k < npoints ? k : (k - npoints);
508         if (Math.abs(saveXShift) > AcopConst.zero_check) x[j] += saveXShift;// shift
509                                                                             // first
510         x[j] *= saveXScale;
511       }
512       // should check direction?????
513       if (acop.sca[0].xtime == 1 && x[j] > acop.sca[0].max && x[j] > acop.sca[0].usermax)
514         autoTimeScaling = (int) (x[j] + gaps * AcopConst.timeScale[acop.sca[0].time_scale]);
515       newX = 1;
516     }
517     if (acop.aFrame.drawFlag == false && acop.m_lock == 0) acop.m_histstart = hisIndex;
518     displayON = 1;
519     acop.aFrame.drawFlag = true;
520     if (dismode == AcopConst.mode_histogram || dismode == AcopConst.mode_histogram_rastoring
521         || dismode == AcopConst.mode_dots || dismode == AcopConst.mode_rectangle
522         || dismode == AcopConst.mode_circle)
523     { // bring to top histogram!
524       tagHist = 1;
525       acop.lastTagHisto = hisIndex;
526     }
527     acop.lastDisp = hisIndex;
528     // refresh new input data
529     if (autoTimeScaling > 1 || (refEnd - refBegin) >= npoints || dismode >= AcopConst.mode_textbox)
530     { // redraw complete curver
531       if (autoTimeScaling > 1) // one should not use xbestsclae flag!
532       {
533         maximum = autoTimeScaling - acop.sca[0].usermax;
534         acop.sca[0].setDispscale(acop.sca[0].min + maximum, acop.sca[0].max + maximum);
535         acop.sca[0].usermin += maximum;
536         acop.sca[0].usermax = autoTimeScaling;
537         if (acop.sca[1].log != 0)
538           acop.sca[1].setDispscale(Math.pow(10.0, acop.sca[1].min), Math.pow(10.0, acop.sca[1].max));
539         tmpboolean = acop.sca[0].bestScale;
540         acop.sca[0].bestScale = false;
541         acop.sca[0].scaleToGrid();
542         if (acop.m_marker == 2) acop.setmarkerflag(2); // recalculate marker
543                                                         // array
544         acop.rescaleFlag = 1;
545         acop.rescaleTextFlag = AcopConst.NEW_ZOOM_WINDOW;
546         acop.prepareDraw();
547         // de.desy.acop.chart.repaint(de.desy.acop.chart.sca[0].ticksRect.x, -de.desy.acop.chart.sca[0].ticksRect.y
548         // ,de.desy.acop.chart.sca[0].ticksRect.width, de.desy.acop.chart.sca[0].ticksRect.height);
549         // prepareDraw(TRUE, -1, FALSE, nScaleText); // rescale and not set max
550         // limit
551         acop.sca[0].bestScale = tmpboolean;
552       }
553       else
554       {
555         if (acop.wrapAround && acop.sca[0].log == 0) setwrapindex(); // find
556                                                                       // wrapindex
557         if (acop.m_marker == 2) acop.setmarkerflag(2); // recalculate marker
558                                                         // array
559         acop.histIndex = hisIndex;
560         acop.prepareDraw();
561         // prepareDraw(FALSE,hDisplay,FALSE, 0);
562       }
563     }
564     else
565     { // fast update
566       int[] repLow = new int[2];
567       int[] repHigh = new int[2];
568       int repeat, lowFlag;
569       int xpos1 = 0, xpos2, ittpp, xonLast = 0, yonLast = 0;
570       // int *iy, *ix, n;
571       double xtemp = 0, ytemp, ttpp, xlast = 0, ylast = 0;
572       double lowT = 0, highT = 0, ttmmpp = 0;
573       int xxPP = 0; // temperary
574       double overflow;
575       // LPPOINT ipoint;
576       boolean xlow, xhigh, ylow, yhigh;
577       repLow[0] = refBegin;
578       if (refEnd > npoints || refEnd < refBegin) // Appendscreen case 5
579       {
580         repeat = 2;
581         repHigh[0] = npoints;
582         repLow[1] = 0;
583         repHigh[1] = refEnd > npoints ? refEnd - npoints : refEnd;
584       }
585       else
586       {
587         repeat = 1;
588         repHigh[0] = refEnd;
589       }
590       for (k = 0; k < repeat; k++)
591       { // preset for finding refresh window
592         xpostmp = xaryFlag == 1 ? -1.7e+308 : 1.7e+308;
593         lowFlag = 0;
594         lowTmp = 1.7e+308; // for case of ( disp[n]->xaryFlag > 1 )
595         highTmp = -1.7e+308;
596         for (i = (repLow[k] != 0 ? repLow[k] - 1 : repLow[k]); i < (repHigh[k] == npoints ? repHigh[k]
597             : repHigh[k] + 1); i++)
598         {
599           ytemp = acop.sca[1].log != 0 ? Math.log(AcopConst.log_check(y[i])) / Math.log(10) : y[i];
600           xtemp = correctWrapPosition(i);
601           ix[i] = (int) ((xtemp - acop.sca[0].min) / acop.sca[0].dispSize * acop.aFrame.dxwidth
602               + acop.aFrame.xleft + 0.01);
603           iy[i] = (int) (acop.aFrame.histRect.height - ((ytemp - acop.sca[1].min) / acop.sca[1].dispSize * acop.aFrame.histRect.height));
604           if (i < repLow[k]) // get left point x position
605           {
606             if (disable[i] == 0 && (dismode == AcopConst.mode_barline ? dispxOn[i] : dispOn[i]) != 0)
607             {
608               xpostmp = xtemp;
609               lowFlag = 1;
610             }
611           }
612           else if (i < repHigh[k]) // refresh points
613           {
614             xlow = xtemp < acop.sca[0].min ? true : false;
615             xhigh = xtemp > acop.sca[0].max ? true : false;
616             ylow = ytemp < acop.sca[1].min ? true : false;
617             yhigh = ytemp > acop.sca[1].max ? true : false;
618             if (dismode != AcopConst.mode_polyline)
619             {
620               if (dismode == AcopConst.mode_barline)
621               {
622                 dispxOn[i] = (xlow || xhigh) ? 0 : 1;
623                 dispyOn[i] = (ylow || yhigh) ? 0 : 1;
624                 if (i != (repLow[k] != 0 ? repLow[k] - 1 : repLow[k])) // avoid
625                                                                         // first
626                                                                         // index
627                 {
628                   if ((dispxOn[i] == 0 && xonLast == 0
629                       && ((xlow && xlast > acop.sca[0].max) || (xlast < acop.sca[0].min && xhigh)) && yonLast != 0)
630                       || (dispyOn[i] == 0 && yonLast == 0
631                           && ((ylow && ylast > acop.sca[1].max) || (ylast < acop.sca[1].min && yhigh)) && dispxOn[i] != 0))
632                   {
633                     dispxOn[i] = 1;
634                     dispyOn[i] = 1;
635                   }
636                 }
637                 // store last value from the first index of the loop
638                 xonLast = dispxOn[i];
639                 yonLast = dispyOn[i];
640                 xlast = xtemp;
641                 ylast = ytemp;
642                 dispOn[i] = dispxOn[i] * dispyOn[i];
643               }
644               else if (dismode == AcopConst.mode_dots || dismode == AcopConst.mode_rectangle
645                   || dismode == AcopConst.mode_circle)
646               {
647                 dispOn[i] = (xlow || xhigh || ylow || yhigh) ? 0 : 1;
648               }
649               else
650                 dispOn[i] = (xlow || xhigh) ? 0 : 1;
651               if (disable[i] != 0) dispOn[i] = 0; // disable this point
652               if (dismode == AcopConst.mode_histogram || dismode == AcopConst.mode_histogram_rastoring)
653               { // avoid 100% cpu time to display a huge number!!
654                 if (iy[i] < 0)
655                   iy[i] = -20;
656                 else if (iy[i] > acop.aFrame.histRect.height) iy[i] = acop.aFrame.histRect.height + 20;
657               }
658             }
659             else
660             // fastest drawing mode is to use polyline()
661             {
662               dispOn[i] = disable[i] != 0 ? 0 : 1;
663               if (dispOn[i] != 0)
664               {
665                 dispxOn[i] = 0;
666                 if (xlow) dispxOn[i] |= 0x1; // mask 4 cases
667                 if (xhigh) dispxOn[i] |= 0x2;
668                 if (ylow) dispxOn[i] |= 0x4;
669                 if (yhigh) dispxOn[i] |= 0x8;
670                 if (dispxOn[i] == 0)
671                 {
672                   if (dispyOn[i] == 0) // not marked yet
673                   {
674                     dispyOn[i] = 1; // point inside
675                     polycounter++;
676                   }
677                 }
678                 else
679                 {
680                   if (dispyOn[i] != 0) // was marked
681                   {
682                     dispyOn[i] = 0; // point outside
683                     polycounter--;
684                   }
685                 }
686               }
687             }
688             if (marker_ary_cpy != 0 && markerFlag != 0) loadMarker(i);
689             if (newX != 0 && xaryFlag <= 1 && lowFlag == 1) // check x direction
690             {
691               if (xaryFlag == 1)
692               {
693                 if (xpostmp < xtemp) xaryFlag = 2;
694               }
695               else if (xpostmp > xtemp) xaryFlag = 2;
696             }
697             if (i == repLow[k] && xaryFlag <= 1) // calculate xpos1 for
698                                                   // freshscreen area
699             {
700               if (lowFlag == 1)
701               {
702                 if (xaryFlag == 1)
703                 {
704                   ttpp = xpostmp > xtemp ? xpostmp : xtemp;
705                   if (xpostmp > xtemp) xpostmp = xtemp; // select small one
706                 }
707                 else
708                 {
709                   ttpp = xpostmp < xtemp ? xpostmp : xtemp;
710                   if (xpostmp < xtemp) xpostmp = xtemp; // select large one
711                 }
712               }
713               else
714               {
715                 xpostmp = xtemp; // set the left one as xpos1
716                 lowFlag = 1;
717                 ttpp = xtemp;
718               }
719               xpos1 = (int) ((ttpp - acop.sca[0].min) / acop.sca[0].dispSize * acop.aFrame.dxwidth
720                   + acop.aFrame.xleft + 0.01);
721             }
722             // compare every point for xpos2
723             if ((dismode == AcopConst.mode_barline ? dispxOn[i] : dispOn[i]) != 0)
724             {
725               if (xaryFlag == 1)
726               {
727                 if (xpostmp > xtemp) xpostmp = xtemp; // select small one
728               }
729               else
730               {
731                 if (xpostmp < xtemp) xpostmp = xtemp; // select large one
732               }
733             }
734           }
735           else
736           { // get right point x position
737             if (disable[i] == 0 && (dismode == AcopConst.mode_barline ? dispxOn[i] : dispOn[i]) != 0)
738             {
739               if (xaryFlag <= 1)
740               {
741                 if (xaryFlag == 1 ? (xpostmp < xtemp) : (xpostmp > xtemp)) xtemp = xpostmp;
742               }
743               if (newX != 0 && xaryFlag <= 1 && lowFlag == 1) // check x
744                                                               // direction
745               {
746                 if (xaryFlag == 1)
747                 {
748                   if (xpostmp < xtemp) xaryFlag = 2;
749                 }
750                 else if (xpostmp > xtemp) xaryFlag = 2;
751               }
752             }
753             // else if (repeat == 1)xtemp = xpostmp; // load valid xtemp
754           }
755           // if ( disp[n]->xaryFlag > 1 ) // mixed up and down x
756           if (disable[i] == 0 && (dismode == AcopConst.mode_barline ? dispxOn[i] : dispOn[i]) != 0)
757           {
758             if (xtemp < lowTmp) lowTmp = xtemp;
759             if (xtemp > highTmp) highTmp = xtemp;
760           }
761         }
762         if (repeat == 2 && k == 0) // save first part
763         {
764           lowT = lowTmp;
765           highT = highTmp;
766           ttmmpp = xtemp;
767           xxPP = xpos1; // temperary
768         }
769       }
770       if (dismode == AcopConst.mode_polyline) makePolyArray();
771       if (marker_ary_cpy != 0 && markerFlag != 0) marker_ary_cpy = 0;
772       for (k = repeat - 1; k >= 0; k--)
773       {
774         if (repeat == 2 && k == 0)
775         {
776           lowTmp = lowT;
777           highTmp = highT;
778           xtemp = ttmmpp;
779           xpos1 = xxPP; // restore
780         }
781         if (xaryFlag <= 1)
782         {
783           xpos2 = (int) ((xtemp - acop.sca[0].min) / acop.sca[0].dispSize * acop.aFrame.dxwidth
784               + acop.aFrame.xleft + 0.01);
785         }
786         else
787         {
788           xpos1 = (int) ((lowTmp - acop.sca[0].min) / acop.sca[0].dispSize * acop.aFrame.dxwidth
789               + acop.aFrame.xleft + 0.01);
790           xpos2 = (int) ((highTmp - acop.sca[0].min) / acop.sca[0].dispSize * acop.aFrame.dxwidth
791               + acop.aFrame.xleft + 0.01);
792         }
793         // if ( (xpos1 >= de.desy.acop.chart.aFrame.histRect.x && xpos1 <=
794         // de.desy.acop.chart.aFrame.histRect.x + de.desy.acop.chart.aFrame.histRect.width) ||
795         // (xpos2 >= de.desy.acop.chart.aFrame.histRect.x && xpos2 <= de.desy.acop.chart.aFrame.histRect.x +
796         // de.desy.acop.chart.aFrame.histRect.width) )
797         if ((xpos1 >= 0 && xpos1 <= acop.aFrame.histRect.width)
798             || (xpos2 >= 0 && xpos2 <= acop.aFrame.histRect.width))
799         {
800           if (xaryFlag == 1)
801           {
802             ittpp = xpos1;
803             xpos1 = xpos2;
804             xpos2 = ittpp;
805           }
806           fsize = (edgeMode != 0 && edgePixel > 2) ? (edgePixel + 1) * acop.aFrame.histRect.width : 0;
807           if (xpos1 <= xpos2)
808           {
809             if (xpos1 < 0) xpos1 = 0;
810             if (xpos2 > acop.aFrame.histRect.width)
811               xpos2 = acop.aFrame.histRect.width;
812             else
813               xpos2 += penWidth; // disp[tagHist]
814             acop.tagRect.x = xpos1 - fsize + acop.aFrame.histRect.x; // +de.desy.acop.chart.tagRect.x;
815             acop.tagRect.width = xpos2 + fsize - xpos1 + fsize;
816             acop.repaintTagging();
817           }
818           else
819           {
820             if (xpos1 < acop.aFrame.histRect.width)
821             {
822               acop.tagRect.x = xpos1 - fsize + acop.aFrame.histRect.x;
823               acop.tagRect.width = acop.aFrame.histRect.width - (xpos1 - fsize);
824               acop.repaintTagging();
825             }
826             if (xpos2 > 0)
827             {
828               if (xpos2 < acop.aFrame.histRect.width) xpos2 += penWidth; // disp[tagHist]
829               acop.tagRect.x = acop.aFrame.histRect.x;
830               acop.tagRect.width = xpos2;
831               acop.repaintTagging();
832             }
833           }
834         }
835       }
836     }
837     return num - 1; // last updated point, before was hDisplay;
838   }
839   protected int setHisto(Object ydata, Object xdata, Object dis, java.lang.String[] xlabel, int arraySize,
840       int maxNumber, java.awt.Color c)
841   {
842     int inputNumber, ndata, i, xlength, dislength, tmpPoints;
843     int itmp = 0, fftret = 0;
844     if (ydata instanceof String[])
845     {
846       ndata = ((String[]) ydata).length;
847       str = new String[ndata];
848       for (i = 0; i < ndata; i++)
849         str[i] = ((String[]) ydata)[i];
850       npoints = ndata;
851       return 0;
852     }
853     if (ydata instanceof String)
854     {
855       str = ((String) ydata).split("\n");
856       npoints = str.length;
857       return 0;
858     }
859     str = null;
860     double[] yaxis; // = acop.getAcopTransport().getYAxis(ydata);
861     double[] xaxis; // = acop.getAcopTransport().getXAxis(xdata);
862     if (acop.getAcopTransport() != null && !Beans.isDesignTime())
863     {
864       yaxis = acop.getAcopTransport().getYAxis(ydata);
865       xaxis = acop.getAcopTransport().getXAxis(xdata);
866     }
867     else
868     {
869       yaxis = getPlotableArray(ydata);
870       xaxis = getPlotableArray(xdata);
871     }
872     if (ydata == null) npoints = 0;
873     ndata = getArrayLength(yaxis); // ydata.length;
874     if (arraySize > 0 && arraySize < ndata) ndata = arraySize; // user given
875                                                                 // input size
876     xlength = getArrayLength(xaxis);
877     dislength = getArrayLength(dis);
878     inputNumber = ndata; // at least y array size or less if user give a
879                           // smaller number!
880     if (maxNumber > ndata) ndata = maxNumber; // user request more memory to be
881                                               // allocated!
882     if (ndata <= (acop.globalDisplayMode < AcopConst.mode_histogram ? 1 : 0)) return -1;
883     for (i = 0; i < 2; i++)
884       if (acop.sca[i].usermax <= acop.sca[i].usermin && acop.sca[i].bestScale == false
885           && acop.sca[i].log == 0) return -1;
886     if (ndata > AcopConst.max_points) ndata = AcopConst.max_points;
887     if (y == null || y.length < ndata)
888     {
889       displayON = 0;
890       markerFlag = 0;
891       marker_ary_cpy = 0;
892       lockFlag = 0;
893       if (acop.pTagColorArray == m_tagColorArray) acop.pTagColorArray = null;
894       iy = new int[ndata];
895       ix = new int[ndata];
896       imy = new int[ndata];
897       y = new double[ndata];
898       x = new double[ndata];
899       markery = new double[ndata];
900       dispOn = new int[ndata];
901       dispxOn = new int[ndata];
902       dispyOn = new int[ndata];
903       disable = new char[ndata];
904       dispindex = new int[ndata];
905       dispnumber = new int[ndata];
906       m_tagColorArray = new java.awt.Color[ndata];
907 //      xlab = new java.lang.String[ndata];
908       wrapindex = 0; // drawing dtart index for wraparound
909       wraphigh = 0; // right boundary greater than s_xmax
910       disFlag = 0;
911       originxmin = -1.7e+308;
912       originxmax = 1.7e+308;
913       initTagBuffer = 0;
914       errWindowEnable = acop.errWindowOn;
915       yScaleEnable = acop.ScaleEnable;
916       yReferenceEnable = acop.ReferenceEnable;
917       err_xmin = acop.e_xmin;
918       err_xmax = acop.e_xmax;
919       err_ymin = acop.e_ymin;
920       err_ymax = acop.e_ymax;
921       edgeIndex = 0;
922     }
923     bindSecondaryY = false;
924     arrpoints = inputNumber; // input data length, user given or y size
925     npoints = ndata; // total displayable data
926     if (xlength > ndata) xlength = ndata;
927     if (dislength > ndata) dislength = ndata;
928     errorColor = acop.m_errorColor;
929     polycounter = 0;
930     if ( npoints > 5000 && acop.drawWidth > 1 && !acop.forceWidth) acop.drawWidth = 1; //2008-11 hwu
931     if (stroke == null || penWidth != acop.drawWidth || penStyle != acop.drawStyle)
932     {
933       penWidth = acop.drawWidth;
934       penStyle = acop.drawStyle;
935       stroke = AcopConst.createStroke(penWidth, penStyle);
936     }
937     penColor = c; // getForeground();
938     halfWidth = acop.drawWidth / 2;
939     xaryFlag = 0;
940     // fill in the LeadingEdge parameters here:
941     gaps = acop.LeadingEdgeGapSize;
942     if (gaps >= npoints) gaps = 0;
943     moving = acop.LeadingEdgeMotion;
944     edgeMode = acop.LeadingEdgeMode;
945     edgeExtentX = acop.LeadingEdgeXExtent;
946     edgeExtentY = acop.LeadingEdgeYExtent;
947     edgePercentX = -1;
948     edgePercentY = -1;
949     edgePixel = acop.LeadingEdgeWidth; // de.desy.acop.chart.aFrame.dxwidth;
950     edgeColor = acop.LeadingEdgeColor;
951     if (edgeStroke == null || edgeWidth != acop.LeadingEdgeWidth || edgeStyle != acop.LeadingEdgeStyle)
952       edgeStroke = AcopConst.createStroke(acop.LeadingEdgeWidth, acop.LeadingEdgeStyle);
953     edgeWidth = acop.LeadingEdgeWidth;
954     edgeStyle = acop.LeadingEdgeStyle;
955     // fill in the marker parameters here:
956     if (mStroke == null || markerWidth != acop.m_markerWidth || markerStyle != acop.m_markerStyle)
957       mStroke = AcopConst.createStroke(acop.m_markerWidth, acop.m_markerStyle);
958     markerMode = acop.m_markerMode;
959     markerStyle = acop.m_markerStyle;
960     markerWidth = acop.m_markerWidth;
961     markerColor = acop.m_markerColor;
962     markerExtentX = acop.m_markerXExtent;
963     markerExtentY = acop.m_markerYExtent;
964     markerPercentX = -1;
965     markerPercentY = -1;
966     if (acop.globalDisplayMode == AcopConst.mode_histogram
967         || acop.globalDisplayMode == AcopConst.mode_histogram_rastoring || acop.globalDisplayMode == AcopConst.mode_dots
968         || acop.globalDisplayMode == AcopConst.mode_rectangle || acop.globalDisplayMode == AcopConst.mode_circle)
969     { // bring to top histogram!
970       if (acop.pTagColorArray == null) // init tagColorArray only for first
971                                         // time, Dont care data size changed!!
972       {
973         acop.nElement = ndata;
974         for (i = 0; i < ndata; i++)
975           m_tagColorArray[i] = penColor;
976         acop.pTagColorArray = m_tagColorArray;
977         acop.TagBackColor = penColor;
978       }
979       else if (initTagBuffer == 0
980           || (dismode != AcopConst.mode_histogram && dismode != AcopConst.mode_histogram_rastoring
981               && dismode != AcopConst.mode_dots && dismode != AcopConst.mode_rectangle && dismode != AcopConst.mode_circle))
982       { // new buffer or change mode ==> sign new backgroud color (tagging
983         // inheritance!!)
984         for (i = 0; i < ndata; i++)
985         {
986           if (i < acop.nElement)
987             m_tagColorArray[i] = acop.TagBackColor == acop.pTagColorArray[i] ? penColor
988                 : acop.pTagColorArray[i];
989           else
990             m_tagColorArray[i] = penColor;
991         }
992         acop.pTagColorArray = m_tagColorArray;
993         acop.TagBackColor = penColor;
994         acop.nElement = ndata;
995       }
996       else if (vorColor != penColor)
997       { // only change vorcolor
998         for (i = 0; i < ndata; i++)
999           if (m_tagColorArray[i] == vorColor) m_tagColorArray[i] = penColor;
1000         acop.pTagColorArray = m_tagColorArray;
1001         acop.TagBackColor = penColor;
1002         acop.nElement = ndata;
1003       }
1004       initTagBuffer = 1;
1005       tagHist = 1;
1006       tagColor = acop.m_tagColor; // store pen color and tagging color, sign top
1007                                   // hist number
1008       vorColor = penColor; // TagBackColor;
1009       acop.lastTagHisto = hisIndex;
1010     }
1011     else
1012       tagHist = 0;
1013     if (xlabel == null)
1014       xlabON = 0;
1015     else
1016     {
1017       xlabON = 1;
1018       xlabLength = xlabel.length;
1019       if ( xlab == null || xlab.length != ndata) xlab = new java.lang.String[ndata];
1020       for (i = 0; i < xlabel.length; i++)
1021       {
1022         if (i >= ndata) break;
1023         xlab[i] = xlabel[i];
1024       }
1025     }
1026     tmpPoints = arrpoints < npoints ? arrpoints : npoints;
1027     copyArray(y, yaxis, 0, tmpPoints, tmpPoints, 1);
1028     acop.averagingScaling(y, 0, npoints, hisIndex);
1029     if (xlength != 0) copyArray(x, xaxis, 0, xlength, xlength, 1);
1030     for (i = xlength; i < tmpPoints; i++)
1031     {
1032       if (xaxis == null)
1033         x[i] = i;
1034       else
1035         x[i] = x[xlength - 1];
1036     }
1037     disFlag = 0;
1038     if (dislength != 0) copyCharArray(disable, dis, dislength);
1039     for (i = 0; i < tmpPoints; i++)
1040     {
1041       if (dis == null)
1042         disable[i] = 0;
1043       else if (i < dislength)
1044       {
1045         if (disable[i] != 0) disFlag++;
1046       }
1047       else
1048       {
1049         disable[i] = 1;
1050         disFlag++;
1051       }
1052     }
1053     if (arrpoints < npoints) for (i = arrpoints; i < ndata; i++)
1054     {
1055       y[i] = y[arrpoints - 1];
1056       x[i] = x[arrpoints - 1];
1057       disable[i] = 1;
1058       disFlag++;
1059     }
1060     for (i = 0; i < ndata; i++)
1061     {
1062       if (i >= npoints) break;
1063       if (Math.abs(acop.XShift) > AcopConst.zero_check) x[i] += acop.XShift; // shift
1064                                                                               // first
1065       if (Math.abs(acop.XScale) > AcopConst.zero_check) x[i] *= acop.XScale;
1066       if (Math.abs(acop.YShift) > AcopConst.zero_check) y[i] += acop.YShift; // shift
1067                                                                               // first
1068       if (Math.abs(acop.YScale) > AcopConst.zero_check) y[i] *= acop.YScale;
1069       if (acop.invert && Math.abs(y[i]) > AcopConst.zero_check) y[i] = 1 / y[i];
1070       if (xaxis == null) continue; // dont check x array
1071       if (i > 0)
1072       {
1073         if (itmp == 0) // check down
1074         {
1075           if (x[i] < x[i - 1])
1076           {
1077             fftret++;
1078             if (i != 1 && fftret == 1) fftret++; // catch first up then down
1079             itmp = 1;
1080           }
1081         }
1082         else
1083         { // check up
1084           if (x[i] > x[i - 1])
1085           {
1086             fftret++;
1087             itmp = 0;
1088           }
1089         }
1090       }
1091     }
1092     saveXShift = acop.XShift;
1093     saveXScale = acop.XScale;
1094     saveYShift = acop.YShift;
1095     saveYScale = acop.YScale;
1096     saveInvert = acop.invert;
1097     if (xaxis == null)
1098       xaryFlag = acop.XShift < 0 ? 1 : 0;
1099     else
1100       xaryFlag = fftret;
1101     fFT = acop.FFT;
1102     if (fFT != 0) // fft => overwrite y array
1103     {
1104       if (acopfft == null) acopfft = new AcopFFT();
1105       double[] maxPerCut = new double[3];
1106       maxPerCut[1] = 0.5;
1107       maxPerCut[2] = 12;
1108       acopfft.fFT(npoints, y, y, maxPerCut, fFT);
1109     }
1110     nextPos = disFlag < npoints ? npoints : 0;
1111     // set nextPos for Appendscreen if available data points are less then
1112     // requested maxpoints
1113     if (arrpoints < npoints && disFlag == npoints - arrpoints) nextPos = arrpoints;
1114     return 0;
1115   }
1116   private Color selTagErrPen(java.awt.Graphics2D a, int i, Color lastColor)
1117   {
1118     Color selColor;
1119     // error color take precedence
1120     if (errWindowEnable && (x[i] < err_xmin || x[i] > err_xmax || y[i] < err_ymin || y[i] > err_ymax))
1121       selColor = errorColor;
1122     else if (tagHist != 0 && acop.m_tagging)
1123       selColor = m_tagColorArray[i];
1124     else
1125       selColor = penColor;
1126     if (selColor != lastColor) a.setColor(selColor);
1127     return selColor;
1128   }
1129   protected void setExtent()
1130   {
1131     if (dismode != AcopConst.mode_rectangle && dismode != AcopConst.mode_circle && dismode != AcopConst.mode_dots && disDots == 0 ) return;
1132     if ( dismode != AcopConst.mode_dots && disDots == 0 )
1133     {
1134       xextent = (short) (acop.aFrame.dxwidth * Math.abs(xext / 2) / (acop.sca[0].log != 0 ? (Math.pow(10.0,
1135         acop.sca[0].max) - Math.pow(10.0, acop.sca[0].min)) : acop.sca[0].dispSize));
1136       yextent = (short) (acop.aFrame.histRect.height * Math.abs(yext / 2) / (acop.sca[1].log != 0 ? (Math.pow(
1137         10.0, acop.sca[1].max) - Math.pow(10.0, acop.sca[1].min)) : acop.sca[1].dispSize));   
1138     }
1139     else if ( disDots != 0 )
1140     {
1141       if ( penWidth > 7 )
1142       {
1143         xextent = penWidth * 105 / 100;
1144         yextent = penWidth * 105 / 100;
1145       }
1146       else
1147       {
1148         xextent = penWidth * dotsScale[penWidth] / 100;
1149         yextent = penWidth * dotsScale[penWidth] / 100;
1150       }
1151     }
1152     else
1153     {
1154       xextent = 1;
1155       yextent = 1;     
1156     }
1157     if (xextent == 0) xextent = penWidth;
1158     if (yextent == 0) yextent = penWidth;
1159   }
1160   private void loadMarker(int i)
1161   {
1162     double ytemp;
1163     if (marker_ary_cpy == 1) // store marker array
1164     {
1165       markery[i] = y[i];
1166       imy[i] = iy[i];
1167     }
1168     else
1169     // get stored marker array
1170     {
1171       ytemp = acop.sca[1].log != 0 ? Math.log(AcopConst.log_check(markery[i])) / Math.log(10) : markery[i];
1172       imy[i] = (int) (acop.aFrame.histRect.height - ((ytemp - acop.sca[1].min) / acop.sca[1].dispSize * acop.aFrame.histRect.height));
1173       // avoid 100% cpu time to display a huge number!!
1174       if (imy[i] < 0)
1175         imy[i] = -20;
1176       else if (imy[i] > acop.aFrame.histRect.height) imy[i] = acop.aFrame.histRect.height + 20;
1177     }
1178   }
1179   private double correctWrapPosition(int i)
1180   {
1181     double xtemp;
1182     xtemp = acop.sca[0].log != 0 ? Math.log(AcopConst.log_check(x[i])) / Math.log(10) : x[i];
1183     if (acop.wrapAround == false || wraphigh == 0 || acop.sca[0].log != 0) return xtemp;
1184     if (wraphigh < 0)
1185     {
1186       if (i >= -(wraphigh + 1))
1187       {
1188         if (xaryFlag == 1)
1189           xtemp += (acop.wrapxmax - acop.wrapxmin);
1190         else
1191           xtemp -= (acop.wrapxmax - acop.wrapxmin);
1192       }
1193     }
1194     else
1195     {
1196       if (i < wraphigh)
1197       {
1198         if (xaryFlag == 1)
1199           xtemp -= (acop.wrapxmax - acop.wrapxmin);
1200         else
1201           xtemp += (acop.wrapxmax - acop.wrapxmin);
1202       }
1203     }
1204     return xtemp;
1205   }
1206   protected void mapScreen(int index)
1207   {
1208     double xtemp, ytemp;
1209     int kk, i, start, stop, scaleIndex;
1210     boolean xlow, xhigh, ylow, yhigh;
1211     int xonLast = 0, yonLast = 0;
1212     double xlast = 0, ylast = 0;
1213     String stmp;
1214     if (index < 0)
1215     {
1216       start = 0;
1217       stop = npoints;
1218       polycounter = 0;
1219     }
1220     else
1221     {
1222       start = index;
1223       stop = index + 1;
1224     }
1225     String allStmp = "";
1226     scaleIndex = bindSecondaryY ? 2 : 1;
1227     for (kk = start, i = wrapindex; kk < stop; kk++, i++)
1228     {
1229       if (i >= npoints) i = 0;
1230       if (dismode == AcopConst.mode_textbox)
1231       {
1232         if (str != null)
1233         {
1234           if (i >= str.length) return;
1235           stmp = "(" + String.valueOf(hisIndex) + "," + String.valueOf(i) + ")  " + str[i];
1236         }
1237         else
1238         {
1239           stmp = "(" + String.valueOf(hisIndex) + "," + String.valueOf(i) + ")  " + String.valueOf(x[i])
1240               + "    " + AcopConst.textFormat.format(y[i]);
1241         }
1242         if (disable != null && i < disable.length && disable[i] != 0) stmp += " [disabled]";
1243 //        acop.listTextBox.add(stmp); // addItem(stmp);
1244         allStmp = allStmp + stmp + "\n";
1245         continue;
1246       }
1247       ytemp = acop.sca[scaleIndex].log != 0 ? Math.log(AcopConst.log_check(y[i])) / Math.log(10) : y[i];
1248       xtemp = correctWrapPosition(i);
1249       ix[i] = (int) ((xtemp - acop.sca[0].min) / acop.sca[0].dispSize * acop.aFrame.dxwidth
1250           + acop.aFrame.xleft + 0.01);
1251       iy[i] = (int) (acop.aFrame.histRect.height - ((ytemp - acop.sca[scaleIndex].min) / acop.sca[scaleIndex].dispSize * acop.aFrame.histRect.height));
1252       xlow = xtemp < acop.sca[0].min ? true : false;
1253       xhigh = xtemp > acop.sca[0].max ? true : false;
1254       ylow = ytemp < acop.sca[scaleIndex].min ? true : false;
1255       yhigh = ytemp > acop.sca[scaleIndex].max ? true : false;
1256       if (ix[i] < -acop.aFrame.histRect.width * 4)
1257         ix[i] = -acop.aFrame.histRect.width * 4;
1258       else if (ix[i] > acop.aFrame.histRect.width * 4) ix[i] = acop.aFrame.histRect.width * 4;
1259       if (dismode != AcopConst.mode_polyline) // map x,y to display area
1260       {
1261         if (dismode == AcopConst.mode_barline)
1262         {
1263           dispxOn[i] = (xlow || xhigh) ? 0 : 1;
1264           dispyOn[i] = (ylow || yhigh) ? 0 : 1;
1265           if ((wrapindex != npoints && i != wrapindex) || (wrapindex == npoints && i != 0)) // avoid
1266                                                                                             // first
1267                                                                                             // point
1268           {
1269             if ((dispxOn[i] == 0 && xonLast == 0
1270                 && ((xlow && xlast > acop.sca[0].max) || (xlast < acop.sca[0].min && xhigh)) && yonLast != 0)
1271                 || (dispyOn[i] == 0 && yonLast == 0
1272                     && ((ylow && ylast > acop.sca[scaleIndex].max) || (ylast < acop.sca[scaleIndex].min && yhigh)) && dispxOn[i] != 0))
1273             {
1274               dispxOn[i] = 1;
1275               dispyOn[i] = 1;
1276             }
1277           }
1278           // store last value
1279           xonLast = dispxOn[i];
1280           yonLast = dispyOn[i];
1281           xlast = xtemp;
1282           ylast = ytemp;
1283           dispOn[i] = dispxOn[i] * dispyOn[i];
1284         }
1285         else if (dismode == AcopConst.mode_dots || dismode == AcopConst.mode_rectangle
1286             || dismode == AcopConst.mode_circle)
1287         {
1288           dispOn[i] = (xlow || xhigh || ylow || yhigh) ? 0 : 1;
1289         }
1290         else
1291           dispOn[i] = (xlow || xhigh) ? 0 : 1;
1292         if (disable[i] != 0) dispOn[i] = 0; // disable this point
1293         if (dismode == AcopConst.mode_histogram || dismode == AcopConst.mode_histogram_rastoring)
1294         { // avoid 100% cpu time to display a huge number!!
1295           if (iy[i] < 0)
1296             iy[i] = -20;
1297           else if (iy[i] > acop.aFrame.histRect.height) iy[i] = acop.aFrame.histRect.height + 20;
1298         }
1299       }
1300       else
1301       // fastest drawing mode is to use polyline()
1302       {
1303         dispOn[i] = disable[i] != 0 ? 0 : 1;
1304         if (dispOn[i] != 0)
1305         {
1306           dispxOn[i] = 0;
1307           dispyOn[i] = 0;
1308           if (xlow) dispxOn[i] |= 0x1; // mask 4 cases
1309           if (xhigh) dispxOn[i] |= 0x2;
1310           if (ylow) dispxOn[i] |= 0x4;
1311           if (yhigh) dispxOn[i] |= 0x8;
1312           if (dispxOn[i] == 0)
1313           {
1314             if (dispyOn[i] == 0 || index < 0) // not marked yet
1315             {
1316               dispyOn[i] = 1; // point inside
1317               polycounter++;
1318             }
1319           }
1320           else if (index >= 0 && dispyOn[i] != 0) // was marked
1321           {
1322             dispyOn[i] = 0; // point outside
1323             polycounter--;
1324           }
1325         }
1326       }
1327       if (marker_ary_cpy != 0 && markerFlag != 0) loadMarker(i);
1328     }
1329     if (dismode == AcopConst.mode_textbox)
1330     {
1331       acop.textArea.setText(allStmp);
1332       acop.textArea.setCaretPosition(0);
1333     }
1334     if (dismode == AcopConst.mode_polyline) makePolyArray();
1335     if (marker_ary_cpy != 0 && markerFlag != 0) marker_ary_cpy = 0;
1336   }
1337   protected int getIndex(int x)
1338   {
1339     int i, j, tmpflg = 0, XarrayElement, xtmp;
1340     if (ix == null) return 0;
1341     if (dismode == AcopConst.mode_textbox) return 0;
1342     for (i = 0, j = wrapindex; i < npoints; i++, j++)
1343     {
1344       if (j >= npoints) j = 0;
1345       if (j == wrapindex)
1346       {
1347         if (xaryFlag == 1)
1348         {
1349           if (x >= ix[j])
1350           {
1351             tmpflg = 1;
1352             break;
1353           }
1354         }
1355         else
1356         {
1357           if (x < ix[j])
1358           {
1359             tmpflg = 1;
1360             break;
1361           }
1362         }
1363         xtmp = penWidth;
1364       }
1365       else
1366       {
1367         xtmp = j == 0 ? npoints - 1 : j - 1;
1368         // TODO: there's (sometimes) an array index out of bound exception here when there's a
1369         // mouse move over a text-mode display. 
1370         // 1). why ?
1371         // 2).  text mode should not even check for this event
1372         xtmp = (ix[j] - ix[xtmp]) / 2;
1373       }
1374       if (xaryFlag == 1)
1375       {
1376         if (x >= ix[j] + xtmp) break;
1377       }
1378       else
1379       {
1380         if (x < ix[j] - xtmp) break;
1381       }
1382     }
1383     if (tmpflg == 1)
1384       XarrayElement = j;
1385     else
1386     {
1387       if (xaryFlag == 1)
1388       {
1389         XarrayElement = j == npoints ? j - 1 : j;
1390       }
1391       else
1392       {
1393         if (wrapindex != 0 && j == 0) j = npoints;
1394         XarrayElement = j == 0 ? 0 : j - 1;
1395       }
1396     }
1397     return XarrayElement;
1398   }
1399   protected int getHistoIndex(double x, double y)
1400   {
1401     int devX;
1402     double tmpX;
1403     tmpX = acop.sca[0].log != 0 ? Math.log(AcopConst.log_check(x)) / Math.log(10) : x;
1404     devX = (int) ((tmpX - acop.sca[0].min) * acop.aFrame.dxwidth / acop.sca[0].dispSize + acop.aFrame.xleft);
1405     return getIndex(devX);
1406   }
1407   protected int getMousePosition(Point point, double[] userPoint)
1408   {
1409     int i, j, tmpflg = 0, XarrayElement, xtmp;
1410     point.x -= acop.aFrame.histRect.x;
1411     point.y -= acop.aFrame.histRect.y;
1412     userPoint[0] = acop.sca[0].dispSize * (point.x - acop.aFrame.xleft) / acop.aFrame.dxwidth
1413         + acop.sca[0].min;
1414     userPoint[1] = acop.sca[1].dispSize * (acop.aFrame.histRect.height - point.y)
1415         / acop.aFrame.histRect.height + acop.sca[1].min;
1416     if (acop.sca[0].log != 0) userPoint[0] = Math.pow(10.0, userPoint[0]);
1417     if (acop.sca[1].log != 0) userPoint[1] = Math.pow(10.0, userPoint[1]);
1418     return getIndex(point.x);
1419   }
1420   protected double maxOf(double arr[])
1421   {
1422     int i;
1423     double max = -1.7E308;
1424     if (disFlag == 0)
1425     {
1426       for (i = 0; i < npoints; i++)
1427         if (arr[i] > max) max = arr[i];
1428     }
1429     else
1430     {
1431       for (i = 0; i < npoints; i++)
1432       {
1433         if (disable[i] != 0) continue;
1434         if (arr[i] > max) max = arr[i];
1435       }
1436     }
1437     return max;
1438   }
1439   protected double minOf(double arr[])
1440   {
1441     int i;
1442     double min = 1.7E308;
1443     if (disFlag == 0)
1444     {
1445       for (i = 0; i < npoints; i++)
1446         if (arr[i] < min) min = arr[i];
1447     }
1448     else
1449     {
1450       for (i = 0; i < npoints; i++)
1451       {
1452         if (disable[i] != 0) continue;
1453         if (arr[i] < min) min = arr[i];
1454       }
1455     }
1456     return min;
1457   }
1458   protected void getMaxWindow()
1459   {
1460     double off, tmin, tmax;
1461     int setFirstTime = 0;
1462     if (npoints < 2)
1463     {
1464       tmax = x[0] + 1;
1465       tmin = x[0] - 1;
1466     }
1467     else
1468     {
1469       tmax = maxOf(x);
1470       tmin = minOf(x);
1471       // all points disabled!
1472       if (Math.abs(tmax + 1.7e+308) < AcopConst.zero_check
1473           && Math.abs(originxmin + 1.7e+308) < AcopConst.zero_check
1474           && Math.abs(originxmax - 1.7e+308) < AcopConst.zero_check)
1475       {
1476         setFirstTime = 1;
1477         tmax = acop.sca[0].dispSize / 2 + 1;
1478         tmin = tmax - 2;
1479       }
1480       off = (tmax - tmin) / (2 * (npoints - 1));
1481       if (off < AcopConst.zero_check) off = 1;
1482       tmax += off;
1483       tmin -= off;
1484     }
1485     // if different x size, then
1486     if (Math.abs(tmax - originxmax) > AcopConst.zero_check
1487         || Math.abs(tmin - originxmin) > AcopConst.zero_check || setFirstTime != 0)
1488     {
1489       originxmax = tmax;
1490       originxmin = tmin;
1491       if (hisIndex == acop.m_histstart)
1492       {
1493         acop.wrapxmin = originxmin;
1494         acop.wrapxmax = originxmax;
1495       }
1496     }
1497     if (acop.sca[0].log != 0) setwrapindex();
1498   }
1499   protected void setwrapindex()
1500   {
1501     int i, j, highfound;
1502     double xtemp;
1503     if (acop.sca[0].min < acop.wrapxmin && acop.sca[0].max < acop.wrapxmax)
1504       j = xaryFlag == 1 ? 2 : 1; // left
1505     else if (acop.sca[0].max > acop.wrapxmax && acop.sca[0].min > acop.wrapxmin)
1506       j = xaryFlag == 1 ? 1 : 2;// right
1507     else
1508       j = 0;
1509     wrapindex = wraphigh = 0;
1510     if (j > 0)
1511     {
1512       for (i = 0, highfound = -1; i < npoints; i++)
1513       {
1514         xtemp = x[i];
1515         if (j == 1)
1516         {
1517           if (xaryFlag == 1)
1518           {
1519             if (xtemp <= acop.wrapxmin + (acop.sca[0].max - acop.wrapxmax) // ???
1520                                                                             // change
1521                                                                             // to
1522                                                                             // <=
1523                 && xtemp <= acop.sca[0].min) break;
1524           }
1525           else
1526           {
1527             if (xtemp >= acop.wrapxmax - (acop.wrapxmin - acop.sca[0].min) // ???
1528                                                                             // change
1529                                                                             // to
1530                                                                             // >=
1531                 && xtemp >= acop.sca[0].max) break;
1532           }
1533         }
1534         else
1535         {
1536           if (xaryFlag == 1)
1537           {
1538             if (xtemp >= acop.wrapxmax - (acop.wrapxmin - acop.sca[0].min) && xtemp > acop.sca[0].max)
1539               highfound = i;
1540             if (xtemp <= acop.sca[0].max) break;
1541           }
1542           else
1543           {
1544             if (xtemp <= acop.wrapxmin + (acop.sca[0].max - acop.wrapxmax) && xtemp < acop.sca[0].min)
1545               highfound = i;
1546             if (xtemp >= acop.sca[0].min) break;
1547           }
1548         }
1549       }
1550       wrapindex = i == npoints ? 0 : i;
1551       if (j == 1)
1552       {
1553         if (i != npoints) wraphigh = -(wrapindex + 1);
1554       }
1555       else if (highfound != -1)
1556       {
1557         wraphigh = highfound;
1558         if (highfound < npoints - 1 && i != npoints)
1559           wraphigh = i == (highfound + 1) ? highfound : highfound + 1;
1560         wraphigh++;
1561       }
1562       // disp[n]->wraphigh = (j == 1) ? 0 : (k+1);
1563     }
1564   }
1565   private void makePolyArray()
1566   {
1567     int i, j, k, kk;
1568     if (disFlag == 0 && (acop.wrapAround == false || acop.sca[0].log != 0))
1569     {
1570       dispindex[0] = 0;
1571       dispnumber[0] = npoints; // # of points
1572       dispindex[1] = -1;
1573     }
1574     else
1575     {
1576       j = 0;
1577       k = 0;
1578       dispindex[k] = -1;
1579       for (kk = 0, i = wrapindex; kk < npoints && k < npoints; kk++, i++)
1580       {
1581         if (i >= npoints) i = 0;
1582         if (dispOn[i] != 0)
1583         {
1584           if (wrapindex != 0 && wraphigh > 0 && i >= wraphigh && i < wrapindex) break;
1585           if (dispindex[k] == -1) dispindex[k] = i; // load first index
1586           j++;
1587           if (wrapindex != 0 && i == (npoints - 1))
1588           {
1589             dispnumber[k] = j; // # of points
1590             j = 0;
1591             dispindex[++k] = -1;
1592           }
1593         }
1594         else
1595         {
1596           if (dispindex[k] != -1)
1597           {
1598             dispnumber[k] = j; // # of points
1599             j = 0;
1600             dispindex[++k] = -1;
1601           }
1602         }
1603       }
1604       if (dispindex[k] != -1)
1605       {
1606         dispnumber[k] = j;
1607         dispindex[++k] = -1;
1608       }
1609     }
1610   }
1611   private void drawPoly(java.awt.Graphics2D a, int pstart, int pend)
1612   {
1613     if ( pstart == 0 )
1614     {
1615       a.drawPolyline(ix,iy,pend);
1616       return;
1617     }
1618     int[] tix = new int[pend-pstart], tiy = new int[pend-pstart];
1619     System.arraycopy(ix, pstart, tix, 0, pend-pstart);
1620     System.arraycopy(iy, pstart, tiy, 0, pend-pstart);
1621     a.drawPolyline(tix,tiy,pend-pstart);
1622   }
1623   
1624   protected void drawhist(java.awt.Graphics2D a)
1625   {
1626     int i, j, k, OndisFlag, wx, wy, mx;
1627     Color selColor, lastColor;
1628     boolean colorCheck;
1629     if (displayON == 0) return;
1630     a.setColor(penColor);
1631     lastColor = penColor; // init tag drawing
1632     if (dismode == AcopConst.mode_textbox)
1633     {
1634       acop.listTextBox.setVisible(true);
1635       return;
1636     }
1637     a.setStroke(stroke);
1638     acop.listTextBox.setVisible(false);
1639     if (dismode == AcopConst.mode_polyline)
1640     {
1641       double tantheta, atantheta, abssin, abscos, delta;
1642       int xstart, ystart, xstart2, ystart2, delx, dely;
1643       /*
1644        * for (i=wrapindex, j=0; j<npoints -1; j++,i++) { if ( i >= npoints ) i =
1645        * 0; // i: current point k = i+1; if ( k >= npoints ) k = 0; // i:
1646        * current point if ( dispOn[i] == 0 || dispOn[k] == 0 ) continue; //
1647        * aLine.DrawAcopLine(ix[i],iy[i],ix[k],iy[k]);
1648        * a.drawLine(ix[i],iy[i],ix[k],iy[k]); } if ( i >= -10 ) return;
1649        */
1650       for (i = 0; i < npoints; i++)
1651       {
1652         if ((wx = dispindex[i]) == -1) break;
1653         wy = wx; // load first index
1654         for (j = 1; j < dispnumber[i]; j++)
1655         {
1656           // both outside, draw last part if there is one, then set index = -1
1657           if ((dispxOn[wx + j] & dispxOn[wx + j - 1]) != 0)
1658           {
1659             if (wy != -1 && (wx + j - 1) > wy)
1660             {
1661 //              a.drawPolyline(tix,tiy,wx+j-wy);
1662               drawPoly(a, wy, wx+j);
1663               if ( disDots != 0 )
1664               {
1665               for (k = wy; k < wx + j - 1; k++)
1666               {
1667 //                a.drawLine(ix[k], iy[k], ix[k + 1], iy[k + 1]);
1668                 if ( disDots != 0 && dispyOn[k] != 0) a.fillRect(ix[k] - xextent, iy[k] - yextent, xextent * 2, yextent * 2);
1669               }
1670               if ( disDots != 0 && dispyOn[k+1] != 0) a.fillRect(ix[k+1] - xextent, iy[k+1] - yextent, xextent * 2, yextent * 2);
1671               }
1672             }
1673             wy = -1;
1674             continue;
1675           }
1676           // otherwise: if nindex not yet set, load new index number
1677           if (wy == -1)
1678           {
1679             // pdc->MoveTo(ipoint[wx+j-1].x, ipoint[wx+j-1].y); // move to
1680             // lastpoint
1681             wy = wx + j - 1;
1682           }
1683           // pdc->LineTo(ipoint[wx+j].x, ipoint[wx+j].y);
1684         }
1685         // draw last part if there is one
1686         if (wy != -1 && (wx + j - 1) > wy)
1687         {
1688           // drawPolyline(ix[wy],iy[wy],wx+j-wy);
1689           drawPoly(a, wy, wx+j);
1690           if ( disDots != 0 )
1691           {
1692           for (k = wy; k < wx + j - 1; k++)
1693           {
1694 //            a.drawLine(ix[k], iy[k], ix[k + 1], iy[k + 1]);
1695             if ( disDots != 0 && dispyOn[k] != 0) a.fillRect(ix[k] - xextent, iy[k] - yextent, xextent * 2, yextent * 2);
1696           }
1697           if ( disDots != 0 && dispyOn[k] != 0) a.fillRect(ix[k] - xextent, iy[k] - yextent, xextent * 2, yextent * 2);
1698           }
1699         }
1700       }
1701       if (acop.wrapAround && wrapindex != 0 && acop.sca[0].log == 0) // connect
1702                                                                       // end
1703                                                                       // with
1704                                                                       // begining
1705       {
1706         i = npoints - 1;
1707         if (dispOn[0] != 0 && dispOn[i] != 0 && (dispxOn[0] & dispxOn[i]) == 0)
1708         {
1709           OndisFlag = 0;
1710           if (xaryFlag == 1)
1711           {
1712             if (ix[0] <= ix[i]) OndisFlag = 1;
1713           }
1714           else if (ix[0] >= ix[i]) OndisFlag = 1;
1715           if (OndisFlag != 0) a.drawLine(ix[0], iy[0], ix[i], iy[i]);
1716         }
1717       }
1718       // if ( i >= -10 ) return;
1719       /*
1720        * if ( penWidth < 2 ) a.drawPolyline(ix, iy, npoints); else { //
1721        * java.awt.Polygon poly = new java.awt.Polygon(ix, iy, npoints); // Line
1722        * penLine = new Line(); for (i = 0; i < npoints-1; i++) { if ( ix[i] ==
1723        * ix[i+1] || iy[i] == iy[i+1] ) {
1724        * a.drawLine(ix[i],iy[i],ix[i+1],iy[i+1]); continue; } tantheta =
1725        * (iy[i+1]-iy[i])/(ix[i+1]-ix[i]); atantheta = Math.atan(tantheta);
1726        * abssin = Math.abs(Math.sin(atantheta)); abscos =
1727        * Math.abs(Math.cos(atantheta)); // abssin = Math.abs(tantheta /
1728        * Math.sqrt(1+tantheta*tantheta)); // abscos = Math.abs(abssin/tantheta);
1729        * if ( tantheta > 1 || tantheta < -1 ) { delta = 1/tantheta; if (tantheta<0.)
1730        * abscos = -abscos; } else { delta = tantheta; if (tantheta<0.) abssin =
1731        * -abssin; } xstart = (int)(ix[i] - penWidth / 2 * abssin); xstart2 =
1732        * (int)(ix[i+1] - penWidth / 2 * abssin); ystart = (int)(iy[i] + penWidth /
1733        * 2 * abscos); ystart2 = (int)(iy[i+1] + penWidth / 2 * abscos); // for
1734        * (int j = 0; j < penWidth; j++) // { // delx = (int) (j * abssin); //
1735        * dely = (int) (j * abscos); // AcopLine.a.drawLine(xstart+delx,
1736        * ystart-dely,xstart2+delx, ystart2-dely); // } if ( tantheta > 1 ||
1737        * tantheta < -1 ) { delx = (int) (penWidth * abssin); for (j=0; j < delx;
1738        * j++) { dely = (int) (delta * j) ; a.drawLine(xstart+j, ystart
1739        * -dely,xstart2+j, ystart2-dely); } } else { dely = (int) (penWidth *
1740        * abscos); for (j=0; j < dely; j++) { delx = (int) (delta * j) ;
1741        * a.drawLine(xstart+delx, ystart-j ,xstart2+delx, ystart2-j); } } } //
1742        * for (int j = 0; j < penWidth; j++) // for (int i = 0; i < npoints-1;
1743        * i++) AcopLine.a.drawLine(ix[i],iy[i]-penWidth / 2+ j
1744        * ,ix[i+1],iy[i+1]-penWidth / 2 + j); }
1745        */
1746     }
1747     else if (dismode == AcopConst.mode_barline)
1748     {
1749       for (i = wrapindex, j = 0; j < npoints - 1; j++, i++)
1750       {
1751         if (i >= npoints) i = 0; // i: current point
1752         k = i + 1;
1753         if (k >= npoints) k = 0; // i: current point
1754         if (disable[k] != 0 || disable[i] != 0) continue; // current disable
1755         
1756         if ( disBarHisto != 0 )
1757         {
1758           mx = ix[i] + (ix[k]-ix[i])/2;
1759           if ( barlineColorFilled == 0 )
1760           {
1761           a.drawLine(ix[i], iy[i], mx, iy[i]);
1762           a.drawLine(mx, iy[i], mx, iy[k]);
1763           a.drawLine(mx, iy[k], ix[k], iy[k]);         
1764           }
1765           else if ( barlineColorFilled < 0 )
1766           {
1767             a.fillRect(ix[i], iy[i], mx - ix[i], acop.aFrame.histRect.height - iy[i]);
1768             a.fillRect(mx, iy[k], ix[k] - mx, acop.aFrame.histRect.height - iy[k]);
1769           }
1770           else
1771           {
1772             a.fillRect(ix[i], 0, mx - ix[i], iy[i]);          
1773             a.fillRect(mx, 0, ix[k] - mx, iy[k]);          
1774           }
1775         }
1776         else
1777         {
1778           if ( barlineColorFilled == 0 )
1779           {
1780           a.drawLine(ix[i], iy[i], ix[k], iy[i]);
1781           a.drawLine(ix[k], iy[i], ix[k], iy[k]);
1782           }
1783           else if ( barlineColorFilled < 0 )
1784             a.fillRect(ix[i], iy[i], ix[k] - ix[i], acop.aFrame.histRect.height - iy[i]);
1785           else
1786             a.fillRect(ix[i], 0, ix[k] - ix[i],  iy[i]);
1787         }
1788         if ( disDots != 0 ) a.fillRect(ix[k] - xextent, iy[k] - yextent, xextent * 2, yextent * 2);
1789       }
1790     }
1791     else if (dismode == AcopConst.mode_histogram || dismode == AcopConst.mode_histogram_rastoring)
1792     {
1793       colorCheck = (errWindowEnable || (tagHist != 0 && acop.m_tagging)) ? true : false;
1794       for (i = 0; i < npoints; i++)
1795       {
1796         if (dispOn[i] == 0) continue;
1797         // a.drawLine(ix[i],de.desy.acop.chart.aFrame.histRect.height,ix[i],iy[i]);
1798         if (colorCheck && (selColor = selTagErrPen(a, i, lastColor)) != lastColor) lastColor = selColor;
1799         if (iy[i] != acop.yzero)
1800         {
1801           a.drawLine(ix[i], acop.yzero, ix[i], iy[i]);
1802           if ( disDots != 0 ) a.fillRect(ix[i] - xextent, iy[i] - yextent, xextent * 2, yextent * 2);
1803         }
1804         else
1805           a.drawRect(ix[i] - 1, iy[i] - 1, 2, 2);
1806       }
1807     }
1808     else if (dismode == AcopConst.mode_dots)
1809     {
1810       colorCheck = (errWindowEnable || (tagHist != 0 && acop.m_tagging)) ? true : false;
1811       for (i = 0; i < npoints; i++)
1812       {
1813         if (dispOn[i] == 0) continue;
1814         if (colorCheck && (selColor = selTagErrPen(a, i, lastColor)) != lastColor) lastColor = selColor;
1815 //        a.fillRect(ix[i] - 1, iy[i] - 1, 3, 3);
1816         a.fillRect(ix[i] - xextent, iy[i] - yextent, xextent * 2 + 1, yextent * 2 + 1);
1817       }
1818     }
1819     else if (dismode == AcopConst.mode_rectangle)
1820     {
1821       colorCheck = (errWindowEnable || (tagHist != 0 && acop.m_tagging)) ? true : false;
1822       for (i = 0; i < npoints; i++)
1823       {
1824         if (dispOn[i] == 0) continue;
1825         if (colorCheck && (selColor = selTagErrPen(a, i, lastColor)) != lastColor) lastColor = selColor;
1826         if (colorfilled)
1827           a.fillRect(ix[i] - xextent, iy[i] - yextent, xextent * 2, yextent * 2);
1828         else
1829           a.drawRect(ix[i] - xextent, iy[i] - yextent, xextent * 2, yextent * 2);
1830       }
1831     }
1832     else if (dismode == AcopConst.mode_circle)
1833     {
1834       colorCheck = (errWindowEnable || (tagHist != 0 && acop.m_tagging)) ? true : false;
1835       for (i = 0; i < npoints; i++)
1836       {
1837         if (dispOn[i] == 0) continue;
1838         if (colorCheck && (selColor = selTagErrPen(a, i, lastColor)) != lastColor) lastColor = selColor;
1839         a.drawOval(ix[i] - xextent, iy[i] - yextent, xextent * 2, yextent * 2);
1840       }
1841     }
1842     else
1843     {
1844       acop.listTextBox.setVisible(true);
1845     }
1846     if (edgeMode != 0) drawLeadingEdgeMarker(a);
1847     drawMarker(a);
1848   }
1849   private void drawLeadingEdgeMarker(java.awt.Graphics2D a)
1850   {
1851     int mx;
1852     a.setColor(edgeColor);
1853     a.setStroke(edgeStroke);
1854     if ((edgeMode & 0x1) != 0)
1855     {
1856       if (edgePercentX < 0)
1857       {
1858         if (edgeExtentX < 0)
1859           edgePercentX = 1;
1860         else
1861           edgePercentX = (acop.sca[0].log != 0 ? Math.log(edgeExtentX) / Math.log(10) : edgeExtentX)
1862               / (acop.sca[0].xtime != 0 ? acop.sca[0].dispSize : (acop.sca[0].tick_max - acop.sca[0].tick_min)) / 2;
1863         edgePixel = (int) (acop.aFrame.dxwidth * edgePercentX * 2);
1864         if (edgePixel < edgeWidth) edgePixel = edgeWidth;
1865       }
1866       mx = (int) (acop.aFrame.dxwidth * edgePercentX);
1867       if ( mx < 1 ) mx = 1; // at least 1 pixel
1868       a.drawLine(ix[edgeIndex] - mx, iy[edgeIndex], ix[edgeIndex] + mx, iy[edgeIndex]);
1869     }
1870     if ((edgeMode & 0x2) != 0)
1871     {
1872       if (edgePercentY < 0)
1873       {
1874         if (edgeExtentY < 0)
1875           edgePercentY = 1;
1876         else
1877           edgePercentY = (acop.sca[1].log != 0 ? Math.log(edgeExtentY) / Math.log(10) : edgeExtentY)
1878               / acop.sca[1].dispSize / 2;
1879       }
1880       mx = (int) (acop.aFrame.histRect.height * edgePercentY);
1881       a.drawLine(ix[edgeIndex], iy[edgeIndex] - mx, ix[edgeIndex], iy[edgeIndex] + mx);
1882     }
1883   }
1884   private void drawMarker(java.awt.Graphics2D a)
1885   {
1886     int wy, mx, tickflag;
1887     if (acop.m_marker == 0 || markerFlag == 0) return;
1888     if (acop.m_markerMode == 0)
1889     {
1890       if (acop.saveMarkerWidth != penWidth)
1891       {
1892         acop.markerStroke = AcopConst.createStroke(penWidth, AcopConst.PS_SOLID);
1893         acop.saveMarkerWidth = penWidth;
1894       }
1895       a.setColor(acop.m_markerColor);
1896       a.setStroke(acop.markerStroke);
1897     }
1898     else
1899     {
1900       a.setColor(markerColor);
1901       a.setStroke(mStroke);
1902     }
1903     for (int i = 0; i < npoints; i++)
1904     {
1905       if (dispOn[i] == 0) continue;
1906       tickflag = acop.m_marker == 2 ? imy[i] : iy[i];
1907       mx = ix[i];
1908       if (acop.m_markerMode == 0)
1909       {
1910         if (tickflag > 0 && tickflag < acop.aFrame.histRect.height)
1911           a.drawLine(mx - acop.m_markerWidth, tickflag, mx + acop.m_markerWidth, tickflag);
1912       }
1913       else
1914       // new one
1915       {
1916         if ((markerMode & 0x1) != 0)
1917         {
1918           if (markerPercentX < 0) // new one
1919           {
1920             if (markerExtentX < 0)
1921               markerPercentX = 1;
1922             else
1923               markerPercentX = (acop.sca[0].log != 0 ? Math.log(markerExtentX) / Math.log(10) : markerExtentX)
1924                   / (acop.sca[0].xtime != 0 ? acop.sca[0].dispSize : (acop.sca[0].tick_max - acop.sca[0].tick_min)) / 2;
1925           }
1926           wy = (int) (acop.aFrame.histRect.width * markerPercentX);
1927           if ( wy < 1 ) wy = 1; // at least 1 pixel
1928           a.drawLine(mx - wy, tickflag, mx + wy, tickflag);
1929         }
1930         if ((markerMode & 0x2) != 0)
1931         {
1932           if (markerPercentY < 0)
1933           {
1934             if (markerExtentY < 0)
1935               markerPercentY = 1;
1936             else
1937               markerPercentY = (acop.sca[1].log != 0 ? Math.log(markerExtentY) / Math.log(10) : markerExtentY)
1938                   / acop.sca[1].dispSize / 2;
1939           }
1940           wy = (int) (acop.aFrame.histRect.height * markerPercentY);
1941           a.drawLine(mx, tickflag - wy, mx, tickflag + wy);
1942         }
1943       }
1944     }
1945   }
1946   // }}
1947 }