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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
package com.vaadin.tests.themes;
import java.util.Locale;
import com.vaadin.server.ThemeResource;
import com.vaadin.server.UserError;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Layout;
import com.vaadin.ui.LegacyWindow;
import com.vaadin.ui.NativeButton;
@SuppressWarnings("serial")
public class ButtonsTest extends com.vaadin.server.LegacyApplication {
final LegacyWindow main = new LegacyWindow("Button states & themes");
CheckBox styleToggle;
CheckBox iconToggle;
CheckBox nativeToggle;
CheckBox themeToggle;
boolean largeIcons = false;
boolean nativeButtons = false;
final HorizontalLayout toggles = new HorizontalLayout();
@Override
public void init() {
setMainWindow(main);
setTheme("reindeer");
themeToggle = new CheckBox("Runo theme");
themeToggle.addValueChangeListener(event -> {
if (getTheme() == "reindeer") {
setTheme("runo");
} else {
setTheme("reindeer");
}
});
themeToggle.setStyleName("small");
styleToggle = new CheckBox("Black style");
styleToggle.addValueChangeListener(event -> {
if (!main.getContent().getStyleName().contains("black")) {
main.getContent().setStyleName("black");
} else {
main.getContent().setStyleName("");
}
});
styleToggle.setStyleName("small");
iconToggle = new CheckBox("64x icons");
iconToggle.addValueChangeListener(event -> {
largeIcons = !largeIcons;
recreateAll();
});
iconToggle.setStyleName("small");
nativeToggle = new CheckBox("Native buttons");
nativeToggle.addValueChangeListener(event -> {
nativeButtons = !nativeButtons;
recreateAll();
});
nativeToggle.setStyleName("small");
toggles.setSpacing(true);
toggles.addComponent(themeToggle);
toggles.addComponent(styleToggle);
toggles.addComponent(iconToggle);
toggles.addComponent(nativeToggle);
main.addComponent(toggles);
recreateAll();
}
private void recreateAll() {
main.removeAllComponents();
main.addComponent(toggles);
main.addComponent(buildButtons(false, false, false, false));
main.addComponent(buildButtons(false, false, true, false));
main.addComponent(buildButtons(false, true, false, false));
main.addComponent(buildButtons(false, true, true, false));
main.addComponent(buildButtons(true, false, false, false));
main.addComponent(buildButtons(true, false, true, false));
main.addComponent(buildButtons(true, true, false, false));
main.addComponent(buildButtons(true, true, true, false));
main.addComponent(buildButtons(false, false, false, true));
main.addComponent(buildButtons(false, false, true, true));
main.addComponent(buildButtons(false, true, false, true));
main.addComponent(buildButtons(false, true, true, true));
main.addComponent(buildButtons(true, false, false, true));
main.addComponent(buildButtons(true, false, true, true));
main.addComponent(buildButtons(true, true, false, true));
main.addComponent(buildButtons(true, true, true, true));
final Button b = new Button("Tabindex");
b.setTabIndex(1);
main.addComponent(b);
Button c = new Button("toggle enabled",
event -> b.setEnabled(!b.isEnabled()));
main.addComponent(c);
}
private Layout buildButtons(boolean disabled, boolean icon, boolean error,
boolean sized) {
String[] buttonStyles = { "Normal", "Primary", "Small", "Link" };
HorizontalLayout hl = new HorizontalLayout();
hl.setSpacing(true);
hl.setMargin(true);
for (String style : buttonStyles) {
Button b;
if (nativeButtons) {
b = new NativeButton(style + " style");
} else {
b = new Button(style + " style");
}
b.setStyleName(style.toLowerCase(Locale.ROOT));
if (icon) {
b.setIcon(new ThemeResource("../runo/icons/"
+ (largeIcons ? "64" : "16") + "/document.png"));
}
if (error) {
b.setComponentError(new UserError("Error"));
}
if (disabled) {
b.setEnabled(false);
}
if (sized) {
b.setWidth("250px");
b.setCaption(b.getCaption() + " (250px)");
}
hl.addComponent(b);
}
return hl;
}
}
|