-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathFormBuilderWithRowsTest.java
116 lines (99 loc) Β· 4.61 KB
/
FormBuilderWithRowsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package de.milchreis.uibooster;
import de.milchreis.uibooster.model.Form;
import org.junit.jupiter.api.Test;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
class FormBuilderWithRowsTest {
UiBooster booster = new UiBooster();
@Test
public void test_form_dialog_with_rows() {
Form form = booster
.createForm("Personal information")
.addText("Whats your first name?")
.startRow("Select one")
.addButton(" ", "half full", () -> booster.showInfoDialog("Optimist")).setID("btn1")
.addButton(" ", "half empty", () -> booster.showInfoDialog("Pessimist"))
.addText("?").setID("?")
.endRow()
.addSlider("How many liters did you drink today?", 0, 5, 1, 5, 1)
.addColorPicker("Favorite color?")
.addFontChooser("Favorite font?")
.setChangeListener((element, value, filledForm) -> System.out.println(
"Component " + element.getLabel() +
" at position " + element.getIndex() +
" changed to " + value.toString()))
.show();
assert form.getByIndex(1).getId().equals("btn1");
assert form.getById("?") != null;
form.getElements().forEach(e -> System.out.println(e.getLabel() + " -> " + e.getValue()));
}
@Test
public void calculator() {
booster.createForm("Calculator")
.setMargin(0,0,0,0)
.addText("Result", "", true).setID("result").setMargin(0,0,0,5)
.startRow()
.addButton("7", () -> {})
.addButton("8", () -> {})
.addButton("9", () -> {})
.endRow()
.startRow()
.addButton("4", () -> {})
.addButton("5", () -> {})
.addButton("6", () -> {})
.endRow()
.startRow()
.addButton("1", () -> {})
.addButton("2", () -> {})
.addButton("3", () -> {})
.endRow()
.startRow(0,0, 0, 10)
.addButton("0", () -> {})
.addButton("+", () -> {}).setID("plus")
.addButton("-", () -> {}).setID("minus")
.endRow()
.addButton("=", () -> {})
.setChangeListener((element, value, filledForm) -> {
String input = filledForm.getById("result").getValue() + "";
filledForm.getById("plus").setEnabled(!value.equals("+") && !value.equals("-"));
filledForm.getById("minus").setEnabled(!value.equals("-") && !value.equals("+"));
if (value.equals("=")) {
final Integer result = calculate(input);
input = result != null ? result.toString() : "ERROR";
} else {
input += value;
}
filledForm.getById("result").setValue(input);
})
.show();
}
@Test
public void test_form_dialog_with_rows_and_disable() {
Form form = booster
.createForm("Personal information")
.addText("Whats your first name?")
.startRow("Select one")
.addButton(" ", "half full", () -> booster.showInfoDialog("Optimist")).setID("btn1")
.addButton(" ", "half empty", () -> booster.showInfoDialog("Pessimist")).setDisabled()
.endRow()
.addButton("Favorite font?", (Runnable) null).setDisabled()
.startRow("Select one")
.addText("?").setID("?")
.addButton("Favorite font 1?", (Runnable) null).setDisabled()
.endRow()
.addButton("Favorite font 2?", (Runnable) null)
.addButton("Favorite font 3?", (Runnable) null).setDisabled()
.setChangeListener((element, value, filledForm) -> System.out.println(
"Component " + element.getLabel() +
" at position " + element.getIndex() +
" changed to " + value.toString()))
.show();
assert form.getByIndex(1).getId().equals("btn1");
assert form.getById("?") != null;
form.getElements().forEach(e -> System.out.println(e.getLabel() + " -> " + e.getValue()));
}
private Integer calculate(String input) {
return (int) MathEvaluator.eval(input);
}
}