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.

LabelExample.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.demo.featurebrowser;
  5. import com.itmill.toolkit.ui.CustomComponent;
  6. import com.itmill.toolkit.ui.GridLayout;
  7. import com.itmill.toolkit.ui.Label;
  8. import com.itmill.toolkit.ui.OrderedLayout;
  9. import com.itmill.toolkit.ui.Panel;
  10. /**
  11. * Shows a few variations of Labels, including the effects of XHTML- and
  12. * pre-formatted mode.
  13. *
  14. * @author IT Mill Ltd.
  15. */
  16. public class LabelExample extends CustomComponent {
  17. private static final String xhtml = "This text has <b>HTML</b> formatting.<br/>"
  18. + "A plain <i>Label</i> will show the markup, while a <u>XHTML-mode</u>"
  19. + " <i>Label</i> will show the formatted text.";
  20. private static final String pre = "This text has linebreaks.\n\n"
  21. + "They will show up in a preformatted Label,\n"
  22. + "but not in a \"plain\" Label.\n\n"
  23. + " This is an indented row. \n Same indentation here.";
  24. public LabelExample() {
  25. final OrderedLayout main = new OrderedLayout();
  26. main.setMargin(true);
  27. setCompositionRoot(main);
  28. final GridLayout g = new GridLayout(2, 4);
  29. main.addComponent(g);
  30. // plain w/o caption
  31. Panel p = new Panel("Plain");
  32. p.setStyleName(Panel.STYLE_LIGHT);
  33. Label l = new Label("A plain label without caption.");
  34. p.addComponent(l);
  35. g.addComponent(p);
  36. // plain w/ caption
  37. p = new Panel("Plain w/ caption + tooltip");
  38. p.setStyleName(Panel.STYLE_LIGHT);
  39. l = new Label("A plain label with caption.");
  40. l.setCaption("Label caption");
  41. l.setDescription("This is a description (tooltip) for the label.");
  42. p.addComponent(l);
  43. g.addComponent(p);
  44. // plain w/ xhtml
  45. p = new Panel("Plain w/ XHTML content");
  46. p.setStyleName(Panel.STYLE_LIGHT);
  47. l = new Label(xhtml);
  48. p.addComponent(l);
  49. g.addComponent(p);
  50. // xhtml w/ xhtml
  51. p = new Panel("XHTML-mode w/ XHTML content");
  52. p.setStyleName(Panel.STYLE_LIGHT);
  53. l = new Label(xhtml);
  54. l.setContentMode(Label.CONTENT_XHTML);
  55. p.addComponent(l);
  56. g.addComponent(p);
  57. // plain w/ preformatted
  58. p = new Panel("Plain w/ preformatted content");
  59. p.setStyleName(Panel.STYLE_LIGHT);
  60. l = new Label(pre);
  61. p.addComponent(l);
  62. g.addComponent(p);
  63. // preformatted w/ preformatted
  64. p = new Panel("Preformatted-mode w/ preformatted content");
  65. p.setStyleName(Panel.STYLE_LIGHT);
  66. l = new Label(pre);
  67. l.setContentMode(Label.CONTENT_PREFORMATTED);
  68. p.addComponent(l);
  69. g.addComponent(p);
  70. }
  71. }