You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RichTextExample.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.demo.featurebrowser;
  5. import com.itmill.toolkit.ui.Button;
  6. import com.itmill.toolkit.ui.CustomComponent;
  7. import com.itmill.toolkit.ui.Label;
  8. import com.itmill.toolkit.ui.OrderedLayout;
  9. import com.itmill.toolkit.ui.RichTextArea;
  10. import com.itmill.toolkit.ui.Button.ClickEvent;
  11. /**
  12. * An example using a RichTextArea to edit a Label in XHTML-mode.
  13. *
  14. */
  15. public class RichTextExample extends CustomComponent {
  16. public static final String txt = "<h1>RichText editor example</h1>"
  17. + "To edit this text, press the <b>Edit</b> button below."
  18. + "<br/>"
  19. + "See the <A href=\"http://www.itmill.com/manual/\">manual</a> "
  20. + "for more information.";
  21. private final OrderedLayout main;
  22. private final Label l;
  23. private final RichTextArea editor = new RichTextArea();
  24. private final Button b;
  25. public RichTextExample() {
  26. // main layout
  27. main = new OrderedLayout();
  28. main.setMargin(true);
  29. setCompositionRoot(main);
  30. // Add the label
  31. l = new Label(txt);
  32. l.setContentMode(Label.CONTENT_XHTML);
  33. main.addComponent(l);
  34. // Edit button with inline click-listener
  35. b = new Button("Edit", new Button.ClickListener() {
  36. public void buttonClick(ClickEvent event) {
  37. // swap Label <-> RichTextArea
  38. if (main.getComponentIterator().next() == l) {
  39. editor.setValue(l.getValue());
  40. main.replaceComponent(l, editor);
  41. b.setCaption("Save");
  42. } else {
  43. l.setValue(editor.getValue());
  44. main.replaceComponent(editor, l);
  45. b.setCaption("Edit");
  46. }
  47. }
  48. });
  49. main.addComponent(b);
  50. main.setComponentAlignment(b, OrderedLayout.ALIGNMENT_RIGHT,
  51. OrderedLayout.ALIGNMENT_VERTICAL_CENTER);
  52. }
  53. }