@@ -27,124 +27,182 @@ This file is part of the iText (R) project.
27
27
* grid-auto-columns/rows properties and the type it is measured in.
28
28
*/
29
29
public class GridValue {
30
- /**
31
- * The type of the value.
32
- */
33
- private GridValueType type ;
34
- /**
35
- * The flexible value.
36
- */
37
- private Float flex ;
38
- /**
39
- * The sizing value.
40
- */
41
- private SizingValue sizingValue ;
30
+ private static final GridValue MIN_CONTENT_VALUE = new GridValue (SizingValueType .MIN_CONTENT );
31
+ private static final GridValue MAX_CONTENT_VALUE = new GridValue (SizingValueType .MAX_CONTENT );
32
+ private static final GridValue AUTO_VALUE = new GridValue (SizingValueType .AUTO );
33
+
34
+ private SizingValueType type ;
35
+ private Float value ;
42
36
43
- /**
44
- * Creates a new empty instance of {@link GridValue} class.
45
- */
46
37
private GridValue () {
47
- // do nothing
38
+ // Do nothing
39
+ }
40
+
41
+ private GridValue (SizingValueType type ) {
42
+ this .type = type ;
48
43
}
49
44
50
45
/**
51
- * Creates an instance of {@link GridValue} with {@link SizingValue} value.
46
+ * Creates an instance of {@link GridValue} with point value.
52
47
*
53
- * @param sizingValue the sizing value
48
+ * @param value the point value
54
49
*
55
50
* @return the grid value instance
56
51
*/
57
- public static GridValue createSizeValue ( SizingValue sizingValue ) {
52
+ public static GridValue createPointValue ( float value ) {
58
53
GridValue result = new GridValue ();
59
- result .sizingValue = sizingValue ;
60
- result .type = GridValueType . SIZING ;
54
+ result .type = SizingValueType . POINT ;
55
+ result .value = value ;
61
56
return result ;
62
57
}
63
58
64
59
/**
65
- * Creates an instance of {@link GridValue} with {@link UnitValue} inside of {@link SizingValue} value.
60
+ * Creates an instance of {@link GridValue} with percent value.
66
61
*
67
- * @param unitValue the unit value
62
+ * @param value the percent value
68
63
*
69
64
* @return the grid value instance
70
65
*/
71
- public static GridValue createUnitValue ( UnitValue unitValue ) {
66
+ public static GridValue createPercentValue ( float value ) {
72
67
GridValue result = new GridValue ();
73
- result .sizingValue = SizingValue . createUnitValue ( unitValue ) ;
74
- result .type = GridValueType . SIZING ;
68
+ result .type = SizingValueType . PERCENT ;
69
+ result .value = value ;
75
70
return result ;
76
71
}
77
72
78
73
/**
79
- * Creates an instance of {@link GridValue} with flex value.
74
+ * Creates an instance of {@link GridValue} with min-content value.
75
+ *
76
+ * @return the grid value instance
77
+ */
78
+ public static GridValue createMinContentValue () {
79
+ return MIN_CONTENT_VALUE ;
80
+ }
81
+
82
+ /**
83
+ * Creates an instance of {@link GridValue} with max-content value.
84
+ *
85
+ * @return the grid value instance
86
+ */
87
+ public static GridValue createMaxContentValue () {
88
+ return MAX_CONTENT_VALUE ;
89
+ }
90
+
91
+ /**
92
+ * Creates an instance of {@link GridValue} with auto value.
93
+ *
94
+ * @return the grid value instance
95
+ */
96
+ public static GridValue createAutoValue () {
97
+ return AUTO_VALUE ;
98
+ }
99
+
100
+ /**
101
+ * Creates an instance of {@link GridValue} with flexible value.
80
102
*
81
- * @param flex the flex value
103
+ * @param value the flexible value
82
104
*
83
105
* @return the grid value instance
84
106
*/
85
- public static GridValue createFlexValue (float flex ) {
107
+ public static GridValue createFlexValue (float value ) {
86
108
GridValue result = new GridValue ();
87
- result .flex = flex ;
88
- result .type = GridValueType . FLEX ;
109
+ result .type = SizingValueType . FLEX ;
110
+ result .value = value ;
89
111
return result ;
90
112
}
91
113
114
+
92
115
/**
93
- * Checks whether the value is absolute.
116
+ * Checks whether the value is absolute.
94
117
*
95
118
* @return {@code true} if absolute, {@code false} otherwise
96
119
*/
97
- public boolean isAbsoluteValue () {
98
- return type == GridValueType . SIZING && sizingValue . isAbsoluteValue () ;
120
+ public boolean isPointValue () {
121
+ return type == SizingValueType . POINT ;
99
122
}
100
123
101
124
/**
102
- * Gets absolute value, if exists .
125
+ * Checks whether the value is percent .
103
126
*
104
- * @return absolute value, or {@code null } if value is relative
127
+ * @return {@code true } if percent, {@code false} otherwise
105
128
*/
106
- public Float getAbsoluteValue () {
107
- if (isAbsoluteValue ()) {
108
- return sizingValue .getAbsoluteValue ();
109
- }
110
- return null ;
129
+ public boolean isPercentValue () {
130
+ return type == SizingValueType .PERCENT ;
111
131
}
112
132
113
133
/**
114
- * Gets type of value.
134
+ * Checks whether the value is auto .
115
135
*
116
- * @return the type of the value
136
+ * @return {@code true} if auto, {@code false} otherwise
117
137
*/
118
- public GridValueType getType () {
119
- return type ;
138
+ public boolean isAutoValue () {
139
+ return type == SizingValueType . AUTO ;
120
140
}
121
141
122
142
/**
123
- * Gets the flex value.
143
+ * Checks whether the value is min-content .
124
144
*
125
- * @return the flex value of {@code null } if another value type is stored
145
+ * @return {@code true } if min-content, {@code false} otherwise
126
146
*/
127
- public Float getFlexValue () {
128
- return flex ;
147
+ public boolean isMinContentValue () {
148
+ return type == SizingValueType . MIN_CONTENT ;
129
149
}
130
150
131
151
/**
132
- * Gets the sizing value.
152
+ * Checks whether the value is max-content .
133
153
*
134
- * @return the instance of {@link SizingValue} or {@code null} if another value type is stored
154
+ * @return {@code true} if max-content, {@code false} otherwise
135
155
*/
136
- public SizingValue getSizingValue () {
137
- return sizingValue ;
156
+ public boolean isMaxContentValue () {
157
+ return type == SizingValueType . MAX_CONTENT ;
138
158
}
139
159
140
160
/**
141
- * Enum of grid value types.
161
+ * Checks whether the value is flexible.
162
+ *
163
+ * @return {@code true} if flexible, {@code false} otherwise
142
164
*/
143
- public enum GridValueType {
165
+ public boolean isFlexibleValue () {
166
+ return type == SizingValueType .FLEX ;
167
+ }
168
+
169
+ /**
170
+ * Gets value, if exists.
171
+ *
172
+ * @return the value, or {@code null} if there is no value
173
+ */
174
+ public Float getValue () {
175
+ return value ;
176
+ }
177
+
178
+ /**
179
+ * Enum of sizing value types.
180
+ */
181
+ private enum SizingValueType {
182
+ /**
183
+ * Type which presents absolute point value.
184
+ */
185
+ POINT ,
186
+ /**
187
+ * Type which presents relative percent value.
188
+ */
189
+ PERCENT ,
190
+ /**
191
+ * Type which presents relative auto value.
192
+ */
193
+ AUTO ,
194
+ /**
195
+ * Type which presents relative min content value.
196
+ */
197
+ MIN_CONTENT ,
198
+ /**
199
+ * Type which presents relative max content value.
200
+ */
201
+ MAX_CONTENT ,
144
202
/**
145
- * Type which presents {@link SizingValue} value.
203
+ * Type which presents relative fit content function value.
146
204
*/
147
- SIZING ,
205
+ FIT_CONTENT ,
148
206
/**
149
207
* Type which presents relative flexible value.
150
208
*/
0 commit comments