gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / dynform / src / org / gvsig / tools / dynform / impl / dynformfield / file / JDynFormFieldFile.java @ 841
History | View | Annotate | Download (1.89 KB)
1 |
package org.gvsig.tools.dynform.impl.dynformfield.file; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.event.ActionEvent; |
5 |
import java.awt.event.ActionListener; |
6 |
import java.io.File; |
7 |
|
8 |
import javax.swing.JButton; |
9 |
import javax.swing.JPanel; |
10 |
import javax.swing.JTextField; |
11 |
|
12 |
import org.gvsig.tools.dynform.api.JDynFormField; |
13 |
import org.gvsig.tools.dynform.impl.dynformfield.AbstractJDynFormField; |
14 |
import org.gvsig.tools.dynobject.DynObject; |
15 |
import org.gvsig.tools.service.spi.ServiceManager; |
16 |
|
17 |
public class JDynFormFieldFile extends AbstractJDynFormField implements JDynFormField { |
18 |
|
19 |
private File value = null; |
20 |
private JTextField jtext = null; |
21 |
private JButton jbutton = null; |
22 |
|
23 |
public JDynFormFieldFile(DynObject parameters,
|
24 |
ServiceManager serviceManager) { |
25 |
super(parameters, serviceManager);
|
26 |
this.value = (File) this.getParameterValue(); |
27 |
} |
28 |
|
29 |
public void initComponent() { |
30 |
this.contents = new JPanel(); |
31 |
this.contents.setLayout(new BorderLayout()); |
32 |
|
33 |
this.jtext = new JTextField(); |
34 |
this.jtext.setEditable(false); |
35 |
this.jbutton = new JButton("Browse..."); |
36 |
this.jbutton.addActionListener(new ActionListener() { |
37 |
public void actionPerformed(ActionEvent e) { |
38 |
onClickBrowse(); |
39 |
} |
40 |
}); |
41 |
|
42 |
this.contents.add(jtext,BorderLayout.CENTER); |
43 |
this.contents.add(jbutton,BorderLayout.LINE_END); |
44 |
this.contents.setVisible(true); |
45 |
this.setValue(this.value); |
46 |
} |
47 |
|
48 |
public void onClickBrowse() { |
49 |
// TODO: implements onClickBrowse in JDynFormFieldFile
|
50 |
// this.value = value entered by the user
|
51 |
} |
52 |
|
53 |
public void setValue(Object value) { |
54 |
if( value == null ) { |
55 |
this.jtext.setText(""); |
56 |
return;
|
57 |
} |
58 |
if( !(value instanceof File) ) { |
59 |
logger.info("setValue invoked with non File value ("+value.toString()+")."); |
60 |
return;
|
61 |
} |
62 |
this.value = (File) value; |
63 |
this.jtext.setText(this.value.getPath()); |
64 |
} |
65 |
|
66 |
public Object getValue() { |
67 |
return this.value; |
68 |
} |
69 |
|
70 |
public boolean hasValidValue() { |
71 |
return true; |
72 |
} |
73 |
} |