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.

LayoutDemo.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package com.vaadin.tests;
  2. import com.vaadin.server.ClassResource;
  3. import com.vaadin.shared.ui.ContentMode;
  4. import com.vaadin.ui.Component;
  5. import com.vaadin.ui.Embedded;
  6. import com.vaadin.ui.GridLayout;
  7. import com.vaadin.ui.HorizontalLayout;
  8. import com.vaadin.ui.Label;
  9. import com.vaadin.ui.Layout;
  10. import com.vaadin.ui.LegacyWindow;
  11. import com.vaadin.ui.Panel;
  12. import com.vaadin.ui.TabSheet;
  13. import com.vaadin.ui.VerticalLayout;
  14. /**
  15. * This example demonstrates layouts. Layouts are populated with sample Vaadin
  16. * UI components.
  17. *
  18. * @author Vaadin Ltd.
  19. * @since 4.0.0
  20. *
  21. */
  22. public class LayoutDemo extends com.vaadin.server.LegacyApplication {
  23. /**
  24. * Initialize Application. Demo components are added to main window.
  25. */
  26. @Override
  27. public void init() {
  28. final LegacyWindow mainWindow = new LegacyWindow("Layout demo");
  29. setMainWindow(mainWindow);
  30. //
  31. // Create horizontal ordered layout
  32. //
  33. final HorizontalLayout layoutA = new HorizontalLayout();
  34. // Add 4 panels
  35. fillLayout(layoutA, 4);
  36. //
  37. // Create vertical ordered layout
  38. //
  39. final VerticalLayout layoutB = new VerticalLayout();
  40. // Add 4 panels
  41. fillLayout(layoutB, 4);
  42. //
  43. // Create grid layout
  44. //
  45. final GridLayout layoutG = new GridLayout(4, 4);
  46. // Add 16 panels components
  47. fillLayout(layoutG, 16);
  48. //
  49. // Create grid layout
  50. //
  51. final GridLayout layoutG2 = new GridLayout(4, 4);
  52. // Add 4 panels with absolute coordinates (diagonally)
  53. layoutG2.addComponent(getExampleComponent("x=0, y=0"), 0, 0);
  54. layoutG2.addComponent(getExampleComponent("x=1, y=1"), 1, 1);
  55. layoutG2.addComponent(getExampleComponent("x=2, y=2"), 2, 2);
  56. layoutG2.addComponent(getExampleComponent("x=3, y=3"), 3, 3);
  57. // Add 4 pictures with absolute coordinates (diagonally)
  58. layoutG2.addComponent(getExamplePicture("x=3, y=0"), 3, 0);
  59. layoutG2.addComponent(getExamplePicture("x=2, y=1"), 2, 1);
  60. layoutG2.addComponent(getExamplePicture("x=1, y=2"), 1, 2);
  61. layoutG2.addComponent(getExamplePicture("x=0, y=3"), 0, 3);
  62. //
  63. // Create TabSheet
  64. //
  65. final TabSheet tabsheet = new TabSheet();
  66. tabsheet.setCaption(
  67. "Tabsheet, above layouts are added to this component");
  68. tabsheet.addTab(layoutA, "Horizontal ordered layout", null);
  69. tabsheet.addTab(layoutB, "Vertical ordered layout", null);
  70. tabsheet.addTab(layoutG, "First grid layout", null);
  71. tabsheet.addTab(layoutG2, "Second grid layout", null);
  72. //
  73. // Add demo layouts to main window
  74. //
  75. mainWindow.addComponent(new Label(
  76. "<h3>Horizontal ordered layout</h3>Added four components.",
  77. ContentMode.HTML));
  78. mainWindow.addComponent(layoutA);
  79. mainWindow.addComponent(new Label(
  80. "<br /><h3>Vertical ordered layout</h3>Added four components.",
  81. ContentMode.HTML));
  82. mainWindow.addComponent(layoutB);
  83. mainWindow.addComponent(new Label(
  84. "<br /><h3>Grid Layout (4 x 4)</h3>Added 16 components.",
  85. ContentMode.HTML));
  86. mainWindow.addComponent(layoutG);
  87. mainWindow.addComponent(new Label(
  88. "<br /><h3>Grid Layout (4 x 4)</h3>"
  89. + "Added four panels and four embedded components "
  90. + "diagonally with absolute coordinates.",
  91. ContentMode.HTML));
  92. mainWindow.addComponent(layoutG2);
  93. mainWindow.addComponent(
  94. new Label("<br /><h3>TabSheet</h3>Added above layouts as tabs.",
  95. ContentMode.HTML));
  96. mainWindow.addComponent(tabsheet);
  97. }
  98. private Component getExamplePicture(String caption) {
  99. // loads image from package com.vaadin.demo
  100. final ClassResource cr = new ClassResource("m-bullet-blue.gif");
  101. final Embedded em = new Embedded("Embedded " + caption, cr);
  102. em.setWidth("170px");
  103. return em;
  104. }
  105. private Component getExampleComponent(String caption) {
  106. VerticalLayout layout = new VerticalLayout();
  107. layout.setMargin(true);
  108. final Panel panel = new Panel(layout);
  109. panel.setCaption("Panel component " + caption);
  110. layout.addComponent(new Label(
  111. "Panel is a container for other components, by default it draws a frame around it's "
  112. + "extremities and may have a caption to clarify the nature of the contained components' purpose."
  113. + " Panel contains a layout where the actual contained components are added, "
  114. + "this layout may be switched on the fly.",
  115. ContentMode.HTML));
  116. panel.setWidth("222px");
  117. return panel;
  118. }
  119. /**
  120. * Add multiple demo component to given layout.
  121. *
  122. * @param layout
  123. * where components are added
  124. * @param numberOfComponents
  125. * to add
  126. */
  127. private void fillLayout(Layout layout, int numberOfComponents) {
  128. for (int i = 1; i <= numberOfComponents; i++) {
  129. layout.addComponent(getExampleComponent(Integer.toString(i)));
  130. }
  131. }
  132. }