Example usage for com.vaadin.ui Image Image

List of usage examples for com.vaadin.ui Image Image

Introduction

In this page you can find the example usage for com.vaadin.ui Image Image.

Prototype

public Image(String caption, Resource source) 

Source Link

Document

Creates a new Image whose contents is loaded from given resource.

Usage

From source file:org.lunifera.christmastree.control.DesktopControlComponent.java

License:Creative Commons License

protected AbsoluteLayout buildMainLayout() {
    // common part: create layout
    mainLayout = new AbsoluteLayout();
    mainLayout.setImmediate(false);//ww  w. j  a  v a  2 s .c  om
    mainLayout.setWidth("100%");
    mainLayout.setHeight("100%");

    // 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("108px");
    title.setWidth("827px");
    mainLayout.addComponent(title, "top:22.0px;left:120.0px");

    VerticalLayout vl = new VerticalLayout();
    vl.setHeight("500px");
    vl.setWidth("400px");
    vl.setSpacing(true);
    mainLayout.addComponent(vl, "top:140.0px;left:100.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);

    Label image = new Label();
    image.setHeight("400px");
    image.setWidth("100%");
    // image.setValue("<div style=\"overflow:hidden; width: 400px;
    // margin-left: -60px;\">"
    // + "<img src=\"http://77.119.240.22:8081\"/>" + "</div>");
    image.setValue("<div style=\"overflow:hidden; width: 370px; margin-left: -60px;\">"
            + "<img src=\"http://192.168.0.108:8081\"/>" + "</div>");
    image.setContentMode(ContentMode.HTML);
    mainLayout.addComponent(image, "top:140.0px;left:600.0px;");

    return mainLayout;
}

From source file:org.lunifera.christmastree.control.MobileControlComponent.java

License:Creative Commons License

protected AbsoluteLayout buildMainLayout() {
    // common part: create layout
    mainLayout = new AbsoluteLayout();
    mainLayout.setImmediate(false);/*  www.  j av a 2s. c o  m*/
    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;
}

From source file:org.opencms.ui.components.CmsResourceTable.java

License:Open Source License

/**
 * Static helper method to initialize the 'standard' properties of a data item from a given resource.<p>
 * @param resourceItem the resource item to fill
 * @param cms the CMS context//from w  w w  . ja  v a2 s .c o  m
 * @param resource the resource
 * @param messages the message bundle
 * @param locale the locale
 */
public static void fillItemDefault(Item resourceItem, CmsObject cms, CmsResource resource, CmsMessages messages,
        Locale locale) {

    if (resource == null) {
        LOG.error("Error rendering item for 'null' resource");
        return;
    }

    if (resourceItem == null) {
        LOG.error("Error rendering 'null' item for resource " + resource.getRootPath());
        return;
    }
    if (cms == null) {
        cms = A_CmsUI.getCmsObject();
        LOG.warn("CmsObject was 'null', using thread local CmsObject");
    }
    CmsResourceUtil resUtil = new CmsResourceUtil(cms, resource);
    Map<String, CmsProperty> resourceProps = null;
    try {
        List<CmsProperty> props = cms.readPropertyObjects(resource, false);
        resourceProps = new HashMap<String, CmsProperty>();
        for (CmsProperty prop : props) {
            resourceProps.put(prop.getName(), prop);
        }
    } catch (CmsException e1) {
        LOG.debug("Unable to read properties for resource '" + resource.getRootPath() + "'.", e1);
    }
    I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(resource);
    if (resourceItem.getItemProperty(PROPERTY_TYPE_ICON) != null) {
        resourceItem.getItemProperty(PROPERTY_TYPE_ICON)
                .setValue(new CmsResourceIcon(resUtil, resource.getState(), true));
    }

    if (resourceItem.getItemProperty(PROPERTY_PROJECT) != null) {
        Image projectFlag = null;
        switch (resUtil.getProjectState().getMode()) {
        case 1:
            projectFlag = new Image(resUtil.getLockedInProjectName(),
                    new ThemeResource(OpenCmsTheme.PROJECT_CURRENT_PATH));
            break;
        case 2:
            projectFlag = new Image(resUtil.getLockedInProjectName(),
                    new ThemeResource(OpenCmsTheme.PROJECT_OTHER_PATH));
            break;
        case 5:
            projectFlag = new Image(resUtil.getLockedInProjectName(),
                    new ThemeResource(OpenCmsTheme.PROJECT_PUBLISH_PATH));
            break;
        default:
        }
        if (projectFlag != null) {
            projectFlag.setDescription(resUtil.getLockedInProjectName());
        }
        resourceItem.getItemProperty(PROPERTY_PROJECT).setValue(projectFlag);
    }

    if (resourceItem.getItemProperty(PROPERTY_INSIDE_PROJECT) != null) {
        resourceItem.getItemProperty(PROPERTY_INSIDE_PROJECT)
                .setValue(Boolean.valueOf(resUtil.isInsideProject()));
    }

    if (resourceItem.getItemProperty(PROPERTY_RELEASED_NOT_EXPIRED) != null) {
        resourceItem.getItemProperty(PROPERTY_RELEASED_NOT_EXPIRED)
                .setValue(Boolean.valueOf(resUtil.isReleasedAndNotExpired()));
    }

    if (resourceItem.getItemProperty(PROPERTY_RESOURCE_NAME) != null) {
        resourceItem.getItemProperty(PROPERTY_RESOURCE_NAME).setValue(resource.getName());
    }

    if (resourceItem.getItemProperty(PROPERTY_SITE_PATH) != null) {
        resourceItem.getItemProperty(PROPERTY_SITE_PATH).setValue(cms.getSitePath(resource));
    }

    if ((resourceItem.getItemProperty(PROPERTY_TITLE) != null) && (resourceProps != null)) {
        resourceItem.getItemProperty(PROPERTY_TITLE)
                .setValue(resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_TITLE)
                        ? resourceProps.get(CmsPropertyDefinition.PROPERTY_TITLE).getValue()
                        : "");
    }
    boolean inNavigation = false;
    if ((resourceItem.getItemProperty(PROPERTY_NAVIGATION_TEXT) != null) && (resourceProps != null)) {
        resourceItem.getItemProperty(PROPERTY_NAVIGATION_TEXT)
                .setValue(resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVTEXT)
                        ? resourceProps.get(CmsPropertyDefinition.PROPERTY_NAVTEXT).getValue()
                        : "");
        inNavigation = resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVTEXT);
    }

    if ((resourceItem.getItemProperty(PROPERTY_NAVIGATION_POSITION) != null) && (resourceProps != null)) {
        try {
            Float navPos = resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVPOS)
                    ? Float.valueOf(resourceProps.get(CmsPropertyDefinition.PROPERTY_NAVPOS).getValue())
                    : (inNavigation ? Float.valueOf(Float.MAX_VALUE) : null);
            resourceItem.getItemProperty(PROPERTY_NAVIGATION_POSITION).setValue(navPos);
            inNavigation = navPos != null;
        } catch (Exception e) {
            LOG.debug("Error evaluating navPos property", e);
        }
    }

    if (resourceItem.getItemProperty(PROPERTY_IN_NAVIGATION) != null) {
        if (inNavigation && (resourceProps != null)
                && resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_NAVINFO)
                && CmsClientSitemapEntry.HIDDEN_NAVIGATION_ENTRY
                        .equals(resourceProps.get(CmsPropertyDefinition.PROPERTY_NAVINFO).getValue())) {
            inNavigation = false;
        }
        resourceItem.getItemProperty(PROPERTY_IN_NAVIGATION).setValue(Boolean.valueOf(inNavigation));
    }

    if ((resourceItem.getItemProperty(PROPERTY_COPYRIGHT) != null) && (resourceProps != null)) {
        resourceItem.getItemProperty(PROPERTY_COPYRIGHT)
                .setValue(resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_COPYRIGHT)
                        ? resourceProps.get(CmsPropertyDefinition.PROPERTY_COPYRIGHT).getValue()
                        : "");
    }

    if ((resourceItem.getItemProperty(PROPERTY_CACHE) != null) && (resourceProps != null)) {
        resourceItem.getItemProperty(PROPERTY_CACHE)
                .setValue(resourceProps.containsKey(CmsPropertyDefinition.PROPERTY_CACHE)
                        ? resourceProps.get(CmsPropertyDefinition.PROPERTY_CACHE).getValue()
                        : "");
    }

    if (resourceItem.getItemProperty(PROPERTY_RESOURCE_TYPE) != null) {
        resourceItem.getItemProperty(PROPERTY_RESOURCE_TYPE)
                .setValue(CmsWorkplaceMessages.getResourceTypeName(locale, type.getTypeName()));
    }

    if (resourceItem.getItemProperty(PROPERTY_IS_FOLDER) != null) {
        resourceItem.getItemProperty(PROPERTY_IS_FOLDER).setValue(Boolean.valueOf(resource.isFolder()));
    }

    if (resourceItem.getItemProperty(PROPERTY_SIZE) != null) {
        if (resource.isFile()) {
            resourceItem.getItemProperty(PROPERTY_SIZE).setValue(Integer.valueOf(resource.getLength()));
        }
    }

    if (resourceItem.getItemProperty(PROPERTY_PERMISSIONS) != null) {
        resourceItem.getItemProperty(PROPERTY_PERMISSIONS).setValue(resUtil.getPermissionString());
    }

    if (resourceItem.getItemProperty(PROPERTY_DATE_MODIFIED) != null) {
        resourceItem.getItemProperty(PROPERTY_DATE_MODIFIED)
                .setValue(Long.valueOf(resource.getDateLastModified()));
    }

    if (resourceItem.getItemProperty(PROPERTY_USER_MODIFIED) != null) {
        resourceItem.getItemProperty(PROPERTY_USER_MODIFIED).setValue(resUtil.getUserLastModified());
    }

    if (resourceItem.getItemProperty(PROPERTY_DATE_CREATED) != null) {
        resourceItem.getItemProperty(PROPERTY_DATE_CREATED).setValue(Long.valueOf(resource.getDateCreated()));
    }

    if (resourceItem.getItemProperty(PROPERTY_USER_CREATED) != null) {
        resourceItem.getItemProperty(PROPERTY_USER_CREATED).setValue(resUtil.getUserCreated());
    }

    if (resourceItem.getItemProperty(PROPERTY_DATE_RELEASED) != null) {
        long release = resource.getDateReleased();
        if (release != CmsResource.DATE_RELEASED_DEFAULT) {
            resourceItem.getItemProperty(PROPERTY_DATE_RELEASED).setValue(Long.valueOf(release));
        }
    }

    if (resourceItem.getItemProperty(PROPERTY_DATE_EXPIRED) != null) {
        long expire = resource.getDateExpired();
        if (expire != CmsResource.DATE_EXPIRED_DEFAULT) {
            resourceItem.getItemProperty(PROPERTY_DATE_EXPIRED).setValue(Long.valueOf(expire));
        }
    }

    if (resourceItem.getItemProperty(PROPERTY_STATE_NAME) != null) {
        resourceItem.getItemProperty(PROPERTY_STATE_NAME).setValue(resUtil.getStateName());
    }

    if (resourceItem.getItemProperty(PROPERTY_STATE) != null) {
        resourceItem.getItemProperty(PROPERTY_STATE).setValue(resource.getState());
    }

    if (resourceItem.getItemProperty(PROPERTY_USER_LOCKED) != null) {
        resourceItem.getItemProperty(PROPERTY_USER_LOCKED).setValue(resUtil.getLockedByName());
    }
}

From source file:org.opencms.ui.dataview.CmsColumnValueConverter.java

License:Open Source License

/**
 * Gets the actual column value for the given data value.<p>
 *
 * @param value the data value/*from   w  w  w.  j  a  va2s  .c  om*/
 * @param type the column type enum
 *
 * @return the actual column value to use
 */
public static Object getColumnValue(Object value, CmsDataViewColumn.Type type) {

    if (type == Type.imageType) {
        Image image = new Image("", new ExternalResource((String) value));
        image.addStyleName("o-table-image");
        return image;
    } else {
        return value;
    }
}

From source file:org.opencms.ui.dialogs.history.diff.CmsImageDiff.java

License:Open Source License

/**
 * @see org.opencms.ui.dialogs.history.diff.I_CmsDiffProvider#diff(org.opencms.file.CmsObject, org.opencms.gwt.shared.CmsHistoryResourceBean, org.opencms.gwt.shared.CmsHistoryResourceBean)
 *///from w ww  . j ava2 s . co m
public Optional<Component> diff(CmsObject cms, CmsHistoryResourceBean v1, CmsHistoryResourceBean v2)
        throws CmsException {

    CmsResource r1 = A_CmsAttributeDiff.readResource(cms, v1);
    if (OpenCms.getResourceManager().matchResourceType(CmsResourceTypeImage.getStaticTypeName(),
            r1.getTypeId())) {
        HorizontalLayout hl = new HorizontalLayout();
        hl.setSpacing(true);
        String v1Param = v1.getVersion().getVersionNumber() != null ? "" + v1.getVersion().getVersionNumber()
                : "" + CmsHistoryResourceHandler.PROJECT_OFFLINE_VERSION;
        String v2Param = v2.getVersion().getVersionNumber() != null ? "" + v2.getVersion().getVersionNumber()
                : "" + CmsHistoryResourceHandler.PROJECT_OFFLINE_VERSION;

        String link1 = OpenCms.getLinkManager().substituteLinkForUnknownTarget(cms,
                CmsHistoryListUtil.getHistoryLink(cms, v1.getStructureId(), v1Param));
        String link2 = OpenCms.getLinkManager().substituteLinkForUnknownTarget(cms,
                CmsHistoryListUtil.getHistoryLink(cms, v2.getStructureId(), v2Param));
        int scaleWidth = 400;
        int scaleHeight = (2 * scaleWidth) / 3;
        final String scaleParams = "w:" + scaleWidth + ",h:" + scaleHeight + ",t:1"; // scale type 1 for thumbnails (no enlargement)
        link1 = CmsRequestUtil.appendParameter(link1, "__scale", scaleParams);
        link2 = CmsRequestUtil.appendParameter(link2, "__scale", scaleParams);
        Image img1 = new Image("", new ExternalResource(link1));
        Image img2 = new Image("", new ExternalResource(link2));
        for (Image img : new Image[] { img1, img2 }) {
            img.setWidth("" + scaleWidth + "px");
        }
        img1.setCaption("V1");
        img2.setCaption("V2");
        hl.addComponent(img1);
        hl.addComponent(img2);
        Panel result = new Panel("Image comparison");
        hl.setMargin(true);
        result.setContent(hl);
        return Optional.fromNullable((Component) result);
    } else {
        return Optional.absent();
    }

}

From source file:org.opennms.features.vaadin.dashboard.dashlets.ChartsConfigurationWindow.java

License:Open Source License

/**
 * Constructor for instantiating new objects of this class.
 *
 * @param dashletSpec the {@link DashletSpec} to be edited
 *//*from  ww w.  j  a v a  2s  . c  om*/
public ChartsConfigurationWindow(DashletSpec dashletSpec) {
    /**
     * Setting the members
     */
    m_dashletSpec = dashletSpec;

    /**
     * Setting up the base layouts
     */

    setHeight(410, Unit.PIXELS);
    setWidth(40, Unit.PERCENTAGE);

    HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setWidth(100, Unit.PERCENTAGE);
    horizontalLayout.setSpacing(true);
    horizontalLayout.setMargin(true);

    FormLayout formLayout = new FormLayout();
    formLayout.setWidth(100, Unit.PERCENTAGE);
    formLayout.setSpacing(true);
    formLayout.setMargin(true);

    /**
     * Adding the checkboxes
     */
    m_maximizeWidth = new CheckBox();
    m_maximizeWidth.setCaption("Maximize width");
    m_maximizeWidth.setDescription("Maximize width");

    m_maximizeHeight = new CheckBox();
    m_maximizeHeight.setCaption("Maximize height");
    m_maximizeHeight.setDescription("Maximize height");

    String maximizeWidthString = m_dashletSpec.getParameters().get("maximizeWidth");
    String maximizeHeightString = m_dashletSpec.getParameters().get("maximizeHeight");

    boolean maximizeHeight = ("true".equals(maximizeHeightString) || "yes".equals(maximizeHeightString)
            || "1".equals(maximizeHeightString));
    boolean maximizeWidth = ("true".equals(maximizeWidthString) || "yes".equals(maximizeWidthString)
            || "1".equals(maximizeWidthString));

    m_maximizeWidth.setValue(maximizeWidth);
    m_maximizeHeight.setValue(maximizeHeight);

    m_chartSelect = new NativeSelect();
    m_chartSelect.setDescription("Select chart to be displayed");
    m_chartSelect.setCaption("Chart");
    m_chartSelect.setNullSelectionAllowed(false);
    m_chartSelect.setInvalidAllowed(false);
    m_chartSelect.setNewItemsAllowed(false);

    String firstChartName = null;

    try {
        Iterator<BarChart> it = ChartUtils.getChartCollectionIterator();

        while (it.hasNext()) {
            BarChart chartConfig = (BarChart) it.next();

            if (firstChartName == null) {
                firstChartName = chartConfig.getName();
            }

            m_chartSelect.addItem(chartConfig.getName());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    String chartName = m_dashletSpec.getParameters().get("chart");

    if (chartName == null || "".equals(chartName)) {
        chartName = firstChartName;
    }

    final Panel panel = new Panel();

    panel.setWidth(230, Unit.PIXELS);

    panel.setCaption("Preview");

    formLayout.addComponent(m_chartSelect);

    Page.getCurrent().getStyles().add(".preview { width:225px; }");

    m_chartSelect.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            String newImage = "/opennms/charts?chart-name=" + valueChangeEvent.getProperty().getValue();
            Image image = new Image(null, new ExternalResource(newImage));
            image.setStyleName("preview");
            panel.setContent(image);
        }
    });

    m_chartSelect.setValue(chartName);
    m_chartSelect.setImmediate(true);

    formLayout.addComponent(m_maximizeWidth);
    formLayout.addComponent(m_maximizeHeight);

    horizontalLayout.addComponent(formLayout);
    horizontalLayout.addComponent(panel);

    /**
     * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons
     */
    HorizontalLayout buttonLayout = new HorizontalLayout();

    buttonLayout.setMargin(true);
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth("100%");
    /**
     * Adding the cancel button...
     */
    Button cancel = new Button("Cancel");
    cancel.setDescription("Cancel editing");
    cancel.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            close();
        }
    });

    cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
    buttonLayout.addComponent(cancel);
    buttonLayout.setExpandRatio(cancel, 1.0f);
    buttonLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT);

    /**
     * ...and the OK button
     */
    Button ok = new Button("Save");
    ok.setDescription("Save properties and close");
    ok.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            m_dashletSpec.getParameters().put("maximizeWidth", (m_maximizeWidth.getValue() ? "true" : "false"));
            m_dashletSpec.getParameters().put("maximizeHeight",
                    (m_maximizeHeight.getValue() ? "true" : "false"));
            m_dashletSpec.getParameters().put("chart", String.valueOf(m_chartSelect.getValue()));

            WallboardProvider.getInstance().save();
            ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Properties");

            close();
        }
    });

    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);
    buttonLayout.addComponent(ok);

    /**
     * Adding the layout and setting the content
     */
    //verticalLayout.addComponent(buttonLayout);

    VerticalLayout verticalLayout = new VerticalLayout();

    verticalLayout.addComponent(horizontalLayout);
    verticalLayout.addComponent(buttonLayout);

    setContent(verticalLayout);
}

From source file:org.opennms.features.vaadin.dashboard.dashlets.ChartsDashlet.java

License:Open Source License

@Override
public DashletComponent getWallboardComponent() {
    if (m_dashletComponent == null) {
        m_dashletComponent = new AbstractDashletComponent() {
            private VerticalLayout m_verticalLayout = new VerticalLayout();

            {//from   w  w w.  j a v a2  s . co  m
                m_verticalLayout.setCaption(getName());
                m_verticalLayout.setSizeFull();
            }

            @Override
            public void refresh() {
                String newImage = "/opennms/charts?chart-name=" + getDashletSpec().getParameters().get("chart");

                String maximizeHeightString = getDashletSpec().getParameters().get("maximizeHeight");
                String maximizeWidthString = getDashletSpec().getParameters().get("maximizeWidth");

                boolean maximizeHeight = ("true".equals(maximizeHeightString)
                        || "yes".equals(maximizeHeightString) || "1".equals(maximizeHeightString));
                boolean maximizeWidth = ("true".equals(maximizeWidthString) || "yes".equals(maximizeWidthString)
                        || "1".equals(maximizeWidthString));

                if (!newImage.equals(m_imageUrl)) {
                    m_imageUrl = newImage;
                    m_verticalLayout.removeAllComponents();
                    Image image = new Image(null, new ExternalResource(m_imageUrl));
                    if (maximizeHeight && maximizeWidth) {
                        image.setSizeFull();
                    } else {
                        if (maximizeHeight) {
                            image.setHeight(100, Sizeable.Unit.PERCENTAGE);
                        }
                        if (maximizeWidth) {
                            image.setWidth(100, Sizeable.Unit.PERCENTAGE);
                        }
                    }
                    m_verticalLayout.addComponent(image);
                    m_verticalLayout.setComponentAlignment(image, Alignment.MIDDLE_CENTER);
                }
            }

            @Override
            public Component getComponent() {
                return m_verticalLayout;
            }
        };
    }

    return m_dashletComponent;
}

From source file:org.opennms.features.vaadin.dashboard.dashlets.ImageDashlet.java

License:Open Source License

@Override
public DashletComponent getWallboardComponent() {
    if (m_dashletComponent == null) {
        m_dashletComponent = new AbstractDashletComponent() {
            private VerticalLayout m_verticalLayout = new VerticalLayout();

            {/*from  w  w w .  j a v  a  2  s .  c  o  m*/
                m_verticalLayout.setCaption(getName());
                m_verticalLayout.setSizeFull();
            }

            @Override
            public void refresh() {
                String newImage = getDashletSpec().getParameters().get("imageUrl");

                String maximizeHeightString = getDashletSpec().getParameters().get("maximizeHeight");
                String maximizeWidthString = getDashletSpec().getParameters().get("maximizeWidth");

                boolean maximizeHeight = ("true".equals(maximizeHeightString)
                        || "yes".equals(maximizeHeightString) || "1".equals(maximizeHeightString));
                boolean maximizeWidth = ("true".equals(maximizeWidthString) || "yes".equals(maximizeWidthString)
                        || "1".equals(maximizeWidthString));

                if (!newImage.equals(m_imageUrl)) {
                    m_imageUrl = newImage;
                    m_verticalLayout.removeAllComponents();
                    Image image = new Image(null, new ExternalResource(m_imageUrl));
                    if (maximizeHeight && maximizeWidth) {
                        image.setSizeFull();
                    } else {
                        if (maximizeHeight) {
                            image.setHeight(100, Sizeable.Unit.PERCENTAGE);
                        }
                        if (maximizeWidth) {
                            image.setWidth(100, Sizeable.Unit.PERCENTAGE);
                        }
                    }
                    m_verticalLayout.addComponent(image);
                    m_verticalLayout.setComponentAlignment(image, Alignment.MIDDLE_CENTER);
                }
            }

            @Override
            public Component getComponent() {
                return m_verticalLayout;
            }
        };
    }

    return m_dashletComponent;
}

From source file:org.opennms.features.vaadin.dashboard.dashlets.SummaryDashlet.java

License:Open Source License

private Component getLegend(String entity) {
    HorizontalLayout horizontalLayout = new HorizontalLayout();

    horizontalLayout.setSpacing(true);//from www  .j a  v a2 s  .co m
    horizontalLayout.addStyleName("summary");
    horizontalLayout.addStyleName("global");

    Label labelx = new Label(entity);
    labelx.addStyleName("summary-font-legend");

    Image ackdImage = new Image(null, new ThemeResource("img/acknowledged.png"));
    ackdImage.setWidth(16, Sizeable.Unit.PIXELS);

    Image unackdImage = new Image(null, new ThemeResource("img/unacknowledged.png"));
    unackdImage.setWidth(16, Sizeable.Unit.PIXELS);

    Label dummyLabel = new Label();
    dummyLabel.setWidth(32, Sizeable.Unit.PIXELS);

    horizontalLayout.addComponent(labelx);
    horizontalLayout.addComponent(ackdImage);
    horizontalLayout.addComponent(unackdImage);
    horizontalLayout.addComponent(dummyLabel);

    horizontalLayout.setComponentAlignment(ackdImage, Alignment.TOP_RIGHT);
    horizontalLayout.setComponentAlignment(unackdImage, Alignment.TOP_RIGHT);

    horizontalLayout.setExpandRatio(labelx, 4.0f);
    horizontalLayout.setExpandRatio(ackdImage, 1.0f);
    horizontalLayout.setExpandRatio(unackdImage, 1.0f);
    horizontalLayout.setExpandRatio(dummyLabel, 1.0f);

    horizontalLayout.setWidth(375, Sizeable.Unit.PIXELS);

    return horizontalLayout;
}

From source file:org.opennms.features.vaadin.dashboard.dashlets.SummaryDashlet.java

License:Open Source License

/**
 * Returns the component showing the alarms and the trends by severity
 *
 * @return the {@link Component}//from   w ww . j  a v a2 s .  c o m
 */
private Component getComponentSeverity(int width) {
    VerticalLayout verticalLayout = new VerticalLayout();

    int overallSum = 0;
    int severitySum = 0;

    verticalLayout.addComponent(getLegend("Severity"));

    for (OnmsSeverity onmsSeverity : OnmsSeverity.values()) {
        HorizontalLayout horizontalLayout = new HorizontalLayout();
        horizontalLayout.setSpacing(true);
        horizontalLayout.addStyleName("summary");
        horizontalLayout.addStyleName(onmsSeverity.name().toLowerCase());

        int acknowledged = countBySeverity(true, m_timeslot, onmsSeverity);
        int notAcknowledged = countBySeverity(false, m_timeslot, onmsSeverity);

        Label labelSeverity = new Label(onmsSeverity.getLabel());
        labelSeverity.addStyleName("summary-font");
        Label labelAcknowledge = new Label(String.valueOf(acknowledged));
        labelAcknowledge.addStyleName("summary-font");
        Label labelNotAcknowledged = new Label(String.valueOf(notAcknowledged));
        labelNotAcknowledged.addStyleName("summary-font");

        horizontalLayout.addComponent(labelSeverity);
        horizontalLayout.addComponent(labelAcknowledge);
        horizontalLayout.addComponent(labelNotAcknowledged);

        int status = computeTrend(acknowledged, notAcknowledged);

        severitySum += onmsSeverity.getId();
        overallSum += onmsSeverity.getId() * status;

        Image image = new Image(null, new ThemeResource("img/a" + status + ".png"));
        image.setWidth(width, Sizeable.Unit.PIXELS);
        horizontalLayout.addComponent(image);

        horizontalLayout.setExpandRatio(labelSeverity, 4.0f);
        horizontalLayout.setExpandRatio(labelAcknowledge, 1.0f);
        horizontalLayout.setExpandRatio(labelNotAcknowledged, 1.0f);
        horizontalLayout.setExpandRatio(image, 1.0f);

        horizontalLayout.setComponentAlignment(image, Alignment.TOP_CENTER);

        horizontalLayout.setWidth(375, Sizeable.Unit.PIXELS);
        verticalLayout.addComponent(horizontalLayout);
    }

    int globalTrend = (int) Math.max(0,
            Math.min(4, Math.round(((double) overallSum) / ((double) severitySum))));

    Image image = new Image(null, new ThemeResource("img/a" + globalTrend + ".png"));
    image.setWidth(width * 8, Sizeable.Unit.PIXELS);

    VerticalLayout globalTrendLayout = new VerticalLayout();
    globalTrendLayout.setSpacing(true);
    globalTrendLayout.addStyleName("summary");
    globalTrendLayout.addStyleName("global");
    globalTrendLayout.setSizeFull();

    Label labelTitle = new Label("Alarms trend by severity");
    labelTitle.addStyleName("summary-font");
    labelTitle.setSizeUndefined();

    Label labelTimeslot = new Label("(" + getHumanReadableFormat(m_timeslot) + ")");
    labelTimeslot.addStyleName("summary-font");
    labelTimeslot.setSizeUndefined();

    globalTrendLayout.addComponent(labelTitle);
    globalTrendLayout.addComponent(labelTimeslot);
    globalTrendLayout.addComponent(image);

    globalTrendLayout.setWidth(375, Sizeable.Unit.PIXELS);

    globalTrendLayout.setComponentAlignment(labelTitle, Alignment.MIDDLE_CENTER);
    globalTrendLayout.setComponentAlignment(labelTimeslot, Alignment.MIDDLE_CENTER);
    globalTrendLayout.setComponentAlignment(image, Alignment.MIDDLE_CENTER);

    globalTrendLayout.setExpandRatio(labelTitle, 1.0f);

    verticalLayout.addComponent(globalTrendLayout, 0);

    m_boosted = (globalTrend > 2);

    return verticalLayout;
}