View Javadoc

1   /*
2    * Copyright (c) 2003-2008 by Cosylab d. d.
3    *
4    * This file is part of CosyBeans-Common.
5    *
6    * CosyBeans-Common is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * CosyBeans-Common is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with CosyBeans-Common.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  
20  package com.cosylab.gui.components.gauger;
21  
22  import java.awt.geom.Point2D;
23  
24  
25  /**
26   * Defines vertical polar transform. This transform will define gauger with 
27   * arc scale with origin at left and arc spanning to the right. Minimum will
28   * be at top and maximum at bottom.
29   *
30   * @author <a href="mailto:ales.pucelj@cosylab.com">Ales Pucelj</a>
31   * @version $id$
32   */
33  public class PolarVerticalTransform extends PolarTransform
34  {
35  	private static final int MAXIMUM_HEIGHT = 90;
36  	private static final int MINIMUM_HEIGHT = 35;
37  	private static final double RELATIVE_X_OFFSET = 0.1;
38  	private static final double RELATIVE_Y_OFFSET = 0.05;
39  	private static final double RELATIVE_SCALE_SIZE_COMPARED_TO_WIDTH = 0.3;
40  
41  	/*
42  	 * @see ScaleTransform#setParameters(int, int, int, int, int)
43  	 */
44  	public void setParameters(int w, int h, int marginX, int marginY,
45  	    int tickOffset)
46  	{
47  		super.setParameters(w, h, marginX, marginY, tickOffset);
48  
49  		double heightDouble = h * (1 - RELATIVE_Y_OFFSET);
50  		double widthDouble = (w - MAXIMUM_HEIGHT / 2) * (1 - RELATIVE_X_OFFSET);
51  
52  		height = (int)(widthDouble * RELATIVE_SCALE_SIZE_COMPARED_TO_WIDTH);
53  		height = Math.min(height, MAXIMUM_HEIGHT);
54  		height = Math.max(height, MINIMUM_HEIGHT);
55  
56  		double RDouble = 0.5 * widthDouble * (1
57  			+ Math.pow(0.5 * heightDouble / widthDouble, 2));
58  
59  		double phi = (Math.asin(0.5 * heightDouble / RDouble) * 180 / Math.PI);
60  
61  		R = RDouble;
62  		r = R - height;
63  
64  		double cw = R
65  			+ (RELATIVE_X_OFFSET * widthDouble / 2 + MAXIMUM_HEIGHT / 6);
66  
67  		centre = new Point2D.Double((w - cw), h / 2);
68  		alpha = phi;
69  		span = 2 * phi;
70  
71  		this.tickOffset = ((tickOffset * 180.0 / Math.PI) / r);
72  
73  		setLabelPosition((int)(3 * w / 8), (int)centre.getY());
74  
75  		ArcSegment segment = new ArcSegment(centre, r, R, alpha, span);
76  		addSegment(segment);
77  	}
78  }
79  
80  /* __oOo__ */