1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.desy.acop.chart;
24 import java.awt.BasicStroke;
25 import java.awt.Color;
26
27 public class AcopAxis
28 {
29 protected int axisIndex;
30 protected int npoints;
31 protected boolean axisON;
32
33 protected double[] Position;
34 protected Color[] penColor;
35 protected int[] penWidth, penStyle;
36 protected BasicStroke axisStroke;
37 private int strokeWidth, strokeStyle;
38 private Color lastColor;
39
40 private Acop acop;
41
42 public AcopAxis(Acop acop, int index)
43 {
44 this.acop = acop;
45 npoints = 0;
46 axisON = false;
47 axisIndex = index;
48 }
49
50 protected int loadData(int size, Object PositionArray, Color[] ColorArray, int[] StyleArray, int[] WidthArray)
51 { int i, ndata, dataChanged, penChange;
52
53 dataChanged = 0;
54 penChange = 0;
55
56 if ( npoints < size )
57 {
58 dataChanged++;
59 npoints = size;
60 Position = new double[npoints];
61 penColor = new Color[npoints];
62 penWidth = new int[npoints];
63 penStyle = new int[npoints];
64 for (i=0; i<npoints; i++)
65 {
66 penColor[i] = AcopScale.gridLineColor;
67 Position[i] = 0.0;
68 penWidth[i] = 1;
69 penStyle[i] = AcopConst.PS_DOT;
70 }
71 penChange++;
72 }
73 ndata = AcopHisto.getArrayLength(PositionArray);
74 if ( ndata > 0 )
75 {
76 dataChanged++;
77 if ( npoints < ndata ) ndata = npoints;
78 AcopHisto.copyArray(Position, PositionArray, 0, ndata, ndata, 1);
79 }
80 ndata = AcopHisto.getArrayLength(ColorArray);
81 if ( ndata > 0 )
82 {
83 dataChanged++;
84 if ( npoints < ndata ) ndata = npoints;
85 for(i=0;i<ndata;i++) penColor[i] = ColorArray[i];
86 }
87 ndata = AcopHisto.getArrayLength(StyleArray);
88 if ( ndata > 0 )
89 {
90 dataChanged++;
91 if ( penStyle[0] != StyleArray[0] ) penChange++;
92 if ( npoints < ndata ) ndata = npoints;
93 for(i=0;i<ndata;i++)penStyle[i] = StyleArray[i];
94 }
95 ndata = AcopHisto.getArrayLength(WidthArray);
96 if ( ndata > 0 )
97 {
98 dataChanged++;
99 if ( penWidth[0] != WidthArray[0] ) penChange++;
100 if ( npoints < ndata ) ndata = npoints;
101 for(i=0;i<ndata;i++)penWidth[i] = WidthArray[i];
102 }
103 if ( penChange != 0 ) getStroke(0);
104 return dataChanged;
105 }
106
107 private void getStroke(int i)
108 {
109 strokeWidth = penWidth[i];
110 strokeStyle = penStyle[i];
111 axisStroke = AcopConst.createStroke(strokeWidth,strokeStyle);
112 }
113
114 protected void drawAxis(java.awt.Graphics2D a)
115 { int xtemp, ytemp, lastWidth, lastStyle;
116 double tmp;
117 Color lastColor;
118
119 if ( axisON == false || npoints <= 0 ) return;
120
121 a.setColor(penColor[0]);
122 lastColor = penColor[0];
123 a.setStroke(axisStroke);
124
125 for ( int i=0; i<npoints; i++ )
126 {
127 tmp = acop.sca[axisIndex].log != 0 ? Math.log( AcopConst.log_check(Position[i]) )/Math.log(10) : Position[i];
128 if ( tmp < acop.sca[axisIndex].min || tmp > acop.sca[axisIndex].max ) continue;
129
130 if ( penColor[i] != lastColor )
131 {
132 a.setColor(penColor[i]);
133 lastColor = penColor[i];
134 }
135 if ( strokeWidth != penWidth[i] || strokeStyle != penStyle[i] )
136 {
137 getStroke(i);
138 a.setStroke(axisStroke);
139 }
140 if ( axisIndex == 0 )
141 {
142 xtemp = (int)((tmp - acop.sca[axisIndex].min) / acop.sca[axisIndex].dispSize * acop.aFrame.dxwidth + acop.aFrame.xleft + 0.01);
143 a.drawLine(xtemp, acop.aFrame.histRect.height, xtemp, 0);
144 }
145 else
146 {
147 ytemp = (int)(acop.aFrame.histRect.height - ( (tmp - acop.sca[axisIndex].min) / acop.sca[axisIndex].dispSize * acop.aFrame.histRect.height ));
148 a.drawLine(acop.aFrame.xleft, ytemp, acop.aFrame.dxwidth, ytemp);
149 }
150 }
151 }
152
153 }