aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/tickets/Ticket1572.java
blob: a511bae6d952cad20cf987f7691fe96f23a8f8ca (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package com.vaadin.tests.tickets;

import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.UI.LegacyWindow;

public class Ticket1572 extends com.vaadin.Application.LegacyApplication {

    private Label state;
    private GridLayout gl;
    private Label spacingstate;

    @Override
    public void init() {

        final LegacyWindow main = new LegacyWindow(getClass().getName()
                .substring(getClass().getName().lastIndexOf(".") + 1));
        setMainWindow(main);

        Panel p = new Panel("Test wrapper for gridlayout margin/spacing");

        p.setContent(new HorizontalLayout());

        gl = new GridLayout(3, 3);
        gl.setMargin(true);
        for (int i = 0; i < 3 * 3; i++) {
            gl.addComponent(new Button("test"));
        }
        p.addComponent(gl);
        p.addComponent(new Label("| next component"));

        Button b = new Button("next margin state");
        b.addListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                nextMarginState();
            }

        });

        state = new Label();
        state.setCaption("Current margin state:");
        main.addComponent(state);
        main.addComponent(b);

        Button b2 = new Button("next spacing state");
        b2.addListener(new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                nextSpacingState();
            }

        });

        spacingstate = new Label();
        spacingstate.setCaption("Current Spacing State:");
        main.addComponent(spacingstate);
        main.addComponent(b2);

        main.addComponent(p);

        nextMarginState();
        nextSpacingState();

    }

    private int stateCounter = -1;

    private void nextMarginState() {
        stateCounter++;
        switch (stateCounter) {
        case 0:
            gl.setMargin(false);
            state.setValue("Margin off");
            break;
        case 1:
            gl.setMargin(true);
            state.setValue("Margin on");
            break;
        case 2:
            gl.setMargin(new MarginInfo(true, false, false, false));
            state.setValue("Margin top");
            break;
        case 3:
            gl.setMargin(new MarginInfo(false, true, false, false));
            state.setValue("Margin right");
            break;
        case 4:
            gl.setMargin(new MarginInfo(false, false, true, false));
            state.setValue("Margin bottom");
            break;
        case 5:
            gl.setMargin(new MarginInfo(false, false, false, true));
            state.setValue("Margin left");
            break;
        default:
            stateCounter = -1;
            nextMarginState();
            break;
        }
    }

    private boolean spacing = true;

    private void nextSpacingState() {
        spacing = !spacing;
        if (spacing) {
            gl.setSpacing(true);
            spacingstate.setValue("Spacing on");
        } else {
            gl.setSpacing(false);
            spacingstate.setValue("Spacing off");
        }
    }

}