~sword-devel/jsword/trunk

« back to all changes in this revision

Viewing changes to jsword/java/common/org/crosswire/common/config/swing/OptionsField.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 javax.swing.DefaultComboBoxModel;
 
5
import javax.swing.JComboBox;
 
6
import javax.swing.JComponent;
 
7
 
 
8
import org.apache.log4j.Logger;
 
9
import org.crosswire.common.config.Choice;
 
10
import org.crosswire.common.config.MultipleChoice;
 
11
 
 
12
/**
 
13
 * Allow the user to choose from True/False.
 
14
 * 
 
15
 * <p><table border='1' cellPadding='3' cellSpacing='0'>
 
16
 * <tr><td bgColor='white' class='TableRowColor'><font size='-7'>
 
17
 *
 
18
 * Distribution Licence:<br />
 
19
 * JSword is free software; you can redistribute it
 
20
 * and/or modify it under the terms of the GNU General Public License,
 
21
 * version 2 as published by the Free Software Foundation.<br />
 
22
 * This program is distributed in the hope that it will be useful,
 
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
25
 * General Public License for more details.<br />
 
26
 * The License is available on the internet
 
27
 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, or by writing to:
 
28
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 
29
 * MA 02111-1307, USA<br />
 
30
 * The copyright to this program is held by it's authors.
 
31
 * </font></td></tr></table>
 
32
 * @see docs.Licence
 
33
 * @author Joe Walker [joe at eireneh dot com]
 
34
 * @version $Id$
 
35
 */
 
36
public class OptionsField extends JComboBox implements Field
 
37
{
 
38
    /**
 
39
     * Give the values list (true/false) to the ComboBox
 
40
     */
 
41
    public OptionsField()
 
42
    {
 
43
        super(new String[] { "No Options Set" } );
 
44
    }
 
45
 
 
46
    /**
 
47
     * Some fields will need some extra info to display properly
 
48
     * like the options in an options field. FieldMap calls this
 
49
     * method with options provided by the choice.
 
50
     * @param param The options provided by the Choice
 
51
     */
 
52
    public void setChoice(Choice param)
 
53
    {
 
54
        if (param instanceof MultipleChoice)
 
55
        {
 
56
            MultipleChoice mc = (MultipleChoice) param;
 
57
            list = mc.getOptions();
 
58
        }
 
59
        else
 
60
        {
 
61
            log.warn("Unknown Choice type: "+param.getClass().getName());
 
62
            list = new String[] { "ERROR" };
 
63
        }
 
64
 
 
65
        setModel(new DefaultComboBoxModel(list));
 
66
    }
 
67
 
 
68
    /**
 
69
     * Return a string for use in the properties file
 
70
     * @return The current value
 
71
     */
 
72
    public String getValue()
 
73
    {
 
74
        return (String) getSelectedItem();
 
75
    }
 
76
 
 
77
    /**
 
78
     * Set the current value
 
79
     * @param value The new text
 
80
     */
 
81
    public void setValue(String value)
 
82
    {
 
83
        for (int i=0; i<list.length; i++)
 
84
        {
 
85
            if (value.equals(list[i]))
 
86
            {
 
87
                setSelectedItem(list[i]);
 
88
                return;
 
89
            }
 
90
        }
 
91
 
 
92
        log.warn("Illegal option setting: '"+value+"'. Using default");
 
93
        setSelectedItem(list[0]);
 
94
    }
 
95
 
 
96
    /**
 
97
     * Get the actual component that we can add to a Panel.
 
98
     * (This can well be this in an implementation).
 
99
     */
 
100
    public JComponent getComponent()
 
101
    {
 
102
        return this;
 
103
    }
 
104
 
 
105
    /**
 
106
     * Return the Choice that created us.
 
107
     * @return Our source Choice
 
108
     */
 
109
    public Choice getChoice()
 
110
    {
 
111
        return Field;
 
112
    }
 
113
 
 
114
    /** Our source Field */
 
115
    private Choice Field = null;
 
116
 
 
117
    /** The options */
 
118
    private String[] list = null;
 
119
 
 
120
    /** The log stream */
 
121
    protected static Logger log = Logger.getLogger(OptionsField.class);
 
122
}