aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/textarea/ScrollCursor.java
blob: 154a30a64b09594a6c5b3cbe6a96fbfdd81fc087 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.vaadin.tests.components.textarea;

import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.TextArea;

/**
 * @author denis
 * 
 */
public class ScrollCursor extends TestBase {

    private TextArea textArea;
    private int position;

    @Override
    protected void setup() {
        textArea = new TextArea();
        textArea.setValue("saddddddddddd     fdgdfgfdgfd\n"
                + "aasddddddddddd\n" + "dsaffffffdsf\n" + "sdf\n"
                + "dsfsdfsdfsdfsd\n\n" + "ffffffffffffffffffff\n"
                + "sdfdsfdsfsdfsdfsd  xxxxxxxxxxxxxxxx\n" + "sdgfsd\n"
                + "dsf\n" + "ds\n" + "fds\n" + "fds\nfs");
        addComponent(textArea);
        Button button = new Button("Scroll");
        button.addListener(new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                textArea.setCursorPosition(getPosition());
            }
        });
        Button wrap = new Button("Set wrap");
        wrap.addListener(new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                textArea.setWordwrap(false);
            }
        });

        Button toBegin = new Button("To begin");
        toBegin.addListener(new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                position = 3;
            }
        });

        Button toMiddle = new Button("To middle");
        toMiddle.addListener(new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                position = 130;
            }
        });

        Button toEnd = new Button("To end");
        toEnd.addListener(new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                position = textArea.getValue().toString().length();
            }
        });

        addComponent(button);
        addComponent(wrap);
        addComponent(toBegin);
        addComponent(toMiddle);
        addComponent(toEnd);
    }

    @Override
    protected String getDescription() {
        return "Tests scrolling for TextArea with different word wrapping settings. "
                + "Sets cursor position at the beginning, middle and the end "
                + "of text and checks textarea is scrolled.";
    }

    @Override
    protected Integer getTicketNumber() {
        return 8769;
    }

    private int getPosition() {
        return position;
    }

}