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.

DefaultAlignmentTest.java 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.vaadin.tests.server.component.orderedlayout;
  2. import org.junit.Assert;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import com.vaadin.legacy.ui.LegacyTextField;
  6. import com.vaadin.ui.AbstractOrderedLayout;
  7. import com.vaadin.ui.Alignment;
  8. import com.vaadin.ui.HorizontalLayout;
  9. import com.vaadin.ui.Label;
  10. import com.vaadin.ui.VerticalLayout;
  11. public class DefaultAlignmentTest {
  12. private VerticalLayout verticalLayout;
  13. private HorizontalLayout horizontalLayout;
  14. @Before
  15. public void setup() {
  16. verticalLayout = new VerticalLayout();
  17. horizontalLayout = new HorizontalLayout();
  18. }
  19. @Test
  20. public void testDefaultAlignmentVerticalLayout() {
  21. testDefaultAlignment(verticalLayout);
  22. }
  23. @Test
  24. public void testDefaultAlignmentHorizontalLayout() {
  25. testDefaultAlignment(horizontalLayout);
  26. }
  27. public void testDefaultAlignment(AbstractOrderedLayout layout) {
  28. Label label = new Label("A label");
  29. LegacyTextField tf = new LegacyTextField("A TextField");
  30. layout.addComponent(label);
  31. layout.addComponent(tf);
  32. Assert.assertEquals(Alignment.TOP_LEFT,
  33. layout.getComponentAlignment(label));
  34. Assert.assertEquals(Alignment.TOP_LEFT,
  35. layout.getComponentAlignment(tf));
  36. }
  37. @Test
  38. public void testAlteredDefaultAlignmentVerticalLayout() {
  39. testAlteredDefaultAlignment(verticalLayout);
  40. }
  41. @Test
  42. public void testAlteredDefaultAlignmentHorizontalLayout() {
  43. testAlteredDefaultAlignment(horizontalLayout);
  44. }
  45. public void testAlteredDefaultAlignment(AbstractOrderedLayout layout) {
  46. Label label = new Label("A label");
  47. LegacyTextField tf = new LegacyTextField("A TextField");
  48. layout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
  49. layout.addComponent(label);
  50. layout.addComponent(tf);
  51. Assert.assertEquals(Alignment.MIDDLE_CENTER,
  52. layout.getComponentAlignment(label));
  53. Assert.assertEquals(Alignment.MIDDLE_CENTER,
  54. layout.getComponentAlignment(tf));
  55. }
  56. }