Example usage for com.vaadin.ui Image setWidth

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

Introduction

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

Prototype

@Override
    public void setWidth(float width, Unit unit) 

Source Link

Usage

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  w  w.  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;
}

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}//  w  ww. ja va 2 s . c o m
 */
private Component getComponentUei(int width) {
    VerticalLayout verticalLayout = new VerticalLayout();

    int overallSum = 0;
    int severitySum = 0;

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

    String[] ueis = { "uei.opennms.org/nodes/nodeLostService", "uei.opennms.org/nodes/interfaceDown",
            "uei.opennms.org/nodes/nodeDown" };

    for (int i = 0; i < ueis.length; i++) {
        String uei = ueis[i];
        HorizontalLayout horizontalLayout = new HorizontalLayout();
        horizontalLayout.setSpacing(true);
        horizontalLayout.addStyleName("summary");

        if (i == 0) {
            horizontalLayout.addStyleName(OnmsSeverity.MINOR.name().toLowerCase());
        } else {
            if (i == 1) {
                horizontalLayout.addStyleName(OnmsSeverity.MINOR.name().toLowerCase());
            } else {
                horizontalLayout.addStyleName(OnmsSeverity.MAJOR.name().toLowerCase());
            }
        }

        int acknowledged = countByUei(true, m_timeslot, uei);
        int notAcknowledged = countByUei(false, m_timeslot, uei);

        Label labelSeverity = new Label(uei.replace("uei.opennms.org/nodes/", ""));
        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 += i;
        overallSum += i * 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 UEI");
    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;
}