gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.dynform / org.gvsig.tools.dynform.services / src / main / java / org / gvsig / tools / dynform / services / dynformfield / Double / JDynFormFieldDouble.java @ 1881
History | View | Annotate | Download (2.63 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program 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 this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.tools.dynform.services.dynformfield.Double; |
25 |
|
26 |
import javax.swing.JComboBox; |
27 |
import javax.swing.JTextField; |
28 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
29 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
30 |
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory; |
31 |
|
32 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldWithValueList; |
33 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
34 |
import org.gvsig.tools.dynobject.exception.DynFieldValidateException; |
35 |
|
36 |
public class JDynFormFieldDouble extends AbstractJDynFormFieldWithValueList { |
37 |
|
38 |
public JDynFormFieldDouble(
|
39 |
DynFormSPIManager serviceManager, |
40 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
41 |
JDynFormFieldFactory factory, |
42 |
DynFormFieldDefinition definition, |
43 |
Object value
|
44 |
) { |
45 |
super(serviceManager, componentsFactory, factory, definition, value);
|
46 |
} |
47 |
|
48 |
public Object getValue() { |
49 |
Object value = null; |
50 |
if( this.contents instanceof JTextField ) { |
51 |
String s = getJTextField().getText();
|
52 |
if( s.trim().length()==0 ) { |
53 |
value = this.getDefinition().getDefaultValue();
|
54 |
} else {
|
55 |
try {
|
56 |
value = Double.valueOf(s);
|
57 |
} catch(Exception ex) { |
58 |
throw new IllegalFieldValue(this, "Is not a valid double."); |
59 |
} |
60 |
} |
61 |
} else {
|
62 |
DynObjectValueItem x = (DynObjectValueItem) ((JComboBox)this.contents).getSelectedItem(); |
63 |
if( x==null ) { |
64 |
value = null;
|
65 |
} else {
|
66 |
value = x.getValue(); |
67 |
} |
68 |
} |
69 |
try {
|
70 |
this.getDefinition().validate(value);
|
71 |
this.problemIndicator().clear();
|
72 |
} catch (DynFieldValidateException e) {
|
73 |
throw new IllegalFieldValue(this, e.getLocalizedMessage()); |
74 |
} |
75 |
return value;
|
76 |
} |
77 |
|
78 |
} |