~sword-devel/jsword/trunk

« back to all changes in this revision

Viewing changes to jsword/java/common/org/crosswire/common/config/swing/fields/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.fields;
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.swing.Field;
15
 
 
16
 
/**
17
 
* A Filename selection.
18
 
*
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}>
37
 
* @author Joe Walker
38
 
*/
39
 
public class FileField extends JPanel implements Field
40
 
{
41
 
    /**
42
 
    * Create a new FileField
43
 
    */
44
 
    public FileField()
45
 
    {
46
 
        setLayout(new BorderLayout(10, 0));
47
 
        add("Center", text);
48
 
        add("East", browse);
49
 
 
50
 
        browse.addActionListener(new ActionListener()
51
 
        {
52
 
            public void actionPerformed(ActionEvent ex)
53
 
            {
54
 
                JFileChooser chooser = new JFileChooser(text.getText());
55
 
                if (chooser.showOpenDialog(FileField.this) == JFileChooser.APPROVE_OPTION)
56
 
                {
57
 
                    text.setText(chooser.getSelectedFile().getPath());
58
 
                }
59
 
            }
60
 
        });
61
 
    }
62
 
 
63
 
    /**
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
68
 
    */
69
 
    public void setOptions(Object param)
70
 
    {
71
 
    }
72
 
 
73
 
    /**
74
 
    * Return a string version of the current value
75
 
    * @return The current value
76
 
    */
77
 
    public String getValue()
78
 
    {
79
 
        return text.getText();
80
 
    }
81
 
 
82
 
    /**
83
 
    * Set the current value
84
 
    * @param value The new text
85
 
    */
86
 
    public void setValue(String value)
87
 
    {
88
 
        text.setText(value);
89
 
    }
90
 
 
91
 
    /**
92
 
    * Get the actual component that we can add to a Panel.
93
 
    * (This can well be this in an implementation).
94
 
    */
95
 
    public JComponent getComponent()
96
 
    {
97
 
        return this;
98
 
    }
99
 
 
100
 
    /** The text field */
101
 
    protected JTextField text = new JTextField();
102
 
 
103
 
    /** The browse button */
104
 
    private JButton browse = new JButton("Browse");
105
 
}
106