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 polar transform for angles larger than 180 degrees, but less than
27   * 360. Minimum will be at lower left and maximum at lower right. 
28   *
29   * @author <a href="mailto:ales.pucelj@cosylab.com">Ales Pucelj</a>
30   * @version $id$
31   */
32  public class PolarFullTransform extends PolarTransform
33  {
34  	private static final int MAXIMUM_HEIGHT = 60;
35  	private static final int MINIMUM_HEIGHT = 35;
36  	private static final double RELATIVE_OFFSET = 0.9;
37  	private static final double RELATIVE_SCALE_SIZE_COMPARED_TO_SIZE = 0.15;
38  
39  	/*
40  	 * @see ScaleTransform#setParameters(int, int, int, int, int)
41  	 */
42  	public void setParameters(int w, int h, int marginX, int marginY,
43  	    int tickOffset)
44  	{
45  		super.setParameters(w, h, marginX, marginY, tickOffset);
46  
47  		double size = (Math.min(w, h * 1.171573411) * RELATIVE_OFFSET);
48  
49  		R = size / 2.0;
50  		centre = new Point2D.Double(0.5 * w, 0.5 * h + (R * 0.17));
51  
52  		h = (int)(h * RELATIVE_SCALE_SIZE_COMPARED_TO_SIZE);
53  		h = Math.min(h, MAXIMUM_HEIGHT);
54  		h = Math.max(h, MINIMUM_HEIGHT);
55  		height = h;
56  
57  		r = R - h;
58  
59  		alpha = 225.0;
60  		span = 270.0;
61  
62  		setLabelPosition((int)centre.getX(), (int)centre.getY());
63  
64  		//		this.tickOffset = PolarPoint.degToRad(tickOffset) / r;
65  		this.tickOffset = Math.toDegrees(tickOffset) / r;
66  
67  		ArcSegment segment = new ArcSegment(centre, r, R, alpha, span);
68  		addSegment(segment);
69  	}
70  }
71  
72  /* __oOo__ */