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.Graphics;
23  import java.awt.geom.Point2D;
24  
25  
26  /**
27   * Base class for polar transforms. All polar transforms will be rendered using
28   * scale in the shape of arc.
29   *
30   * @author <a href="mailto:ales.pucelj@cosylab.com">Ales Pucelj</a>
31   * @version $id$
32   */
33  public abstract class PolarTransform extends ScaleTransform
34  {
35  	protected Point2D centre;
36  	protected double R;
37  	protected double r;
38  	protected double alpha;
39  	protected double span;
40  	protected int height;
41  	protected double tickOffset;
42  
43  	/*
44  	 * @see ScaleTransform#setParameters(int, int, int, int, int)
45  	 */
46  	public void setParameters(int w, int h, int marginX, int marginY,
47  	    int tickOffset)
48  	{
49  		setPolar(true);
50  	}
51  
52  	/*
53  	 * @see ScaleTransform#mapUVtoXY(PointDouble, Point)
54  	 */
55  	public void mapUVtoXY(Point2D scaleSpace, Point2D cartesianSpace)
56  	{
57  		double phi = alpha
58  			- (tickOffset + scaleSpace.getX() * (span - 2.0 * tickOffset));
59  
60  		PolarPoint.polarToCartesian(cartesianSpace,
61  		    r + scaleSpace.getY() * height, phi);
62  
63  		cartesianSpace.setLocation(cartesianSpace.getX() + centre.getX(),
64  		    cartesianSpace.getY() + centre.getY());
65  	}
66  
67  	/*
68  	 * @see ScaleTransform#maxXYtoUV(Point, PointDouble)
69  	 */
70  	public void mapXYtoUV(Point2D cartesianSpace, Point2D scaleScape)
71  	{
72  		// not implemented
73  	}
74  
75  	/*
76  	 * @see ScaleTransform#scaleWidth(double)
77  	 */
78  	public double scaleWidth(double v)
79  	{
80  		return Math.abs(((r + v * height) * Math.PI * (span - 2 * tickOffset) / 180.0));
81  	}
82  
83  	/*
84  	 * @see ScaleTransform#scaleHeight(double)
85  	 */
86  	public double scaleHeight(double u)
87  	{
88  		return height;
89  	}
90  
91  	/**
92  	 * @see com.cosylab.gui.components.gauger.ScaleTransform#measureTick(Graphics,
93  	 *      double, String)
94  	 */
95  	public int measureTick(Graphics g, double x, String text)
96  	{
97  		return g.getFontMetrics().stringWidth(text);
98  	}
99  }
100 
101 /* __oOo__ */