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

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