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 / URI / JDynFormFieldURI.java @ 1425
History | View | Annotate | Download (2.88 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.URI; |
25 |
|
26 |
import java.io.File; |
27 |
import java.net.URI; |
28 |
import java.net.URISyntaxException; |
29 |
|
30 |
import javax.swing.JFileChooser; |
31 |
|
32 |
import org.gvsig.tools.dynform.services.dynformfield.File.JDynFormFieldFile; |
33 |
import org.gvsig.tools.dynobject.DynObject; |
34 |
import org.gvsig.tools.service.spi.ServiceManager; |
35 |
|
36 |
public class JDynFormFieldURI extends JDynFormFieldFile { |
37 |
|
38 |
protected URI assignedValue = null; |
39 |
protected URI currentValue = null; |
40 |
|
41 |
public JDynFormFieldURI(DynObject parameters,
|
42 |
ServiceManager serviceManager) { |
43 |
super(parameters, serviceManager);
|
44 |
this.assignedValue = (URI) this.getParameterValue(); |
45 |
} |
46 |
|
47 |
public Object getValue() { |
48 |
URI value = null; |
49 |
String s = ""; |
50 |
s = this.jtext.getText();
|
51 |
if( s.trim().length()==0 ) { |
52 |
Object x = this.getDefinition().getDefaultValue(); |
53 |
if( x == null ) { |
54 |
value = null;
|
55 |
} else {
|
56 |
try {
|
57 |
value = new URI(x.toString()); |
58 |
} catch (URISyntaxException e) { |
59 |
logger.info("Error. URI Syntax: "+x.toString());
|
60 |
value = null;
|
61 |
} |
62 |
} |
63 |
} else {
|
64 |
try {
|
65 |
value = new URI(s); |
66 |
} catch (URISyntaxException e) { |
67 |
logger.info("Error. URI Syntax: "+s);
|
68 |
value = null;
|
69 |
} |
70 |
} |
71 |
return value;
|
72 |
} |
73 |
|
74 |
public void setValue(Object value) { |
75 |
if( value == null ) { |
76 |
this.jtext.setText(""); |
77 |
this.assignedValue = null; |
78 |
} else {
|
79 |
if( !(value instanceof URI) ) { |
80 |
logger.info("setValue invoked with non URI value ("+value.toString()+")."); |
81 |
return;
|
82 |
} |
83 |
this.jtext.setText(((URI)value).toString()); |
84 |
try {
|
85 |
this.assignedValue = new URI(((URI)value).toString()); |
86 |
} catch (URISyntaxException e) { |
87 |
logger.info("Error in URI creation.");
|
88 |
this.assignedValue = null; |
89 |
} |
90 |
} |
91 |
|
92 |
this.currentValue = this.assignedValue; |
93 |
|
94 |
} |
95 |
|
96 |
public File[] showOpenFileDialog(String title, File initialPath) { |
97 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_AND_DIRECTORIES, false, initialPath, null, false); |
98 |
} |
99 |
|
100 |
} |