1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sourceforge.jeuclid.elements.support.attributes;
20
21 import net.sourceforge.jeuclid.layout.LayoutInfo;
22 import net.sourceforge.jeuclid.layout.LayoutStage;
23
24
25
26
27 public enum HAlign {
28
29 LEFT,
30
31 CENTER,
32
33 RIGHT;
34
35 public static final String ALIGN_CENTER = "center";
36
37
38 public static final String ALIGN_RIGHT = "right";
39
40
41
42
43
44
45
46
47
48
49 public static HAlign parseString(final String alignString,
50 final HAlign defaultt) {
51 final HAlign retVal;
52 if (HAlign.ALIGN_CENTER.equalsIgnoreCase(alignString)) {
53 retVal = CENTER;
54 } else if ("left".equalsIgnoreCase(alignString)) {
55 retVal = LEFT;
56 } else if (HAlign.ALIGN_RIGHT.equalsIgnoreCase(alignString)) {
57 retVal = RIGHT;
58 } else {
59 retVal = defaultt;
60 }
61 return retVal;
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75 public float getHAlignOffset(final LayoutStage stage,
76 final LayoutInfo info, final float width) {
77 final float offset;
78 switch (this) {
79 case LEFT:
80 offset = 0.0f;
81 break;
82 case RIGHT:
83 offset = width - info.getWidth(stage);
84 break;
85 case CENTER:
86 offset = width / 2.0f - info.getHorizontalCenterOffset(stage);
87 break;
88 default:
89 assert false;
90 offset = 0.0f;
91 }
92 return offset;
93 }
94
95 }