2
package org.crosswire.common.config.swing;
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.Choice;
17
* A Filename selection.
19
* <p><table border='1' cellPadding='3' cellSpacing='0'>
20
* <tr><td bgColor='white' class='TableRowColor'><font size='-7'>
22
* Distribution Licence:<br />
23
* JSword is free software; you can redistribute it
24
* and/or modify it under the terms of the GNU General Public License,
25
* version 2 as published by the Free Software Foundation.<br />
26
* This program is distributed in the hope that it will be useful,
27
* but WITHOUT ANY WARRANTY; without even the implied warranty of
28
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29
* General Public License for more details.<br />
30
* The License is available on the internet
31
* <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, or by writing to:
32
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
33
* MA 02111-1307, USA<br />
34
* The copyright to this program is held by it's authors.
35
* </font></td></tr></table>
37
* @author Joe Walker [joe at eireneh dot com]
40
public class FileField extends JPanel implements Field
43
* Create a new FileField
47
setLayout(new BorderLayout(10, 0));
51
browse.addActionListener(new ActionListener()
53
public void actionPerformed(ActionEvent ex)
55
JFileChooser chooser = new JFileChooser(text.getText());
56
if (chooser.showOpenDialog(FileField.this) == JFileChooser.APPROVE_OPTION)
58
text.setText(chooser.getSelectedFile().getPath());
65
* Some fields will need some extra info to display properly
66
* like the options in an options field. FieldMap calls this
67
* method with options provided by the choice.
68
* @param param The options provided by the Choice
70
public void setChoice(Choice param)
75
* Return a string version of the current value
76
* @return The current value
78
public String getValue()
80
return text.getText();
84
* Set the current value
85
* @param value The new text
87
public void setValue(String value)
93
* Get the actual component that we can add to a Panel.
94
* (This can well be this in an implementation).
96
public JComponent getComponent()
101
/** The text field */
102
protected JTextField text = new JTextField();
104
/** The browse button */
105
private JButton browse = new JButton("Browse");