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 / Unknow / JDynFormFieldUnknow.java @ 931
History | View | Annotate | Download (2.07 KB)
1 |
package org.gvsig.tools.dynform.services.dynformfield.Unknow; |
---|---|
2 |
|
3 |
import java.awt.event.FocusEvent; |
4 |
import java.awt.event.FocusListener; |
5 |
|
6 |
import javax.swing.JTextField; |
7 |
|
8 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
9 |
import org.gvsig.tools.dynform.spi.dynformfield.JCustomTextField; |
10 |
import org.gvsig.tools.dynforms.JDynFormField; |
11 |
import org.gvsig.tools.dynobject.DynObject; |
12 |
import org.gvsig.tools.service.spi.ServiceManager; |
13 |
|
14 |
/**
|
15 |
* This class is used when need to view a field that type is not supported.
|
16 |
* It shows an string not editable with the toString representation of the
|
17 |
* value.
|
18 |
*
|
19 |
* @author gvSIG Association
|
20 |
*
|
21 |
*/
|
22 |
public class JDynFormFieldUnknow extends AbstractJDynFormField implements JDynFormField, FocusListener { |
23 |
|
24 |
private Object assignedValue = null; |
25 |
|
26 |
public JDynFormFieldUnknow(DynObject parameters,
|
27 |
ServiceManager serviceManager) { |
28 |
super(parameters, serviceManager);
|
29 |
this.assignedValue = (String) this.getParameterValue(); |
30 |
} |
31 |
|
32 |
public Object getAssignedValue() { |
33 |
return this.assignedValue; |
34 |
} |
35 |
|
36 |
private JTextField getJTextField() { |
37 |
return (JTextField) this.asJComponent(); |
38 |
} |
39 |
|
40 |
public void initComponent() { |
41 |
this.contents = new JCustomTextField(); |
42 |
this.contents.addFocusListener(this); |
43 |
this.getJTextField().setEditable(false);; |
44 |
this.setValue(this.assignedValue); |
45 |
} |
46 |
|
47 |
public void setValue(Object value) { |
48 |
String s = null; |
49 |
if( value == null ) { |
50 |
value = this.getDefinition().getDefaultValue();
|
51 |
if( value == null ) { |
52 |
s = "";
|
53 |
} else {
|
54 |
s = value.toString(); |
55 |
} |
56 |
} else {
|
57 |
s = value.toString(); |
58 |
} |
59 |
this.getJTextField().setText(s);
|
60 |
this.assignedValue = value;
|
61 |
} |
62 |
|
63 |
public Object getValue() { |
64 |
return this.assignedValue; |
65 |
} |
66 |
|
67 |
public boolean hasValidValue() { |
68 |
return true; |
69 |
} |
70 |
|
71 |
public void focusGained(FocusEvent arg0) { |
72 |
fireFieldEnterEvent(); |
73 |
} |
74 |
|
75 |
public void focusLost(FocusEvent arg0) { |
76 |
fireFieldExitEvent(); |
77 |
} |
78 |
|
79 |
public void setReadOnly(boolean readonly) { |
80 |
this.getJTextField().setEditable(false);; |
81 |
} |
82 |
|
83 |
public boolean isReadOnly() { |
84 |
return true; |
85 |
} |
86 |
|
87 |
public boolean isModified() { |
88 |
return false; |
89 |
} |
90 |
} |