| NumberField.java |
1 /**
2 * Distribution License:
3 * JSword is free software; you can redistribute it and/or modify it under
4 * the terms of the GNU Lesser General Public License, version 2.1 as published by
5 * the Free Software Foundation. This program is distributed in the hope
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 * See the GNU Lesser General Public License for more details.
9 *
10 * The License is available on the internet at:
11 * http://www.gnu.org/copyleft/lgpl.html
12 * or by writing to:
13 * Free Software Foundation, Inc.
14 * 59 Temple Place - Suite 330
15 * Boston, MA 02111-1307, USA
16 *
17 * Copyright: 2005
18 * The copyright to this program is held by it's authors.
19 *
20 * ID: $Id: NumberField.java 1966 2009-10-30 01:15:14Z dmsmith $
21 */
22 package org.crosswire.common.config.swing;
23
24 import java.awt.BorderLayout;
25
26 import javax.swing.JComponent;
27 import javax.swing.JPanel;
28 import javax.swing.JTextField;
29
30 import org.crosswire.common.config.Choice;
31 import org.crosswire.common.icu.NumberShaper;
32 import org.crosswire.common.swing.NumericDocument;
33
34 /**
35 * A PropertyNumberField is a PropertyTextField that only stores numbers.
36 *
37 * @see gnu.lgpl.License for license details.<br>
38 * The copyright to this program is held by it's authors.
39 * @author Joe Walker [joe at eireneh dot com]
40 */
41 public class NumberField extends JPanel implements Field {
42 /**
43 * Create a new FileField
44 */
45 public NumberField() {
46 shaper = new NumberShaper();
47 text = new JTextField();
48 text.setDocument(new NumericDocument());
49 text.setColumns(10);
50
51 setLayout(new BorderLayout(10, 0));
52 add(BorderLayout.LINE_START, text);
53 }
54
55 /**
56 * Some fields will need some extra info to display properly like the
57 * options in an options field. FieldMap calls this method with options
58 * provided by the choice.
59 *
60 * @param param
61 * The options provided by the Choice
62 */
63 public void setChoice(Choice param) {
64 }
65
66 /**
67 * Return a string version of the current value
68 *
69 * @return The current value
70 */
71 public String getValue() {
72 return shaper.unshape(text.getText());
73 }
74
75 /**
76 * Set the current value
77 *
78 * @param value
79 * The new text
80 */
81 public void setValue(String value) {
82 text.setText(shaper.shape(value));
83 }
84
85 /**
86 * Get the actual component that we can add to a Panel. (This can well be
87 * this in an implementation).
88 */
89 public JComponent getComponent() {
90 return this;
91 }
92
93 /**
94 * The text field
95 */
96 private JTextField text = new JTextField();
97
98 /**
99 * The internationalizer for numbers.
100 */
101 private NumberShaper shaper;
102
103 /**
104 * Serialization ID
105 */
106 private static final long serialVersionUID = 3256443594867750451L;
107 }
108