summaryrefslogtreecommitdiffstats
path: root/vaadin-app/src/ch/asynk/helloworld/LayoutLayout.java
blob: 6ebb1e386905ed9b3ed8fbe9982ea505e6f6df02 (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
package ch.asynk.helloworld;

import com.vaadin.ui.Alignment;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Label;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.ListSelect;

public class LayoutLayout extends VerticalLayout {
    //
    private static final long serialVersionUID = 1L;
    //
    private Context ctx = null;

    public LayoutLayout(Context context) {
        ctx = context;
        //
        final AbstractComponent topComponent = buildTopComponent();
        topComponent.setWidth(500,UNITS_PIXELS);
        topComponent.setHeight(400,UNITS_PIXELS);
        addComponent(topComponent);
        setComponentAlignment(topComponent, Alignment.MIDDLE_CENTER);
        //
        final AbstractComponent grid = buildGrid();
        grid.setSizeFull();
        addComponent(grid);
        //
        Button nextButton = new Button("next layout");
        nextButton.setDescription("Go to next layout");
        addComponent(nextButton );
        nextButton.addListener( new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                getApplication().getMainWindow().setContent( new EndLayout(ctx) );
            }
        });
    }

    private AbstractComponent buildTopComponent() {

        Panel panel = new Panel("Panel 1");
        VerticalLayout layout = (VerticalLayout) panel.getContent();
        layout.setMargin(true);
        layout.setSpacing(true);
        layout.setHeight(100,UNITS_PERCENTAGE);
        //
        float width  = 90;
        float height = 100;
        //
        ListSelect receptionList = new ListSelect("List 1");
        receptionList.setWidth(width, UNITS_PERCENTAGE);
        receptionList.setHeight(height, UNITS_PERCENTAGE);
        layout.addComponent(receptionList);
        //
        ListSelect splitList = new ListSelect("List 2");
        splitList.setWidth(width, UNITS_PERCENTAGE);
        splitList.setHeight(height, UNITS_PERCENTAGE);
        layout.addComponent(splitList);
        //
        ListSelect ctrlList = new ListSelect("Liste 3");
        ctrlList.setWidth(width, UNITS_PERCENTAGE);
        ctrlList.setHeight(height, UNITS_PERCENTAGE);
        layout.addComponent(ctrlList);
        //
        Button goButton = new Button("Select");
        goButton.setHeight(height, UNITS_PERCENTAGE);
        layout.addComponent(goButton);
        //
        layout.setExpandRatio(receptionList,3.0f);
        layout.setExpandRatio(splitList,3.0f);
        layout.setExpandRatio(ctrlList,3.0f);
        layout.setExpandRatio(goButton,1.0f);
        layout.setComponentAlignment(goButton, Alignment.MIDDLE_CENTER);
        //
        return panel;
    }

    private AbstractComponent buildGrid() {
        Panel panel = new Panel("Grid Panel");
        VerticalLayout layout = (VerticalLayout) panel.getContent();
        layout.setMargin(true);
        layout.setSpacing(true);
        layout.setHeight(100,UNITS_PERCENTAGE);
        //
        GridLayout grid = new GridLayout(3, 3);
        grid.setSizeFull();
        grid.addStyleName("mygrid");
        // excess space usage
        //grid.setColumnExpandRatio(1, 1);
        //grid.setColumnExpandRatio(2, 5);
        //grid.setRowExpandRatio(1, 1);
        Button b0 = new Button("[0;0] [0;2]");
        b0.setSizeFull();
        grid.addComponent(b0,0,0,0,2);
        final Panel p2 = new Panel("Panel 2");
        p2.setSizeFull();
        grid.addComponent(p2,1,0,2,1);
        Button b1 = new Button("[1;2] [2;2]");
        b1.setSizeFull();
        grid.addComponent(b1,1,2,2,2);
        panel.setContent(grid);
        //
        return panel;
    }
}