-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCustomFormBuilderElementTest.java
67 lines (52 loc) · 1.74 KB
/
CustomFormBuilderElementTest.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
package de.milchreis.uibooster;
import de.milchreis.uibooster.model.Form;
import de.milchreis.uibooster.model.FormElement;
import de.milchreis.uibooster.model.FormElementChangeListener;
import org.junit.jupiter.api.Test;
import javax.swing.*;
class CustomFormBuilderElementTest {
UiBooster booster = new UiBooster();
/**
* Example custom form element
*/
class CustomRobotFormElement extends FormElement<Integer> {
JButton button;
int count = 1;
public CustomRobotFormElement(String label) {
super(label);
button = new JButton("Speak");
button.addActionListener(l -> booster.showInfoDialog(
"Hi, I'm Robo !!!\n " +
"You called me for the " + count++ + " time"));
}
@Override
public JComponent createComponent(FormElementChangeListener onChange) {
Box box = Box.createVerticalBox();
box.add(new JLabel(new ImageIcon("src/test/resources/avatar1.png")));
box.add(button);
return box;
}
@Override
public void setEnabled(boolean enable) {
button.setEnabled(enable);
}
@Override
public Integer getValue() {
return count;
}
@Override
public void setValue(Integer value) {
button.setText(value.toString());
}
}
@Test
public void test_custom_form_dialog() {
Form form = booster
.createForm("Custom elements")
.addCustomElement(new CustomRobotFormElement("Your custom robot"))
.show();
form.getElements().forEach(e -> {
System.out.println(e.getLabel() + " -> " + e.getValue());
});
}
}