blob: 7a58a4c80ca97611936829ab68734906faeffd45 (
plain)
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
|
package com.vaadin.tests.util;
import java.util.ArrayList;
import java.util.List;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
public class Log extends VerticalLayout {
List<Label> eventLabels = new ArrayList<Label>();
private boolean numberLogRows = true;
private int nextLogNr = 1;
public Log(int nr) {
for (int i = 0; i < nr; i++) {
Label l = createEventLabel();
l.setId("Log_row_" + i);
eventLabels.add(l);
addComponent(l);
}
setId("Log");
setCaption("Events:");
}
/**
* Clears the rows and reset the row number to zero.
*/
public Log clear() {
for (Label l : eventLabels) {
l.setValue(" ");
}
nextLogNr = 0;
return this;
}
public Log log(String event) {
int nr = eventLabels.size();
for (int i = nr - 1; i > 0; i--) {
eventLabels.get(i).setValue(eventLabels.get(i - 1).getValue());
}
String msg = event;
if (numberLogRows) {
msg = nextLogNr + ". " + msg;
nextLogNr++;
}
eventLabels.get(0).setValue(msg);
System.out.println(event);
return this;
}
private Label createEventLabel() {
Label l = new Label(" ", ContentMode.XHTML);
l.setWidth(null);
return l;
}
public Log setNumberLogRows(boolean numberLogRows) {
this.numberLogRows = numberLogRows;
return this;
}
}
|