01: package net.xoetrope.swing;
02:
03: import javax.swing.JTextField;
04:
05: import net.xoetrope.xui.XTextHolder;
06: import net.xoetrope.xui.XAttributedComponent;
07: import java.awt.Insets;
08:
09: /**
10: * <p>A wrapper for the Swing JTextField class</p>
11: * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003<br>
12: * License: see license.txt
13: * @version 1.0
14: */
15: public class XEdit extends JTextField implements XTextHolder,
16: XAttributedComponent {
17: public XEdit() {
18: }
19:
20: /**
21: * Set one or more attributes of the component.
22: * <OL>
23: * <LI>alignment, value=(Left|Right|Center|Leading|Trailing)</LI>
24: * <LI>border, value=0, to tun off the border</LI>
25: * <LI>margin, value=the size in pixels of the margin (the space between the border and the text)</LI>
26: * </OL>
27: * @param attribName the name of the attribute
28: * @param attribValue the value of the attribute
29: */
30: public void setAttribute(String attribName, String attribValue) {
31: String attribNameLwr = attribName.toLowerCase();
32: String attribValueLwr = attribValue.toLowerCase();
33: if (attribNameLwr.equals("alignment"))
34: setHorizontalAlignment(XAlignmentHelper
35: .getAlignmentOption(attribValue));
36: else if (attribNameLwr.equals("border")) {
37: if (attribValueLwr.equals("0"))
38: setBorder(null);
39: } else if (attribNameLwr.equals("margin")) {
40: int margin = new Integer(attribValueLwr).intValue();
41: setMargin(new Insets(margin, margin, margin, margin));
42: }
43: }
44: }
|