Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

HtmlInCaption.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package com.vaadin.tests.layouts;
  2. import com.vaadin.server.VaadinRequest;
  3. import com.vaadin.tests.components.AbstractReindeerTestUI;
  4. import com.vaadin.ui.AbsoluteLayout;
  5. import com.vaadin.ui.AbstractComponent;
  6. import com.vaadin.ui.Button;
  7. import com.vaadin.ui.CheckBox;
  8. import com.vaadin.ui.ColorPicker;
  9. import com.vaadin.ui.ColorPickerArea;
  10. import com.vaadin.ui.Component;
  11. import com.vaadin.ui.CssLayout;
  12. import com.vaadin.ui.GridLayout;
  13. import com.vaadin.ui.HorizontalLayout;
  14. import com.vaadin.ui.Link;
  15. import com.vaadin.ui.NativeButton;
  16. import com.vaadin.ui.Panel;
  17. import com.vaadin.ui.VerticalLayout;
  18. import com.vaadin.ui.Window;
  19. import com.vaadin.v7.ui.TextField;
  20. public class HtmlInCaption extends AbstractReindeerTestUI {
  21. @Override
  22. protected void setup(VaadinRequest request) {
  23. HorizontalLayout main = new HorizontalLayout();
  24. addComponent(main);
  25. VerticalLayout components = new VerticalLayout();
  26. components.setId("components");
  27. VerticalLayout layouts = new VerticalLayout();
  28. layouts.setId("layouts");
  29. main.addComponent(layouts);
  30. main.addComponent(components);
  31. createComponents(components);
  32. createLayouts(layouts);
  33. Window w = new Window();
  34. w.setCaption(getTextCaption("Window"));
  35. w.setPositionX(600);
  36. addWindow(w);
  37. w = new Window();
  38. w.setCaptionAsHtml(true);
  39. w.setCaption(getHtmlCaption("Window"));
  40. w.setPositionX(600);
  41. w.setPositionY(100);
  42. addWindow(w);
  43. }
  44. private void createLayouts(VerticalLayout layouts) {
  45. VerticalLayout vl = new VerticalLayout(tf(false), tf(true));
  46. vl.setCaption("VerticalLayout");
  47. layouts.addComponent(vl);
  48. HorizontalLayout hl = new HorizontalLayout(tf(false), tf(true));
  49. hl.setCaption("HorizontalLayout");
  50. layouts.addComponent(hl);
  51. GridLayout gl = new GridLayout(2, 1);
  52. gl.setCaption("GridLayout");
  53. gl.addComponents(tf(false), tf(true));
  54. layouts.addComponent(gl);
  55. CssLayout cl = new CssLayout();
  56. cl.setCaption("CssLayout");
  57. cl.addComponents(tf(false), tf(true));
  58. layouts.addComponent(cl);
  59. AbsoluteLayout al = new AbsoluteLayout();
  60. al.setCaption("AbsoluteLayout");
  61. al.setWidth("300px");
  62. al.setHeight("200px");
  63. al.addComponent(tf(false), "top:30px");
  64. al.addComponent(tf(true), "top: 100px");
  65. layouts.addComponent(al);
  66. }
  67. private void createComponents(VerticalLayout components) {
  68. createComponent(components, Button.class);
  69. createComponent(components, NativeButton.class);
  70. createComponent(components, CheckBox.class);
  71. createComponent(components, Link.class);
  72. createComponent(components, Panel.class);
  73. createComponent(components, ColorPicker.class);
  74. createComponent(components, ColorPickerArea.class);
  75. }
  76. private void createComponent(VerticalLayout components,
  77. Class<? extends AbstractComponent> class1) {
  78. AbstractComponent ac;
  79. try {
  80. ac = class1.newInstance();
  81. ac.setCaption(getTextCaption(class1.getSimpleName()));
  82. components.addComponent(ac);
  83. } catch (Exception e) {
  84. e.printStackTrace();
  85. }
  86. try {
  87. ac = class1.newInstance();
  88. ac.setCaption(getHtmlCaption(class1.getSimpleName()));
  89. ac.setCaptionAsHtml(true);
  90. components.addComponent(ac);
  91. } catch (Exception e) {
  92. e.printStackTrace();
  93. }
  94. }
  95. private Component tf(boolean htmlCaption) {
  96. TextField tf = new TextField();
  97. if (htmlCaption) {
  98. tf.setCaptionAsHtml(htmlCaption);
  99. tf.setCaption(getHtmlCaption(""));
  100. } else {
  101. tf.setCaption(getTextCaption(""));
  102. }
  103. return tf;
  104. }
  105. private String getTextCaption(String string) {
  106. return "<b>Plain text " + string + "</b>";
  107. }
  108. private String getHtmlCaption(String string) {
  109. return "<b><font color='red'>HTML " + string + "</font></b>";
  110. }
  111. @Override
  112. protected Integer getTicketNumber() {
  113. return 9426;
  114. }
  115. }