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.

ScrollCursor.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package com.vaadin.tests.components.textarea;
  2. import com.vaadin.tests.components.TestBase;
  3. import com.vaadin.ui.Button;
  4. import com.vaadin.ui.Button.ClickEvent;
  5. import com.vaadin.ui.Button.ClickListener;
  6. import com.vaadin.ui.TextArea;
  7. /**
  8. * @author denis
  9. *
  10. */
  11. public class ScrollCursor extends TestBase {
  12. private TextArea textArea;
  13. private int position;
  14. @Override
  15. protected void setup() {
  16. textArea = new TextArea();
  17. textArea.setValue("saddddddddddd fdgdfgfdgfd\n" + "aasddddddddddd\n"
  18. + "dsaffffffdsf\n" + "sdf\n" + "dsfsdfsdfsdfsd\n\n"
  19. + "ffffffffffffffffffff\n"
  20. + "sdfdsfdsfsdfsdfsd xxxxxxxxxxxxxxxx\n" + "sdgfsd\n" + "dsf\n"
  21. + "ds\n" + "fds\n" + "fds\nfs");
  22. addComponent(textArea);
  23. Button button = new Button("Scroll");
  24. button.addClickListener(new ClickListener() {
  25. @Override
  26. public void buttonClick(ClickEvent event) {
  27. textArea.setCursorPosition(getPosition());
  28. }
  29. });
  30. Button wrap = new Button("Set wrap");
  31. wrap.addClickListener(new ClickListener() {
  32. @Override
  33. public void buttonClick(ClickEvent event) {
  34. textArea.setWordWrap(false);
  35. }
  36. });
  37. Button toBegin = new Button("To begin");
  38. toBegin.addClickListener(new ClickListener() {
  39. @Override
  40. public void buttonClick(ClickEvent event) {
  41. position = 3;
  42. }
  43. });
  44. Button toMiddle = new Button("To middle");
  45. toMiddle.addClickListener(new ClickListener() {
  46. @Override
  47. public void buttonClick(ClickEvent event) {
  48. position = 130;
  49. }
  50. });
  51. Button toEnd = new Button("To end");
  52. toEnd.addClickListener(new ClickListener() {
  53. @Override
  54. public void buttonClick(ClickEvent event) {
  55. position = textArea.getValue().length();
  56. }
  57. });
  58. addComponent(button);
  59. addComponent(wrap);
  60. addComponent(toBegin);
  61. addComponent(toMiddle);
  62. addComponent(toEnd);
  63. }
  64. @Override
  65. protected String getDescription() {
  66. return "Tests scrolling for TextArea with different word wrapping settings. "
  67. + "Sets cursor position at the beginning, middle and the end "
  68. + "of text and checks textarea is scrolled.";
  69. }
  70. @Override
  71. protected Integer getTicketNumber() {
  72. return 8769;
  73. }
  74. private int getPosition() {
  75. return position;
  76. }
  77. }