2
package org.crosswire.common.config.swing.fields;
4
import java.awt.BorderLayout;
5
import java.awt.event.ActionEvent;
6
import java.awt.event.ActionListener;
8
import javax.swing.JButton;
9
import javax.swing.JComponent;
10
import javax.swing.JFileChooser;
11
import javax.swing.JPanel;
12
import javax.swing.JTextField;
14
import org.crosswire.common.config.swing.Field;
17
* A Filename selection.
19
* <table border='1' cellPadding='3' cellSpacing='0' width="100%">
20
* <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
21
* Distribution Licence:<br />
22
* Project B is free software; you can redistribute it
23
* and/or modify it under the terms of the GNU General Public License,
24
* version 2 as published by the Free Software Foundation.<br />
25
* This program is distributed in the hope that it will be useful,
26
* but WITHOUT ANY WARRANTY; without even the implied warranty of
27
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28
* General Public License for more details.<br />
29
* The License is available on the internet
30
* <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
31
* <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
32
* MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
33
* The copyright to this program is held by it's authors.
34
* </font></td></tr></table>
35
* @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
36
* @see <{docs.Licence}>
39
public class FileField extends JPanel implements Field
42
* Create a new FileField
46
setLayout(new BorderLayout(10, 0));
50
browse.addActionListener(new ActionListener()
52
public void actionPerformed(ActionEvent ex)
54
JFileChooser chooser = new JFileChooser(text.getText());
55
if (chooser.showOpenDialog(FileField.this) == JFileChooser.APPROVE_OPTION)
57
text.setText(chooser.getSelectedFile().getPath());
64
* Some fields will need some extra info to display properly
65
* like the options in an options field. FieldMap calls this
66
* method with options provided by the choice.
67
* @param param The options provided by the Choice
69
public void setOptions(Object param)
74
* Return a string version of the current value
75
* @return The current value
77
public String getValue()
79
return text.getText();
83
* Set the current value
84
* @param value The new text
86
public void setValue(String value)
92
* Get the actual component that we can add to a Panel.
93
* (This can well be this in an implementation).
95
public JComponent getComponent()
100
/** The text field */
101
protected JTextField text = new JTextField();
103
/** The browse button */
104
private JButton browse = new JButton("Browse");