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.

SplitPositionChange.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.splitpanel;
  17. import com.vaadin.server.VaadinRequest;
  18. import com.vaadin.tests.components.AbstractTestUIWithLog;
  19. import com.vaadin.ui.AbstractSplitPanel;
  20. import com.vaadin.ui.HorizontalSplitPanel;
  21. import com.vaadin.ui.Label;
  22. import com.vaadin.ui.Panel;
  23. import com.vaadin.ui.VerticalLayout;
  24. import com.vaadin.ui.VerticalSplitPanel;
  25. /**
  26. * Test for {@link SplitPositionChangeListeners}.
  27. *
  28. * @author Vaadin Ltd
  29. */
  30. public class SplitPositionChange extends AbstractTestUIWithLog {
  31. @Override
  32. protected void setup(VaadinRequest request) {
  33. addSplitPanel(true, "Left", "Right");
  34. addSplitPanel(false, "Top", "Bottom");
  35. }
  36. private void addSplitPanel(final boolean horizontal, String firstCaption,
  37. String secondCaption) {
  38. AbstractSplitPanel splitPanel;
  39. if (horizontal) {
  40. splitPanel = new HorizontalSplitPanel();
  41. } else {
  42. splitPanel = new VerticalSplitPanel();
  43. }
  44. splitPanel.setWidth("200px");
  45. splitPanel.setHeight("200px");
  46. splitPanel.addComponent(buildPanel(firstCaption));
  47. splitPanel.addComponent(buildPanel(secondCaption));
  48. splitPanel
  49. .addSplitPositionChangeListener(new AbstractSplitPanel.SplitPositionChangeListener() {
  50. @Override
  51. public void onSplitPositionChanged(
  52. AbstractSplitPanel.SplitPositionChangeEvent event) {
  53. log(String.format(
  54. "Split position changed: %s, position: %s %s",
  55. (horizontal ? "horizontal" : "vertical"),
  56. event.getSplitPosition(),
  57. event.getSplitPositionUnit()));
  58. }
  59. });
  60. addComponent(splitPanel);
  61. }
  62. private Panel buildPanel(String caption) {
  63. VerticalLayout pl = new VerticalLayout();
  64. pl.setMargin(true);
  65. pl.addComponent(new Label("content"));
  66. Panel panel = new Panel(caption, pl);
  67. panel.setSizeFull();
  68. return panel;
  69. }
  70. @Override
  71. protected String getTestDescription() {
  72. return "SplitPanel should have an event for the splitter being moved";
  73. }
  74. @Override
  75. protected Integer getTicketNumber() {
  76. return 3855;
  77. }
  78. }