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/Unknow/JDynFormFieldUnknow.java
JDynFormFieldUnknow.java | ||
---|---|---|
28 | 28 |
|
29 | 29 |
import javax.swing.JTextField; |
30 | 30 |
import org.apache.commons.codec.binary.Hex; |
31 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
31 | 32 |
|
32 | 33 |
import org.gvsig.tools.dynform.JDynFormField; |
34 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
35 |
import org.gvsig.tools.dynform.spi.dynformfield.JDynFormFieldFactory; |
|
33 | 36 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
34 | 37 |
import org.gvsig.tools.dynform.spi.dynformfield.JCustomTextField; |
35 |
import org.gvsig.tools.dynobject.DynObject; |
|
36 |
import org.gvsig.tools.service.spi.ServiceManager; |
|
37 | 38 |
|
38 | 39 |
/** |
39 |
* This class is used when need to view a field that type is not supported. |
|
40 |
* It shows an string not editable with the toString representation of the |
|
41 |
* value. |
|
42 |
* |
|
40 |
* This class is used when need to view a field that type is not supported. It |
|
41 |
* shows an string not editable with the toString representation of the value. |
|
42 |
* |
|
43 | 43 |
* @author gvSIG Association |
44 | 44 |
* |
45 | 45 |
*/ |
46 |
public class JDynFormFieldUnknow extends AbstractJDynFormField implements JDynFormField, FocusListener { |
|
47 |
|
|
48 |
private Object assignedValue = null; |
|
49 |
|
|
50 |
public JDynFormFieldUnknow(DynObject parameters, |
|
51 |
ServiceManager serviceManager) { |
|
52 |
super(parameters, serviceManager); |
|
53 |
this.assignedValue = (String) this.getParameterValue(); |
|
54 |
} |
|
55 |
|
|
56 |
public Object getAssignedValue() { |
|
57 |
return this.assignedValue; |
|
58 |
} |
|
46 |
public class JDynFormFieldUnknow extends AbstractJDynFormField implements JDynFormField, FocusListener { |
|
59 | 47 |
|
60 |
private JTextField getJTextField() { |
|
61 |
return (JTextField) this.asJComponent(); |
|
62 |
} |
|
48 |
private Object assignedValue = null; |
|
63 | 49 |
|
64 |
public void initComponent() { |
|
65 |
this.contents = new JCustomTextField(this.getLabel()); |
|
66 |
this.contents.addFocusListener(this); |
|
67 |
this.getJTextField().setEditable(false);; |
|
68 |
this.setValue(this.assignedValue); |
|
69 |
} |
|
70 |
|
|
71 |
public void setValue(Object value) { |
|
72 |
String s = null; |
|
73 |
if( value == null ) { |
|
74 |
value = this.getDefinition().getDefaultValue(); |
|
75 |
if( value == null ) { |
|
76 |
s = ""; |
|
77 |
} else { |
|
78 |
s = value.toString(); |
|
79 |
} |
|
80 |
} else { |
|
81 |
if( value instanceof byte[] ) { |
|
82 |
s = Hex.encodeHexString((byte[]) value); |
|
83 |
} else { |
|
84 |
s = value.toString(); |
|
85 |
} |
|
86 |
} |
|
87 |
this.getJTextField().setText(s); |
|
88 |
this.assignedValue = value; |
|
89 |
} |
|
90 |
|
|
91 |
public Object getValue() { |
|
92 |
return this.assignedValue; |
|
93 |
} |
|
94 |
|
|
95 |
public boolean hasValidValue() { |
|
96 |
return true; |
|
97 |
} |
|
50 |
public JDynFormFieldUnknow( |
|
51 |
DynFormSPIManager serviceManager, |
|
52 |
DynFormSPIManager.ComponentsFactory componentsFactory, |
|
53 |
JDynFormFieldFactory factory, |
|
54 |
DynFormFieldDefinition definition, |
|
55 |
Object value |
|
56 |
) { |
|
57 |
super(serviceManager, componentsFactory, factory, definition, value); |
|
58 |
this.assignedValue = (String) value; |
|
59 |
} |
|
98 | 60 |
|
99 |
public void focusGained(FocusEvent arg0) {
|
|
100 |
fireFieldEnterEvent();
|
|
101 |
}
|
|
61 |
public Object getAssignedValue() {
|
|
62 |
return this.assignedValue;
|
|
63 |
}
|
|
102 | 64 |
|
103 |
public void focusLost(FocusEvent arg0) { |
|
104 |
fireFieldExitEvent(); |
|
105 |
} |
|
106 |
|
|
107 |
public void setReadOnly(boolean readonly) { |
|
108 |
super.setReadOnly(false); |
|
109 |
this.getJTextField().setEditable(false);; |
|
110 |
} |
|
111 |
|
|
112 |
public boolean isReadOnly() { |
|
113 |
return true; |
|
114 |
} |
|
65 |
private JTextField getJTextField() { |
|
66 |
return (JTextField) this.asJComponent(); |
|
67 |
} |
|
115 | 68 |
|
116 |
public boolean isModified() { |
|
117 |
return false; |
|
118 |
} |
|
69 |
public void initComponent() { |
|
70 |
this.contents = new JCustomTextField(this.getLabel()); |
|
71 |
this.contents.addFocusListener(this); |
|
72 |
this.getJTextField().setEditable(false);; |
|
73 |
this.setValue(this.assignedValue); |
|
74 |
} |
|
75 |
|
|
76 |
public void setValue(Object value) { |
|
77 |
String s = null; |
|
78 |
if (value == null) { |
|
79 |
value = this.getDefinition().getDefaultValue(); |
|
80 |
if (value == null) { |
|
81 |
s = ""; |
|
82 |
} else { |
|
83 |
s = value.toString(); |
|
84 |
} |
|
85 |
} else { |
|
86 |
if (value instanceof byte[]) { |
|
87 |
s = Hex.encodeHexString((byte[]) value); |
|
88 |
} else { |
|
89 |
s = value.toString(); |
|
90 |
} |
|
91 |
} |
|
92 |
this.getJTextField().setText(s); |
|
93 |
this.assignedValue = value; |
|
94 |
} |
|
95 |
|
|
96 |
public Object getValue() { |
|
97 |
return this.assignedValue; |
|
98 |
} |
|
99 |
|
|
100 |
public boolean hasValidValue() { |
|
101 |
return true; |
|
102 |
} |
|
103 |
|
|
104 |
public void focusGained(FocusEvent arg0) { |
|
105 |
fireFieldEnterEvent(); |
|
106 |
} |
|
107 |
|
|
108 |
public void focusLost(FocusEvent arg0) { |
|
109 |
fireFieldExitEvent(); |
|
110 |
} |
|
111 |
|
|
112 |
public void setReadOnly(boolean readonly) { |
|
113 |
super.setReadOnly(false); |
|
114 |
this.getJTextField().setEditable(false);; |
|
115 |
} |
|
116 |
|
|
117 |
public boolean isReadOnly() { |
|
118 |
return true; |
|
119 |
} |
|
120 |
|
|
121 |
public boolean isModified() { |
|
122 |
return false; |
|
123 |
} |
|
119 | 124 |
} |
Also available in: Unified diff