Revision 1881 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/Float/JDynFormFieldFloat.java
JDynFormFieldFloat.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import javax.swing.JComboBox; |
27 | 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; |
|
28 | 31 |
|
29 | 32 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldWithValueList; |
30 |
import org.gvsig.tools.dynobject.DynObject; |
|
31 | 33 |
import org.gvsig.tools.dynobject.DynObjectValueItem; |
32 | 34 |
import org.gvsig.tools.dynobject.exception.DynFieldValidateException; |
33 |
import org.gvsig.tools.service.spi.ServiceManager; |
|
34 | 35 |
|
35 | 36 |
public class JDynFormFieldFloat extends AbstractJDynFormFieldWithValueList { |
36 |
|
|
37 |
public JDynFormFieldFloat(DynObject parameters, |
|
38 |
ServiceManager serviceManager) { |
|
39 |
super(parameters, serviceManager); |
|
40 |
} |
|
41 | 37 |
|
42 |
public Object getValue() { |
|
43 |
Object value = null; |
|
44 |
if( this.contents instanceof JTextField ) { |
|
45 |
String s = getJTextField().getText(); |
|
46 |
if( s.trim().length()==0 ) { |
|
47 |
value = this.getDefinition().getDefaultValue(); |
|
48 |
} else { |
|
49 |
try { |
|
50 |
value = Float.valueOf(s); |
|
51 |
} catch(Exception ex) { |
|
52 |
throw new IllegalFieldValue(this, "Is not a valid float."); |
|
53 |
} |
|
54 |
} |
|
55 |
} else { |
|
56 |
DynObjectValueItem x = (DynObjectValueItem) ((JComboBox)this.contents).getSelectedItem(); |
|
57 |
if( x==null ) { |
|
58 |
value = null; |
|
59 |
} else { |
|
60 |
value = x.getValue(); |
|
61 |
} |
|
62 |
} |
|
63 |
try { |
|
64 |
this.getDefinition().validate(value); |
|
65 |
this.problemIndicator().clear(); |
|
66 |
} catch (DynFieldValidateException e) { |
|
67 |
throw new IllegalFieldValue(this, e.getLocalizedMessage()); |
|
68 |
} |
|
69 |
return value; |
|
70 |
} |
|
38 |
public JDynFormFieldFloat( |
|
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 |
} |
|
71 | 47 |
|
72 |
public String getJTextFieldRegex(){ |
|
73 |
return "[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$"; |
|
74 |
} |
|
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 = Float.valueOf(s); |
|
57 |
} catch (Exception ex) { |
|
58 |
throw new IllegalFieldValue(this, "Is not a valid float."); |
|
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 |
} |
|
75 | 77 |
|
78 |
public String getJTextFieldRegex() { |
|
79 |
return "[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?$"; |
|
80 |
} |
|
81 |
|
|
76 | 82 |
} |
Also available in: Unified diff