16
16
* justification, position, control type, drawing mode, and custom drawing configuration.
17
17
*/
18
18
public class ComponentSettingsBuilder {
19
+ public enum BuildingMode { MENU , TEXT , IMAGE }
20
+
19
21
private final static Set <EditItemType > POSSIBLE_TIME_TYPES = Set .of (
20
22
EditItemType .TIME_12H ,
21
23
EditItemType .TIME_24_HUNDREDS ,
22
24
EditItemType .TIME_24H ,
23
25
EditItemType .TIME_12H_HHMM ,
24
26
EditItemType .TIME_24H_HHMM );
25
27
28
+ private BuildingMode mode ;
29
+ private String text ;
26
30
private MenuItem item ;
27
31
private FontInformation fontInfo = FONT_100_PERCENT ;
28
32
private ConditionalColoring colors ;
@@ -39,13 +43,24 @@ public class ComponentSettingsBuilder {
39
43
/// @param color the colors to use for the control
40
44
public static ComponentSettingsBuilder forMenuItem (MenuItem item , ConditionalColoring color ) {
41
45
var b = new ComponentSettingsBuilder ();
46
+ b .mode = BuildingMode .MENU ;
42
47
b .colors = color ;
43
48
b .item = item ;
44
49
b .withControlType (defaultControlForType (item ));
45
50
b .withJustification (defaultJustificationForType (b .controlType ));
46
51
return b ;
47
52
}
48
53
54
+ public static ComponentSettingsBuilder forText (String text , ConditionalColoring color ) {
55
+ var b = new ComponentSettingsBuilder ();
56
+ b .mode = BuildingMode .TEXT ;
57
+ b .colors = color ;
58
+ b .text = text ;
59
+ b .withControlType (ControlType .TEXT_CONTROL );
60
+ b .withJustification (PortableAlignment .LEFT );
61
+ return b ;
62
+ }
63
+
49
64
private static PortableAlignment defaultJustificationForType (ControlType controlType ) {
50
65
return switch (controlType ) {
51
66
case HORIZONTAL_SLIDER , UP_DOWN_CONTROL -> PortableAlignment .LEFT_VAL_RIGHT ;
@@ -89,22 +104,34 @@ public ComponentSettingsBuilder withJustification(PortableAlignment justificatio
89
104
return this ;
90
105
}
91
106
92
- /// Set the position of the control in the grid. Pretty much must always be set
107
+ /// Set the position of the control in the grid. Must always be set, for simpler cases with
108
+ /// no span you can use `withRowCol`
93
109
/// @param position the position and span in the grid to create with
94
110
public ComponentSettingsBuilder withPosition (ComponentPositioning position ) {
95
111
this .position = position ;
96
112
return this ;
97
113
}
98
114
115
+ /// Set the position of the control in the grid. Must always be set
116
+ /// @param row the zero based row
117
+ /// @param col the zero based column
118
+ public ComponentSettingsBuilder withRowCol (int row , int col ) {
119
+ this .position = new ComponentPositioning (row , col );
120
+ return this ;
121
+ }
122
+
99
123
/// Override the control type that was guessed during `forMenuItem`. You should be careful that the control type
100
124
/// you choose is compatible with the menu item type.
101
125
/// @param controlType the control type to use
102
126
/// @throws IllegalArgumentException if the control type is invalid for the menu item
103
127
public ComponentSettingsBuilder withControlType (ControlType controlType ) {
104
- if (!controlType .isSupportedFor (item )) {
128
+ if (mode != BuildingMode .MENU ) {
129
+ controlType = ControlType .TEXT_CONTROL ;
130
+ } else if (!controlType .isSupportedFor (item )) {
105
131
throw new IllegalArgumentException ("Control type %s cannot render %s" .formatted (controlType , item .getClass ().getSimpleName ()));
132
+ } else {
133
+ this .controlType = controlType ;
106
134
}
107
- this .controlType = controlType ;
108
135
return this ;
109
136
}
110
137
@@ -132,6 +159,18 @@ public MenuItem getItem() {
132
159
return item ;
133
160
}
134
161
162
+ /// Get the static text associated with this builder
163
+ /// @return the static text
164
+ public String getText () {
165
+ return text ;
166
+ }
167
+
168
+ /// Get the mode of the building, IE text, menu item etc.
169
+ /// @return the building mode
170
+ public BuildingMode getMode () {
171
+ return mode ;
172
+ }
173
+
135
174
/// Creates the component settings
136
175
/// @return the built object
137
176
public ComponentSettings build () {
0 commit comments