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