blob: edc65899f3c41ae15f4e1f1a0a785c5f593b0795 (
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
|
/*
@ITMillApache2LicenseForJavaFiles@
*/
package com.itmill.toolkit.automatedtests.featurebrowser;
import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.CustomComponent;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.OrderedLayout;
import com.itmill.toolkit.ui.RichTextArea;
import com.itmill.toolkit.ui.Button.ClickEvent;
/**
* An example using a RichTextArea to edit a Label in XHTML-mode.
*
*/
public class RichTextExample extends CustomComponent {
public static final String txt = "<h1>RichText editor example</h1>"
+ "To edit this text, press the <b>Edit</b> button below."
+ "<br/>"
+ "See the <A href=\"http://www.itmill.com/documentation/itmill-toolkit-5-reference-manual/\">manual</a> "
+ "for more information.";
private final OrderedLayout main;
private final Label l;
private final RichTextArea editor = new RichTextArea();
private final Button b;
public RichTextExample() {
// main layout
main = new OrderedLayout();
main.setMargin(true);
setCompositionRoot(main);
// Add the label
l = new Label(txt);
l.setContentMode(Label.CONTENT_XHTML);
main.addComponent(l);
// Edit button with inline click-listener
b = new Button("Edit", new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
// swap Label <-> RichTextArea
if (main.getComponentIterator().next() == l) {
editor.setValue(l.getValue());
main.replaceComponent(l, editor);
b.setCaption("Save");
} else {
l.setValue(editor.getValue());
main.replaceComponent(editor, l);
b.setCaption("Edit");
}
}
});
main.addComponent(b);
main.setComponentAlignment(b, OrderedLayout.ALIGNMENT_RIGHT,
OrderedLayout.ALIGNMENT_VERTICAL_CENTER);
}
}
|