svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.library / org.gvsig.raster / org.gvsig.raster.swing / org.gvsig.raster.swing.buffer / org.gvsig.raster.swing.buffer.impl / src / main / java / org / gvsig / raster / swing / buffer / impl / operations / dynformfield / JDynFormFieldBands.java @ 43835
History | View | Annotate | Download (2.74 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.raster.swing.buffer.impl.operations.dynformfield; |
25 |
|
26 |
import java.util.ArrayList; |
27 |
import java.util.List; |
28 |
import java.util.StringTokenizer; |
29 |
|
30 |
import org.apache.commons.lang3.StringUtils; |
31 |
|
32 |
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormFieldWithValueList; |
33 |
import org.gvsig.tools.dynobject.DynObject; |
34 |
import org.gvsig.tools.service.spi.ServiceManager; |
35 |
|
36 |
/**
|
37 |
* @author fdiaz
|
38 |
*
|
39 |
*/
|
40 |
public class JDynFormFieldBands extends AbstractJDynFormFieldWithValueList { |
41 |
|
42 |
|
43 |
/**
|
44 |
* @param parameters
|
45 |
* @param serviceManager
|
46 |
*/
|
47 |
public JDynFormFieldBands(DynObject parameters,
|
48 |
ServiceManager serviceManager) { |
49 |
super(parameters, serviceManager);
|
50 |
} |
51 |
|
52 |
@Override
|
53 |
protected String getDefaultValue(){ |
54 |
return ""; |
55 |
} |
56 |
|
57 |
@Override
|
58 |
public Object getValue() { |
59 |
List<Integer> value = new ArrayList<>(); |
60 |
//coger lo de la caja de texto, parsearla y devolver la lista de enteros (si no puede throws exception)
|
61 |
String txt = getJTextField().getText();
|
62 |
StringTokenizer st = new StringTokenizer(txt, ","); |
63 |
|
64 |
while (st.hasMoreTokens()){
|
65 |
String token = st.nextToken();
|
66 |
try {
|
67 |
value.add(new Integer(token)); |
68 |
} catch (NumberFormatException e) { |
69 |
throw new IllegalFieldValue(this,"Can't convert value '"+txt+"' to integer list."); |
70 |
} |
71 |
} |
72 |
return value;
|
73 |
} |
74 |
|
75 |
@SuppressWarnings("unchecked") |
76 |
@Override
|
77 |
public void setValue(Object value) { |
78 |
if(value == null){ |
79 |
getJTextField().setText("");
|
80 |
} |
81 |
if(value instanceof List<?>){ |
82 |
List<Integer> lista = (List<Integer>)value; |
83 |
getJTextField().setText(StringUtils.join(lista, ","));
|
84 |
} |
85 |
} |
86 |
|
87 |
@Override
|
88 |
public boolean hasValidValue() { |
89 |
try {
|
90 |
getValue(); |
91 |
} catch (IllegalFieldValue ex) {
|
92 |
return false; |
93 |
} |
94 |
return true; |
95 |
} |
96 |
|
97 |
} |