01: package net.xoetrope.swing;
02:
03: import javax.swing.JTextField;
04:
05: /**
06: * A utility class to help in setting alignment options
07: * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003</p>
08: */
09: public class XAlignmentHelper {
10: public static final String alignmentOptions[] = { "Left", "Right",
11: "Center", "Leading", "Trailing" };
12: public static final int alignmentOptionIds[] = { JTextField.LEFT,
13: JTextField.RIGHT, JTextField.CENTER, JTextField.LEADING,
14: JTextField.TRAILING };
15:
16: public XAlignmentHelper() {
17: }
18:
19: public static int getAlignmentOption(String value) {
20: if (value != null) {
21: for (int idx = 0; idx < alignmentOptions.length; idx++) {
22: if (value.equals(alignmentOptions[idx]))
23: return alignmentOptionIds[idx];
24: }
25: }
26:
27: return alignmentOptionIds[0];
28: }
29:
30: public static String getAlignmentOption(int value) {
31: for (int idx = 0; idx < alignmentOptions.length; idx++) {
32: if (value == alignmentOptionIds[idx])
33: return alignmentOptions[idx];
34: }
35:
36: return alignmentOptions[0];
37: }
38: }
|