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 horizontal polar transform. This transform will render the scale
27   * as arc of less the 180 degrees with minimum at left and maximum at right.
28   *
29   * @author <a href="mailto:ales.pucelj@cosylab.com">Ales Pucelj</a>
30   * @version $id$
31   */
32  public class PolarHorizontalTransform extends PolarTransform
33  {
34  	private static final int MAXIMUM_HEIGHT = 90;
35  	private static final int MINIMUM_HEIGHT = 35;
36  	private static final int MAXIMUM_HEIGHT_2 = MAXIMUM_HEIGHT / 2;
37  	private static final int MAXIMUM_HEIGHT_6 = MAXIMUM_HEIGHT / 6;
38  	private static final double RELATIVE_X_OFFSET = 0.05;
39  	private static final double RELATIVE_Y_OFFSET = 0.1;
40  	private static final double RELATIVE_SCALE_SIZE_COMPARED_TO_HEIGHT = 0.3;
41  
42  	/*
43  	 * @see ScaleTransform#setParameters(int, int, int, int, int)
44  	 */
45  	public void setParameters(int w, int h, int marginX, int marginY,
46  	    int tickOffset)
47  	{
48  		super.setParameters(w, h, marginX, marginY, tickOffset);
49  
50  		height = h;
51  
52  		double widthDouble = w * (1 - RELATIVE_X_OFFSET);
53  		double heightDouble = (h - MAXIMUM_HEIGHT_2) * (1 - RELATIVE_Y_OFFSET);
54  
55  		height = (int)(heightDouble * RELATIVE_SCALE_SIZE_COMPARED_TO_HEIGHT);
56  		height = Math.min(height, MAXIMUM_HEIGHT);
57  		height = Math.max(height, MINIMUM_HEIGHT);
58  
59  		// imas height in width;
60  		double RDouble = (0.5 * heightDouble * (1
61  			+ Math.pow(widthDouble / (2 * heightDouble), 2)));
62  
63  		R = RDouble;
64  		r = R - height;
65  
66  		int offset = (int)(RELATIVE_Y_OFFSET * heightDouble / 2
67  			+ MAXIMUM_HEIGHT_6);
68  
69  		centre = new Point2D.Double(w / 2, R + offset);
70  
71  		double phi = Math.asin(widthDouble / (2 * RDouble)) * 180 / Math.PI;
72  
73  		alpha = (90.0 + phi);
74  		span = (2.0 * phi);
75  
76  		setLabelPosition((int)centre.getX(), (int)(h * 0.75));
77  
78  		this.tickOffset = (tickOffset * 180.0 / Math.PI) / r;
79  
80  		ArcSegment segment = new ArcSegment(centre, r, R, alpha, span);
81  		addSegment(segment);
82  	}
83  }
84  
85  /* __oOo__ */