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   * <p>
24   * Implementation of this interface provides conversion of a
25   * <code>Number</code> to <code>String</code> and back. This interface acts as
26   * kind of interpretation of a <code>Number</code> with bijective
27   * transformation to string.
28   * </p>
29   * 
30   * <p>
31   * This interfaces provides more flexible visualization of number as string
32   * than is available with standard ANSI C kind of formatting. For example:
33   * display and edit double value in hh:mm:ss format (interpret it as degrees).
34   * </p>
35   * 
36   * <p>
37   * It is advised for the descriptor implementation to define two final static String fields: <code>NAME</code> and <code>DESCRIPTION</code>. First should be short descriptive name and second should be short description. These strings are used in GUI choosers for NumberField visualization. 
38  
39   * </p>
40   *
41   * @author <a href="mailto:igor.kriznar@cosylab.com">Igor Kriznar</a>
42   */
43  public interface NumberDescriptor
44  {
45  	/**
46  	 * Parses string and creates <code>Number</code>. If string is not
47  	 * presentation of a number and can not be parsed, then null must be
48  	 * returned.
49  	 *
50  	 * @param number a string representing a number
51  	 *
52  	 * @return instance of <code>Number</code> or <code>null</code> if string
53  	 *         can not be parsed
54  	 */
55  	public Number parseNumber(String number);
56  
57  	/**
58  	 * Converts provided <code>Number</code> to a string, which is used for
59  	 * displaying the value.
60  	 *
61  	 * @param number a number to be transformed to string
62  	 *
63  	 * @return a <code>String</code> representing a number.
64  	 */
65  	public String printString(Number number);
66  
67  	/**
68  	 * Converts provided <code>Number</code> to a string, which is displayed
69  	 * when NumberField enters in to edit mode and wants to edit value. Edit
70  	 * string is usually stripped from unnecessary characters and prepared for
71  	 * easyer user editing.
72  	 *
73  	 * @param number a number to be transformed to string
74  	 *
75  	 * @return a <code>String</code> representation a number prepared for
76  	 *         editing.
77  	 */
78  	public String printEditString(Number number);
79  
80  	/**
81  	 * Returns the format
82  	 *
83  	 * @return Format
84  	 */
85  	public String getFormat();
86  
87  	/**
88  	 * Set the Number format
89  	 *
90  	 * @param format
91  	 */
92  	public void setFormat(String format);
93  
94  	/**
95  	 * Sets number type to descriptor, ame as used on number field.
96  	 *
97  	 * @param newClass number type
98  	 */
99  	public void setNumberType(Class newClass);
100 
101 	/**
102 	 * Returns last set number type.
103 	 *
104 	 * @return last set number type
105 	 */
106 	public Class getNumberType();
107 
108 }
109 
110 /* __oOo__ */