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.numberfield;
21  
22  /**
23   * Visualize double value in radians by converting it to hours and displays it
24   * in format XX:XX:XX.
25   *
26   * @author <a href="mailto:igor.kriznar@cosylab.com">Igor Kriznar</a>
27   */
28  public class Rad2HMSNumberDescriptor extends HMSNumberDescriptor
29  {
30  	/**
31  	 * Converts angle in radians to angle in hours. 24 hours is 2PI radians.
32  	 *
33  	 * @param rad angle in radians
34  	 *
35  	 * @return angle in hours
36  	 */
37  	public final static double toHours(double rad)
38  	{
39  		return rad * 12.0 / Math.PI;
40  	}
41  
42  	/**
43  	 * Converts angle in hours to angle in radians. 24 hours is 2PI radians.
44  	 *
45  	 * @param hour angle in hours
46  	 *
47  	 * @return angle in radians
48  	 */
49  	public static double toRadians(double hour)
50  	{
51  		return hour / 12.0 * Math.PI;
52  	}
53  
54  	/**
55  	 * @see NumberDescriptor
56  	 */
57  	public final static String NAME = "Radians as hours Visualization";
58  
59  	/**
60  	 * @see NumberDescriptor
61  	 */
62  	public final static String DESCRIPTION = "Converts double value from radians to hours and diplays in degree format: XX:XX:XX.";
63  
64  	/**
65  	 * Constructs a new Rad2HMSNNumberDescritptor.
66  	 *
67  	 */
68  	public Rad2HMSNumberDescriptor()
69  	{
70  		super();
71  	}
72  
73  	/* (non-Javadoc)
74  	 * @see com.cosylab.gui.components.numberfield.AngleNumberDescriptor#printString(java.lang.Number)
75  	 */
76  	public String printString(Number number)
77  	{
78  		return super.printString(new Double(toHours(number.doubleValue())));
79  	}
80  
81  	/* (non-Javadoc)
82  	 * @see com.cosylab.gui.components.numberfield.AngleNumberDescriptor#parseNumber(java.lang.String)
83  	 */
84  	public Number parseNumber(String number)
85  	{
86  		Number n = super.parseNumber(number);
87  
88  		if (n == null) {
89  			return n;
90  		}
91  
92  		return new Double(toRadians(n.doubleValue()));
93  	}
94  }
95  
96  /* __oOo__ */