summaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/automatedtests/featurebrowser/ValueInputExample.java
blob: 23ecc77b8c8392b065b88e053cb8c0104585e724 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* 
@ITMillApache2LicenseForJavaFiles@
 */

package com.itmill.toolkit.automatedtests.featurebrowser;

import java.util.Date;

import com.itmill.toolkit.data.Property.ValueChangeEvent;
import com.itmill.toolkit.ui.CustomComponent;
import com.itmill.toolkit.ui.DateField;
import com.itmill.toolkit.ui.Field;
import com.itmill.toolkit.ui.HorizontalLayout;
import com.itmill.toolkit.ui.InlineDateField;
import com.itmill.toolkit.ui.Panel;
import com.itmill.toolkit.ui.Slider;
import com.itmill.toolkit.ui.TextField;
import com.itmill.toolkit.ui.VerticalLayout;
import com.itmill.toolkit.ui.Window.Notification;

/**
 * Shows some basic fields for value input; TextField, DateField, Slider...
 * 
 * @author IT Mill Ltd.
 */
public class ValueInputExample extends CustomComponent {

    @SuppressWarnings("deprecation")
    public ValueInputExample() {
        final VerticalLayout main = new VerticalLayout();
        main.setMargin(true);
        setCompositionRoot(main);

        // listener that shows a value change notification
        final Field.ValueChangeListener listener = new Field.ValueChangeListener() {
            public void valueChange(ValueChangeEvent event) {
                getWindow().showNotification("Received",
                        "<pre>" + event.getProperty().getValue() + "</pre>",
                        Notification.TYPE_WARNING_MESSAGE);
            }
        };

        // TextField
        HorizontalLayout horiz = new HorizontalLayout();
        horiz.setWidth("100%");
        main.addComponent(horiz);
        Panel left = new Panel("TextField");
        left.setStyleName(Panel.STYLE_LIGHT);
        horiz.addComponent(left);
        Panel right = new Panel("multiline");
        right.setStyleName(Panel.STYLE_LIGHT);
        horiz.addComponent(right);
        // basic TextField
        TextField tf = new TextField("Basic");
        tf.setDebugId("BasicTextField");
        tf.setColumns(15);
        tf.setImmediate(true);
        tf.addListener(listener);
        left.addComponent(tf);
        // multiline TextField a.k.a TextArea
        tf = new TextField("Area");
        tf.setDebugId("AreaTextField");
        tf.setColumns(15);
        tf.setRows(5);
        tf.setImmediate(true);
        tf.addListener(listener);
        right.addComponent(tf);

        // DateFields
        Date d = new Date(98, 1, 22, 13, 14, 15);
        horiz = new HorizontalLayout();
        horiz.setWidth("100%");
        main.addComponent(horiz);
        left = new Panel("DateField");
        left.setStyleName(Panel.STYLE_LIGHT);
        horiz.addComponent(left);
        right = new Panel("inline");
        right.setStyleName(Panel.STYLE_LIGHT);
        horiz.addComponent(right);
        // default
        DateField df = new DateField("Day resolution");
        df.setDebugId("DayResolutionDateField");
        df.setValue(d);
        df.addListener(listener);
        df.setImmediate(true);
        df.setResolution(DateField.RESOLUTION_DAY);
        left.addComponent(df);
        // minute
        df = new DateField("Minute resolution");
        df.setValue(d);
        df.setDebugId("MinuteResolutionDateField");
        df.addListener(listener);
        df.setImmediate(true);
        df.setResolution(DateField.RESOLUTION_MIN);
        left.addComponent(df);
        // year
        df = new DateField("Year resolution");
        df.setValue(d);
        df.setDebugId("YearResolutionDateField");
        df.addListener(listener);
        df.setImmediate(true);
        df.setResolution(DateField.RESOLUTION_YEAR);
        left.addComponent(df);
        // msec
        df = new DateField("Millisecond resolution");
        df.setValue(d);
        df.setDebugId("MillisecondResolutionDateField");
        df.addListener(listener);
        df.setImmediate(true);
        df.setResolution(DateField.RESOLUTION_MSEC);
        left.addComponent(df);
        // Inline
        df = new InlineDateField();
        df.setValue(d);
        df.setDebugId("InlineDateField");
        df.addListener(listener);
        df.setImmediate(true);
        right.addComponent(df);

        // Slider
        left = new Panel("Slider");
        left.setStyleName(Panel.STYLE_LIGHT);
        main.addComponent(left);
        // int slider
        Slider slider = new Slider(0, 100);
        slider.setDebugId("Slider1");
        slider.setWidth("300px");
        slider.setImmediate(true);
        slider.addListener(new Slider.ValueChangeListener() {
            public void valueChange(ValueChangeEvent event) {
                // update caption when value changes
                final Slider s = (Slider) event.getProperty();
                s.setCaption("Value: " + s.getValue());
            }
        });
        try {
            slider.setValue(20);
        } catch (final Exception e) {
            e.printStackTrace(System.err);
        }
        left.addComponent(slider);
        // double slider
        slider = new Slider(0.0, 1.0, 1);
        slider.setOrientation(Slider.ORIENTATION_VERTICAL);
        slider.setDebugId("Slider2");
        slider.setImmediate(true);
        slider.addListener(new Slider.ValueChangeListener() {
            public void valueChange(ValueChangeEvent event) {
                // update caption when value changes
                final Slider s = (Slider) event.getProperty();
                s.setCaption("Value: " + s.getValue());
            }
        });
        try {
            slider.setValue(0.5);
        } catch (final Exception e) {
            e.printStackTrace(System.err);
        }
        left.addComponent(slider);

    }

}