~sword-devel/jsword/trunk

« back to all changes in this revision

Viewing changes to jsword/java/common/org/crosswire/common/config/swing/FileField.java

  • Committer: joe
  • Date: 2002-10-08 21:36:18 UTC
  • Revision ID: svn-v4:a88caf3b-7e0a-0410-8d0d-cecb45342206:trunk:80
big config and comment update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
package org.crosswire.common.config.swing;
 
3
 
 
4
import java.awt.BorderLayout;
 
5
import java.awt.event.ActionEvent;
 
6
import java.awt.event.ActionListener;
 
7
 
 
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;
 
13
 
 
14
import org.crosswire.common.config.Choice;
 
15
 
 
16
/**
 
17
 * A Filename selection.
 
18
 * 
 
19
 * <p><table border='1' cellPadding='3' cellSpacing='0'>
 
20
 * <tr><td bgColor='white' class='TableRowColor'><font size='-7'>
 
21
 *
 
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>
 
36
 * @see docs.Licence
 
37
 * @author Joe Walker [joe at eireneh dot com]
 
38
 * @version $Id$
 
39
 */
 
40
public class FileField extends JPanel implements Field
 
41
{
 
42
    /**
 
43
     * Create a new FileField
 
44
     */
 
45
    public FileField()
 
46
    {
 
47
        setLayout(new BorderLayout(10, 0));
 
48
        add("Center", text);
 
49
        add("East", browse);
 
50
 
 
51
        browse.addActionListener(new ActionListener()
 
52
        {
 
53
            public void actionPerformed(ActionEvent ex)
 
54
            {
 
55
                JFileChooser chooser = new JFileChooser(text.getText());
 
56
                if (chooser.showOpenDialog(FileField.this) == JFileChooser.APPROVE_OPTION)
 
57
                {
 
58
                    text.setText(chooser.getSelectedFile().getPath());
 
59
                }
 
60
            }
 
61
        });
 
62
    }
 
63
 
 
64
    /**
 
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
 
69
     */
 
70
    public void setChoice(Choice param)
 
71
    {
 
72
    }
 
73
 
 
74
    /**
 
75
     * Return a string version of the current value
 
76
     * @return The current value
 
77
     */
 
78
    public String getValue()
 
79
    {
 
80
        return text.getText();
 
81
    }
 
82
 
 
83
    /**
 
84
     * Set the current value
 
85
     * @param value The new text
 
86
     */
 
87
    public void setValue(String value)
 
88
    {
 
89
        text.setText(value);
 
90
    }
 
91
 
 
92
    /**
 
93
     * Get the actual component that we can add to a Panel.
 
94
     * (This can well be this in an implementation).
 
95
     */
 
96
    public JComponent getComponent()
 
97
    {
 
98
        return this;
 
99
    }
 
100
 
 
101
    /** The text field */
 
102
    protected JTextField text = new JTextField();
 
103
 
 
104
    /** The browse button */
 
105
    private JButton browse = new JButton("Browse");
 
106
}