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  import java.awt.BasicStroke;
25  import java.awt.Color;
26  
27  public class AcopAxis
28  {   
29    protected  int 	axisIndex;       	// own axis index number
30    protected  int 	npoints;    		// display points
31    protected  boolean	axisON;			// on or off
32    
33    protected	double[] Position;          // input display data
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 )	// xaxis
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 }