summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/tests/tickets/Ticket1921.java
blob: 8dae844b75ecd2e0fdeb8b0c5c13e646a0239c96 (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
122
123
124
125
126
127
128
129
130
package com.vaadin.tests.tickets;

import java.util.Map;

import com.vaadin.Application;
import com.vaadin.terminal.ParameterHandler;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.OrderedLayout;
import com.vaadin.ui.Window;

public class Ticket1921 extends Application implements ParameterHandler {

    int state = -1;
    int round = 1;
    Button button;
    OrderedLayout outer, inner;

    @Override
    public void init() {

        outer = new OrderedLayout();
        setMainWindow(new Window("#1921", outer));
        setTheme("tests-tickets");
        inner = new OrderedLayout();
        outer.addComponent(inner);
        button = new Button("foo", this, "newState");
        inner.addComponent(button);

        outer.setStyleName("red");
        inner.setStyleName("blue");

        newState();

        getMainWindow().addParameterHandler(this);
    }

    public void newState() {

        if (state >= 8) {
            state = 0;
            round++;
        } else {
            state++;
        }

        button.setCaption("state " + round + "." + state);

        switch (state) {

        case 0:
            outer.setMargin(true);
            inner.setMargin(true);
            inner.setSizeFull();
            outer.setSizeFull();
            button.setSizeFull();
            break;

        case 1:
            button.setSizeUndefined();
            break;

        case 2:
            inner.setMargin(false);
            break;

        case 3:
            outer.setMargin(false);
            break;

        case 4:
            inner.setMargin(true);
            break;

        case 5:
            inner.addComponent(new Label("Added at " + button.getCaption()));
            break;

        case 6:
            inner
                    .setOrientation(inner.getOrientation() == OrderedLayout.ORIENTATION_HORIZONTAL ? OrderedLayout.ORIENTATION_VERTICAL
                            : OrderedLayout.ORIENTATION_HORIZONTAL);
            getMainWindow()
                    .showNotification(
                            "inner swithed to "
                                    + (inner.getOrientation() == OrderedLayout.ORIENTATION_HORIZONTAL ? "horizontal"
                                            : "vertical"));
            break;

        case 7:
            outer.addComponent(new Label("Added at " + button.getCaption()));
            break;

        case 8:
            outer
                    .setOrientation(outer.getOrientation() == OrderedLayout.ORIENTATION_HORIZONTAL ? OrderedLayout.ORIENTATION_VERTICAL
                            : OrderedLayout.ORIENTATION_HORIZONTAL);
            getMainWindow()
                    .showNotification(
                            "outer swithed to "
                                    + (outer.getOrientation() == OrderedLayout.ORIENTATION_HORIZONTAL ? "horizontal"
                                            : "vertical"));
            break;
        }
    }

    public void handleParameters(Map parameters) {
        String[] s = (String[]) parameters.get("state");
        if (s == null || s.length != 1) {
            return;
        }
        String v[] = s[0].split("\\.");
        if (v == null || v.length != 2) {
            return;
        }
        try {
            int rr = Integer.parseInt(v[0]);
            int rs = Integer.parseInt(v[1]);
            if (rr < round || (rr == round && rs < state)) {
                getMainWindow().showNotification(
                        "Already past requested " + s[0]);
                return;
            }
            while (round < rr || state < rs) {
                newState();
            }
        } catch (NumberFormatException ignored) {
        }
    }
}