summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/tests/featurebrowser/IntroWelcome.java
blob: cffb4c79944964d9b91ba194d585dcc43102cbe1 (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
164
165
166
167
168
169
170
171
172
173
174
/* 
@ITMillApache2LicenseForJavaFiles@
 */

package com.vaadin.tests.featurebrowser;

import java.net.URL;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;

import com.vaadin.terminal.DownloadStream;
import com.vaadin.terminal.ParameterHandler;
import com.vaadin.terminal.URIHandler;
import com.vaadin.terminal.gwt.server.ApplicationServlet;
import com.vaadin.ui.Component;
import com.vaadin.ui.Form;
import com.vaadin.ui.Label;
import com.vaadin.ui.OrderedLayout;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Select;

public class IntroWelcome extends Feature implements URIHandler,
        ParameterHandler {

    Panel panel = new Panel();

    private static final String WELCOME_TEXT_UPPER = ""
            + "This application lets you view and play with some features of "
            + "Vaadin. Use menu on the left to select component."
            + "<br /><br />Note the <b>Properties selection</b> on the top "
            + "right corner. Click it open to access component properties and"
            + " feel free to edit properties at any time."
            + "<br /><br />The area that you are now reading is the component"
            + " demo area. Lower area from here contains component description, API"
            + " documentation and optional code sample. Note that not all selections"
            + " contain demo, only description and API documentation is shown."
            + "<br /><br />You may also change application's theme from below the menu."
            + " This example application is designed to work best with"
            + " <em>Demo</em> theme, other themes are for demonstration purposes only."
            + "<br /><br />Vaadin enables you to construct complex Web"
            + " applications using plain Java, no knowledge of other Web technologies"
            + " such as XML, HTML, DOM, JavaScript or browser differences is required."
            + "<br /><br />For more information, point your browser to"
            + " <a href=\"http://www.vaadin.com\" target=\"_new\">www.vaadin.com</a>.";

    private static final String WELCOME_TEXT_LOWER = ""
            + "This area contains the selected component's description, list of properties, javadoc"
            + " and optional code sample. "
            + "Start your tour now by selecting features from the list"
            + " on the left and remember to experiment with the <b>Properties panel</b>"
            + " located at the top right corner area.";

    // TODO Add browser agent string
    private final String description = WELCOME_TEXT_LOWER
            + "<br /><br />Vaadin Toolkit version: "
            + ApplicationServlet.VERSION;

    public IntroWelcome() {
        super();
    }

    @Override
    protected Component getDemoComponent() {

        final OrderedLayout l = new OrderedLayout();

        panel.setCaption("Welcome to the Vaadin feature tour!");
        l.addComponent(panel);

        final Label label = new Label();
        panel.addComponent(label);

        label.setContentMode(Label.CONTENT_XHTML);
        label.setValue(WELCOME_TEXT_UPPER);

        propertyPanel = new PropertyPanel(panel);
        final Form ap = propertyPanel.createBeanPropertySet(new String[] {
                "width", "height" });
        final Select themes = (Select) propertyPanel.getField("style");
        themes.addItem("light").getItemProperty(
                themes.getItemCaptionPropertyId()).setValue("light");
        themes.addItem("strong").getItemProperty(
                themes.getItemCaptionPropertyId()).setValue("strong");
        propertyPanel.addProperties("Panel Properties", ap);

        setJavadocURL("package-summary.html");

        setPropsReminder(false);

        return l;
    }

    @Override
    protected String getExampleSrc() {
        return "" + "package com.vaadin.demo;\n"
                + "import com.vaadin.ui.*;\n\n"
                + "public class HelloWorld extends com.vaadin.Application {\n"
                + "    public void init() {\n"
                + "        Window main = new Window(\"Hello window\");\n"
                + "        setMainWindow(main);\n"
                + "        main.addComponent(new Label(\"Hello World!\"));\n"
                + "    }\n" + "}\n";
    }

    // not ready yet to give description, see paint instead
    @Override
    protected String getDescriptionXHTML() {
        return description;
    }

    @Override
    protected String getImage() {
        return "icon_intro.png";
    }

    @Override
    protected String getTitle() {
        return "Welcome";
    }

    /**
     * Add URI and parametes handlers to window.
     * 
     * @see com.vaadin.ui.Component#attach()
     */
    @Override
    public void attach() {
        super.attach();
        getWindow().addURIHandler(this);
        getWindow().addParameterHandler(this);
    }

    /**
     * Remove all handlers from window
     * 
     * @see com.vaadin.ui.Component#detach()
     */
    @Override
    public void detach() {
        super.detach();
        getWindow().removeURIHandler(this);
        getWindow().removeParameterHandler(this);
    }

    /**
     * Update URI
     * 
     * @see com.vaadin.terminal.URIHandler#handleURI(URL, String)
     */
    public DownloadStream handleURI(URL context, String relativeUri) {
        return null;
    }

    /**
     * Show system status if systemStatus is given on URL
     * 
     * @see com.vaadin.terminal.ParameterHandler#handleParameters(Map)
     */
    public void handleParameters(Map parameters) {
        for (final Iterator i = parameters.keySet().iterator(); i.hasNext();) {
            final String name = (String) i.next();
            if (name.equals("systemStatus")) {
                String status = "";
                status += "timestamp=" + new Date() + " ";
                status += "free=" + Runtime.getRuntime().freeMemory() + ", ";
                status += "total=" + Runtime.getRuntime().totalMemory() + ", ";
                status += "max=" + Runtime.getRuntime().maxMemory() + "\n";
                System.out.println(status);
            }
        }
    }

}