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 / Text / JDynFormFieldText.java @ 931
History | View | Annotate | Download (2.07 KB)
1 |
package org.gvsig.tools.dynform.services.dynformfield.Text; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
|
5 |
import javax.swing.JScrollPane; |
6 |
import javax.swing.JTextArea; |
7 |
import javax.swing.JViewport; |
8 |
|
9 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
10 |
import org.gvsig.tools.dynform.spi.dynformfield.JCustomTextArea; |
11 |
import org.gvsig.tools.dynforms.JDynFormField; |
12 |
import org.gvsig.tools.dynobject.DynObject; |
13 |
import org.gvsig.tools.service.spi.ServiceManager; |
14 |
|
15 |
public class JDynFormFieldText extends AbstractJDynFormField implements JDynFormField { |
16 |
|
17 |
private final int CHAT_ROW_LIMIT = 3; |
18 |
private String assignedValue = null; |
19 |
|
20 |
public JDynFormFieldText(DynObject parameters,
|
21 |
ServiceManager serviceManager) { |
22 |
super(parameters, serviceManager);
|
23 |
if(this.getParameterValue()!=null) |
24 |
this.assignedValue = this.getParameterValue().toString(); |
25 |
} |
26 |
|
27 |
public Object getAssignedValue() { |
28 |
return this.assignedValue; |
29 |
} |
30 |
|
31 |
private JTextArea getJTextArea() { |
32 |
JViewport port = ((JScrollPane)this.contents).getViewport(); |
33 |
return (JTextArea) port.getView(); |
34 |
} |
35 |
|
36 |
public void initComponent() { |
37 |
this.contents = new JScrollPane(new JCustomTextArea()); |
38 |
this.getJTextArea().setLineWrap(true); |
39 |
this.getJTextArea().setWrapStyleWord(true); |
40 |
this.getJTextArea().setRows(CHAT_ROW_LIMIT);
|
41 |
if(this.getDefinition().isReadOnly()) { |
42 |
this.getJTextArea().setEditable(false); |
43 |
this.getJTextArea().setBackground(Color.white); |
44 |
//this.getJTextArea().setEnabled(false);
|
45 |
} |
46 |
this.setValue(this.assignedValue); |
47 |
} |
48 |
|
49 |
public void setValue(Object value) { |
50 |
String s = null; |
51 |
if( value == null ) { |
52 |
value = this.getDefinition().getDefaultValue();
|
53 |
if( value == null ) { |
54 |
s = "";
|
55 |
} else {
|
56 |
s = value.toString(); |
57 |
} |
58 |
} else {
|
59 |
s = value.toString(); |
60 |
} |
61 |
this.getJTextArea().setText(s);
|
62 |
} |
63 |
|
64 |
public Object getValue() { |
65 |
Object value = null; |
66 |
String s = this.getJTextArea().getText(); |
67 |
if( s.trim().length()==0 ) { |
68 |
value = (String) this.getDefinition().getDefaultValue(); |
69 |
} else {
|
70 |
value = s; |
71 |
} |
72 |
this.setValue(value);
|
73 |
return value;
|
74 |
} |
75 |
|
76 |
public boolean hasValidValue() { |
77 |
return true; |
78 |
} |
79 |
|
80 |
} |