org.lunifera.christmastree.control.MobileControlComponent.java Source code

Java tutorial

Introduction

Here is the source code for org.lunifera.christmastree.control.MobileControlComponent.java

Source

package org.lunifera.christmastree.control;

import com.vaadin.server.ThemeResource;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.Image;
import com.vaadin.ui.Label;
import com.vaadin.ui.PopupView;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
public class MobileControlComponent extends AbstractControllerComponent {

    /**
     * The constructor should first build the main layout, set the composition
     * root and then do any custom initialization.
     * 
     * The constructor will not be automatically regenerated by the visual
     * editor.
     */
    public MobileControlComponent(CommandDelegate delegate) {
        super();
        this.delegate = delegate;
        buildMainLayout();
        setCompositionRoot(mainLayout);
    }

    protected AbsoluteLayout buildMainLayout() {
        // common part: create layout
        mainLayout = new AbsoluteLayout();
        mainLayout.setImmediate(false);
        mainLayout.setWidth("1280px");
        mainLayout.setHeight("720px");

        // top-level component properties
        setWidth("100.0%");
        setHeight("100.0%");

        // title area
        ThemeResource resource = new ThemeResource("images/Title.png");
        Image title = new Image(" ", resource);
        title.setHeight("54px");
        title.setWidth("413px");
        mainLayout.addComponent(title, "top:11.0px;left:60.0px");

        Label image = new Label();
        image.setHeight("340px");
        image.setWidth("600px");
        image.setValue("<div style=\"overflow:hidden; width: 320px; height: 600px; margin-left: -60px;\">"
                + "<img src=\"http://192.168.0.108:8081\"/>" + "</div>");
        image.setContentMode(ContentMode.HTML);
        mainLayout.addComponent(image, "top:70.0px;left:125px;");

        // Image image = new Image();
        // image.setHeight("240px");
        // image.setWidth("320px");
        // image.setSource(new
        // ExternalResource("http://192.168.0.108:8081/stream",
        // "video/x-motion-jpeg"));
        // mainLayout.addComponent(image, "top:70.0px;left:50.0px;");

        VerticalLayout vl = new VerticalLayout();
        //      vl.setHeight("250px");
        vl.setWidth("200px");
        vl.setSpacing(true);

        mainLayout.addComponent(vl, "top:180.0px;left:535.0px;");
        contentLayout = buildContent();
        vl.addComponent(contentLayout);
        vl.setExpandRatio(contentLayout, 1.0f);

        // licenses
        PopupView licenseLink = new PopupView("Attributions",
                new Label("<div><i>Monitor/tablet/smartphone</i> and <i>tree</i> icons </br> made by "
                        + "<a href=\"http://www.freepik.com\" title=\"Freepik\">Freepik</a> "
                        + "from <a href=\"http://www.flaticon.com\" title=\"Flaticon\">www.flaticon.com</a> </br>"
                        + "is licensed under <a href=\"http://creativecommons.org/licenses/by/3.0/\" "
                        + "title=\"Creative Commons BY 3.0\">CC BY 3.0</a></div>", ContentMode.HTML));
        licenseLink.setPrimaryStyleName("attributions");
        vl.addComponent(licenseLink);

        return mainLayout;
    }

    @SuppressWarnings("deprecation")
    protected GridLayout buildContent() {
        // common part: create layout
        contentLayout = new GridLayout();
        contentLayout.setImmediate(false);
        contentLayout.setMargin(false);
        contentLayout.setSpacing(true);
        contentLayout.setColumns(2);
        contentLayout.setRows(5);

        // button_off
        button_off = new Embedded("Off", new ThemeResource("./images/off.png"));
        button_off.setImmediate(true);
        button_off.setWidth("-1px");
        button_off.setHeight("-1px");
        button_off.addClickListener(listener);
        button_off.setStyleName("xmas-button-off");
        contentLayout.addComponent(button_off, 0, 0);
        contentLayout.setComponentAlignment(button_off, Alignment.MIDDLE_LEFT);

        // button_on
        button_on = new Embedded("On", new ThemeResource("./images/on.png"));
        button_on.setImmediate(true);
        button_on.setWidth("-1px");
        button_on.setHeight("-1px");
        button_on.addListener(listener);
        button_on.setStyleName("xmas-button-on");
        contentLayout.addComponent(button_on, 1, 0);
        contentLayout.setComponentAlignment(button_on, Alignment.MIDDLE_RIGHT);

        // button_red
        button_red = new Embedded(null, new ThemeResource("./images/red.png"));
        button_red.setCaption("Red");
        button_red.setImmediate(true);
        button_red.setWidth("-1px");
        button_red.setHeight("-1px");
        button_red.addListener(listener);
        button_red.setStyleName("xmas-button-red");
        contentLayout.addComponent(button_red, 0, 1);
        contentLayout.setComponentAlignment(button_red, Alignment.MIDDLE_LEFT);

        // button_blue
        button_blue = new Embedded(null, new ThemeResource("./images/blue.png"));
        button_blue.setCaption("Blue");
        button_blue.setImmediate(true);
        button_blue.setWidth("-1px");
        button_blue.setHeight("-1px");
        button_blue.setStyleName("xmas-button-blue");
        button_blue.addListener(listener);
        contentLayout.addComponent(button_blue, 1, 1);
        contentLayout.setComponentAlignment(button_blue, Alignment.MIDDLE_RIGHT);

        // button_flash
        button_flash = new Embedded(null, new ThemeResource("./images/flash.png"));
        button_flash.setCaption("Flash");
        button_flash.setImmediate(true);
        button_flash.setWidth("-1px");
        button_flash.setHeight("-1px");
        button_flash.addListener(listener);
        button_flash.setStyleName("xmas-button-flash");
        contentLayout.addComponent(button_flash, 0, 2);
        contentLayout.setComponentAlignment(button_flash, Alignment.MIDDLE_LEFT);

        // button_strobe
        button_strobe = new Embedded(null, new ThemeResource("./images/strobe.png"));
        button_strobe.setCaption("Strobo");
        button_strobe.setImmediate(true);
        button_strobe.setWidth("-1px");
        button_strobe.setHeight("-1px");
        button_strobe.addListener(listener);
        button_strobe.setStyleName("xmas-button-strobe");
        contentLayout.addComponent(button_strobe, 1, 2);
        contentLayout.setComponentAlignment(button_strobe, Alignment.MIDDLE_RIGHT);

        // button_snow
        button_snow = new Embedded(null, new ThemeResource("./images/snowflake.png"));
        button_snow.setCaption("Let it snow");
        button_snow.setImmediate(true);
        button_snow.setWidth("-1px");
        button_snow.setHeight("-1px");
        button_snow.addListener(listener);
        button_snow.setStyleName("xmas-button-snow");
        contentLayout.addComponent(button_snow, 0, 3);
        contentLayout.setComponentAlignment(button_snow, Alignment.MIDDLE_LEFT);

        // button_angel
        button_angel = new Embedded(null, new ThemeResource("./images/angel.png"));
        button_angel.setCaption("Angel");
        button_angel.setImmediate(true);
        button_angel.setWidth("-1px");
        button_angel.setHeight("-1px");
        button_angel.addListener(listener);
        button_angel.setStyleName("xmas-button-angel");
        contentLayout.addComponent(button_angel, 1, 3);
        contentLayout.setComponentAlignment(button_angel, Alignment.MIDDLE_RIGHT);

        // button_star
        button_star = new Embedded(null, new ThemeResource("./images/star.png"));
        button_star.setCaption("Star");
        button_star.setImmediate(true);
        button_star.setWidth("-1px");
        button_star.setHeight("-1px");
        button_star.addListener(listener);
        button_star.setStyleName("xmas-button-star");
        contentLayout.addComponent(button_star, 0, 4);
        contentLayout.setComponentAlignment(button_star, Alignment.MIDDLE_LEFT);

        return contentLayout;
    }

}