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 @ 1405
History | View | Annotate | Download (3.38 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.Text; |
25 |
|
26 |
import javax.swing.JScrollPane; |
27 |
import javax.swing.JViewport; |
28 |
|
29 |
import org.gvsig.tools.dynform.JDynFormField; |
30 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
31 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField; |
32 |
import org.gvsig.tools.dynform.spi.dynformfield.JCustomTextArea; |
33 |
import org.gvsig.tools.dynobject.DynObject; |
34 |
import org.gvsig.tools.service.spi.ServiceManager; |
35 |
|
36 |
public class JDynFormFieldText extends AbstractJDynFormField implements JDynFormField { |
37 |
|
38 |
private final int CHAR_ROW_LIMIT = 3; |
39 |
private String assignedValue = null; |
40 |
|
41 |
public JDynFormFieldText(DynObject parameters,
|
42 |
ServiceManager serviceManager) { |
43 |
super(parameters, serviceManager);
|
44 |
if(this.getParameterValue()!=null) |
45 |
this.assignedValue = this.getParameterValue().toString(); |
46 |
} |
47 |
|
48 |
public Object getAssignedValue() { |
49 |
return this.assignedValue; |
50 |
} |
51 |
|
52 |
private JCustomTextArea getJTextArea() {
|
53 |
JViewport port = ((JScrollPane)this.contents).getViewport(); |
54 |
return (JCustomTextArea) port.getView();
|
55 |
} |
56 |
|
57 |
public void initComponent() { |
58 |
this.contents = new JScrollPane(new JCustomTextArea(this.getLabel())); |
59 |
this.getJTextArea().setLineWrap(true); |
60 |
this.getJTextArea().setWrapStyleWord(true); |
61 |
|
62 |
this.getJTextArea().setRows(getTagValueAsInt(DynFormSPIManager.TAG_DYNFORM_ROWS,CHAR_ROW_LIMIT));
|
63 |
if(this.getDefinition().isReadOnly()) { |
64 |
this.getJTextArea().setEditable(false); |
65 |
} |
66 |
this.setValue(this.assignedValue); |
67 |
} |
68 |
|
69 |
// public void setReadOnly(boolean readonly) {
|
70 |
// this.getJTextArea().setEditable(!readonly);
|
71 |
// }
|
72 |
//
|
73 |
public void setValue(Object value) { |
74 |
String s = null; |
75 |
if( value == null ) { |
76 |
value = this.getDefinition().getDefaultValue();
|
77 |
if( value == null ) { |
78 |
s = "";
|
79 |
} else {
|
80 |
s = value.toString(); |
81 |
} |
82 |
} else {
|
83 |
s = value.toString(); |
84 |
} |
85 |
this.getJTextArea().setText(s);
|
86 |
} |
87 |
|
88 |
public Object getValue() { |
89 |
Object value = null; |
90 |
String s = this.getJTextArea().getText(); |
91 |
if( s.trim().length()==0 ) { |
92 |
value = (String) this.getDefinition().getDefaultValue(); |
93 |
} else {
|
94 |
value = s; |
95 |
} |
96 |
this.setValue(value);
|
97 |
return value;
|
98 |
} |
99 |
|
100 |
public boolean hasValidValue() { |
101 |
return true; |
102 |
} |
103 |
|
104 |
public void clear() { |
105 |
Object value = this.getDefinition().getDefaultValue(); |
106 |
if (value != null) { |
107 |
value = value.toString(); |
108 |
} else {
|
109 |
value = "";
|
110 |
} |
111 |
this.getJTextArea().setText((String) value); |
112 |
} |
113 |
} |