~sword-devel/jsword/trunk

« back to all changes in this revision

Viewing changes to jsword/java/common/org/crosswire/common/config/swing/fields/StyleField.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.FlowLayout;
5
 
 
6
 
import javax.swing.JComponent;
7
 
import javax.swing.JLabel;
8
 
import javax.swing.JPanel;
9
 
import javax.swing.JTextField;
10
 
 
11
 
import org.crosswire.common.config.swing.Field;
12
 
 
13
 
/**
14
 
* A PropertyNumberField is a PropertyTextField that only
15
 
* stores numbers.
16
 
*
17
 
* <table border='1' cellPadding='3' cellSpacing='0' width="100%">
18
 
* <tr><td bgColor='white'class='TableRowColor'><font size='-7'>
19
 
* Distribution Licence:<br />
20
 
* Project B is free software; you can redistribute it
21
 
* and/or modify it under the terms of the GNU General Public License,
22
 
* version 2 as published by the Free Software Foundation.<br />
23
 
* This program is distributed in the hope that it will be useful,
24
 
* but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26
 
* General Public License for more details.<br />
27
 
* The License is available on the internet
28
 
* <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, by writing to
29
 
* <i>Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30
 
* MA 02111-1307, USA</i>, Or locally at the Licence link below.<br />
31
 
* The copyright to this program is held by it's authors.
32
 
* </font></td></tr></table>
33
 
* @see <a href='http://www.eireneh.com/servlets/Web'>Project B Home</a>
34
 
* @see <{docs.Licence}>
35
 
* @author Joe Walker
36
 
*/
37
 
public class StyleField extends JPanel implements Field
38
 
{
39
 
    /**
40
 
    * Create a new FileField
41
 
    */
42
 
    public StyleField()
43
 
    {
44
 
        font = new FontButtonField();
45
 
        font.setOptions("Font");
46
 
        foreground = new ColorField();
47
 
        foreground.setOptions("Fore");
48
 
        background = new ColorField();
49
 
        background.setOptions("Back");
50
 
 
51
 
        match.setColumns(7);
52
 
        iconfile.setColumns(8);
53
 
 
54
 
        setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
55
 
        add(new JLabel("Match:  "));
56
 
        add(match);
57
 
        add(new JLabel("  Style:  "));
58
 
        add(font.getComponent());
59
 
        add(foreground.getComponent());
60
 
        add(background.getComponent());
61
 
        // add(iconfile);
62
 
    }
63
 
 
64
 
    /**
65
 
    * This method does nothing because there is no configuring that this
66
 
    * class requires other than the current value.
67
 
    * @param obj The ignored paramter
68
 
    */
69
 
    public void setOptions(Object obj)
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 match.getText()+":"+
80
 
               font.getValue()+":"+
81
 
               foreground.getValue()+":"+
82
 
               background.getValue()+":"+
83
 
               iconfile.getText();
84
 
    }
85
 
 
86
 
    /**
87
 
    * Set the current value
88
 
    * @param value The new text
89
 
    */
90
 
    public void setValue(String value)
91
 
    {
92
 
        if (value == null || value.equals(""))
93
 
        {
94
 
            match.setText("");
95
 
            font.setValue("");
96
 
            foreground.setValue("");
97
 
            background.setValue("");
98
 
            iconfile.setText("");
99
 
            return;
100
 
        }
101
 
 
102
 
        int c1 = value.indexOf(":", 0);
103
 
        int c2 = value.indexOf(":", c1+1);
104
 
        int c3 = value.indexOf(":", c2+1);
105
 
        int c4 = value.indexOf(":", c3+1);
106
 
 
107
 
        if (c4 == -1) throw new IllegalArgumentException(value);
108
 
 
109
 
        match.setText(value.substring(0, c1));
110
 
        font.setValue(value.substring(c1+1, c2));
111
 
        foreground.setValue(value.substring(c2+1, c3));
112
 
        background.setValue(value.substring(c3+1, c4));
113
 
        iconfile.setText(value.substring(c4+1));
114
 
    }
115
 
 
116
 
    /**
117
 
    * Get the actual component that we can add to a Panel.
118
 
    * (This can well be this in an implementation).
119
 
    */
120
 
    public JComponent getComponent()
121
 
    {
122
 
        return this;
123
 
    }
124
 
 
125
 
    /** The match string */
126
 
    private JTextField match = new JTextField();
127
 
 
128
 
    /** The font */
129
 
    private FontButtonField font;
130
 
 
131
 
    /** The foreground color */
132
 
    private ColorField foreground;
133
 
 
134
 
    /** The background color */
135
 
    private ColorField background;
136
 
 
137
 
    /** The icon */
138
 
    private JTextField iconfile = new JTextField();
139
 
}
140